#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 */
scalar_t__ WEXITSTATUS(int);
scalar_t__ WIFEXITED(int);
scalar_t__ WIFSIGNALED(int);
scalar_t__ fork();
int /*<<< orphan*/ print(int, char *, int);
int /*<<< orphan*/ sf_print_signals(int);
int /*<<< orphan*/ sf_shild(int (*)());
int /*<<< orphan*/ wait(int *);
int /*<<< orphan*/ write(int, char *, int);
int call_test(int (*test_func)(void), int expected_status) {
  int out;
  int state;
  out = 1;
  if (fork() == 0)
    sf_shild(test_func);
  else {
    wait(&state);
    write(1, (out = !(state == expected_status)) ? "\033[31m" : "\033[32m", 5);
    if (WIFSIGNALED(state))
      sf_print_signals(state);
    else if (WIFEXITED(state))
      print(1, WEXITSTATUS(state) ? "[KO]" : "[OK]", 4);
    else
      print(1, "[STOPED]", 8);
    write(1, "\033[0m", 5);
  }
  return (out);
}


x86 assembly (clang, -O0):
<call_test>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x1,-0x10(%rbp)
mov    $0x0,%al
call   10b0 <fork@plt>
cmp    $0x0,%rax
jne    11c5 <call_test+0x35>
mov    -0x8(%rbp),%rdi
call   1070 <sf_shild@plt>
jmp    129f <call_test+0x10f>
lea    -0x14(%rbp),%rdi
call   10a0 <wait@plt>
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
sete   %cl
xor    $0xff,%cl
mov    %cl,%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x10(%rbp)
lea    0xe1b(%rip),%rsi
lea    0xe0e(%rip),%rax
test   $0x1,%cl
cmovne %rax,%rsi
mov    $0x1,%edi
mov    $0x5,%edx
call   1030 <write@plt>
mov    -0x14(%rbp),%edi
call   1060 <WIFSIGNALED@plt>
cmp    $0x0,%rax
je     1227 <call_test+0x97>
mov    -0x14(%rbp),%edi
call   1040 <sf_print_signals@plt>
jmp    1289 <call_test+0xf9>
mov    -0x14(%rbp),%edi
call   1090 <WIFEXITED@plt>
cmp    $0x0,%rax
je     126e <call_test+0xde>
mov    -0x14(%rbp),%edi
call   1080 <WEXITSTATUS@plt>
mov    %rax,%rcx
lea    0xdc6(%rip),%rsi
lea    0xdba(%rip),%rax
cmp    $0x0,%rcx
cmovne %rax,%rsi
mov    $0x1,%edi
mov    $0x4,%edx
call   1050 <print@plt>
jmp    1284 <call_test+0xf4>
mov    $0x1,%edi
lea    0xd9c(%rip),%rsi
mov    $0x8,%edx
call   1050 <print@plt>
jmp    1289 <call_test+0xf9>
mov    $0x1,%edi
lea    0xd8a(%rip),%rsi
mov    $0x5,%edx
call   1030 <write@plt>
mov    -0x10(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<call_test>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%rbx
xor    %eax,%eax
call   10b0 <fork@plt>
test   %rax,%rax
je     11f2 <call_test+0x62>
lea    0x4(%rsp),%rdi
call   10a0 <wait@plt>
xor    %ebx,%ebx
cmp    %ebp,0x4(%rsp)
setne  %bpl
lea    0xe41(%rip),%rax
lea    0xe40(%rip),%rsi
cmovne %rax,%rsi
mov    $0x1,%edi
mov    $0x5,%edx
call   1030 <write@plt>
mov    0x4(%rsp),%edi
call   1060 <WIFSIGNALED@plt>
mov    0x4(%rsp),%edi
test   %rax,%rax
je     1201 <call_test+0x71>
call   1040 <sf_print_signals@plt>
jmp    124b <call_test+0xbb>
mov    %rbx,%rdi
call   1070 <sf_shild@plt>
mov    $0x1,%ebx
jmp    1264 <call_test+0xd4>
call   1090 <WIFEXITED@plt>
test   %rax,%rax
je     1235 <call_test+0xa5>
mov    0x4(%rsp),%edi
call   1080 <WEXITSTATUS@plt>
test   %rax,%rax
lea    0xdf3(%rip),%rax
lea    0xde7(%rip),%rsi
cmove  %rax,%rsi
mov    $0x1,%edi
mov    $0x4,%edx
jmp    1246 <call_test+0xb6>
lea    0xdda(%rip),%rsi
mov    $0x1,%edi
mov    $0x8,%edx
call   1050 <print@plt>
mov    %bpl,%bl
lea    0xdca(%rip),%rsi
mov    $0x1,%edi
mov    $0x5,%edx
call   1030 <write@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [6 x i8] c"\1B[31m\00"
@.str.1 = [6 x i8] c"\1B[32m\00"
@.str.2 = [5 x i8] c"[KO]\00"
@.str.3 = [5 x i8] c"[OK]\00"
@.str.4 = [9 x i8] c"[STOPED]\00"
@.str.5 = [5 x i8] c"\1B[0m\00"
define i32 @call_test(i32 ()* %0, i32 %1) {
%3 = alloca i32 ()*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 ()* %0, i32 ()** %3
store i32 %1, i32* %4
store i32 1, i32* %5
%7 = call i64 (...) @fork()
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %13
9: ; preds = %2
%10 = load i32 ()*, i32 ()** %3
%11 = bitcast i32 ()* %10 to i32 (...)*
%12 = call i32 @sf_shild(i32 (...)* %11)
br label %45
13: ; preds = %2
%14 = call i32 @wait(i32* %6)
%15 = load i32, i32* %6
%16 = load i32, i32* %4
%17 = icmp eq i32 %15, %16
%18 = xor i1 %17, true
%19 = zext i1 %18 to i32
store i32 %19, i32* %5
%20 = zext i1 %18 to i64
%21 = select i1 %18, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0)
%22 = call i32 @write(i32 1, i8* %21, i32 5)
%23 = load i32, i32* %6
%24 = call i64 @WIFSIGNALED(i32 %23)
%25 = icmp ne i64 %24, 0
br i1 %25, label %26, label %29
26: ; preds = %13
%27 = load i32, i32* %6
%28 = call i32 @sf_print_signals(i32 %27)
br label %43
29: ; preds = %13
%30 = load i32, i32* %6
%31 = call i64 @WIFEXITED(i32 %30)
%32 = icmp ne i64 %31, 0
br i1 %32, label %33, label %40
33: ; preds = %29
%34 = load i32, i32* %6
%35 = call i64 @WEXITSTATUS(i32 %34)
%36 = icmp ne i64 %35, 0
%37 = zext i1 %36 to i64
%38 = select i1 %36, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0)
%39 = call i32 @print(i32 1, i8* %38, i32 4)
br label %42
40: ; preds = %29
%41 = call i32 @print(i32 1, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i32 8)
br label %42
42: ; preds = %40, %33
br label %43
43: ; preds = %42, %26
%44 = call i32 @write(i32 1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i32 5)
br label %45
45: ; preds = %43, %9
%46 = load i32, i32* %5
ret i32 %46
}

