#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 */
typedef int ssize_t;
typedef int /*<<< orphan*/ msg_end;
typedef int /*<<< orphan*/ err_msg;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ STDERR_FILENO;
int /*<<< orphan*/ _exit(int /*<<< orphan*/);
int write(int /*<<< orphan*/, char const *, int);
void sighandler(int n) {
  const char err_msg[] = "error: \nKilled by signal ";
  const char msg_end[] = ".\n";
  char num_str[4] = {0};
  ssize_t num_size;
  ssize_t wbytes;
  wbytes = write(STDERR_FILENO, err_msg, sizeof(err_msg) - 1);
  if (wbytes != sizeof(err_msg) - 1)
    goto out;
  if (n < 10) {
    num_str[0] = (char)(0x30 + n);
    num_size = 1;
  } else if (n >= 100) {
    goto out;
  } else {
    num_str[0] = (char)(0x30 + n / 10);
    num_str[1] = (char)(0x30 + n % 10);
    num_size = 2;
  }
  wbytes = write(STDERR_FILENO, num_str, num_size);
  if (wbytes != num_size)
    goto out;
  wbytes = write(STDERR_FILENO, msg_end, sizeof(msg_end) - 1);
  if (wbytes != sizeof(msg_end) - 1)
    goto out;
out:
  _exit(EXIT_FAILURE);
}


