#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 */
typedef int pid_t;

/* Variables and functions */
int /*<<< orphan*/ O_WRONLY;
scalar_t__ WEXITSTATUS(int);
scalar_t__ WIFEXITED(int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ execl(char *, char *, int /*<<< orphan*/ *);
int fork();
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ panic(char *);
int /*<<< orphan*/ puts(char *);
scalar_t__ waitpid(int, int *, int /*<<< orphan*/);
int write(int, char *, int);
void launch_tests(void) {
  int status, fd;
  pid_t pid;
  puts("\x1b[32m\x1b[1m"
       "[+] Launching tests..."
       "\x1b[0m");
  pid = fork();
  if (pid == -1)
    panic("fork");
  else if (pid == 0) {
    execl("/init.sh", "init", NULL);
    panic("exec");
  }
  if (waitpid(pid, &status, 0) < 0)
    panic("waitpid");
  if (WIFEXITED(status) && WEXITSTATUS(status) == 0) {
    puts("\x1b[32m\x1b[1m"
         "[+] Tests successful! :-)"
         "\x1b[0m");
    fd = open("/dev/vport1p1", O_WRONLY);
    if (fd < 0)
      panic("open(vport1p1)");
    if (write(fd, "success\n", 8) != 8)
      panic("write(success)");
    close(fd);
  } else
    puts("\x1b[31m\x1b[1m[-] Tests failed! :-(\x1b[0m");
}


x86 assembly (clang, -O0):
<launch_tests>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xe51(%rip),%rdi
call   1030 <puts@plt>
mov    $0x0,%al
call   10c0 <fork@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0xffffffff,-0xc(%rbp)
jne    11d9 <launch_tests+0x39>
lea    0xe55(%rip),%rdi
call   1050 <panic@plt>
jmp    120b <launch_tests+0x6b>
cmpl   $0x0,-0xc(%rbp)
jne    1206 <launch_tests+0x66>
lea    0xe3f(%rip),%rdi
lea    0xe41(%rip),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   10b0 <execl@plt>
lea    0xe36(%rip),%rdi
call   1050 <panic@plt>
jmp    120b <launch_tests+0x6b>
mov    -0xc(%rbp),%edi
lea    -0x4(%rbp),%rsi
xor    %edx,%edx
call   1080 <waitpid@plt>
cmp    $0x0,%rax
jge    122f <launch_tests+0x8f>
lea    0xe12(%rip),%rdi
call   1050 <panic@plt>
mov    -0x4(%rbp),%edi
call   10a0 <WIFEXITED@plt>
cmp    $0x0,%rax
je     12c3 <launch_tests+0x123>
mov    -0x4(%rbp),%edi
call   1070 <WEXITSTATUS@plt>
cmp    $0x0,%rax
jne    12c3 <launch_tests+0x123>
lea    0xdea(%rip),%rdi
call   1030 <puts@plt>
mov    0x2d72(%rip),%rax
mov    (%rax),%esi
lea    0xdfc(%rip),%rdi
call   1090 <open@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    128d <launch_tests+0xed>
lea    0xdf1(%rip),%rdi
call   1050 <panic@plt>
mov    -0x8(%rbp),%edi
lea    0xdf1(%rip),%rsi
mov    $0x8,%edx
call   1040 <write@plt>
cmp    $0x8,%eax
je     12b6 <launch_tests+0x116>
lea    0xde0(%rip),%rdi
call   1050 <panic@plt>
mov    -0x8(%rbp),%edi
call   1060 <close@plt>
jmp    12cf <launch_tests+0x12f>
lea    0xdd6(%rip),%rdi
call   1030 <puts@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<launch_tests>:
push   %rbx
sub    $0x10,%rsp
lea    0xe54(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   10c0 <fork@plt>
mov    %eax,%ebx
cmp    $0xffffffff,%eax
je     11e1 <launch_tests+0x41>
test   %ebx,%ebx
jne    11ed <launch_tests+0x4d>
lea    0xe5f(%rip),%rdi
lea    0xe61(%rip),%rsi
xor    %edx,%edx
call   10b0 <execl@plt>
lea    0xe58(%rip),%rdi
jmp    11e8 <launch_tests+0x48>
lea    0xe3c(%rip),%rdi
call   1050 <panic@plt>
lea    0xc(%rsp),%rsi
mov    %ebx,%edi
xor    %edx,%edx
call   1080 <waitpid@plt>
test   %rax,%rax
jns    120c <launch_tests+0x6c>
lea    0xe35(%rip),%rdi
call   1050 <panic@plt>
mov    0xc(%rsp),%edi
call   10a0 <WIFEXITED@plt>
test   %rax,%rax
je     1228 <launch_tests+0x88>
mov    0xc(%rsp),%edi
call   1070 <WEXITSTATUS@plt>
test   %rax,%rax
je     1236 <launch_tests+0x96>
lea    0xe71(%rip),%rdi
call   1030 <puts@plt>
jmp    1294 <launch_tests+0xf4>
lea    0xe07(%rip),%rdi
call   1030 <puts@plt>
mov    0x2d8f(%rip),%rax
mov    (%rax),%esi
lea    0xe19(%rip),%rdi
call   1090 <open@plt>
mov    %eax,%ebx
test   %eax,%eax
jns    1269 <launch_tests+0xc9>
lea    0xe15(%rip),%rdi
call   1050 <panic@plt>
lea    0xe18(%rip),%rsi
mov    %ebx,%edi
mov    $0x8,%edx
call   1040 <write@plt>
cmp    $0x8,%eax
je     128d <launch_tests+0xed>
lea    0xe09(%rip),%rdi
call   1050 <panic@plt>
mov    %ebx,%edi
call   1060 <close@plt>
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [36 x i8] c"\1B[32m\1B[1m[+] Launching tests...\1B[0m\00"
@.str.1 = [5 x i8] c"fork\00"
@.str.2 = [9 x i8] c"/init.sh\00"
@.str.3 = [5 x i8] c"init\00"
@.str.4 = [5 x i8] c"exec\00"
@.str.5 = [8 x i8] c"waitpid\00"
@.str.6 = [39 x i8] c"\1B[32m\1B[1m[+] Tests successful! :-)\1B[0m\00"
@.str.7 = [14 x i8] c"/dev/vport1p1\00"
@O_WRONLY = global i32 0
@.str.8 = [15 x i8] c"open(vport1p1)\00"
@.str.9 = [9 x i8] c"success\0A\00"
@.str.10 = [15 x i8] c"write(success)\00"
@.str.11 = [35 x i8] c"\1B[31m\1B[1m[-] Tests failed! :-(\1B[0m\00"
define void @launch_tests() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = call i32 @puts(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
%5 = call i32 (...) @fork()
store i32 %5, i32* %3
%6 = load i32, i32* %3
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %10
8: ; preds = %0
%9 = call i32 @panic(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %17
10: ; preds = %0
%11 = load i32, i32* %3
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %10
%14 = call i32 @execl(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32* null)
%15 = call i32 @panic(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
br label %16
16: ; preds = %13, %10
br label %17
17: ; preds = %16, %8
%18 = load i32, i32* %3
%19 = call i64 @waitpid(i32 %18, i32* %1, i32 0)
%20 = icmp slt i64 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %17
%22 = call i32 @panic(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0))
br label %23
23: ; preds = %21, %17
%24 = load i32, i32* %1
%25 = call i64 @WIFEXITED(i32 %24)
%26 = icmp ne i64 %25, 0
br i1 %26, label %27, label %48
27: ; preds = %23
%28 = load i32, i32* %1
%29 = call i64 @WEXITSTATUS(i32 %28)
%30 = icmp eq i64 %29, 0
br i1 %30, label %31, label %48
31: ; preds = %27
%32 = call i32 @puts(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.6, i64 0, i64 0))
%33 = load i32, i32* @O_WRONLY
%34 = call i32 @open(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.7, i64 0, i64 0), i32 %33)
store i32 %34, i32* %2
%35 = load i32, i32* %2
%36 = icmp slt i32 %35, 0
br i1 %36, label %37, label %39
37: ; preds = %31
%38 = call i32 @panic(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.8, i64 0, i64 0))
br label %39
39: ; preds = %37, %31
%40 = load i32, i32* %2
%41 = call i32 @write(i32 %40, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.9, i64 0, i64 0), i32 8)
%42 = icmp ne i32 %41, 8
br i1 %42, label %43, label %45
43: ; preds = %39
%44 = call i32 @panic(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.10, i64 0, i64 0))
br label %45
45: ; preds = %43, %39
%46 = load i32, i32* %2
%47 = call i32 @close(i32 %46)
br label %50
48: ; preds = %27, %23
%49 = call i32 @puts(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.11, i64 0, i64 0))
br label %50
50: ; preds = %48, %45
ret void
}

