#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*/ error(char *);
int /*<<< orphan*/ execl(char *, char *, char *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int fork();
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ wait(int *);
void main() {
  int pid;
  int status;
  if ((pid = fork()) == 0) {
    execl("/usr/bin/ls", "ls", (char *)NULL);
    error("Could not exec 'ls'");
  }
  wait(&status);
  printf("Spawned 'ls' is a child process at pid %d\n", pid);
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x0,%al
call   1080 <fork@plt>
mov    %eax,-0x4(%rbp)
cmp    $0x0,%eax
jne    119e <main+0x3e>
lea    0xe7e(%rip),%rdi
lea    0xe80(%rip),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1060 <execl@plt>
lea    0xe73(%rip),%rdi
call   1040 <error@plt>
lea    -0x8(%rbp),%rdi
call   1070 <wait@plt>
mov    -0x4(%rbp),%esi
lea    0xe6f(%rip),%rdi
call   1030 <printf@plt>
xor    %edi,%edi
call   1050 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
xor    %eax,%eax
call   1080 <fork@plt>
mov    %eax,%ebx
test   %eax,%eax
jne    1193 <main+0x33>
lea    0xe87(%rip),%rdi
lea    0xe89(%rip),%rsi
xor    %edx,%edx
call   1060 <execl@plt>
lea    0xe7e(%rip),%rdi
call   1040 <error@plt>
lea    0xc(%rsp),%rdi
call   1070 <wait@plt>
lea    0xe7c(%rip),%rdi
mov    %ebx,%esi
call   1030 <printf@plt>
xor    %edi,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@.str = [12 x i8] c"/usr/bin/ls\00"
@.str.1 = [3 x i8] c"ls\00"
@.str.2 = [20 x i8] c"Could not exec 'ls'\00"
@.str.3 = [43 x i8] c"Spawned 'ls' is a child process at pid %d\0A\00"
define void @main() {
%1 = alloca i32
%2 = alloca i32
%3 = call i32 (...) @fork()
store i32 %3, i32* %1
%4 = icmp eq i32 %3, 0
br i1 %4, label %5, label %8
5: ; preds = %0
%6 = call i32 @execl(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* null)
%7 = call i32 @error(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
br label %8
8: ; preds = %5, %0
%9 = call i32 @wait(i32* %2)
%10 = load i32, i32* %1
%11 = call i32 @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.3, i64 0, i64 0), i32 %10)
%12 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str = [12 x i8] c"/usr/bin/ls\00"
@.str.1 = [3 x i8] c"ls\00"
@.str.2 = [20 x i8] c"Could not exec 'ls'\00"
@.str.3 = [43 x i8] c"Spawned 'ls' is a child process at pid %d\0A\00"
define void @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 (...) @fork()
%4 = icmp eq i32 %3, 0
br i1 %4, label %5, label %8
5: ; preds = %0
%6 = tail call i32 @execl(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* null)
%7 = tail call i32 @error(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
br label %8
8: ; preds = %5, %0
%9 = call i32 @wait(i32* %1)
%10 = call i32 @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.3, i64 0, i64 0), i32 %3)
%11 = call i32 @exit(i32 0)
unreachable
}