#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*/ execv(char *, char **);
int /*<<< orphan*/ exit(int);
scalar_t__ fork();
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ waitpid(scalar_t__, int /*<<< orphan*/, int /*<<< orphan*/);
int main() {
  pid_t pid = fork();
  if (pid == 0) {
    static char *argv[] = {"echo", "Foo is my name.", NULL};
    execv("/bin/echo", argv);
    exit(127);
  } else {
    printf("parent running");
    waitpid(pid, 0, 0);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1070 <fork@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1192 <main+0x42>
lea    0xe94(%rip),%rdi
lea    0x2ecd(%rip),%rsi
call   1060 <execv@plt>
mov    $0x7f,%edi
call   1050 <exit@plt>
lea    0xe81(%rip),%rdi
call   1030 <printf@plt>
mov    -0x10(%rbp),%rdi
xor    %edx,%edx
mov    %edx,%esi
call   1040 <waitpid@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
xor    %eax,%eax
call   1070 <fork@plt>
test   %rax,%rax
je     117c <main+0x2c>
mov    %rax,%rbx
lea    0xeb3(%rip),%rdi
call   1030 <printf@plt>
mov    %rbx,%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1040 <waitpid@plt>
xor    %eax,%eax
pop    %rbx
ret
lea    0xe8d(%rip),%rdi
lea    0x2ec6(%rip),%rsi
call   1060 <execv@plt>
mov    $0x7f,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@main.argv = internal global [3 x i8*] [i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i32 0, i32 0), i8* null]
@.str = [5 x i8] c"echo\00"
@.str.1 = [16 x i8] c"Foo is my name.\00"
@.str.2 = [10 x i8] c"/bin/echo\00"
@.str.3 = [15 x i8] c"parent running\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
store i32 0, i32* %1
%3 = call i64 (...) @fork()
store i64 %3, i64* %2
%4 = load i64, i64* %2
%5 = icmp eq i64 %4, 0
br i1 %5, label %6, label %9
6: ; preds = %0
%7 = call i32 @execv(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8** getelementptr inbounds ([3 x i8*], [3 x i8*]* @main.argv, i64 0, i64 0))
%8 = call i32 @exit(i32 127)
unreachable
9: ; preds = %0
%10 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
%11 = load i64, i64* %2
%12 = call i32 @waitpid(i64 %11, i32 0, i32 0)
br label %13
13: ; preds = %9
ret i32 0
}

LLVM IR (-O2):
@main.argv = internal global [3 x i8*] [i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i32 0, i32 0), i8* null]
@.str = [5 x i8] c"echo\00"
@.str.1 = [16 x i8] c"Foo is my name.\00"
@.str.2 = [10 x i8] c"/bin/echo\00"
@.str.3 = [15 x i8] c"parent running\00"
define i32 @main() {
%1 = tail call i64 (...) @fork()
%2 = icmp eq i64 %1, 0
br i1 %2, label %3, label %6
3: ; preds = %0
%4 = tail call i32 @execv(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8** getelementptr inbounds ([3 x i8*], [3 x i8*]* @main.argv, i64 0, i64 0))
%5 = tail call i32 @exit(i32 127)
unreachable
6: ; preds = %0
%7 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
%8 = tail call i32 @waitpid(i64 %1, i32 0, i32 0)
ret i32 0
}