LLVM IR (-O2):
@.str = [36 x i8] c"\1B[32m\1B[1m[+] Launching tests...\1B[0m\00"
@.str.1 = [5 x i8] c"fork\00"
@.str.2 = [9 x i8] c"/init.sh\00"
@.str.3 = [5 x i8] c"init\00"
@.str.4 = [5 x i8] c"exec\00"
@.str.5 = [8 x i8] c"waitpid\00"
@.str.6 = [39 x i8] c"\1B[32m\1B[1m[+] Tests successful! :-)\1B[0m\00"
@.str.7 = [14 x i8] c"/dev/vport1p1\00"
@O_WRONLY = global i32 0
@.str.8 = [15 x i8] c"open(vport1p1)\00"
@.str.9 = [9 x i8] c"success\0A\00"
@.str.10 = [15 x i8] c"write(success)\00"
@.str.11 = [35 x i8] c"\1B[31m\1B[1m[-] Tests failed! :-(\1B[0m\00"
define void @launch_tests() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
%4 = tail call i32 (...) @fork()
switch i32 %4, label %10 [
i32 -1, label %7
i32 0, label %5
]
5: ; preds = %0
%6 = tail call i32 @execl(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32* null)
br label %7
7: ; preds = %0, %5
%8 = phi i8* [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), %5 ], [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), %0 ]
%9 = tail call i32 @panic(i8* %8)
br label %10
10: ; preds = %7, %0
%11 = call i64 @waitpid(i32 %4, i32* %1, i32 0)
%12 = icmp slt i64 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %10
%14 = call i32 @panic(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0))
br label %15
15: ; preds = %13, %10
%16 = load i32, i32* %1
%17 = call i64 @WIFEXITED(i32 %16)
%18 = icmp eq i64 %17, 0
br i1 %18, label %37, label %19
19: ; preds = %15
%20 = load i32, i32* %1
%21 = call i64 @WEXITSTATUS(i32 %20)
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %37
23: ; preds = %19
%24 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @.str.6, i64 0, i64 0))
%25 = load i32, i32* @O_WRONLY
%26 = call i32 @open(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.7, i64 0, i64 0), i32 %25)
%27 = icmp slt i32 %26, 0
br i1 %27, label %28, label %30
28: ; preds = %23
%29 = call i32 @panic(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.8, i64 0, i64 0))
br label %30
30: ; preds = %28, %23
%31 = call i32 @write(i32 %26, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.9, i64 0, i64 0), i32 8)
%32 = icmp eq i32 %31, 8
br i1 %32, label %35, label %33
33: ; preds = %30
%34 = call i32 @panic(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.10, i64 0, i64 0))
br label %35
35: ; preds = %33, %30
%36 = call i32 @close(i32 %26)
br label %39
37: ; preds = %19, %15
%38 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.11, i64 0, i64 0))
br label %39
39: ; preds = %37, %35
ret void
}