LLVM IR (-O2):
@.str = [6 x i8] c"\1B[31m\00"
@.str.1 = [6 x i8] c"\1B[32m\00"
@.str.2 = [5 x i8] c"[KO]\00"
@.str.3 = [5 x i8] c"[OK]\00"
@.str.4 = [9 x i8] c"[STOPED]\00"
@.str.5 = [5 x i8] c"\1B[0m\00"
define i32 @call_test(i32 ()* %0, i32 %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = tail call i64 (...) @fork()
%6 = icmp eq i64 %5, 0
br i1 %6, label %7, label %10
7: ; preds = %2
%8 = bitcast i32 ()* %0 to i32 (...)*
%9 = tail call i32 @sf_shild(i32 (...)* %8)
br label %36
10: ; preds = %2
%11 = call i32 @wait(i32* %3)
%12 = load i32, i32* %3
%13 = icmp ne i32 %12, %1
%14 = zext i1 %13 to i32
%15 = select i1 %13, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0)
%16 = call i32 @write(i32 1, i8* %15, i32 5)
%17 = load i32, i32* %3
%18 = call i64 @WIFSIGNALED(i32 %17)
%19 = icmp eq i64 %18, 0
%20 = load i32, i32* %3
br i1 %19, label %23, label %21
21: ; preds = %10
%22 = call i32 @sf_print_signals(i32 %20)
br label %34
23: ; preds = %10
%24 = call i64 @WIFEXITED(i32 %20)
%25 = icmp eq i64 %24, 0
br i1 %25, label %32, label %26
26: ; preds = %23
%27 = load i32, i32* %3
%28 = call i64 @WEXITSTATUS(i32 %27)
%29 = icmp eq i64 %28, 0
%30 = select i1 %29, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0)
%31 = call i32 @print(i32 1, i8* %30, i32 4)
br label %34
32: ; preds = %23
%33 = call i32 @print(i32 1, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i32 8)
br label %34
34: ; preds = %26, %32, %21
%35 = call i32 @write(i32 1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i32 5)
br label %36
36: ; preds = %34, %7
%37 = phi i32 [ 1, %7 ], [ %14, %34 ]
ret i32 %37
}