#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 /*<<< orphan*/ EXIT_SUCCESS;
int SIGINT;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
void signal_handler(int signum) {
  static int count = 0;
  if (signum == SIGINT) {
    count++;
    printf("Got SIGINT: %d\n", count);
    return;
  }
  printf("Got SIGQUIT, bye bye.\n");
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<signal_handler>:
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 <signal_handler+0x46>
mov    0x2ef1(%rip),%eax
add    $0x1,%eax
mov    %eax,0x2ee8(%rip)
mov    0x2ee2(%rip),%esi
lea    0xea7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret
lea    0xea3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2e5d(%rip),%rax
mov    (%rax),%edi
call   1040 <exit@plt>

x86 assembly (clang, -O2):
<signal_handler>:
push   %rax
mov    0x2eb0(%rip),%rax
cmp    %edi,(%rax)
jne    115a <signal_handler+0x2a>
mov    0x2efa(%rip),%esi
add    $0x1,%esi
mov    %esi,0x2ef1(%rip)
lea    0xeae(%rip),%rdi
xor    %eax,%eax
pop    %rcx
jmp    1040 <printf@plt>
lea    0xeaf(%rip),%rdi
call   1030 <puts@plt>
mov    0x2e6b(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@signal_handler.count = internal global i32 0
@SIGINT = global i32 0
@.str = [16 x i8] c"Got SIGINT: %d\0A\00"
@.str.1 = [23 x i8] c"Got SIGQUIT, bye bye.\0A\00"
@EXIT_SUCCESS = global i32 0
define void @signal_handler(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 %11
6: ; preds = %1
%7 = load i32, i32* @signal_handler.count
%8 = add nsw i32 %7, 1
store i32 %8, i32* @signal_handler.count
%9 = load i32, i32* @signal_handler.count
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 %9)
ret void
11: ; preds = %1
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
%13 = load i32, i32* @EXIT_SUCCESS
%14 = call i32 @exit(i32 %13)
unreachable
}

LLVM IR (-O2):
@signal_handler.count = internal unnamed_addr global i32 0
@SIGINT = global i32 0
@.str = [16 x i8] c"Got SIGINT: %d\0A\00"
@EXIT_SUCCESS = global i32 0
@str = [22 x i8] c"Got SIGQUIT, bye bye.\00"
define void @signal_handler(i32 %0) {
%2 = load i32, i32* @SIGINT
%3 = icmp eq i32 %2, %0
br i1 %3, label %4, label %8
4: ; preds = %1
%5 = load i32, i32* @signal_handler.count
%6 = add nsw i32 %5, 1
store i32 %6, i32* @signal_handler.count
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 %6)
ret void
8: ; preds = %1
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str, i64 0, i64 0))
%10 = load i32, i32* @EXIT_SUCCESS
%11 = tail call i32 @exit(i32 %10)
unreachable
}