#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 SIGALRM;
int SIGCHLD;
int SIGHUP;
int SIGINT;
int SIGQUIT;
int SIGTSTP;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ sub_sigchld();
int /*<<< orphan*/ write(int, char *, int);
void ft_sighand(int sig) {
  if (sig == SIGCHLD)
    sub_sigchld();
  if (sig == SIGINT)
    write(1, "\033[2D\033[K\n\033[1m\033[35m42sh >\033[0m ", 28);
  if (sig == SIGTSTP)
    write(1, "\033[2D\033[K\007", 8);
  if (sig == SIGHUP) {
    write(1, "\033[7m%\033[0m\n", 10);
    exit(1);
  }
  if (sig == SIGALRM) {
    write(1, "\n42sh: timeout\n", 15);
    exit(0);
  }
  if (sig == SIGQUIT)
    write(1, "\033[2D\033[K\007", 8);
}


x86 assembly (clang, -O0):
<ft_sighand>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    0x2e83(%rip),%rcx
cmp    (%rcx),%eax
jne    1154 <ft_sighand+0x24>
mov    $0x0,%al
call   1040 <sub_sigchld@plt>
mov    -0x4(%rbp),%eax
mov    0x2e7a(%rip),%rcx
cmp    (%rcx),%eax
jne    117c <ft_sighand+0x4c>
mov    $0x1,%edi
lea    0xe8e(%rip),%rsi
mov    $0x1c,%edx
call   1030 <write@plt>
mov    -0x4(%rbp),%eax
mov    0x2e3a(%rip),%rcx
cmp    (%rcx),%eax
jne    11a4 <ft_sighand+0x74>
mov    $0x1,%edi
lea    0xe83(%rip),%rsi
mov    $0x8,%edx
call   1030 <write@plt>
mov    -0x4(%rbp),%eax
mov    0x2e42(%rip),%rcx
cmp    (%rcx),%eax
jne    11d6 <ft_sighand+0xa6>
mov    $0x1,%edi
lea    0xe64(%rip),%rsi
mov    $0xa,%edx
call   1030 <write@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
mov    -0x4(%rbp),%eax
mov    0x2e00(%rip),%rcx
cmp    (%rcx),%eax
jne    1205 <ft_sighand+0xd5>
mov    $0x1,%edi
lea    0xe3d(%rip),%rsi
mov    $0xf,%edx
call   1030 <write@plt>
xor    %edi,%edi
call   1050 <exit@plt>
mov    -0x4(%rbp),%eax
mov    0x2dc1(%rip),%rcx
cmp    (%rcx),%eax
jne    122d <ft_sighand+0xfd>
mov    $0x1,%edi
lea    0xdfa(%rip),%rsi
mov    $0x8,%edx
call   1030 <write@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ft_sighand>:
push   %rbx
mov    %edi,%ebx
mov    0x2e8e(%rip),%rax
cmp    %edi,(%rax)
jne    1145 <ft_sighand+0x15>
xor    %eax,%eax
call   1040 <sub_sigchld@plt>
mov    0x2e8c(%rip),%rax
cmp    %ebx,(%rax)
jne    1166 <ft_sighand+0x36>
lea    0xea9(%rip),%rsi
mov    $0x1,%edi
mov    $0x1c,%edx
call   1030 <write@plt>
mov    0x2e53(%rip),%rax
cmp    %ebx,(%rax)
jne    1187 <ft_sighand+0x57>
lea    0xea5(%rip),%rsi
mov    $0x1,%edi
mov    $0x8,%edx
call   1030 <write@plt>
mov    0x2e62(%rip),%rax
cmp    %ebx,(%rax)
je     11c1 <ft_sighand+0x91>
mov    0x2e47(%rip),%rax
cmp    %ebx,(%rax)
je     11e1 <ft_sighand+0xb1>
mov    0x2e2c(%rip),%rax
cmp    %ebx,(%rax)
jne    11bf <ft_sighand+0x8f>
lea    0xe6e(%rip),%rsi
mov    $0x1,%edi
mov    $0x8,%edx
pop    %rbx
jmp    1030 <write@plt>
pop    %rbx
ret
lea    0xe5e(%rip),%rsi
mov    $0x1,%edi
mov    $0xa,%edx
call   1030 <write@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
lea    0xe49(%rip),%rsi
mov    $0x1,%edi
mov    $0xf,%edx
call   1030 <write@plt>
xor    %edi,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@SIGCHLD = global i32 0
@SIGINT = global i32 0
@.str = [29 x i8] c"\1B[2D\1B[K\0A\1B[1m\1B[35m42sh >\1B[0m \00"
@SIGTSTP = global i32 0
@.str.1 = [9 x i8] c"\1B[2D\1B[K\07\00"
@SIGHUP = global i32 0
@.str.2 = [11 x i8] c"\1B[7m%\1B[0m\0A\00"
@SIGALRM = global i32 0
@.str.3 = [16 x i8] c"\0A42sh: timeout\0A\00"
@SIGQUIT = global i32 0
define void @ft_sighand(i32 %0) {
%2 = alloca i32
store i32 %0, i32* %2
%3 = load i32, i32* %2
%4 = load i32, i32* @SIGCHLD
%5 = icmp eq i32 %3, %4
br i1 %5, label %6, label %8
6: ; preds = %1
%7 = call i32 (...) @sub_sigchld()
br label %8
8: ; preds = %6, %1
%9 = load i32, i32* %2
%10 = load i32, i32* @SIGINT
%11 = icmp eq i32 %9, %10
br i1 %11, label %12, label %14
12: ; preds = %8
%13 = call i32 @write(i32 1, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i32 28)
br label %14
14: ; preds = %12, %8
%15 = load i32, i32* %2
%16 = load i32, i32* @SIGTSTP
%17 = icmp eq i32 %15, %16
br i1 %17, label %18, label %20
18: ; preds = %14
%19 = call i32 @write(i32 1, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 8)
br label %20
20: ; preds = %18, %14
%21 = load i32, i32* %2
%22 = load i32, i32* @SIGHUP
%23 = icmp eq i32 %21, %22
br i1 %23, label %24, label %27
24: ; preds = %20
%25 = call i32 @write(i32 1, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32 10)
%26 = call i32 @exit(i32 1)
unreachable
27: ; preds = %20
%28 = load i32, i32* %2
%29 = load i32, i32* @SIGALRM
%30 = icmp eq i32 %28, %29
br i1 %30, label %31, label %34
31: ; preds = %27
%32 = call i32 @write(i32 1, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i32 15)
%33 = call i32 @exit(i32 0)
unreachable
34: ; preds = %27
%35 = load i32, i32* %2
%36 = load i32, i32* @SIGQUIT
%37 = icmp eq i32 %35, %36
br i1 %37, label %38, label %40
38: ; preds = %34
%39 = call i32 @write(i32 1, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 8)
br label %40
40: ; preds = %38, %34
ret void
}

