#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 */
typedef struct TYPE_3__ TYPE_1__;

/* Type definitions */
struct TYPE_3__ {
  int si_code;
  int /*<<< orphan*/ si_addr;
};
typedef TYPE_1__ siginfo_t;

/* Variables and functions */
#define SIGFPE 130
#define SIGILL 129
#define SIGSEGV 128
int /*<<< orphan*/ eiki_print_d(int);
int /*<<< orphan*/ eiki_print_p(int /*<<< orphan*/);
int /*<<< orphan*/ eiki_print_s(char const *);
char *eiki_sigfpe_info(int);
char *eiki_sigill_info(int);
char *eiki_sigsegv_info(int);
char *strsignal(int);
void eiki_print_signal(int signum, const siginfo_t *info) {
  const char *siginfo = NULL;
  int sigcode;
  int info_has_addr = 0;
  eiki_print_s("Caught signal ");
  eiki_print_d(signum);
  eiki_print_s(" (");
  if (signum == SIGFPE) {
    eiki_print_s("Arithmetic exception");
  } else {
    eiki_print_s(strsignal(signum));
  }
  if (info) {
    sigcode = info->si_code;
    switch (signum) {
    case SIGILL:
      siginfo = eiki_sigill_info(sigcode);
      info_has_addr = 1;
      break;
    case SIGFPE:
      siginfo = eiki_sigfpe_info(sigcode);
      info_has_addr = 1;
      break;
    case SIGSEGV:
      siginfo = eiki_sigsegv_info(sigcode);
      info_has_addr = 1;
      break;
    }
  }
  if (siginfo) {
    eiki_print_s(": ");
    eiki_print_s(siginfo);
  }
  if (info_has_addr) {
    eiki_print_s(" at address ");
    eiki_print_p(info->si_addr);
  }
  eiki_print_s(")\n");
}


