#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 */
int /*<<< orphan*/ exit(int);
int fork();
int func(int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int /*<<< orphan*/);
int /*<<< orphan*/ sbrk(int /*<<< orphan*/);
int wait(int *);
int main(void) {
  pid_t CPid;
  int status, arg;
  printf("Program break in parent: %10p\n", sbrk(0));
  switch (fork()) {
  case -1:
    perror("fork");
    exit(1);
  case 0:
    exit(func(arg));
  default:
    if (wait(&status) == -1) {
      perror("wait");
      exit(1);
    }
    printf("PARENT: Program break in parent: %10p\n", sbrk(0));
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
xor    %edi,%edi
mov    %edi,-0x18(%rbp)
call   1040 <sbrk@plt>
mov    %eax,%esi
lea    0xe80(%rip),%rdi
call   1030 <printf@plt>
mov    -0x18(%rbp),%eax
call   1090 <fork@plt>
mov    %eax,%ecx
mov    %ecx,-0x14(%rbp)
sub    $0xffffffff,%eax
je     11c2 <main+0x52>
jmp    11b2 <main+0x42>
mov    -0x14(%rbp),%eax
test   %eax,%eax
je     11d8 <main+0x68>
jmp    11e7 <main+0x77>
lea    0xe37(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x10(%rbp),%edi
call   1050 <func@plt>
mov    %eax,%edi
call   1070 <exit@plt>
lea    -0xc(%rbp),%rdi
call   1080 <wait@plt>
cmp    $0xffffffff,%eax
jne    120f <main+0x9f>
lea    0xe05(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
xor    %edi,%edi
call   1040 <sbrk@plt>
mov    %eax,%esi
lea    0xdeb(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
xor    %edi,%edi
call   1040 <sbrk@plt>
lea    0xe93(%rip),%rdi
mov    %eax,%esi
call   1030 <printf@plt>
xor    %eax,%eax
call   1090 <fork@plt>
test   %eax,%eax
je     11be <main+0x4e>
cmp    $0xffffffff,%eax
je     11ca <main+0x5a>
lea    0x4(%rsp),%rdi
call   1080 <wait@plt>
cmp    $0xffffffff,%eax
je     11d3 <main+0x63>
xor    %edi,%edi
call   1040 <sbrk@plt>
lea    0xe57(%rip),%rdi
mov    %eax,%esi
call   1030 <printf@plt>
xor    %eax,%eax
pop    %rcx
ret
call   1050 <func@plt>
mov    %eax,%edi
call   1070 <exit@plt>
lea    0xe2f(%rip),%rdi
jmp    11da <main+0x6a>
lea    0xe2b(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [31 x i8] c"Program break in parent: %10p\0A\00"
@.str.1 = [5 x i8] c"fork\00"
@.str.2 = [5 x i8] c"wait\00"
@.str.3 = [39 x i8] c"PARENT: Program break in parent: %10p\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
%5 = call i32 @sbrk(i32 0)
%6 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i32 %5)
%7 = call i32 (...) @fork()
switch i32 %7, label %15 [
i32 -1, label %8
i32 0, label %11
]
8: ; preds = %0
%9 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%10 = call i32 @exit(i32 1)
unreachable
11: ; preds = %0
%12 = load i32, i32* %4
%13 = call i32 @func(i32 %12)
%14 = call i32 @exit(i32 %13)
unreachable
15: ; preds = %0
%16 = call i32 @wait(i32* %3)
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %21
18: ; preds = %15
%19 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%20 = call i32 @exit(i32 1)
unreachable
21: ; preds = %15
%22 = call i32 @sbrk(i32 0)
%23 = call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.3, i64 0, i64 0), i32 %22)
br label %24
24: ; preds = %21
ret i32 0
}

LLVM IR (-O2):
@.str = [31 x i8] c"Program break in parent: %10p\0A\00"
@.str.1 = [5 x i8] c"fork\00"
@.str.2 = [5 x i8] c"wait\00"
@.str.3 = [39 x i8] c"PARENT: Program break in parent: %10p\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 @sbrk(i32 0)
%4 = tail call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = tail call i32 (...) @fork()
switch i32 %5, label %12 [
i32 -1, label %6
i32 0, label %9
]
6: ; preds = %0
%7 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%8 = tail call i32 @exit(i32 1)
unreachable
9: ; preds = %0
%10 = tail call i32 @func(i32 undef)
%11 = tail call i32 @exit(i32 %10)
unreachable
12: ; preds = %0
%13 = call i32 @wait(i32* %1)
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %18
15: ; preds = %12
%16 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%17 = call i32 @exit(i32 1)
unreachable
18: ; preds = %12
%19 = call i32 @sbrk(i32 0)
%20 = call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.3, i64 0, i64 0), i32 %19)
ret i32 0
}