x86 assembly (clang, -O0):
<sighandler>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    0xebe(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xebb(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    0xeb8(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    0xeb5(%rip),%ax
mov    %ax,-0x8(%rbp)
mov    0xeac(%rip),%ax
mov    %ax,-0x23(%rbp)
mov    0xea4(%rip),%al
mov    %al,-0x21(%rbp)
lea    -0x27(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1050 <memset@plt>
mov    0x2e4e(%rip),%rax
mov    (%rax),%edi
lea    -0x20(%rbp),%rsi
mov    $0x19,%edx
call   1040 <write@plt>
mov    %eax,-0x30(%rbp)
movslq -0x30(%rbp),%rax
cmp    $0x19,%rax
je     11b8 <sighandler+0x88>
jmp    1271 <sighandler+0x141>
cmpl   $0xa,-0x4(%rbp)
jge    11d7 <sighandler+0xa7>
mov    -0x4(%rbp),%eax
add    $0x30,%eax
mov    %al,-0x27(%rbp)
movl   $0x1,-0x2c(%rbp)
jmp    1216 <sighandler+0xe6>
cmpl   $0x64,-0x4(%rbp)
jl     11e6 <sighandler+0xb6>
jmp    1271 <sighandler+0x141>
mov    -0x4(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
add    $0x30,%eax
mov    %al,-0x27(%rbp)
mov    -0x4(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
add    $0x30,%edx
mov    %dl,%al
mov    %al,-0x26(%rbp)
movl   $0x2,-0x2c(%rbp)
jmp    1216 <sighandler+0xe6>
mov    0x2dc3(%rip),%rax
mov    (%rax),%edi
lea    -0x27(%rbp),%rsi
mov    -0x2c(%rbp),%edx
call   1040 <write@plt>
mov    %eax,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x2c(%rbp),%eax
je     123f <sighandler+0x10f>
jmp    1271 <sighandler+0x141>
mov    0x2d9a(%rip),%rax
mov    (%rax),%edi
lea    -0x23(%rbp),%rsi
mov    $0x2,%edx
call   1040 <write@plt>
mov    %eax,-0x30(%rbp)
movslq -0x30(%rbp),%rax
cmp    $0x2,%rax
je     126c <sighandler+0x13c>
jmp    1271 <sighandler+0x141>
jmp    1271 <sighandler+0x141>
mov    0x2d60(%rip),%rax
mov    (%rax),%edi
call   1030 <_exit@plt>

x86 assembly (clang, -O2):
<sighandler>:
push   %r14
push   %rbx
sub    $0x38,%rsp
mov    %edi,%ebx
movups 0xeda(%rip),%xmm0
movups %xmm0,0x1a(%rsp)
movaps 0xec4(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movb   $0x0,0xe(%rsp)
movw   $0xa2e,0xc(%rsp)
movl   $0x0,0x8(%rsp)
mov    0x2e84(%rip),%r14
mov    (%r14),%edi
lea    0x10(%rsp),%rsi
mov    $0x19,%edx
call   1040 <write@plt>
cmp    $0x19,%eax
jne    11d5 <sighandler+0xb5>
cmp    $0x9,%ebx
jg     1186 <sighandler+0x66>
add    $0x30,%bl
mov    %bl,0x8(%rsp)
mov    $0x1,%ebx
jmp    11b0 <sighandler+0x90>
cmp    $0x63,%ebx
ja     11d5 <sighandler+0xb5>
movzbl %bl,%eax
imul   $0xcd,%eax,%ecx
shr    $0xb,%ecx
lea    0x30(%rcx),%edx
mov    %dl,0x8(%rsp)
add    %ecx,%ecx
lea    (%rcx,%rcx,4),%ecx
sub    %cl,%al
or     $0x30,%al
mov    %al,0x9(%rsp)
mov    $0x2,%ebx
mov    (%r14),%edi
lea    0x8(%rsp),%rsi
mov    %ebx,%edx
call   1040 <write@plt>
cmp    %ebx,%eax
jne    11d5 <sighandler+0xb5>
mov    (%r14),%edi
lea    0xc(%rsp),%rsi
mov    $0x2,%edx
call   1040 <write@plt>
mov    0x2dfc(%rip),%rax
mov    (%rax),%edi
call   1030 <_exit@plt>

LLVM IR (-O0):
@__const.sighandler.err_msg = [26 x i8] c"error: \0AKilled by signal \00"
@__const.sighandler.msg_end = [3 x i8] c".\0A\00"
@STDERR_FILENO = global i32 0
@EXIT_FAILURE = global i32 0
define void @sighandler(i32 %0) {
%2 = alloca i32
%3 = alloca [26 x i8]
%4 = alloca [3 x i8]
%5 = alloca [4 x i8]
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %2
%8 = bitcast [26 x i8]* %3 to i8*
%9 = bitcast [3 x i8]* %4 to i8*
%10 = bitcast [4 x i8]* %5 to i8*
%11 = load i32, i32* @STDERR_FILENO
%12 = getelementptr inbounds [26 x i8], [26 x i8]* %3, i64 0, i64 0
%13 = call i32 @write(i32 %11, i8* %12, i32 25)
store i32 %13, i32* %7
%14 = load i32, i32* %7
%15 = sext i32 %14 to i64
%16 = icmp ne i64 %15, 25
br i1 %16, label %17, label %18
17: ; preds = %1
br label %60
18: ; preds = %1
%19 = load i32, i32* %2
%20 = icmp slt i32 %19, 10
br i1 %20, label %21, label %26
21: ; preds = %18
%22 = load i32, i32* %2
%23 = add nsw i32 48, %22
%24 = trunc i32 %23 to i8
%25 = getelementptr inbounds [4 x i8], [4 x i8]* %5, i64 0, i64 0
store i8 %24, i8* %25
store i32 1, i32* %6
br label %42
26: ; preds = %18
%27 = load i32, i32* %2
%28 = icmp sge i32 %27, 100
br i1 %28, label %29, label %30
29: ; preds = %26
br label %60
30: ; preds = %26
%31 = load i32, i32* %2
%32 = sdiv i32 %31, 10
%33 = add nsw i32 48, %32
%34 = trunc i32 %33 to i8
%35 = getelementptr inbounds [4 x i8], [4 x i8]* %5, i64 0, i64 0
store i8 %34, i8* %35
%36 = load i32, i32* %2
%37 = srem i32 %36, 10
%38 = add nsw i32 48, %37
%39 = trunc i32 %38 to i8
%40 = getelementptr inbounds [4 x i8], [4 x i8]* %5, i64 0, i64 1
store i8 %39, i8* %40
store i32 2, i32* %6
br label %41
41: ; preds = %30
br label %42
42: ; preds = %41, %21
%43 = load i32, i32* @STDERR_FILENO
%44 = getelementptr inbounds [4 x i8], [4 x i8]* %5, i64 0, i64 0
%45 = load i32, i32* %6
%46 = call i32 @write(i32 %43, i8* %44, i32 %45)
store i32 %46, i32* %7
%47 = load i32, i32* %7
%48 = load i32, i32* %6
%49 = icmp ne i32 %47, %48
br i1 %49, label %50, label %51
50: ; preds = %42
br label %60
51: ; preds = %42
%52 = load i32, i32* @STDERR_FILENO
%53 = getelementptr inbounds [3 x i8], [3 x i8]* %4, i64 0, i64 0
%54 = call i32 @write(i32 %52, i8* %53, i32 2)
store i32 %54, i32* %7
%55 = load i32, i32* %7
%56 = sext i32 %55 to i64
%57 = icmp ne i64 %56, 2
br i1 %57, label %58, label %59
58: ; preds = %51
br label %60
59: ; preds = %51
br label %60
60: ; preds = %59, %58, %50, %29, %17
%61 = load i32, i32* @EXIT_FAILURE
%62 = call i32 @_exit(i32 %61)
unreachable
}

LLVM IR (-O2):
@__const.sighandler.err_msg = [26 x i8] c"error: \0AKilled by signal \00"
@__const.sighandler.msg_end = [3 x i8] c".\0A\00"
@STDERR_FILENO = global i32 0
@EXIT_FAILURE = global i32 0
define void @sighandler(i32 %0) {
%2 = alloca [26 x i8]
%3 = alloca [3 x i8]
%4 = alloca i32
%5 = bitcast i32* %4 to [4 x i8]*
%6 = getelementptr inbounds [26 x i8], [26 x i8]* %2, i64 0, i64 0
%7 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 0
%8 = bitcast i32* %4 to i8*
store i32 0, i32* %4
%9 = load i32, i32* @STDERR_FILENO
%10 = call i32 @write(i32 %9, i8* %6, i32 25)
%11 = icmp eq i32 %10, 25
br i1 %11, label %12, label %34
12: ; preds = %1
%13 = icmp slt i32 %0, 10
br i1 %13, label %14, label %17
14: ; preds = %12
%15 = trunc i32 %0 to i8
%16 = add i8 %15, 48
store i8 %16, i8* %8
br label %26
17: ; preds = %12
%18 = icmp ugt i32 %0, 99
br i1 %18, label %34, label %19
19: ; preds = %17
%20 = trunc i32 %0 to i8
%21 = udiv i8 %20, 10
%22 = add nuw nsw i8 %21, 48
store i8 %22, i8* %8
%23 = urem i8 %20, 10
%24 = or i8 %23, 48
%25 = getelementptr inbounds [4 x i8], [4 x i8]* %5, i64 0, i64 1
store i8 %24, i8* %25
br label %26
26: ; preds = %19, %14
%27 = phi i32 [ 1, %14 ], [ 2, %19 ]
%28 = load i32, i32* @STDERR_FILENO
%29 = call i32 @write(i32 %28, i8* %8, i32 %27)
%30 = icmp eq i32 %29, %27
br i1 %30, label %31, label %34
31: ; preds = %26
%32 = load i32, i32* @STDERR_FILENO
%33 = call i32 @write(i32 %32, i8* %7, i32 2)
br label %34
34: ; preds = %31, %26, %17, %1
%35 = load i32, i32* @EXIT_FAILURE
%36 = tail call i32 @_exit(i32 %35)
unreachable
}