#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 /*<<< orphan*/ exit(int);
int fork();
int /*<<< orphan*/ printf(char *, ...);
long wait(int *);
main() {
  int i, b;
  long a;
  i = fork();
  if (i == 0) {
    printf("kind 1\n");
    i = fork();
    if (i == 0) {
      printf("kind 1.1\n");
      exit(111);
    } else {
      wait(&b);
      printf("h:%d, l:%d\n", (b & 0xFF00) >> 8, b & 0xFF);
      exit(11);
    }
  } else {
    printf("parent\n");
    i = fork();
    if (i == 0) {
      printf("kind 2\n");
      exit(22);
    } else {
      a = wait(&b);
      printf("pid:%d, h:%d, l:%d\n", a, (b & 0xFF00) >> 8, b & 0xFF);
      a = wait(&b);
      printf("pid:%d, h:%d, l:%d\n", a, (b & 0xFF00) >> 8, b & 0xFF);
      exit(99);
    }
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1060 <fork@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jne    11d3 <main+0x93>
lea    0xe96(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x0,%al
call   1060 <fork@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jne    119d <main+0x5d>
lea    0xe7c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x6f,%edi
call   1040 <exit@plt>
lea    -0xc(%rbp),%rdi
call   1050 <wait@plt>
mov    -0xc(%rbp),%esi
and    $0xff00,%esi
sar    $0x8,%esi
mov    -0xc(%rbp),%edx
and    $0xff,%edx
lea    0xe68(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0xb,%edi
call   1040 <exit@plt>
lea    0xe38(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x0,%al
call   1060 <fork@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jne    120d <main+0xcd>
lea    0xe1e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x16,%edi
call   1040 <exit@plt>
lea    -0xc(%rbp),%rdi
call   1050 <wait@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rsi
mov    -0xc(%rbp),%edx
and    $0xff00,%edx
sar    $0x8,%edx
mov    -0xc(%rbp),%ecx
and    $0xff,%ecx
lea    0xde8(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0xc(%rbp),%rdi
call   1050 <wait@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rsi
mov    -0xc(%rbp),%edx
and    $0xff00,%edx
sar    $0x8,%edx
mov    -0xc(%rbp),%ecx
and    $0xff,%ecx
lea    0xdb4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x63,%edi
call   1040 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
xor    %eax,%eax
call   1070 <fork@plt>
test   %eax,%eax
jne    118c <main+0x3c>
lea    0xebc(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1070 <fork@plt>
test   %eax,%eax
jne    11b9 <main+0x69>
lea    0xeac(%rip),%rdi
call   1030 <puts@plt>
mov    $0x6f,%edi
call   1050 <exit@plt>
lea    0xe81(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1070 <fork@plt>
test   %eax,%eax
jne    11e5 <main+0x95>
lea    0xe71(%rip),%rdi
call   1030 <puts@plt>
mov    $0x16,%edi
call   1050 <exit@plt>
lea    0x4(%rsp),%rdi
call   1060 <wait@plt>
mov    0x4(%rsp),%eax
movzbl %ah,%esi
movzbl %al,%edx
lea    0xe34(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xb,%edi
call   1050 <exit@plt>
lea    0x4(%rsp),%r14
mov    %r14,%rdi
call   1060 <wait@plt>
mov    0x4(%rsp),%ecx
movzbl %ch,%edx
movzbl %cl,%ecx
lea    0xdfd(%rip),%rbx
mov    %rbx,%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r14,%rdi
call   1060 <wait@plt>
mov    0x4(%rsp),%ecx
movzbl %ch,%edx
movzbl %cl,%ecx
mov    %rbx,%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x63,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@.str = [8 x i8] c"kind 1\0A\00"
@.str.1 = [10 x i8] c"kind 1.1\0A\00"
@.str.2 = [12 x i8] c"h:%d, l:%d\0A\00"
@.str.3 = [8 x i8] c"parent\0A\00"
@.str.4 = [8 x i8] c"kind 2\0A\00"
@.str.5 = [20 x i8] c"pid:%d, h:%d, l:%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i64
store i32 0, i32* %1
%5 = call i32 (...) @fork()
store i32 %5, i32* %2
%6 = load i32, i32* %2
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %25
8: ; preds = %0
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%10 = call i32 (...) @fork()
store i32 %10, i32* %2
%11 = load i32, i32* %2
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %8
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%15 = call i32 @exit(i32 111)
unreachable
16: ; preds = %8
%17 = call i64 @wait(i32* %3)
%18 = load i32, i32* %3
%19 = and i32 %18, 65280
%20 = ashr i32 %19, 8
%21 = load i32, i32* %3
%22 = and i32 %21, 255
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32 %20, i32 %22)
%24 = call i32 @exit(i32 11)
unreachable
25: ; preds = %0
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
%27 = call i32 (...) @fork()
store i32 %27, i32* %2
%28 = load i32, i32* %2
%29 = icmp eq i32 %28, 0
br i1 %29, label %30, label %33
30: ; preds = %25
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
%32 = call i32 @exit(i32 22)
unreachable
33: ; preds = %25
%34 = call i64 @wait(i32* %3)
store i64 %34, i64* %4
%35 = load i64, i64* %4
%36 = load i32, i32* %3
%37 = and i32 %36, 65280
%38 = ashr i32 %37, 8
%39 = load i32, i32* %3
%40 = and i32 %39, 255
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0), i64 %35, i32 %38, i32 %40)
%42 = call i64 @wait(i32* %3)
store i64 %42, i64* %4
%43 = load i64, i64* %4
%44 = load i32, i32* %3
%45 = and i32 %44, 65280
%46 = ashr i32 %45, 8
%47 = load i32, i32* %3
%48 = and i32 %47, 255
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0), i64 %43, i32 %46, i32 %48)
%50 = call i32 @exit(i32 99)
unreachable
}

LLVM IR (-O2):
@.str.2 = [12 x i8] c"h:%d, l:%d\0A\00"
@.str.5 = [20 x i8] c"pid:%d, h:%d, l:%d\0A\00"
@str = [7 x i8] c"parent\00"
@str.6 = [7 x i8] c"kind 2\00"
@str.7 = [7 x i8] c"kind 1\00"
@str.8 = [9 x i8] c"kind 1.1\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 (...) @fork()
%4 = icmp eq i32 %3, 0
br i1 %4, label %5, label %20
5: ; preds = %0
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str.7, i64 0, i64 0))
%7 = tail call i32 (...) @fork()
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %12
9: ; preds = %5
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @str.8, i64 0, i64 0))
%11 = tail call i32 @exit(i32 111)
unreachable
12: ; preds = %5
%13 = call i64 @wait(i32* %1)
%14 = load i32, i32* %1
%15 = lshr i32 %14, 8
%16 = and i32 %15, 255
%17 = and i32 %14, 255
%18 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32 %16, i32 %17)
%19 = call i32 @exit(i32 11)
unreachable
20: ; preds = %0
%21 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str, i64 0, i64 0))
%22 = tail call i32 (...) @fork()
%23 = icmp eq i32 %22, 0
br i1 %23, label %24, label %27
24: ; preds = %20
%25 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str.6, i64 0, i64 0))
%26 = tail call i32 @exit(i32 22)
unreachable
27: ; preds = %20
%28 = call i64 @wait(i32* %1)
%29 = load i32, i32* %1
%30 = lshr i32 %29, 8
%31 = and i32 %30, 255
%32 = and i32 %29, 255
%33 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0), i64 %28, i32 %31, i32 %32)
%34 = call i64 @wait(i32* %1)
%35 = load i32, i32* %1
%36 = lshr i32 %35, 8
%37 = and i32 %36, 255
%38 = and i32 %35, 255
%39 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0), i64 %34, i32 %37, i32 %38)
%40 = call i32 @exit(i32 99)
unreachable
}