x86 assembly (clang, -O0):
<eiki_print_signal>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movl   $0x0,-0x20(%rbp)
lea    0xe6b(%rip),%rdi
call   1040 <eiki_print_s@plt>
mov    -0x4(%rbp),%edi
call   1070 <eiki_print_d@plt>
lea    0xe66(%rip),%rdi
call   1040 <eiki_print_s@plt>
cmpl   $0x82,-0x4(%rbp)
jne    11cc <eiki_print_signal+0x5c>
lea    0xe50(%rip),%rdi
call   1040 <eiki_print_s@plt>
jmp    11dc <eiki_print_signal+0x6c>
mov    -0x4(%rbp),%edi
call   1060 <strsignal@plt>
mov    %rax,%rdi
call   1040 <eiki_print_s@plt>
cmpq   $0x0,-0x10(%rbp)
je     1274 <eiki_print_signal+0x104>
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x24(%rbp)
sub    $0x80,%eax
je     125c <eiki_print_signal+0xec>
jmp    1206 <eiki_print_signal+0x96>
mov    -0x24(%rbp),%eax
sub    $0x81,%eax
je     122c <eiki_print_signal+0xbc>
jmp    1219 <eiki_print_signal+0xa9>
mov    -0x24(%rbp),%eax
sub    $0x82,%eax
je     1244 <eiki_print_signal+0xd4>
jmp    126f <eiki_print_signal+0xff>
mov    -0x1c(%rbp),%edi
call   1030 <eiki_sigill_info@plt>
mov    %rax,-0x18(%rbp)
movl   $0x1,-0x20(%rbp)
jmp    126f <eiki_print_signal+0xff>
mov    -0x1c(%rbp),%edi
call   1090 <eiki_sigfpe_info@plt>
mov    %rax,-0x18(%rbp)
movl   $0x1,-0x20(%rbp)
jmp    126f <eiki_print_signal+0xff>
mov    -0x1c(%rbp),%edi
call   1050 <eiki_sigsegv_info@plt>
mov    %rax,-0x18(%rbp)
movl   $0x1,-0x20(%rbp)
jmp    1274 <eiki_print_signal+0x104>
cmpq   $0x0,-0x18(%rbp)
je     1294 <eiki_print_signal+0x124>
lea    0xda1(%rip),%rdi
call   1040 <eiki_print_s@plt>
mov    -0x18(%rbp),%rdi
call   1040 <eiki_print_s@plt>
cmpl   $0x0,-0x20(%rbp)
je     12b6 <eiki_print_signal+0x146>
lea    0xd85(%rip),%rdi
call   1040 <eiki_print_s@plt>
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%edi
call   1080 <eiki_print_p@plt>
lea    0xd7a(%rip),%rdi
call   1040 <eiki_print_s@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<eiki_print_signal>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%ebp
lea    0xe81(%rip),%rdi
call   1040 <eiki_print_s@plt>
mov    %ebp,%edi
call   1070 <eiki_print_d@plt>
lea    0xe7d(%rip),%rdi
call   1040 <eiki_print_s@plt>
cmp    $0x82,%ebp
jne    11a8 <eiki_print_signal+0x38>
lea    0xe6c(%rip),%rdi
jmp    11b2 <eiki_print_signal+0x42>
mov    %ebp,%edi
call   1060 <strsignal@plt>
mov    %rax,%rdi
call   1040 <eiki_print_s@plt>
test   %rbx,%rbx
je     1219 <eiki_print_signal+0xa9>
mov    (%rbx),%edi
cmp    $0x80,%ebp
je     11dd <eiki_print_signal+0x6d>
cmp    $0x82,%ebp
je     11e4 <eiki_print_signal+0x74>
cmp    $0x81,%ebp
jne    1219 <eiki_print_signal+0xa9>
call   1030 <eiki_sigill_info@plt>
jmp    11e9 <eiki_print_signal+0x79>
call   1050 <eiki_sigsegv_info@plt>
jmp    11e9 <eiki_print_signal+0x79>
call   1090 <eiki_sigfpe_info@plt>
mov    %rax,%rbp
test   %rax,%rax
je     1205 <eiki_print_signal+0x95>
lea    0xe2f(%rip),%rdi
call   1040 <eiki_print_s@plt>
mov    %rbp,%rdi
call   1040 <eiki_print_s@plt>
lea    0xe1e(%rip),%rdi
call   1040 <eiki_print_s@plt>
mov    0x4(%rbx),%edi
call   1080 <eiki_print_p@plt>
lea    0xe17(%rip),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1040 <eiki_print_s@plt>

