#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 */
#define SIGHUP 129
#define SIGINT 128
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, int, ...);
void sighandler(int sig) {
  static int int_counter;
  switch (sig) {
  case SIGINT:
    int_counter++;
    if (int_counter == 3) {
      exit(0);
    }
    printf("SIGINT (%d) pressed %d times,"
           "will print this and continue afterwards\n",
           sig, int_counter);
    break;
  case SIGHUP:
    printf("SIGHUP (%d) pressed "
           "will print this and continue afterwards\n",
           sig);
    break;
  }
}


x86 assembly (clang, -O0):
<sighandler>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x8(%rbp)
sub    $0x80,%eax
je     1154 <sighandler+0x34>
jmp    1141 <sighandler+0x21>
mov    -0x8(%rbp),%eax
sub    $0x81,%eax
je     1193 <sighandler+0x73>
jmp    11a4 <sighandler+0x84>
mov    0x2eda(%rip),%eax
add    $0x1,%eax
mov    %eax,0x2ed1(%rip)
cmpl   $0x3,0x2eca(%rip)
jne    1177 <sighandler+0x57>
xor    %edi,%edi
call   1040 <exit@plt>
mov    -0x4(%rbp),%esi
mov    0x2eb4(%rip),%edx
lea    0xe79(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11a4 <sighandler+0x84>
mov    -0x4(%rbp),%esi
lea    0xea9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sighandler>:
push   %rax
cmp    $0x81,%edi
je     1159 <sighandler+0x39>
cmp    $0x80,%edi
jne    116d <sighandler+0x4d>
mov    0x2efd(%rip),%edx
add    $0x1,%edx
mov    %edx,0x2ef4(%rip)
cmp    $0x3,%edx
je     116f <sighandler+0x4f>
lea    0xeb4(%rip),%rdi
mov    $0x80,%esi
xor    %eax,%eax
pop    %rcx
jmp    1030 <printf@plt>
lea    0xee6(%rip),%rdi
mov    $0x81,%esi
xor    %eax,%eax
pop    %rcx
jmp    1030 <printf@plt>
pop    %rax
ret
xor    %edi,%edi
call   1040 <exit@plt>

LLVM IR (-O0):
@sighandler.int_counter = internal global i32 0
@.str = [70 x i8] c"SIGINT (%d) pressed %d times,will print this and continue afterwards\0A\00"
@.str.1 = [61 x i8] c"SIGHUP (%d) pressed will print this and continue afterwards\0A\00"
define void @sighandler(i32 %0) {
%2 = alloca i32
store i32 %0, i32* %2
%3 = load i32, i32* %2
switch i32 %3, label %18 [
i32 128, label %4
i32 129, label %15
]
4: ; preds = %1
%5 = load i32, i32* @sighandler.int_counter
%6 = add nsw i32 %5, 1
store i32 %6, i32* @sighandler.int_counter
%7 = load i32, i32* @sighandler.int_counter
%8 = icmp eq i32 %7, 3
br i1 %8, label %9, label %11
9: ; preds = %4
%10 = call i32 @exit(i32 0)
unreachable
11: ; preds = %4
%12 = load i32, i32* %2
%13 = load i32, i32* @sighandler.int_counter
%14 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([70 x i8], [70 x i8]* @.str, i64 0, i64 0), i32 %12, i32 %13)
br label %18
15: ; preds = %1
%16 = load i32, i32* %2
%17 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.1, i64 0, i64 0), i32 %16)
br label %18
18: ; preds = %1, %15, %11
ret void
}

LLVM IR (-O2):
@sighandler.int_counter = internal unnamed_addr global i32 0
@.str = [70 x i8] c"SIGINT (%d) pressed %d times,will print this and continue afterwards\0A\00"
@.str.1 = [61 x i8] c"SIGHUP (%d) pressed will print this and continue afterwards\0A\00"
define void @sighandler(i32 %0) {
switch i32 %0, label %12 [
i32 128, label %2
i32 129, label %10
]
2: ; preds = %1
%3 = load i32, i32* @sighandler.int_counter
%4 = add nsw i32 %3, 1
store i32 %4, i32* @sighandler.int_counter
%5 = icmp eq i32 %4, 3
br i1 %5, label %6, label %8
6: ; preds = %2
%7 = tail call i32 @exit(i32 0)
unreachable
8: ; preds = %2
%9 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([70 x i8], [70 x i8]* @.str, i64 0, i64 0), i32 128, i32 %4)
br label %12
10: ; preds = %1
%11 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.1, i64 0, i64 0), i32 129)
br label %12
12: ; preds = %1, %10, %8
ret void
}