LLVM IR (-O2):
@SIGCHLD = global i32 0
@SIGINT = global i32 0
@.str = [29 x i8] c"\1B[2D\1B[K\0A\1B[1m\1B[35m42sh >\1B[0m \00"
@SIGTSTP = global i32 0
@.str.1 = [9 x i8] c"\1B[2D\1B[K\07\00"
@SIGHUP = global i32 0
@.str.2 = [11 x i8] c"\1B[7m%\1B[0m\0A\00"
@SIGALRM = global i32 0
@.str.3 = [16 x i8] c"\0A42sh: timeout\0A\00"
@SIGQUIT = global i32 0
define void @ft_sighand(i32 %0) {
%2 = load i32, i32* @SIGCHLD
%3 = icmp eq i32 %2, %0
br i1 %3, label %4, label %6
4: ; preds = %1
%5 = tail call i32 (...) @sub_sigchld()
br label %6
6: ; preds = %4, %1
%7 = load i32, i32* @SIGINT
%8 = icmp eq i32 %7, %0
br i1 %8, label %9, label %11
9: ; preds = %6
%10 = tail call i32 @write(i32 1, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i32 28)
br label %11
11: ; preds = %9, %6
%12 = load i32, i32* @SIGTSTP
%13 = icmp eq i32 %12, %0
br i1 %13, label %14, label %16
14: ; preds = %11
%15 = tail call i32 @write(i32 1, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 8)
br label %16
16: ; preds = %14, %11
%17 = load i32, i32* @SIGHUP
%18 = icmp eq i32 %17, %0
br i1 %18, label %19, label %22
19: ; preds = %16
%20 = tail call i32 @write(i32 1, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32 10)
%21 = tail call i32 @exit(i32 1)
unreachable
22: ; preds = %16
%23 = load i32, i32* @SIGALRM
%24 = icmp eq i32 %23, %0
br i1 %24, label %25, label %28
25: ; preds = %22
%26 = tail call i32 @write(i32 1, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i32 15)
%27 = tail call i32 @exit(i32 0)
unreachable
28: ; preds = %22
%29 = load i32, i32* @SIGQUIT
%30 = icmp eq i32 %29, %0
br i1 %30, label %31, label %33
31: ; preds = %28
%32 = tail call i32 @write(i32 1, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 8)
br label %33
33: ; preds = %31, %28
ret void
}