#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 SIGALRM 136
#define SIGCONT 135
#define SIGHUP 134
#define SIGINT 133
#define SIGQUIT 132
#define SIGTERM 131
#define SIGUSR1 130
#define SIGUSR2 129
#define SIGWINCH 128
int /*<<< orphan*/ _exit(int);
int /*<<< orphan*/ memcpy(char *, char const *, int);
int strlen(char const *);
int write(int, char *, int);
void catch_sig(int sig) {
  char buf[7 + 14 + 2] = "Caught ";
  const char *name;
  int ignored;
  int i;
  switch (sig) {
  case SIGALRM:
    name = "ALRM";
    break;
  case SIGCONT:
    name = "CONT";
    break;
  case SIGHUP:
    name = "HUP";
    break;
  case SIGINT:
    name = "INT";
    break;
  case SIGQUIT:
    name = "QUIT";
    break;
  case SIGTERM:
    name = "TERM";
    break;
  case SIGUSR1:
    name = "USR1";
    break;
  case SIGUSR2:
    name = "USR2";
    break;
  case SIGWINCH:
    name = "WINCH";
    break;
  default:
    name = "unknown signal";
  }
  i = strlen(name);
  memcpy((buf + 7), (name), (i));
  i += 7;
  buf[i++] = '\n';
  ignored = write(1, buf, i);
  if (sig != SIGCONT)
    _exit(1);
  (void)ignored;
}


x86 assembly (clang, -O0):
<catch_sig>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
movaps 0xede(%rip),%xmm0
movaps %xmm0,-0x20(%rbp)
movq   $0x0,-0x11(%rbp)
mov    -0x4(%rbp),%eax
add    $0xffffff80,%eax
mov    %eax,%ecx
mov    %rcx,-0x38(%rbp)
sub    $0x8,%eax
ja     1217 <catch_sig+0xd7>
mov    -0x38(%rbp),%rax
lea    0xe82(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xeb9(%rip),%rax
mov    %rax,-0x28(%rbp)
jmp    1222 <catch_sig+0xe2>
lea    0xeae(%rip),%rax
mov    %rax,-0x28(%rbp)
jmp    1222 <catch_sig+0xe2>
lea    0xea3(%rip),%rax
mov    %rax,-0x28(%rbp)
jmp    1222 <catch_sig+0xe2>
lea    0xe97(%rip),%rax
mov    %rax,-0x28(%rbp)
jmp    1222 <catch_sig+0xe2>
lea    0xe8b(%rip),%rax
mov    %rax,-0x28(%rbp)
jmp    1222 <catch_sig+0xe2>
lea    0xe80(%rip),%rax
mov    %rax,-0x28(%rbp)
jmp    1222 <catch_sig+0xe2>
lea    0xe75(%rip),%rax
mov    %rax,-0x28(%rbp)
jmp    1222 <catch_sig+0xe2>
lea    0xe6a(%rip),%rax
mov    %rax,-0x28(%rbp)
jmp    1222 <catch_sig+0xe2>
lea    0xe5f(%rip),%rax
mov    %rax,-0x28(%rbp)
jmp    1222 <catch_sig+0xe2>
lea    0xe55(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x30(%rbp)
lea    -0x20(%rbp),%rdi
add    $0x7,%rdi
mov    -0x28(%rbp),%rsi
mov    -0x30(%rbp),%edx
call   1060 <memcpy@plt>
mov    -0x30(%rbp),%eax
add    $0x7,%eax
mov    %eax,-0x30(%rbp)
mov    -0x30(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x30(%rbp)
cltq
movb   $0xa,-0x20(%rbp,%rax,1)
lea    -0x20(%rbp),%rsi
mov    -0x30(%rbp),%edx
mov    $0x1,%edi
call   1040 <write@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x87,-0x4(%rbp)
je     1288 <catch_sig+0x148>
mov    $0x1,%edi
call   1030 <_exit@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<catch_sig>:
push   %rbp
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %edi,%r14d
movaps 0xeae(%rip),%xmm0
movaps %xmm0,(%rsp)
movq   $0x0,0xf(%rsp)
lea    -0x80(%r14),%eax
cmp    $0x8,%eax
ja     117a <catch_sig+0x3a>
cltq
lea    0xea7(%rip),%rcx
movslq (%rcx,%rax,4),%rbx
add    %rcx,%rbx
jmp    1181 <catch_sig+0x41>
lea    0xee7(%rip),%rbx
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %eax,%ebp
lea    0x7(%rsp),%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1060 <memcpy@plt>
movslq %ebp,%rax
lea    0x8(%rax),%edx
mov    %rsp,%rsi
movb   $0xa,0x7(%rax,%rsi,1)
mov    $0x1,%edi
call   1040 <write@plt>
cmp    $0x87,%r14d
jne    11c4 <catch_sig+0x84>
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    $0x1,%edi
call   1030 <_exit@plt>

LLVM IR (-O0):
@__const.catch_sig.buf = [23 x i8] c"Caught \00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@.str = [5 x i8] c"ALRM\00"
@.str.1 = [5 x i8] c"CONT\00"
@.str.2 = [4 x i8] c"HUP\00"
@.str.3 = [4 x i8] c"INT\00"
@.str.4 = [5 x i8] c"QUIT\00"
@.str.5 = [5 x i8] c"TERM\00"
@.str.6 = [5 x i8] c"USR1\00"
@.str.7 = [5 x i8] c"USR2\00"
@.str.8 = [6 x i8] c"WINCH\00"
@.str.9 = [15 x i8] c"unknown signal\00"
define void @catch_sig(i32 %0) {
%2 = alloca i32
%3 = alloca [23 x i8]
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %2
%7 = bitcast [23 x i8]* %3 to i8*
%8 = load i32, i32* %2
switch i32 %8, label %18 [
i32 136, label %9
i32 135, label %10
i32 134, label %11
i32 133, label %12
i32 132, label %13
i32 131, label %14
i32 130, label %15
i32 129, label %16
i32 128, label %17
]
9: ; preds = %1
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8** %4
br label %19
10: ; preds = %1
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8** %4
br label %19
11: ; preds = %1
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8** %4
br label %19
12: ; preds = %1
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8** %4
br label %19
13: ; preds = %1
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i8** %4
br label %19
14: ; preds = %1
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i8** %4
br label %19
15: ; preds = %1
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0), i8** %4
br label %19
16: ; preds = %1
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0), i8** %4
br label %19
17: ; preds = %1
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.8, i64 0, i64 0), i8** %4
br label %19
18: ; preds = %1
store i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.9, i64 0, i64 0), i8** %4
br label %19
19: ; preds = %18, %17, %16, %15, %14, %13, %12, %11, %10, %9
%20 = load i8*, i8** %4
%21 = call i32 @strlen(i8* %20)
store i32 %21, i32* %6
%22 = getelementptr inbounds [23 x i8], [23 x i8]* %3, i64 0, i64 0
%23 = getelementptr inbounds i8, i8* %22, i64 7
%24 = load i8*, i8** %4
%25 = load i32, i32* %6
%26 = call i32 @memcpy(i8* %23, i8* %24, i32 %25)
%27 = load i32, i32* %6
%28 = add nsw i32 %27, 7
store i32 %28, i32* %6
%29 = load i32, i32* %6
%30 = add nsw i32 %29, 1
store i32 %30, i32* %6
%31 = sext i32 %29 to i64
%32 = getelementptr inbounds [23 x i8], [23 x i8]* %3, i64 0, i64 %31
store i8 10, i8* %32
%33 = getelementptr inbounds [23 x i8], [23 x i8]* %3, i64 0, i64 0
%34 = load i32, i32* %6
%35 = call i32 @write(i32 1, i8* %33, i32 %34)
store i32 %35, i32* %5
%36 = load i32, i32* %2
%37 = icmp ne i32 %36, 135
br i1 %37, label %38, label %40
38: ; preds = %19
%39 = call i32 @_exit(i32 1)
unreachable
40: ; preds = %19
%41 = load i32, i32* %5
ret void
}

