#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_5__ TYPE_2__;
typedef struct TYPE_4__ TYPE_1__;

/* Type definitions */
struct TYPE_4__ {
  char *sival_int;
};
struct TYPE_5__ {
  TYPE_1__ si_value;
  scalar_t__ si_pid;
};
typedef TYPE_2__ siginfo_t;

/* Variables and functions */
int /*<<< orphan*/ printf(char *, ...);
char *strsignal(int);
void handler(int signal, siginfo_t *sinfo,
             __attribute__((unused)) void *ucontext) {
  printf("\tCaught signal %d (%s)\n", signal, strsignal(signal));
  if (sinfo == NULL) {
    printf("\t sinfo is NULL\n");
  } else {
    printf("\tPID: %ld, data: %d\n", (long)sinfo->si_pid,
           sinfo->si_value.sival_int);
  }
}


x86 assembly (clang, -O0):
<handler>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x4(%rbp),%edi
call   1040 <strsignal@plt>
mov    -0x1c(%rbp),%esi
mov    %rax,%rdx
lea    0xeb2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpq   $0x0,-0x10(%rbp)
jne    1173 <handler+0x53>
lea    0xeb1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1190 <handler+0x70>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xea0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<handler>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%ebp
call   1050 <strsignal@plt>
lea    0xebc(%rip),%rdi
mov    %ebp,%esi
mov    %rax,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
test   %rbx,%rbx
je     1170 <handler+0x40>
mov    (%rbx),%rdx
mov    0x8(%rbx),%rsi
lea    0xeb5(%rip),%rdi
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1040 <printf@plt>
lea    0xeb6(%rip),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1030 <puts@plt>

LLVM IR (-O0):
%struct.TYPE_5__ = type { %struct.TYPE_4__, i64 }
%struct.TYPE_4__ = type { i8* }
@.str = [24 x i8] c"\09Caught signal %d (%s)\0A\00"
@.str.1 = [17 x i8] c"\09 sinfo is NULL\0A\00"
@.str.2 = [21 x i8] c"\09PID: %ld, data: %d\0A\00"
define void @handler(i32 %0, %struct.TYPE_5__* %1, i8* %2) {
%4 = alloca i32
%5 = alloca %struct.TYPE_5__*
%6 = alloca i8*
store i32 %0, i32* %4
store %struct.TYPE_5__* %1, %struct.TYPE_5__** %5
store i8* %2, i8** %6
%7 = load i32, i32* %4
%8 = load i32, i32* %4
%9 = call i8* @strsignal(i32 %8)
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i32 %7, i8* %9)
%11 = load %struct.TYPE_5__*, %struct.TYPE_5__** %5
%12 = icmp eq %struct.TYPE_5__* %11, null
br i1 %12, label %13, label %15
13: ; preds = %3
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
br label %24
15: ; preds = %3
%16 = load %struct.TYPE_5__*, %struct.TYPE_5__** %5
%17 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %16, i32 0, i32 1
%18 = load i64, i64* %17
%19 = load %struct.TYPE_5__*, %struct.TYPE_5__** %5
%20 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %19, i32 0, i32 0
%21 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %20, i32 0, i32 0
%22 = load i8*, i8** %21
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i64 %18, i8* %22)
br label %24
24: ; preds = %15, %13
ret void
}

LLVM IR (-O2):
%struct.TYPE_5__ = type { %struct.TYPE_4__, i64 }
%struct.TYPE_4__ = type { i8* }
@.str = [24 x i8] c"\09Caught signal %d (%s)\0A\00"
@.str.2 = [21 x i8] c"\09PID: %ld, data: %d\0A\00"
@str = [16 x i8] c"\09 sinfo is NULL\00"
define void @handler(i32 %0, %struct.TYPE_5__* %1, i8* nocapture readnone %2) {
%4 = tail call i8* @strsignal(i32 %0)
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i32 %0, i8* %4)
%6 = icmp eq %struct.TYPE_5__* %1, null
br i1 %6, label %7, label %9
7: ; preds = %3
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str, i64 0, i64 0))
br label %15
9: ; preds = %3
%10 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %1, i64 0, i32 1
%11 = load i64, i64* %10
%12 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %1, i64 0, i32 0, i32 0
%13 = load i8*, i8** %12
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i64 %11, i8* %13)
br label %15
15: ; preds = %9, %7
ret void
}