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

/* Variables and functions */
scalar_t__ WEXITSTATUS(int);
scalar_t__ WIFEXITED(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fork();
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ wait(int *);
int split(int branch1, int branch2) {
  pid_t child_pid;
  pid_t wpid;
  int status = 0;
  if ((child_pid = fork()) > 0)
    while ((wpid = wait(&status)) > 0)
      ;
  else
    return branch1;
  if (WIFEXITED(status)) {
    if (WEXITSTATUS(status) == 0)
      exit(0);
    else
      ;
  } else {
    printf("Unexpected Error Case.\n");
    exit(1);
  }
  if ((child_pid = fork()) > 0)
    while ((wpid = wait(&status)) > 0)
      ;
  else
    return branch2;
  if (WIFEXITED(status)) {
    if (WEXITSTATUS(status) == 0)
      exit(0);
    else
      exit(1);
  } else {
    printf("Unexpected Error Case.\n");
    exit(1);
  }
}


x86 assembly (clang, -O0):
<split>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x18(%rbp)
mov    $0x0,%al
call   1080 <fork@plt>
mov    %eax,-0x10(%rbp)
cmp    $0x0,%eax
jle    11ac <split+0x4c>
jmp    118d <split+0x2d>
lea    -0x18(%rbp),%rdi
call   1070 <wait@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jle    11a7 <split+0x47>
jmp    118d <split+0x2d>
jmp    11b7 <split+0x57>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    128f <split+0x12f>
mov    -0x18(%rbp),%edi
call   1050 <WIFEXITED@plt>
cmp    $0x0,%rax
je     11ec <split+0x8c>
mov    -0x18(%rbp),%edi
call   1040 <WEXITSTATUS@plt>
cmp    $0x0,%rax
jne    11e2 <split+0x82>
xor    %edi,%edi
call   1060 <exit@plt>
jmp    11e7 <split+0x87>
jmp    1202 <split+0xa2>
lea    0xe0d(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    $0x0,%al
call   1080 <fork@plt>
mov    %eax,-0x10(%rbp)
cmp    $0x0,%eax
jle    1239 <split+0xd9>
jmp    121a <split+0xba>
lea    -0x18(%rbp),%rdi
call   1070 <wait@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jle    1234 <split+0xd4>
jmp    121a <split+0xba>
jmp    1244 <split+0xe4>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    128f <split+0x12f>
mov    -0x18(%rbp),%edi
call   1050 <WIFEXITED@plt>
cmp    $0x0,%rax
je     1279 <split+0x119>
mov    -0x18(%rbp),%edi
call   1040 <WEXITSTATUS@plt>
cmp    $0x0,%rax
jne    126f <split+0x10f>
xor    %edi,%edi
call   1060 <exit@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
lea    0xd80(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<split>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebx
mov    %edi,%ebp
movl   $0x0,0x4(%rsp)
xor    %eax,%eax
call   1080 <fork@plt>
test   %eax,%eax
jle    11b5 <split+0x55>
lea    0x4(%rsp),%rbp
nop
mov    %rbp,%rdi
call   1070 <wait@plt>
test   %eax,%eax
jg     1180 <split+0x20>
mov    0x4(%rsp),%edi
call   1050 <WIFEXITED@plt>
test   %rax,%rax
je     11ea <split+0x8a>
mov    0x4(%rsp),%edi
call   1040 <WEXITSTATUS@plt>
test   %rax,%rax
je     120e <split+0xae>
xor    %eax,%eax
call   1080 <fork@plt>
mov    %ebx,%ebp
test   %eax,%eax
jg     11be <split+0x5e>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
lea    0x4(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rbx,%rdi
call   1070 <wait@plt>
test   %eax,%eax
jg     11d0 <split+0x70>
mov    0x4(%rsp),%edi
call   1050 <WIFEXITED@plt>
test   %rax,%rax
jne    1200 <split+0xa0>
lea    0xe0f(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    0x4(%rsp),%edi
call   1040 <WEXITSTATUS@plt>
test   %rax,%rax
jne    1215 <split+0xb5>
xor    %edi,%edi
call   1060 <exit@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [24 x i8] c"Unexpected Error Case.\0A\00"
define i32 @split(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 0, i32* %8
%9 = call i32 (...) @fork()
store i32 %9, i32* %6
%10 = icmp sgt i32 %9, 0
br i1 %10, label %11, label %17
11: ; preds = %2
br label %12
12: ; preds = %15, %11
%13 = call i32 @wait(i32* %8)
store i32 %13, i32* %7
%14 = icmp sgt i32 %13, 0
br i1 %14, label %15, label %16
15: ; preds = %12
br label %12
16: ; preds = %12
br label %19
17: ; preds = %2
%18 = load i32, i32* %4
store i32 %18, i32* %3
br label %60
19: ; preds = %16
%20 = load i32, i32* %8
%21 = call i64 @WIFEXITED(i32 %20)
%22 = icmp ne i64 %21, 0
br i1 %22, label %23, label %31
23: ; preds = %19
%24 = load i32, i32* %8
%25 = call i64 @WEXITSTATUS(i32 %24)
%26 = icmp eq i64 %25, 0
br i1 %26, label %27, label %29
27: ; preds = %23
%28 = call i32 @exit(i32 0)
unreachable
29: ; preds = %23
br label %30
30: ; preds = %29
br label %34
31: ; preds = %19
%32 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
%33 = call i32 @exit(i32 1)
unreachable
34: ; preds = %30
%35 = call i32 (...) @fork()
store i32 %35, i32* %6
%36 = icmp sgt i32 %35, 0
br i1 %36, label %37, label %43
37: ; preds = %34
br label %38
38: ; preds = %41, %37
%39 = call i32 @wait(i32* %8)
store i32 %39, i32* %7
%40 = icmp sgt i32 %39, 0
br i1 %40, label %41, label %42
41: ; preds = %38
br label %38
42: ; preds = %38
br label %45
43: ; preds = %34
%44 = load i32, i32* %5
store i32 %44, i32* %3
br label %60
45: ; preds = %42
%46 = load i32, i32* %8
%47 = call i64 @WIFEXITED(i32 %46)
%48 = icmp ne i64 %47, 0
br i1 %48, label %49, label %57
49: ; preds = %45
%50 = load i32, i32* %8
%51 = call i64 @WEXITSTATUS(i32 %50)
%52 = icmp eq i64 %51, 0
br i1 %52, label %53, label %55
53: ; preds = %49
%54 = call i32 @exit(i32 0)
unreachable
55: ; preds = %49
%56 = call i32 @exit(i32 1)
unreachable
57: ; preds = %45
%58 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
%59 = call i32 @exit(i32 1)
unreachable
60: ; preds = %43, %17
%61 = load i32, i32* %3
ret i32 %61
}

LLVM IR (-O2):
@str.1 = [23 x i8] c"Unexpected Error Case.\00"
define i32 @split(i32 %0, i32 %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%5 = tail call i32 (...) @fork()
%6 = icmp sgt i32 %5, 0
br i1 %6, label %7, label %44
7: ; preds = %2, %7
%8 = call i32 @wait(i32* %3)
%9 = icmp sgt i32 %8, 0
br i1 %9, label %7, label %10
10: ; preds = %7
%11 = load i32, i32* %3
%12 = call i64 @WIFEXITED(i32 %11)
%13 = icmp eq i64 %12, 0
br i1 %13, label %20, label %14
14: ; preds = %10
%15 = load i32, i32* %3
%16 = call i64 @WEXITSTATUS(i32 %15)
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %23
18: ; preds = %14
%19 = call i32 @exit(i32 0)
unreachable
20: ; preds = %10
%21 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str.1, i64 0, i64 0))
%22 = call i32 @exit(i32 1)
unreachable
23: ; preds = %14
%24 = call i32 (...) @fork()
%25 = icmp sgt i32 %24, 0
br i1 %25, label %26, label %44
26: ; preds = %23, %26
%27 = call i32 @wait(i32* %3)
%28 = icmp sgt i32 %27, 0
br i1 %28, label %26, label %29
29: ; preds = %26
%30 = load i32, i32* %3
%31 = call i64 @WIFEXITED(i32 %30)
%32 = icmp eq i64 %31, 0
br i1 %32, label %41, label %33
33: ; preds = %29
%34 = load i32, i32* %3
%35 = call i64 @WEXITSTATUS(i32 %34)
%36 = icmp eq i64 %35, 0
br i1 %36, label %37, label %39
37: ; preds = %33
%38 = call i32 @exit(i32 0)
unreachable
39: ; preds = %33
%40 = call i32 @exit(i32 1)
unreachable
41: ; preds = %29
%42 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str.1, i64 0, i64 0))
%43 = call i32 @exit(i32 1)
unreachable
44: ; preds = %23, %2
%45 = phi i32 [ %0, %2 ], [ %1, %23 ]
ret i32 %45
}