#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 scalar_t__ pid_t;

/* Variables and functions */
scalar_t__ fork();
scalar_t__ getpid();
int /*<<< orphan*/ printf(char *, int);
int main() {
  pid_t child_pid;
  printf("The main program process ID is %d\n", (int)getpid());
  child_pid = fork();
  if (child_pid != 0) {
    printf("This is the parent process, with id %d\n", (int)getpid());
    printf("The child's process ID is %d\n", (int)child_pid);
  } else {
    printf("This is the child process, with id %d\n", (int)getpid());
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,%esi
lea    0xeb1(%rip),%rdi
call   1040 <printf@plt>
mov    $0x0,%al
call   1050 <fork@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1196 <main+0x66>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,%esi
lea    0xea9(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%rax
mov    %eax,%esi
lea    0xebf(%rip),%rdi
call   1040 <printf@plt>
jmp    11ab <main+0x7b>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,%esi
lea    0xec3(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
xor    %eax,%eax
call   1030 <getpid@plt>
lea    0xec1(%rip),%rdi
mov    %eax,%esi
call   1040 <printf@plt>
xor    %eax,%eax
call   1050 <fork@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   1030 <getpid@plt>
test   %rbx,%rbx
je     1175 <main+0x45>
lea    0xec0(%rip),%rdi
mov    %eax,%esi
call   1040 <printf@plt>
lea    0xeda(%rip),%rdi
mov    %ebx,%esi
jmp    117e <main+0x4e>
lea    0xeed(%rip),%rdi
mov    %eax,%esi
call   1040 <printf@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [35 x i8] c"The main program process ID is %d\0A\00"
@.str.1 = [40 x i8] c"This is the parent process, with id %d\0A\00"
@.str.2 = [30 x i8] c"The child's process ID is %d\0A\00"
@.str.3 = [39 x i8] c"This is the child process, with id %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
store i32 0, i32* %1
%3 = call i64 (...) @getpid()
%4 = trunc i64 %3 to i32
%5 = call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i32 %4)
%6 = call i64 (...) @fork()
store i64 %6, i64* %2
%7 = load i64, i64* %2
%8 = icmp ne i64 %7, 0
br i1 %8, label %9, label %16
9: ; preds = %0
%10 = call i64 (...) @getpid()
%11 = trunc i64 %10 to i32
%12 = call i32 @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0), i32 %11)
%13 = load i64, i64* %2
%14 = trunc i64 %13 to i32
%15 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i32 %14)
br label %20
16: ; preds = %0
%17 = call i64 (...) @getpid()
%18 = trunc i64 %17 to i32
%19 = call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.3, i64 0, i64 0), i32 %18)
br label %20
20: ; preds = %16, %9
ret i32 0
}

LLVM IR (-O2):
@.str = [35 x i8] c"The main program process ID is %d\0A\00"
@.str.1 = [40 x i8] c"This is the parent process, with id %d\0A\00"
@.str.2 = [30 x i8] c"The child's process ID is %d\0A\00"
@.str.3 = [39 x i8] c"This is the child process, with id %d\0A\00"
define i32 @main() {
%1 = tail call i64 (...) @getpid()
%2 = trunc i64 %1 to i32
%3 = tail call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i32 %2)
%4 = tail call i64 (...) @fork()
%5 = icmp eq i64 %4, 0
%6 = tail call i64 (...) @getpid()
%7 = trunc i64 %6 to i32
br i1 %5, label %12, label %8
8: ; preds = %0
%9 = tail call i32 @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0), i32 %7)
%10 = trunc i64 %4 to i32
%11 = tail call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i32 %10)
br label %14
12: ; preds = %0
%13 = tail call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.3, i64 0, i64 0), i32 %7)
br label %14
14: ; preds = %12, %8
ret i32 0
}