#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 */

/* Variables and functions */
int SIGINT;
int SIGQUIT;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int);
int getpid();
int /*<<< orphan*/ stderr;
void catch_sig(int sig) {
  if (sig == SIGINT)
    fprintf(stderr, "%d catch SIGINT.\n", getpid());
  else if (sig == SIGQUIT)
    fprintf(stderr, "%d catch SIGQUIT.\n", getpid());
}


x86 assembly (clang, -O0):
<catch_sig>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    0x2eb3(%rip),%rcx
cmp    (%rcx),%eax
jne    1166 <catch_sig+0x46>
mov    0x2e8c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x8(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    -0x8(%rbp),%edi
mov    %eax,%edx
lea    0xea4(%rip),%rsi
call   1040 <fprintf@plt>
jmp    11a1 <catch_sig+0x81>
mov    -0x4(%rbp),%eax
mov    0x2e70(%rip),%rcx
cmp    (%rcx),%eax
jne    119c <catch_sig+0x7c>
mov    0x2e51(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    -0xc(%rbp),%edi
mov    %eax,%edx
lea    0xe7b(%rip),%rsi
call   1040 <fprintf@plt>
jmp    11a1 <catch_sig+0x81>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<catch_sig>:
push   %rbp
push   %rbx
push   %rax
mov    0x2ebe(%rip),%rax
cmp    %edi,(%rax)
jne    1137 <catch_sig+0x17>
lea    0xecb(%rip),%rbx
jmp    1149 <catch_sig+0x29>
mov    0x2ea2(%rip),%rax
cmp    %edi,(%rax)
jne    116b <catch_sig+0x4b>
lea    0xec9(%rip),%rbx
mov    0x2e80(%rip),%rax
mov    (%rax),%ebp
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1040 <fprintf@plt>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@SIGINT = global i32 0
@stderr = global i32 0
@.str = [18 x i8] c"%d catch SIGINT.\0A\00"
@SIGQUIT = global i32 0
@.str.1 = [19 x i8] c"%d catch SIGQUIT.\0A\00"
define void @catch_sig(i32 %0) {
%2 = alloca i32
store i32 %0, i32* %2
%3 = load i32, i32* %2
%4 = load i32, i32* @SIGINT
%5 = icmp eq i32 %3, %4
br i1 %5, label %6, label %10
6: ; preds = %1
%7 = load i32, i32* @stderr
%8 = call i32 (...) @getpid()
%9 = call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 %8)
br label %19
10: ; preds = %1
%11 = load i32, i32* %2
%12 = load i32, i32* @SIGQUIT
%13 = icmp eq i32 %11, %12
br i1 %13, label %14, label %18
14: ; preds = %10
%15 = load i32, i32* @stderr
%16 = call i32 (...) @getpid()
%17 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i32 %16)
br label %18
18: ; preds = %14, %10
br label %19
19: ; preds = %18, %6
ret void
}

LLVM IR (-O2):
@SIGINT = global i32 0
@stderr = global i32 0
@.str = [18 x i8] c"%d catch SIGINT.\0A\00"
@SIGQUIT = global i32 0
@.str.1 = [19 x i8] c"%d catch SIGQUIT.\0A\00"
define void @catch_sig(i32 %0) {
%2 = load i32, i32* @SIGINT
%3 = icmp eq i32 %2, %0
br i1 %3, label %7, label %4
4: ; preds = %1
%5 = load i32, i32* @SIGQUIT
%6 = icmp eq i32 %5, %0
br i1 %6, label %7, label %12
7: ; preds = %4, %1
%8 = phi i8* [ getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), %1 ], [ getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), %4 ]
%9 = load i32, i32* @stderr
%10 = tail call i32 (...) @getpid()
%11 = tail call i32 @fprintf(i32 %9, i8* %8, i32 %10)
br label %12
12: ; preds = %7, %4
ret void
}