#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 /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, int, ...);
int /*<<< orphan*/ sleep(int);
void handler(__attribute__((unused)) int signal) {
  static int count = 0;
  ++count;
  if (count == 10) {
    exit(EXIT_SUCCESS);
  }
  int id = count;
  printf("\t[%d] SIGINT received. Sleeping for %d seconds...\n", id, (5));
  sleep((5));
  printf("\t[%d] Done\n", id);
}


x86 assembly (clang, -O0):
<handler>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    0x2efb(%rip),%eax
add    $0x1,%eax
mov    %eax,0x2ef2(%rip)
cmpl   $0xa,0x2eeb(%rip)
jne    1165 <handler+0x35>
mov    0x2e82(%rip),%rax
mov    (%rax),%edi
call   1040 <exit@plt>
mov    0x2ed1(%rip),%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%esi
lea    0xe88(%rip),%rdi
mov    $0x5,%edx
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x5,%edi
call   1050 <sleep@plt>
mov    -0x8(%rbp),%esi
lea    0xe9b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<handler>:
push   %rbx
mov    0x2f05(%rip),%ebx
add    $0x1,%ebx
mov    %ebx,0x2efc(%rip)
cmp    $0xa,%ebx
je     1175 <handler+0x45>
lea    0xeb4(%rip),%rdi
mov    %ebx,%esi
mov    $0x5,%edx
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0x5,%edi
call   1050 <sleep@plt>
lea    0xec8(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
pop    %rbx
jmp    1030 <printf@plt>
mov    0x2e64(%rip),%rax
mov    (%rax),%edi
call   1040 <exit@plt>

LLVM IR (-O0):
@handler.count = internal global i32 0
@EXIT_SUCCESS = global i32 0
@.str = [51 x i8] c"\09[%d] SIGINT received. Sleeping for %d seconds...\0A\00"
@.str.1 = [12 x i8] c"\09[%d] Done\0A\00"
define void @handler(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %2
%4 = load i32, i32* @handler.count
%5 = add nsw i32 %4, 1
store i32 %5, i32* @handler.count
%6 = load i32, i32* @handler.count
%7 = icmp eq i32 %6, 10
br i1 %7, label %8, label %11
8: ; preds = %1
%9 = load i32, i32* @EXIT_SUCCESS
%10 = call i32 @exit(i32 %9)
unreachable
11: ; preds = %1
%12 = load i32, i32* @handler.count
store i32 %12, i32* %3
%13 = load i32, i32* %3
%14 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str, i64 0, i64 0), i32 %13, i32 5)
%15 = call i32 @sleep(i32 5)
%16 = load i32, i32* %3
%17 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %16)
ret void
}

LLVM IR (-O2):
@handler.count = internal unnamed_addr global i32 0
@EXIT_SUCCESS = global i32 0
@.str = [51 x i8] c"\09[%d] SIGINT received. Sleeping for %d seconds...\0A\00"
@.str.1 = [12 x i8] c"\09[%d] Done\0A\00"
define void @handler(i32 %0) {
%2 = load i32, i32* @handler.count
%3 = add nsw i32 %2, 1
store i32 %3, i32* @handler.count
%4 = icmp eq i32 %3, 10
br i1 %4, label %5, label %8
5: ; preds = %1
%6 = load i32, i32* @EXIT_SUCCESS
%7 = tail call i32 @exit(i32 %6)
unreachable
8: ; preds = %1
%9 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str, i64 0, i64 0), i32 %3, i32 5)
%10 = tail call i32 @sleep(i32 5)
%11 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %3)
ret void
}