#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*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
int /*<<< orphan*/ write(int, char *, int);
void handler(int signum) {
  char buf[200], *cp;
  int offset;
  strcpy(buf, "handler: caught signal ");
  cp = buf + strlen(buf);
  if (signum > 100)
    offset = 3;
  else if (signum > 10)
    offset = 2;
  else
    offset = 1;
  cp += offset;
  *cp-- = '\0';
  while (signum > 0) {
    *cp-- = (signum % 10) + '0';
    signum /= 10;
  }
  strcat(buf, "\n");
  (void)write(2, buf, strlen(buf));
}


x86 assembly (clang, -O0):
<handler>:
push   %rbp
mov    %rsp,%rbp
sub    $0xf0,%rsp
mov    %edi,-0x4(%rbp)
lea    -0xd0(%rbp),%rdi
lea    0xea4(%rip),%rsi
call   1030 <strcpy@plt>
lea    -0xd0(%rbp),%rax
mov    %rax,-0xe8(%rbp)
lea    -0xd0(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0xe8(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0xd8(%rbp)
cmpl   $0x64,-0x4(%rbp)
jle    11aa <handler+0x6a>
movl   $0x3,-0xdc(%rbp)
jmp    11d2 <handler+0x92>
cmpl   $0xa,-0x4(%rbp)
jle    11c3 <handler+0x83>
movl   $0x2,-0xdc(%rbp)
jmp    11cd <handler+0x8d>
movl   $0x1,-0xdc(%rbp)
jmp    11d2 <handler+0x92>
mov    -0xdc(%rbp),%ecx
mov    -0xd8(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0xd8(%rbp)
mov    -0xd8(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0xd8(%rbp)
movb   $0x0,(%rax)
cmpl   $0x0,-0x4(%rbp)
jle    1248 <handler+0x108>
mov    -0x4(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
add    $0x30,%edx
mov    %dl,%cl
mov    -0xd8(%rbp),%rax
mov    %rax,%rdx
add    $0xffffffffffffffff,%rdx
mov    %rdx,-0xd8(%rbp)
mov    %cl,(%rax)
mov    -0x4(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,-0x4(%rbp)
jmp    1204 <handler+0xc4>
lea    -0xd0(%rbp),%rdi
lea    0xdc2(%rip),%rsi
call   1060 <strcat@plt>
lea    -0xd0(%rbp),%rax
mov    %rax,-0xf0(%rbp)
lea    -0xd0(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0xf0(%rbp),%rsi
mov    %eax,%edx
mov    $0x2,%edi
call   1040 <write@plt>
add    $0xf0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<handler>:
push   %r14
push   %rbx
sub    $0xc8,%rsp
mov    %edi,%ebx
lea    0xead(%rip),%rsi
mov    %rsp,%r14
mov    %r14,%rdi
call   1030 <strcpy@plt>
mov    %r14,%rdi
call   1050 <strlen@plt>
cltq
lea    (%rsp,%rax,1),%rdx
xor    %esi,%esi
cmp    $0xb,%ebx
setge  %sil
add    $0x1,%rsi
cmp    $0x65,%ebx
mov    $0x3,%ecx
cmovl  %rsi,%rcx
movb   $0x0,(%rcx,%rdx,1)
test   %ebx,%ebx
jle    11c6 <handler+0x86>
add    %rax,%rcx
lea    (%rsp,%rcx,1),%rax
add    $0xffffffffffffffff,%rax
mov    $0xcccccccd,%ecx
nopl   (%rax)
mov    %ebx,%edx
imul   %rcx,%rdx
shr    $0x23,%rdx
lea    (%rdx,%rdx,1),%esi
lea    (%rsi,%rsi,4),%esi
mov    %ebx,%edi
sub    %esi,%edi
or     $0x30,%dil
mov    %dil,(%rax)
add    $0xffffffffffffffff,%rax
cmp    $0x9,%ebx
mov    %edx,%ebx
ja     11a0 <handler+0x60>
lea    0xe4b(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1060 <strcat@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    $0x2,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1040 <write@plt>
add    $0xc8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [24 x i8] c"handler: caught signal \00"
@.str.1 = [2 x i8] c"\0A\00"
define void @handler(i32 %0) {
%2 = alloca i32
%3 = alloca [200 x i8]
%4 = alloca i8*
%5 = alloca i32
store i32 %0, i32* %2
%6 = getelementptr inbounds [200 x i8], [200 x i8]* %3, i64 0, i64 0
%7 = call i32 @strcpy(i8* %6, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
%8 = getelementptr inbounds [200 x i8], [200 x i8]* %3, i64 0, i64 0
%9 = getelementptr inbounds [200 x i8], [200 x i8]* %3, i64 0, i64 0
%10 = call i32 @strlen(i8* %9)
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds i8, i8* %8, i64 %11
store i8* %12, i8** %4
%13 = load i32, i32* %2
%14 = icmp sgt i32 %13, 100
br i1 %14, label %15, label %16
15: ; preds = %1
store i32 3, i32* %5
br label %22
16: ; preds = %1
%17 = load i32, i32* %2
%18 = icmp sgt i32 %17, 10
br i1 %18, label %19, label %20
19: ; preds = %16
store i32 2, i32* %5
br label %21
20: ; preds = %16
store i32 1, i32* %5
br label %21
21: ; preds = %20, %19
br label %22
22: ; preds = %21, %15
%23 = load i32, i32* %5
%24 = load i8*, i8** %4
%25 = sext i32 %23 to i64
%26 = getelementptr inbounds i8, i8* %24, i64 %25
store i8* %26, i8** %4
%27 = load i8*, i8** %4
%28 = getelementptr inbounds i8, i8* %27, i32 -1
store i8* %28, i8** %4
store i8 0, i8* %27
br label %29
29: ; preds = %32, %22
%30 = load i32, i32* %2
%31 = icmp sgt i32 %30, 0
br i1 %31, label %32, label %41
32: ; preds = %29
%33 = load i32, i32* %2
%34 = srem i32 %33, 10
%35 = add nsw i32 %34, 48
%36 = trunc i32 %35 to i8
%37 = load i8*, i8** %4
%38 = getelementptr inbounds i8, i8* %37, i32 -1
store i8* %38, i8** %4
store i8 %36, i8* %37
%39 = load i32, i32* %2
%40 = sdiv i32 %39, 10
store i32 %40, i32* %2
br label %29
41: ; preds = %29
%42 = getelementptr inbounds [200 x i8], [200 x i8]* %3, i64 0, i64 0
%43 = call i32 @strcat(i8* %42, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%44 = getelementptr inbounds [200 x i8], [200 x i8]* %3, i64 0, i64 0
%45 = getelementptr inbounds [200 x i8], [200 x i8]* %3, i64 0, i64 0
%46 = call i32 @strlen(i8* %45)
%47 = call i32 @write(i32 2, i8* %44, i32 %46)
ret void
}

LLVM IR (-O2):
@.str = [24 x i8] c"handler: caught signal \00"
@.str.1 = [2 x i8] c"\0A\00"
define void @handler(i32 %0) {
%2 = alloca [200 x i8]
%3 = getelementptr inbounds [200 x i8], [200 x i8]* %2, i64 0, i64 0
%4 = call i32 @strcpy(i8* %3, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
%5 = call i32 @strlen(i8* %3)
%6 = sext i32 %5 to i64
%7 = getelementptr inbounds [200 x i8], [200 x i8]* %2, i64 0, i64 %6
%8 = icmp sgt i32 %0, 100
%9 = icmp sgt i32 %0, 10
%10 = select i1 %9, i64 2, i64 1
%11 = select i1 %8, i64 3, i64 %10
%12 = getelementptr inbounds i8, i8* %7, i64 %11
store i8 0, i8* %12
%13 = icmp sgt i32 %0, 0
br i1 %13, label %14, label %23
14: ; preds = %1, %14
%15 = phi i8* [ %17, %14 ], [ %12, %1 ]
%16 = phi i32 [ %21, %14 ], [ %0, %1 ]
%17 = getelementptr inbounds i8, i8* %15, i64 -1
%18 = urem i32 %16, 10
%19 = trunc i32 %18 to i8
%20 = or i8 %19, 48
store i8 %20, i8* %17
%21 = udiv i32 %16, 10
%22 = icmp ult i32 %16, 10
br i1 %22, label %23, label %14
23: ; preds = %14, %1
%24 = call i32 @strcat(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%25 = call i32 @strlen(i8* %3)
%26 = call i32 @write(i32 2, i8* %3, i32 %25)
ret void
}