#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
typedef int int32_t;

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ if_handles_exception(int);
int /*<<< orphan*/ printf(char *, ...);
void on_error(int32_t error, char *msg, int32_t action, int32_t if_exception) {
  switch (action) {
  case 90:
    if (if_handles_exception(if_exception))
      printf("[CONCEPTUM-Runtime] INFO: %s {%d}", msg, error);
    break;
  case 91:
    if (if_handles_exception(if_exception))
      printf("[CONCEPTUM-Runtime] WARNING: %s {%d}", msg, error);
    break;
  case 92:
    if (if_handles_exception(if_exception))
      printf("[CONCEPTUM-Runtime] NONEXIT ERROR: %s {%d}", msg, error);
    else
      printf("[CONCEPTUM-Runtime] EXIT ERROR: %s {%d}", msg, error);
    exit(if_exception);
    break;
  case 93:
    printf("[CONCEPTUM-Runtime]");
    exit(if_exception);
  }
}


x86 assembly (clang, -O0):
<on_error>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    -0x14(%rbp),%eax
add    $0xffffffa6,%eax
mov    %eax,%ecx
mov    %rcx,-0x20(%rbp)
sub    $0x3,%eax
ja     1222 <on_error+0xf2>
mov    -0x20(%rbp),%rax
lea    0xe9b(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x18(%rbp),%edi
call   1030 <if_handles_exception@plt>
cmp    $0x0,%eax
je     1194 <on_error+0x64>
mov    -0x10(%rbp),%rsi
mov    -0x4(%rbp),%edx
lea    0xe83(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1222 <on_error+0xf2>
mov    -0x18(%rbp),%edi
call   1030 <if_handles_exception@plt>
cmp    $0x0,%eax
je     11bf <on_error+0x8f>
mov    -0x10(%rbp),%rsi
mov    -0x4(%rbp),%edx
lea    0xe7a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1222 <on_error+0xf2>
mov    -0x18(%rbp),%edi
call   1030 <if_handles_exception@plt>
cmp    $0x0,%eax
je     11ef <on_error+0xbf>
mov    -0x10(%rbp),%rsi
mov    -0x4(%rbp),%edx
lea    0xe74(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1204 <on_error+0xd4>
mov    -0x10(%rbp),%rsi
mov    -0x4(%rbp),%edx
lea    0xe85(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%edi
call   1050 <exit@plt>
lea    0xe97(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%edi
call   1050 <exit@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<on_error>:
push   %rbp
push   %r14
push   %rbx
add    $0xffffffa6,%edx
cmp    $0x3,%edx
ja     118b <on_error+0x5b>
mov    %ecx,%ebp
mov    %rsi,%rbx
mov    %edi,%r14d
lea    0xeb5(%rip),%rax
movslq (%rax,%rdx,4),%rcx
add    %rax,%rcx
jmp    *%rcx
mov    %ebp,%edi
call   1030 <if_handles_exception@plt>
test   %eax,%eax
je     118b <on_error+0x5b>
lea    0xeaa(%rip),%rdi
jmp    117a <on_error+0x4a>
mov    %ebp,%edi
call   1030 <if_handles_exception@plt>
test   %eax,%eax
je     118b <on_error+0x5b>
lea    0xeb8(%rip),%rdi
mov    %rbx,%rsi
mov    %r14d,%edx
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
jmp    1040 <printf@plt>
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    %ebp,%edi
call   1030 <if_handles_exception@plt>
test   %eax,%eax
lea    0xee2(%rip),%rax
lea    0xeb0(%rip),%rdi
cmove  %rax,%rdi
mov    %rbx,%rsi
mov    %r14d,%edx
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebp,%edi
call   1050 <exit@plt>
lea    0xee4(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebp,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@.str = [34 x i8] c"[CONCEPTUM-Runtime] INFO: %s {%d}\00"
@.str.1 = [37 x i8] c"[CONCEPTUM-Runtime] WARNING: %s {%d}\00"
@.str.2 = [43 x i8] c"[CONCEPTUM-Runtime] NONEXIT ERROR: %s {%d}\00"
@.str.3 = [40 x i8] c"[CONCEPTUM-Runtime] EXIT ERROR: %s {%d}\00"
@.str.4 = [20 x i8] c"[CONCEPTUM-Runtime]\00"
define void @on_error(i32 %0, i8* %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %5
store i8* %1, i8** %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%9 = load i32, i32* %7
switch i32 %9, label %47 [
i32 90, label %10
i32 91, label %19
i32 92, label %28
i32 93, label %43
]
10: ; preds = %4
%11 = load i32, i32* %8
%12 = call i32 @if_handles_exception(i32 %11)
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %18
14: ; preds = %10
%15 = load i8*, i8** %6
%16 = load i32, i32* %5
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i8* %15, i32 %16)
br label %18
18: ; preds = %14, %10
br label %47
19: ; preds = %4
%20 = load i32, i32* %8
%21 = call i32 @if_handles_exception(i32 %20)
%22 = icmp ne i32 %21, 0
br i1 %22, label %23, label %27
23: ; preds = %19
%24 = load i8*, i8** %6
%25 = load i32, i32* %5
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i8* %24, i32 %25)
br label %27
27: ; preds = %23, %19
br label %47
28: ; preds = %4
%29 = load i32, i32* %8
%30 = call i32 @if_handles_exception(i32 %29)
%31 = icmp ne i32 %30, 0
br i1 %31, label %32, label %36
32: ; preds = %28
%33 = load i8*, i8** %6
%34 = load i32, i32* %5
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.2, i64 0, i64 0), i8* %33, i32 %34)
br label %40
36: ; preds = %28
%37 = load i8*, i8** %6
%38 = load i32, i32* %5
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.3, i64 0, i64 0), i8* %37, i32 %38)
br label %40
40: ; preds = %36, %32
%41 = load i32, i32* %8
%42 = call i32 @exit(i32 %41)
unreachable
43: ; preds = %4
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0))
%45 = load i32, i32* %8
%46 = call i32 @exit(i32 %45)
unreachable
47: ; preds = %4, %27, %18
ret void
}