LLVM IR (-O0):
%struct.TYPE_3__ = type { i32, i32 }
@.str = [15 x i8] c"Caught signal \00"
@.str.1 = [3 x i8] c" (\00"
@.str.2 = [21 x i8] c"Arithmetic exception\00"
@.str.3 = [3 x i8] c": \00"
@.str.4 = [13 x i8] c" at address \00"
@.str.5 = [3 x i8] c")\0A\00"
define void @eiki_print_signal(i32 %0, %struct.TYPE_3__* %1) {
%3 = alloca i32
%4 = alloca %struct.TYPE_3__*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %3
store %struct.TYPE_3__* %1, %struct.TYPE_3__** %4
store i8* null, i8** %5
store i32 0, i32* %7
%8 = call i32 @eiki_print_s(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%9 = load i32, i32* %3
%10 = call i32 @eiki_print_d(i32 %9)
%11 = call i32 @eiki_print_s(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%12 = load i32, i32* %3
%13 = icmp eq i32 %12, 130
br i1 %13, label %14, label %16
14: ; preds = %2
%15 = call i32 @eiki_print_s(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
br label %20
16: ; preds = %2
%17 = load i32, i32* %3
%18 = call i8* @strsignal(i32 %17)
%19 = call i32 @eiki_print_s(i8* %18)
br label %20
20: ; preds = %16, %14
%21 = load %struct.TYPE_3__*, %struct.TYPE_3__** %4
%22 = icmp ne %struct.TYPE_3__* %21, null
br i1 %22, label %23, label %38
23: ; preds = %20
%24 = load %struct.TYPE_3__*, %struct.TYPE_3__** %4
%25 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %24, i32 0, i32 0
%26 = load i32, i32* %25
store i32 %26, i32* %6
%27 = load i32, i32* %3
switch i32 %27, label %37 [
i32 129, label %28
i32 130, label %31
i32 128, label %34
]
28: ; preds = %23
%29 = load i32, i32* %6
%30 = call i8* @eiki_sigill_info(i32 %29)
store i8* %30, i8** %5
store i32 1, i32* %7
br label %37
31: ; preds = %23
%32 = load i32, i32* %6
%33 = call i8* @eiki_sigfpe_info(i32 %32)
store i8* %33, i8** %5
store i32 1, i32* %7
br label %37
34: ; preds = %23
%35 = load i32, i32* %6
%36 = call i8* @eiki_sigsegv_info(i32 %35)
store i8* %36, i8** %5
store i32 1, i32* %7
br label %37
37: ; preds = %23, %34, %31, %28
br label %38
38: ; preds = %37, %20
%39 = load i8*, i8** %5
%40 = icmp ne i8* %39, null
br i1 %40, label %41, label %45
41: ; preds = %38
%42 = call i32 @eiki_print_s(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%43 = load i8*, i8** %5
%44 = call i32 @eiki_print_s(i8* %43)
br label %45
45: ; preds = %41, %38
%46 = load i32, i32* %7
%47 = icmp ne i32 %46, 0
br i1 %47, label %48, label %54
48: ; preds = %45
%49 = call i32 @eiki_print_s(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0))
%50 = load %struct.TYPE_3__*, %struct.TYPE_3__** %4
%51 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %50, i32 0, i32 1
%52 = load i32, i32* %51
%53 = call i32 @eiki_print_p(i32 %52)
br label %54
54: ; preds = %48, %45
%55 = call i32 @eiki_print_s(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
%struct.TYPE_3__ = type { i32, i32 }
@.str = [15 x i8] c"Caught signal \00"
@.str.1 = [3 x i8] c" (\00"
@.str.2 = [21 x i8] c"Arithmetic exception\00"
@.str.3 = [3 x i8] c": \00"
@.str.4 = [13 x i8] c" at address \00"
@.str.5 = [3 x i8] c")\0A\00"
define void @eiki_print_signal(i32 %0, %struct.TYPE_3__* %1) {
%3 = tail call i32 @eiki_print_s(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%4 = tail call i32 @eiki_print_d(i32 %0)
%5 = tail call i32 @eiki_print_s(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%6 = icmp eq i32 %0, 130
br i1 %6, label %9, label %7
7: ; preds = %2
%8 = tail call i8* @strsignal(i32 %0)
br label %9
9: ; preds = %2, %7
%10 = phi i8* [ %8, %7 ], [ getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), %2 ]
%11 = tail call i32 @eiki_print_s(i8* %10)
%12 = icmp eq %struct.TYPE_3__* %1, null
br i1 %12, label %33, label %13
13: ; preds = %9
%14 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %1, i64 0, i32 0
%15 = load i32, i32* %14
switch i32 %0, label %33 [
i32 129, label %16
i32 130, label %18
i32 128, label %20
]
16: ; preds = %13
%17 = tail call i8* @eiki_sigill_info(i32 %15)
br label %22
18: ; preds = %13
%19 = tail call i8* @eiki_sigfpe_info(i32 %15)
br label %22
20: ; preds = %13
%21 = tail call i8* @eiki_sigsegv_info(i32 %15)
br label %22
22: ; preds = %16, %18, %20
%23 = phi i8* [ %21, %20 ], [ %19, %18 ], [ %17, %16 ]
%24 = icmp eq i8* %23, null
br i1 %24, label %28, label %25
25: ; preds = %22
%26 = tail call i32 @eiki_print_s(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%27 = tail call i32 @eiki_print_s(i8* %23)
br label %28
28: ; preds = %25, %22
%29 = tail call i32 @eiki_print_s(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0))
%30 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %1, i64 0, i32 1
%31 = load i32, i32* %30
%32 = tail call i32 @eiki_print_p(i32 %31)
br label %33
33: ; preds = %9, %13, %28
%34 = tail call i32 @eiki_print_s(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
ret void
}