#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*/ execlp(char *, char *, int /*<<< orphan*/ *);
int fork();
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ wait(int *);
int main(void) {
  int pid, st;
  if ((pid = fork()) == 0) {
    execlp("ls", "ls", NULL);
    printf("error\n");
  } else if (pid == -1) {
    printf("error\n");
  }
  wait(&st);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1060 <fork@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jne    1186 <main+0x46>
lea    0xe97(%rip),%rsi
xor    %eax,%eax
mov    %eax,%edx
mov    %rsi,%rdi
call   1040 <execlp@plt>
lea    0xe87(%rip),%rdi
call   1030 <printf@plt>
jmp    11a1 <main+0x61>
cmpl   $0xffffffff,-0x8(%rbp)
jne    119c <main+0x5c>
lea    0xe6c(%rip),%rdi
call   1030 <printf@plt>
jmp    11a1 <main+0x61>
lea    -0xc(%rbp),%rdi
call   1050 <wait@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
xor    %eax,%eax
call   1060 <fork@plt>
cmp    $0xffffffff,%eax
je     1162 <main+0x22>
test   %eax,%eax
jne    116e <main+0x2e>
lea    0xea8(%rip),%rdi
mov    %rdi,%rsi
xor    %edx,%edx
call   1040 <execlp@plt>
lea    0xe9a(%rip),%rdi
call   1030 <puts@plt>
lea    0x4(%rsp),%rdi
call   1050 <wait@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [3 x i8] c"ls\00"
@.str.1 = [7 x i8] c"error\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
store i32 0, i32* %1
%4 = call i32 (...) @fork()
store i32 %4, i32* %2
%5 = icmp eq i32 %4, 0
br i1 %5, label %6, label %9
6: ; preds = %0
%7 = call i32 @execlp(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* null)
%8 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
br label %15
9: ; preds = %0
%10 = load i32, i32* %2
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %14
12: ; preds = %9
%13 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
br label %14
14: ; preds = %12, %9
br label %15
15: ; preds = %14, %6
%16 = call i32 @wait(i32* %3)
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"ls\00"
@str.2 = [6 x i8] c"error\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 (...) @fork()
switch i32 %3, label %9 [
i32 0, label %4
i32 -1, label %6
]
4: ; preds = %0
%5 = tail call i32 @execlp(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* null)
br label %6
6: ; preds = %0, %4
%7 = phi i8* [ getelementptr inbounds ([6 x i8], [6 x i8]* @str.2, i64 0, i64 0), %4 ], [ getelementptr inbounds ([6 x i8], [6 x i8]* @str.2, i64 0, i64 0), %0 ]
%8 = tail call i32 @puts(i8* dereferenceable(1) %7)
br label %9
9: ; preds = %6, %0
%10 = call i32 @wait(i32* %1)
ret i32 0
}