#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 135
#define SIGBUS 134
#define SIGFPE 133
#define SIGILL 132
#define SIGPIPE 131
#define SIGSEGV 130
#define SIGSYS 129
#define SIGTERM 128
int /*<<< orphan*/ access_log_dump_entry();
int /*<<< orphan*/ access_log_set_flags(int);
int /*<<< orphan*/ debug_log_puts(char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ send_error(int, char *, int /*<<< orphan*/ *, char *);
void sigcatch(int sig) {
  static int must_abort = 0;
  long long int sigflag;
  if (must_abort != 0)
    exit(100);
  switch (sig) {
  case SIGALRM:
    access_log_set_flags(1 << 17);
    access_log_dump_entry();
    send_error(408, "Request Timeout", NULL, "Request timed out.");
    break;
  case SIGPIPE:
    access_log_set_flags(1 << 12);
    debug_log_puts("ERROR: Pipe broken. Transfer interrupted.");
    return;
    break;
  case SIGSEGV:
  case SIGFPE:
  case SIGILL:
  case SIGBUS:
  case SIGSYS:
  case SIGTERM:
    must_abort = -1;
    switch (sig) {
    case SIGSEGV:
      sigflag = 1 << 21;
      break;
    case SIGFPE:
      sigflag = 1 << 22;
      break;
    case SIGILL:
      sigflag = 1 << 23;
      break;
    case SIGBUS:
      sigflag = 1 << 24;
      break;
    case SIGSYS:
      sigflag = 1 << 25;
      break;
    case SIGTERM:
      sigflag = 1 << 26;
      break;
    }
    access_log_set_flags(sigflag);
    access_log_dump_entry();
    exit(100);
    break;
  default:
    access_log_set_flags(1 << 9);
    access_log_dump_entry();
    exit(100);
    break;
  }
}


x86 assembly (clang, -O0):
<sigcatch>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
cmpl   $0x0,0x2eea(%rip)
je     1172 <sigcatch+0x22>
mov    $0x64,%edi
call   1060 <exit@plt>
mov    -0x4(%rbp),%eax
mov    %eax,-0x14(%rbp)
add    $0xffffff80,%eax
sub    $0x3,%eax
jb     1212 <sigcatch+0xc2>
jmp    1189 <sigcatch+0x39>
mov    -0x14(%rbp),%eax
sub    $0x83,%eax
je     11f7 <sigcatch+0xa7>
jmp    119c <sigcatch+0x4c>
mov    -0x14(%rbp),%eax
add    $0xffffff7c,%eax
sub    $0x3,%eax
jb     1212 <sigcatch+0xc2>
jmp    11b2 <sigcatch+0x62>
mov    -0x14(%rbp),%eax
sub    $0x87,%eax
jne    12aa <sigcatch+0x15a>
jmp    11c5 <sigcatch+0x75>
mov    $0x20000,%edi
call   1030 <access_log_set_flags@plt>
mov    $0x0,%al
call   1050 <access_log_dump_entry@plt>
mov    $0x198,%edi
lea    0xe3a(%rip),%rsi
xor    %eax,%eax
mov    %eax,%edx
lea    0xe3f(%rip),%rcx
call   1040 <send_error@plt>
jmp    12c5 <sigcatch+0x175>
mov    $0x1000,%edi
call   1030 <access_log_set_flags@plt>
lea    0xe37(%rip),%rdi
call   1070 <debug_log_puts@plt>
jmp    12c5 <sigcatch+0x175>
movl   $0xffffffff,0x2e30(%rip)
ff ff ff
mov    -0x4(%rbp),%eax
add    $0xffffff80,%eax
mov    %eax,%ecx
mov    %rcx,-0x20(%rbp)
sub    $0x6,%eax
ja     128e <sigcatch+0x13e>
mov    -0x20(%rbp),%rax
lea    0xdc4(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movq   $0x200000,-0x10(%rbp)
jmp    128e <sigcatch+0x13e>
movq   $0x400000,-0x10(%rbp)
jmp    128e <sigcatch+0x13e>
movq   $0x800000,-0x10(%rbp)
jmp    128e <sigcatch+0x13e>
movq   $0x1000000,-0x10(%rbp)
01
jmp    128e <sigcatch+0x13e>
movq   $0x2000000,-0x10(%rbp)
02
jmp    128e <sigcatch+0x13e>
movq   $0x4000000,-0x10(%rbp)
04
mov    -0x10(%rbp),%rax
mov    %eax,%edi
call   1030 <access_log_set_flags@plt>
mov    $0x0,%al
call   1050 <access_log_dump_entry@plt>
mov    $0x64,%edi
call   1060 <exit@plt>
mov    $0x200,%edi
call   1030 <access_log_set_flags@plt>
mov    $0x0,%al
call   1050 <access_log_dump_entry@plt>
mov    $0x64,%edi
call   1060 <exit@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sigcatch>:
push   %rax
cmpb   $0x1,0x2ef4(%rip)
je     11e0 <sigcatch+0x90>
add    $0xffffff80,%edi
cmp    $0x7,%edi
ja     11ea <sigcatch+0x9a>
cmp    $0x3,%edi
je     11a0 <sigcatch+0x50>
cmp    $0x7,%edi
jne    11b7 <sigcatch+0x67>
mov    $0x20000,%edi
call   1030 <access_log_set_flags@plt>
xor    %eax,%eax
call   1050 <access_log_dump_entry@plt>
lea    0xe74(%rip),%rsi
lea    0xe7d(%rip),%rcx
mov    $0x198,%edi
xor    %edx,%edx
pop    %rax
jmp    1040 <send_error@plt>
mov    $0x1000,%edi
call   1030 <access_log_set_flags@plt>
lea    0xe72(%rip),%rdi
pop    %rax
jmp    1070 <debug_log_puts@plt>
movb   $0x1,0x2e8e(%rip)
mov    $0x200000,%eax
jae    11d2 <sigcatch+0x82>
movslq %edi,%rax
lea    0xe81(%rip),%rcx
mov    (%rcx,%rax,4),%eax
mov    %eax,%edi
call   1030 <access_log_set_flags@plt>
xor    %eax,%eax
call   1050 <access_log_dump_entry@plt>
mov    $0x64,%edi
call   1060 <exit@plt>
mov    $0x200,%edi
jmp    11d4 <sigcatch+0x84>

LLVM IR (-O0):
@sigcatch.must_abort = internal global i32 0
@.str = [16 x i8] c"Request Timeout\00"
@.str.1 = [19 x i8] c"Request timed out.\00"
@.str.2 = [42 x i8] c"ERROR: Pipe broken. Transfer interrupted.\00"
define void @sigcatch(i32 %0) {
%2 = alloca i32
%3 = alloca i64
store i32 %0, i32* %2
%4 = load i32, i32* @sigcatch.must_abort
%5 = icmp ne i32 %4, 0
br i1 %5, label %6, label %8
6: ; preds = %1
%7 = call i32 @exit(i32 100)
unreachable
8: ; preds = %1
%9 = load i32, i32* %2
switch i32 %9, label %31 [
i32 135, label %10
i32 131, label %14
i32 130, label %17
i32 133, label %17
i32 132, label %17
i32 134, label %17
i32 129, label %17
i32 128, label %17
]
10: ; preds = %8
%11 = call i32 @access_log_set_flags(i32 131072)
%12 = call i32 (...) @access_log_dump_entry()
%13 = call i32 @send_error(i32 408, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32* null, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
br label %35
14: ; preds = %8
%15 = call i32 @access_log_set_flags(i32 4096)
%16 = call i32 @debug_log_puts(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0))
br label %35
17: ; preds = %8, %8, %8, %8, %8, %8
store i32 -1, i32* @sigcatch.must_abort
%18 = load i32, i32* %2
switch i32 %18, label %25 [
i32 130, label %19
i32 133, label %20
i32 132, label %21
i32 134, label %22
i32 129, label %23
i32 128, label %24
]
19: ; preds = %17
store i64 2097152, i64* %3
br label %25
20: ; preds = %17
store i64 4194304, i64* %3
br label %25
21: ; preds = %17
store i64 8388608, i64* %3
br label %25
22: ; preds = %17
store i64 16777216, i64* %3
br label %25
23: ; preds = %17
store i64 33554432, i64* %3
br label %25
24: ; preds = %17
store i64 67108864, i64* %3
br label %25
25: ; preds = %17, %24, %23, %22, %21, %20, %19
%26 = load i64, i64* %3
%27 = trunc i64 %26 to i32
%28 = call i32 @access_log_set_flags(i32 %27)
%29 = call i32 (...) @access_log_dump_entry()
%30 = call i32 @exit(i32 100)
unreachable
31: ; preds = %8
%32 = call i32 @access_log_set_flags(i32 512)
%33 = call i32 (...) @access_log_dump_entry()
%34 = call i32 @exit(i32 100)
unreachable
35: ; preds = %14, %10
ret void
}

LLVM IR (-O2):
@sigcatch.must_abort = internal unnamed_addr global i1 false
@.str = [16 x i8] c"Request Timeout\00"
@.str.1 = [19 x i8] c"Request timed out.\00"
@.str.2 = [42 x i8] c"ERROR: Pipe broken. Transfer interrupted.\00"
@switch.table.sigcatch = [7 x i32] [i32 67108864, i32 33554432, i32 2097152, i32 2097152, i32 8388608, i32 4194304, i32 16777216]
define void @sigcatch(i32 %0) {
%2 = load i1, i1* @sigcatch.must_abort
br i1 %2, label %3, label %5
3: ; preds = %1
%4 = tail call i32 @exit(i32 100)
unreachable
5: ; preds = %1
switch i32 %0, label %25 [
i32 135, label %6
i32 131, label %10
i32 130, label %13
i32 133, label %13
i32 132, label %13
i32 134, label %13
i32 129, label %13
i32 128, label %13
]
6: ; preds = %5
%7 = tail call i32 @access_log_set_flags(i32 131072)
%8 = tail call i32 (...) @access_log_dump_entry()
%9 = tail call i32 @send_error(i32 408, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32* null, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
br label %29
10: ; preds = %5
%11 = tail call i32 @access_log_set_flags(i32 4096)
%12 = tail call i32 @debug_log_puts(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0))
br label %29
13: ; preds = %5, %5, %5, %5, %5, %5
store i1 true, i1* @sigcatch.must_abort
%14 = add i32 %0, -128
%15 = icmp ult i32 %14, 7
br i1 %15, label %16, label %20
16: ; preds = %13
%17 = sext i32 %14 to i64
%18 = getelementptr inbounds [7 x i32], [7 x i32]* @switch.table.sigcatch, i64 0, i64 %17
%19 = load i32, i32* %18
br label %20
20: ; preds = %16, %13
%21 = phi i32 [ 2097152, %13 ], [ %19, %16 ]
%22 = tail call i32 @access_log_set_flags(i32 %21)
%23 = tail call i32 (...) @access_log_dump_entry()
%24 = tail call i32 @exit(i32 100)
unreachable
25: ; preds = %5
%26 = tail call i32 @access_log_set_flags(i32 512)
%27 = tail call i32 (...) @access_log_dump_entry()
%28 = tail call i32 @exit(i32 100)
unreachable
29: ; preds = %6, %10
ret void
}