#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(int argc, char *argv[]) {
  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    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,%esi
lea    0xeaa(%rip),%rdi
call   1040 <printf@plt>
mov    $0x0,%al
call   1050 <fork@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     119d <main+0x6d>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,%esi
lea    0xea2(%rip),%rdi
call   1040 <printf@plt>
mov    -0x18(%rbp),%rax
mov    %eax,%esi
lea    0xeb8(%rip),%rdi
call   1040 <printf@plt>
jmp    11b2 <main+0x82>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,%esi
lea    0xebc(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x20,%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(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = call i64 (...) @getpid()
%8 = trunc i64 %7 to i32
%9 = call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i32 %8)
%10 = call i64 (...) @fork()
store i64 %10, i64* %6
%11 = load i64, i64* %6
%12 = icmp ne i64 %11, 0
br i1 %12, label %13, label %20
13: ; preds = %2
%14 = call i64 (...) @getpid()
%15 = trunc i64 %14 to i32
%16 = call i32 @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0), i32 %15)
%17 = load i64, i64* %6
%18 = trunc i64 %17 to i32
%19 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i32 %18)
br label %24
20: ; preds = %2
%21 = call i64 (...) @getpid()
%22 = trunc i64 %21 to i32
%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 = %20, %13
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(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i64 (...) @getpid()
%4 = trunc i64 %3 to i32
%5 = tail call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i32 %4)
%6 = tail call i64 (...) @fork()
%7 = icmp eq i64 %6, 0
%8 = tail call i64 (...) @getpid()
%9 = trunc i64 %8 to i32
br i1 %7, label %14, label %10
10: ; preds = %2
%11 = tail call i32 @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0), i32 %9)
%12 = trunc i64 %6 to i32
%13 = tail call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i32 %12)
br label %16
14: ; preds = %2
%15 = tail call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.3, i64 0, i64 0), i32 %9)
br label %16
16: ; preds = %14, %10
ret i32 0
}