#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*/ alarm(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
void signal_handler_func(int sig_num) {
  static int i = 0;
  printf("catch signal %d\n", sig_num);
  if (i < 5) {
    printf("alarm happen...\n");
    ++i;
    alarm(1);
  } else {
    printf("end...\n");
    exit(0);
  }
}


x86 assembly (clang, -O0):
<signal_handler_func>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%esi
lea    0xebb(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0x5,0x2ee9(%rip)
jge    1185 <signal_handler_func+0x55>
lea    0xeb1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2ecf(%rip),%eax
add    $0x1,%eax
mov    %eax,0x2ec6(%rip)
mov    $0x1,%edi
call   1040 <alarm@plt>
jmp    119a <signal_handler_func+0x6a>
lea    0xe96(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %edi,%edi
call   1050 <exit@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<signal_handler_func>:
push   %rax
mov    %edi,%esi
lea    0xeb6(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
cmpl   $0x4,0x2eec(%rip)
jg     1178 <signal_handler_func+0x38>
lea    0xeb7(%rip),%rdi
call   1030 <puts@plt>
addl   $0x1,0x2ed7(%rip)
mov    $0x1,%edi
pop    %rax
jmp    1050 <alarm@plt>
lea    0xe92(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@signal_handler_func.i = internal global i32 0
@.str = [17 x i8] c"catch signal %d\0A\00"
@.str.1 = [17 x i8] c"alarm happen...\0A\00"
@.str.2 = [8 x i8] c"end...\0A\00"
define void @signal_handler_func(i32 %0) {
%2 = alloca i32
store i32 %0, i32* %2
%3 = load i32, i32* %2
%4 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = load i32, i32* @signal_handler_func.i
%6 = icmp slt i32 %5, 5
br i1 %6, label %7, label %12
7: ; preds = %1
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
%9 = load i32, i32* @signal_handler_func.i
%10 = add nsw i32 %9, 1
store i32 %10, i32* @signal_handler_func.i
%11 = call i32 @alarm(i32 1)
br label %15
12: ; preds = %1
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%14 = call i32 @exit(i32 0)
unreachable
15: ; preds = %7
ret void
}

LLVM IR (-O2):
@signal_handler_func.i = internal unnamed_addr global i32 0
@.str = [17 x i8] c"catch signal %d\0A\00"
@str = [7 x i8] c"end...\00"
@str.3 = [16 x i8] c"alarm happen...\00"
define void @signal_handler_func(i32 %0) {
%2 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 %0)
%3 = load i32, i32* @signal_handler_func.i
%4 = icmp slt i32 %3, 5
br i1 %4, label %5, label %10
5: ; preds = %1
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str.3, i64 0, i64 0))
%7 = load i32, i32* @signal_handler_func.i
%8 = add nsw i32 %7, 1
store i32 %8, i32* @signal_handler_func.i
%9 = tail call i32 @alarm(i32 1)
ret void
10: ; preds = %1
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str, i64 0, i64 0))
%12 = tail call i32 @exit(i32 0)
unreachable
}