#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 /*<<< orphan*/);
scalar_t__ fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int, int, char, char *);
int getpid();
int getppid();
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ strcpy(char *, char *);
int main() {
  char c;
  char str[10];
  c = 'X';
  if (fork()) {
    c = 'P';
    strcpy(str, "parent");
    sleep(5);
  } else {
    strcpy(str, "child");
  }
  fprintf(stdout, "PID=%d; PPID=%d; c=%c; str=%s\n", getpid(), getppid(), c,
          str);
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movb   $0x58,-0x5(%rbp)
mov    $0x0,%al
call   1090 <fork@plt>
cmp    $0x0,%rax
je     11b7 <main+0x47>
movb   $0x50,-0x5(%rbp)
lea    -0xf(%rbp),%rdi
lea    0xe5d(%rip),%rsi
call   1030 <strcpy@plt>
mov    $0x5,%edi
call   1080 <sleep@plt>
jmp    11c7 <main+0x57>
lea    -0xf(%rbp),%rdi
lea    0xe45(%rip),%rsi
call   1030 <strcpy@plt>
mov    0x2e12(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    $0x0,%al
call   1040 <getpid@plt>
mov    %eax,-0x14(%rbp)
mov    $0x0,%al
call   1060 <getppid@plt>
mov    -0x18(%rbp),%edi
mov    -0x14(%rbp),%edx
mov    %eax,%ecx
mov    -0x5(%rbp),%al
lea    -0xf(%rbp),%r9
lea    0xe13(%rip),%rsi
movsbl %al,%r8d
call   1050 <fprintf@plt>
xor    %edi,%edi
call   1070 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
xor    %eax,%eax
call   1090 <fork@plt>
test   %rax,%rax
jne    119a <main+0x2a>
lea    0xe7c(%rip),%rsi
lea    0x6(%rsp),%rdi
call   1030 <strcpy@plt>
mov    $0x58,%r14b
jmp    11b8 <main+0x48>
lea    0xe5f(%rip),%rsi
lea    0x6(%rsp),%rdi
call   1030 <strcpy@plt>
mov    $0x5,%edi
call   1080 <sleep@plt>
mov    $0x50,%r14b
mov    0x2e21(%rip),%rax
mov    (%rax),%ebx
xor    %eax,%eax
call   1040 <getpid@plt>
mov    %eax,%ebp
xor    %eax,%eax
call   1060 <getppid@plt>
movzbl %r14b,%r8d
lea    0xe31(%rip),%rsi
lea    0x6(%rsp),%r9
mov    %ebx,%edi
mov    %ebp,%edx
mov    %eax,%ecx
call   1050 <fprintf@plt>
xor    %edi,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [7 x i8] c"parent\00"
@.str.1 = [6 x i8] c"child\00"
@stdout = global i32 0
@.str.2 = [31 x i8] c"PID=%d; PPID=%d; c=%c; str=%s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8
%3 = alloca [10 x i8]
store i32 0, i32* %1
store i8 88, i8* %2
%4 = call i64 (...) @fork()
%5 = icmp ne i64 %4, 0
br i1 %5, label %6, label %10
6: ; preds = %0
store i8 80, i8* %2
%7 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%8 = call i32 @strcpy(i8* %7, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%9 = call i32 @sleep(i32 5)
br label %13
10: ; preds = %0
%11 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%12 = call i32 @strcpy(i8* %11, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
br label %13
13: ; preds = %10, %6
%14 = load i32, i32* @stdout
%15 = call i32 (...) @getpid()
%16 = call i32 (...) @getppid()
%17 = load i8, i8* %2
%18 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%19 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i32 %15, i32 %16, i8 signext %17, i8* %18)
%20 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str = [7 x i8] c"parent\00"
@.str.1 = [6 x i8] c"child\00"
@stdout = global i32 0
@.str.2 = [31 x i8] c"PID=%d; PPID=%d; c=%c; str=%s\0A\00"
define i32 @main() {
%1 = alloca [10 x i8]
%2 = getelementptr inbounds [10 x i8], [10 x i8]* %1, i64 0, i64 0
%3 = tail call i64 (...) @fork()
%4 = icmp eq i64 %3, 0
br i1 %4, label %8, label %5
5: ; preds = %0
%6 = call i32 @strcpy(i8* %2, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%7 = call i32 @sleep(i32 5)
br label %10
8: ; preds = %0
%9 = call i32 @strcpy(i8* %2, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
br label %10
10: ; preds = %8, %5
%11 = phi i8 [ 80, %5 ], [ 88, %8 ]
%12 = load i32, i32* @stdout
%13 = call i32 (...) @getpid()
%14 = call i32 (...) @getppid()
%15 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i32 %13, i32 %14, i8 signext %11, i8* %2)
%16 = call i32 @exit(i32 0)
unreachable
}