#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 */
int /*<<< orphan*/ execl(char *, char *, char *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
scalar_t__ fork();
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ wait(int *);
int main() {
  pid_t pid;
  int status;
  pid = fork();
  if (pid == 0) {
    printf("Child executing \"/bin/date\"\n");
    execl("/bin/date", "date", (char *)0);
    printf("This should not happen!\n");
  }
  printf("Parent waiting for child to finish: child pid=%d\n", pid);
  pid = wait(&status);
  printf("Parent: Child just terminated: pid=%d.\n", pid);
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1070 <fork@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11a8 <main+0x58>
lea    0xe84(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe93(%rip),%rdi
lea    0xe91(%rip),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1050 <execl@plt>
lea    0xe86(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rsi
lea    0xe8d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x14(%rbp),%rdi
call   1060 <wait@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xea0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %edi,%edi
call   1040 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
xor    %eax,%eax
call   1080 <fork@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    11a1 <main+0x41>
lea    0xee9(%rip),%rdi
call   1030 <puts@plt>
lea    0xe79(%rip),%rdi
lea    0xe77(%rip),%rsi
xor    %edx,%edx
call   1060 <execl@plt>
lea    0xee4(%rip),%rdi
call   1030 <puts@plt>
lea    0xe62(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xc(%rsp),%rdi
call   1070 <wait@plt>
lea    0xe79(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %edi,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@.str = [29 x i8] c"Child executing \22/bin/date\22\0A\00"
@.str.1 = [10 x i8] c"/bin/date\00"
@.str.2 = [5 x i8] c"date\00"
@.str.3 = [25 x i8] c"This should not happen!\0A\00"
@.str.4 = [50 x i8] c"Parent waiting for child to finish: child pid=%d\0A\00"
@.str.5 = [40 x i8] c"Parent: Child just terminated: pid=%d.\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca i32
store i32 0, i32* %1
%4 = call i64 (...) @fork()
store i64 %4, i64* %2
%5 = load i64, i64* %2
%6 = icmp eq i64 %5, 0
br i1 %6, label %7, label %11
7: ; preds = %0
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
%9 = call i32 @execl(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* null)
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0))
br label %11
11: ; preds = %7, %0
%12 = load i64, i64* %2
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.4, i64 0, i64 0), i64 %12)
%14 = call i64 @wait(i32* %3)
store i64 %14, i64* %2
%15 = load i64, i64* %2
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.5, i64 0, i64 0), i64 %15)
%17 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str.1 = [10 x i8] c"/bin/date\00"
@.str.2 = [5 x i8] c"date\00"
@.str.4 = [50 x i8] c"Parent waiting for child to finish: child pid=%d\0A\00"
@.str.5 = [40 x i8] c"Parent: Child just terminated: pid=%d.\0A\00"
@str = [28 x i8] c"Child executing \22/bin/date\22\00"
@str.6 = [24 x i8] c"This should not happen!\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i64 (...) @fork()
%4 = icmp eq i64 %3, 0
br i1 %4, label %5, label %9
5: ; preds = %0
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str, i64 0, i64 0))
%7 = tail call i32 @execl(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* null)
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str.6, i64 0, i64 0))
br label %9
9: ; preds = %5, %0
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([50 x i8], [50 x i8]* @.str.4, i64 0, i64 0), i64 %3)
%11 = call i64 @wait(i32* %1)
%12 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str.5, i64 0, i64 0), i64 %11)
%13 = call i32 @exit(i32 0)
unreachable
}