#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 sig_atomic_t;

/* Variables and functions */
int /*<<< orphan*/ SIG_DFL;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ raise(int);
int /*<<< orphan*/ reel_trace();
int /*<<< orphan*/ signal(int, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
void catch (int s) {
  static volatile sig_atomic_t already_dying = 0;
  if (already_dying)
    return;
  already_dying = 1;
  fprintf(stderr, "signal %d caught by pcu\n", s);
  reel_trace();
  signal(s, SIG_DFL);
  raise(s);
}


x86 assembly (clang, -O0):
<catch>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    0x2ef3(%rip),%eax
cmp    $0x0,%eax
je     115f <catch+0x1f>
jmp    11a1 <catch+0x61>
movl   $0x1,0x2edb(%rip)
mov    0x2e70(%rip),%rax
mov    (%rax),%edi
mov    -0x4(%rbp),%edx
lea    0xe84(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x0,%al
call   1040 <reel_trace@plt>
mov    -0x4(%rbp),%edi
mov    0x2e46(%rip),%rax
mov    (%rax),%esi
call   1050 <signal@plt>
mov    -0x4(%rbp),%edi
call   1030 <raise@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<catch>:
push   %rbx
cmpl   $0x0,0x2efc(%rip)
je     114c <catch+0xc>
pop    %rbx
ret
mov    %edi,%ebx
movl   $0x1,0x2eec(%rip)
mov    0x2e81(%rip),%rax
mov    (%rax),%edi
lea    0xe98(%rip),%rsi
mov    %ebx,%edx
call   1060 <fprintf@plt>
xor    %eax,%eax
call   1040 <reel_trace@plt>
mov    0x2e5b(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
call   1050 <signal@plt>
mov    %ebx,%edi
pop    %rbx
jmp    1030 <raise@plt>

LLVM IR (-O0):
@catch.already_dying = internal global i32 0
@stderr = global i32 0
@.str = [25 x i8] c"signal %d caught by pcu\0A\00"
@SIG_DFL = global i32 0
define void @catch(i32 %0) {
%2 = alloca i32
store i32 %0, i32* %2
%3 = load volatile i32, i32* @catch.already_dying
%4 = icmp ne i32 %3, 0
br i1 %4, label %5, label %6
5: ; preds = %1
br label %16
6: ; preds = %1
store volatile i32 1, i32* @catch.already_dying
%7 = load i32, i32* @stderr
%8 = load i32, i32* %2
%9 = call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 %8)
%10 = call i32 (...) @reel_trace()
%11 = load i32, i32* %2
%12 = load i32, i32* @SIG_DFL
%13 = call i32 @signal(i32 %11, i32 %12)
%14 = load i32, i32* %2
%15 = call i32 @raise(i32 %14)
br label %16
16: ; preds = %6, %5
ret void
}

LLVM IR (-O2):
@catch.already_dying = internal global i32 0
@stderr = global i32 0
@.str = [25 x i8] c"signal %d caught by pcu\0A\00"
@SIG_DFL = global i32 0
define void @catch(i32 %0) {
%2 = load volatile i32, i32* @catch.already_dying
%3 = icmp eq i32 %2, 0
br i1 %3, label %4, label %11
4: ; preds = %1
store volatile i32 1, i32* @catch.already_dying
%5 = load i32, i32* @stderr
%6 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 %0)
%7 = tail call i32 (...) @reel_trace()
%8 = load i32, i32* @SIG_DFL
%9 = tail call i32 @signal(i32 %0, i32 %8)
%10 = tail call i32 @raise(i32 %0)
br label %11
11: ; preds = %1, %4
ret void
}