#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 SIGINT 130
#define SIGQUIT 129
#define SIGTERM 128
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ signal(int, void *);
int /*<<< orphan*/ stderr;
int sighandler(int signum) {
  switch (signum) {
  case SIGINT:
  case SIGTERM:
  case SIGQUIT:
    fprintf(stderr,
            "owfs-tlm"
            " Shutting down on signal %d\n",
            signum);
    exit(0);
  default:
    fprintf(stderr,
            "owfs-tlm"
            " SIG %d ignored\n",
            signum);
    break;
  }
  signal(signum, (void *)sighandler);
  return 0;
}


x86 assembly (clang, -O0):
<sighandler>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xffffff80,%eax
sub    $0x2,%eax
ja     116e <sighandler+0x3e>
jmp    114f <sighandler+0x1f>
mov    0x2e82(%rip),%rax
mov    (%rax),%edi
mov    -0x4(%rbp),%edx
lea    0xe9e(%rip),%rsi
call   1040 <fprintf@plt>
xor    %edi,%edi
call   1050 <exit@plt>
mov    0x2e63(%rip),%rax
mov    (%rax),%edi
mov    -0x4(%rbp),%edx
lea    0xea4(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0x4(%rbp),%edi
mov    0x2e58(%rip),%rsi
call   1030 <signal@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sighandler>:
push   %rbx
mov    %edi,%ebx
lea    -0x80(%rbx),%eax
mov    0x2e9b(%rip),%rcx
mov    (%rcx),%edi
cmp    $0x2,%eax
jbe    1164 <sighandler+0x34>
lea    0xeda(%rip),%rsi
mov    %ebx,%edx
call   1040 <fprintf@plt>
mov    0x2e8f(%rip),%rsi
mov    %ebx,%edi
call   1030 <signal@plt>
xor    %eax,%eax
pop    %rbx
ret
lea    0xe95(%rip),%rsi
mov    %ebx,%edx
call   1040 <fprintf@plt>
xor    %edi,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [37 x i8] c"owfs-tlm Shutting down on signal %d\0A\00"
@.str.1 = [25 x i8] c"owfs-tlm SIG %d ignored\0A\00"
define i32 @sighandler(i32 %0) {
%2 = alloca i32
store i32 %0, i32* %2
%3 = load i32, i32* %2
switch i32 %3, label %9 [
i32 130, label %4
i32 128, label %4
i32 129, label %4
]
4: ; preds = %1, %1, %1
%5 = load i32, i32* @stderr
%6 = load i32, i32* %2
%7 = call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i32 %6)
%8 = call i32 @exit(i32 0)
unreachable
9: ; preds = %1
%10 = load i32, i32* @stderr
%11 = load i32, i32* %2
%12 = call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i32 %11)
br label %13
13: ; preds = %9
%14 = load i32, i32* %2
%15 = call i32 @signal(i32 %14, i8* bitcast (i32 (i32)* @sighandler to i8*))
ret i32 0
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [37 x i8] c"owfs-tlm Shutting down on signal %d\0A\00"
@.str.1 = [25 x i8] c"owfs-tlm SIG %d ignored\0A\00"
define i32 @sighandler(i32 %0) {
%2 = add i32 %0, -128
%3 = icmp ult i32 %2, 3
%4 = load i32, i32* @stderr
br i1 %3, label %5, label %8
5: ; preds = %1
%6 = tail call i32 @fprintf(i32 %4, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i32 %0)
%7 = tail call i32 @exit(i32 0)
unreachable
8: ; preds = %1
%9 = tail call i32 @fprintf(i32 %4, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i32 %0)
%10 = tail call i32 @signal(i32 %0, i8* bitcast (i32 (i32)* @sighandler to i8*))
ret i32 0
}