LLVM IR (-O2):
@.str = [34 x i8] c"[CONCEPTUM-Runtime] INFO: %s {%d}\00"
@.str.1 = [37 x i8] c"[CONCEPTUM-Runtime] WARNING: %s {%d}\00"
@.str.2 = [43 x i8] c"[CONCEPTUM-Runtime] NONEXIT ERROR: %s {%d}\00"
@.str.3 = [40 x i8] c"[CONCEPTUM-Runtime] EXIT ERROR: %s {%d}\00"
@.str.4 = [20 x i8] c"[CONCEPTUM-Runtime]\00"
define void @on_error(i32 %0, i8* %1, i32 %2, i32 %3) {
switch i32 %2, label %23 [
i32 90, label %5
i32 91, label %8
i32 92, label %11
i32 93, label %17
]
5: ; preds = %4
%6 = tail call i32 @if_handles_exception(i32 %3)
%7 = icmp eq i32 %6, 0
br i1 %7, label %23, label %20
8: ; preds = %4
%9 = tail call i32 @if_handles_exception(i32 %3)
%10 = icmp eq i32 %9, 0
br i1 %10, label %23, label %20
11: ; preds = %4
%12 = tail call i32 @if_handles_exception(i32 %3)
%13 = icmp eq i32 %12, 0
%14 = select i1 %13, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.2, i64 0, i64 0)
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) %14, i8* %1, i32 %0)
%16 = tail call i32 @exit(i32 %3)
unreachable
17: ; preds = %4
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0))
%19 = tail call i32 @exit(i32 %3)
unreachable
20: ; preds = %8, %5
%21 = phi i8* [ getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), %5 ], [ getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), %8 ]
%22 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) %21, i8* %1, i32 %0)
br label %23
23: ; preds = %20, %8, %5, %4
ret void
}