LLVM IR (-O2):
@__const.catch_sig.buf = [23 x i8] c"Caught \00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@.str = [5 x i8] c"ALRM\00"
@.str.1 = [5 x i8] c"CONT\00"
@.str.2 = [4 x i8] c"HUP\00"
@.str.3 = [4 x i8] c"INT\00"
@.str.4 = [5 x i8] c"QUIT\00"
@.str.5 = [5 x i8] c"TERM\00"
@.str.6 = [5 x i8] c"USR1\00"
@.str.7 = [5 x i8] c"USR2\00"
@.str.8 = [6 x i8] c"WINCH\00"
@.str.9 = [15 x i8] c"unknown signal\00"
@reltable.catch_sig = [9 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([6 x i8]* @.str.8 to i64), i64 ptrtoint ([9 x i32]* @reltable.catch_sig to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([5 x i8]* @.str.7 to i64), i64 ptrtoint ([9 x i32]* @reltable.catch_sig to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([5 x i8]* @.str.6 to i64), i64 ptrtoint ([9 x i32]* @reltable.catch_sig to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([5 x i8]* @.str.5 to i64), i64 ptrtoint ([9 x i32]* @reltable.catch_sig to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([5 x i8]* @.str.4 to i64), i64 ptrtoint ([9 x i32]* @reltable.catch_sig to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([4 x i8]* @.str.3 to i64), i64 ptrtoint ([9 x i32]* @reltable.catch_sig to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([4 x i8]* @.str.2 to i64), i64 ptrtoint ([9 x i32]* @reltable.catch_sig to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([5 x i8]* @.str.1 to i64), i64 ptrtoint ([9 x i32]* @reltable.catch_sig to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([5 x i8]* @.str to i64), i64 ptrtoint ([9 x i32]* @reltable.catch_sig to i64)) to i32)]
define void @catch_sig(i32 %0) {
%2 = alloca [23 x i8]
%3 = getelementptr inbounds [23 x i8], [23 x i8]* %2, i64 0, i64 0
%4 = add i32 %0, -128
%5 = icmp ult i32 %4, 9
br i1 %5, label %6, label %10
6: ; preds = %1
%7 = sext i32 %4 to i64
%8 = shl i64 %7, 2
%9 = call i8* @llvm.load.relative.i64(i8* bitcast ([9 x i32]* @reltable.catch_sig to i8*), i64 %8)
br label %10
10: ; preds = %1, %6
%11 = phi i8* [ %9, %6 ], [ getelementptr inbounds ([15 x i8], [15 x i8]* @.str.9, i64 0, i64 0), %1 ]
%12 = tail call i32 @strlen(i8* %11)
%13 = getelementptr inbounds [23 x i8], [23 x i8]* %2, i64 0, i64 7
%14 = call i32 @memcpy(i8* %13, i8* %11, i32 %12)
%15 = add nsw i32 %12, 7
%16 = add nsw i32 %12, 8
%17 = sext i32 %15 to i64
%18 = getelementptr inbounds [23 x i8], [23 x i8]* %2, i64 0, i64 %17
store i8 10, i8* %18
%19 = call i32 @write(i32 1, i8* %3, i32 %16)
%20 = icmp eq i32 %0, 135
br i1 %20, label %23, label %21
21: ; preds = %10
%22 = call i32 @_exit(i32 1)
unreachable
23: ; preds = %10
ret void
}