#include <cstdint>
extern "C" {
int doesnt_throw(int a) {
volatile int x = 0;
volatile bool b = false;
try {
x = 10;
if(b) throw (int32_t)20;
} catch (...) {
return -1;
}
x++;
try {
if(b) throw (int32_t)20;
if (x + a < 100) {
return 1;
} else {
return 2;
}
} catch (...) {
return -2;
}
}
}
int throw_uncaught(volatile int a) {
if (a % 2) {
return 2;
} else {
throw (int32_t)20;
}
}
int throw_multiple_values(volatile int a) {
switch (a % 4) {
case 1: return 1;
case 2: return 2;
case 3: throw (int32_t)3;
default: throw (int32_t)4;
}
}
int throw_uncaught_wrongtype(volatile int a) {
try {
if (a % 2) {
return 2;
} else {
throw (int32_t)20;
}
} catch (unsigned char c) {
return 10;
}
}
__attribute__((noinline)) void throw_uncaught_void(volatile int* a) {
if (*a == 0) {
*a = 1;
} else {
throw (int32_t)20;
}
}
int throw_uncaught_caller(int a) {
volatile int x = a;
throw_uncaught_void(&x);
return 1;
}
int throw_and_catch_wildcard(bool shouldthrow) {
try {
if(shouldthrow) throw (int32_t)20;
return 2;
} catch (...) {
return 5;
}
}
int throw_and_catch_val(bool shouldthrow) {
try {
if(shouldthrow) throw (int32_t)20;
return 2;
} catch (int e) {
return e;
}
}
int throw_and_catch_in_caller(bool shouldthrow) {
volatile int x = 2;
try {
if(shouldthrow) throw_uncaught_void(&x);
} catch (int e) {
return e;
}
return 2;
}
int throw_and_rethrow_in_caller(bool shouldthrow) {
volatile int x = 2;
try {
if(shouldthrow) throw_uncaught_void(&x);
}
catch (int e) {
throw;
}
return 2;
}