#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 EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ exit(int);
int fork();
int getpid();
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int, ...);
int main(int argc, char *argv[]) {
  pid_t parent, child;
  printf("EXIT_SUCCESS=%d\n,EXIT_FAILURE=%d\n", EXIT_SUCCESS, EXIT_FAILURE);
  if ((child = fork()) == -1) {
    do {
      perror("fork");
      exit(EXIT_FAILURE);
    } while (0);
  }
  if (child) {
    parent = getpid();
    printf("In Parent %d\n", parent);
  } else {
    child = getpid();
    printf("In Child %d\n", child);
  }
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e6b(%rip),%rax
mov    (%rax),%esi
mov    0x2e6a(%rip),%rax
mov    (%rax),%edx
lea    0xe81(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1070 <fork@plt>
mov    %eax,-0x18(%rbp)
cmp    $0xffffffff,%eax
jne    11b8 <main+0x68>
jmp    119e <main+0x4e>
lea    0xe7d(%rip),%rdi
call   1050 <perror@plt>
mov    0x2e2f(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
cmpl   $0x0,-0x18(%rbp)
je     11e2 <main+0x92>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%esi
lea    0xe51(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11fd <main+0xad>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%esi
lea    0xe3f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2dd4(%rip),%rax
mov    (%rax),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    0x2e7d(%rip),%r14
mov    (%r14),%esi
mov    0x2e7b(%rip),%rbx
mov    (%rbx),%edx
lea    0xe92(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
call   1070 <fork@plt>
test   %eax,%eax
je     118e <main+0x3e>
cmp    $0xffffffff,%eax
je     11b3 <main+0x63>
lea    0xe9b(%rip),%rbx
jmp    1195 <main+0x45>
lea    0xea0(%rip),%rbx
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %rbx,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    (%r14),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe68(%rip),%rdi
call   1050 <perror@plt>
mov    (%rbx),%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [34 x i8] c"EXIT_SUCCESS=%d\0A,EXIT_FAILURE=%d\0A\00"
@EXIT_SUCCESS = global i32 0
@EXIT_FAILURE = global i32 0
@.str.1 = [5 x i8] c"fork\00"
@.str.2 = [14 x i8] c"In Parent %d\0A\00"
@.str.3 = [13 x i8] c"In Child %d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* @EXIT_SUCCESS
%9 = load i32, i32* @EXIT_FAILURE
%10 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i32 %8, i32 %9)
%11 = call i32 (...) @fork()
store i32 %11, i32* %7
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %19
13: ; preds = %2
br label %14
14: ; preds = %13
%15 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%16 = load i32, i32* @EXIT_FAILURE
%17 = call i32 @exit(i32 %16)
unreachable
18: ; No predecessors!
br label %19
19: ; preds = %18, %2
%20 = load i32, i32* %7
%21 = icmp ne i32 %20, 0
br i1 %21, label %22, label %26
22: ; preds = %19
%23 = call i32 (...) @getpid()
store i32 %23, i32* %6
%24 = load i32, i32* %6
%25 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32 %24)
br label %30
26: ; preds = %19
%27 = call i32 (...) @getpid()
store i32 %27, i32* %7
%28 = load i32, i32* %7
%29 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i32 %28)
br label %30
30: ; preds = %26, %22
%31 = load i32, i32* @EXIT_SUCCESS
ret i32 %31
}

LLVM IR (-O2):
@.str = [34 x i8] c"EXIT_SUCCESS=%d\0A,EXIT_FAILURE=%d\0A\00"
@EXIT_SUCCESS = global i32 0
@EXIT_FAILURE = global i32 0
@.str.1 = [5 x i8] c"fork\00"
@.str.2 = [14 x i8] c"In Parent %d\0A\00"
@.str.3 = [13 x i8] c"In Child %d\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = load i32, i32* @EXIT_SUCCESS
%4 = load i32, i32* @EXIT_FAILURE
%5 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i32 %3, i32 %4)
%6 = tail call i32 (...) @fork()
switch i32 %6, label %12 [
i32 -1, label %7
i32 0, label %11
]
7: ; preds = %2
%8 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%9 = load i32, i32* @EXIT_FAILURE
%10 = tail call i32 @exit(i32 %9)
unreachable
11: ; preds = %2
br label %12
12: ; preds = %2, %11
%13 = phi i8* [ getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), %11 ], [ getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), %2 ]
%14 = tail call i32 (...) @getpid()
%15 = tail call i32 (i8*, i32, ...) @printf(i8* %13, i32 %14)
%16 = load i32, i32* @EXIT_SUCCESS
ret i32 %16
}