#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*/ EXIT_FAILURE;
int /*<<< orphan*/ _exit(int /*<<< orphan*/);
int /*<<< orphan*/ execl(char *, char *, char *, char *, int /*<<< orphan*/ *);
scalar_t__ fork();
scalar_t__ waitpid(scalar_t__, int *, int /*<<< orphan*/);
int main() {
  int status;
  pid_t pid;
  pid = fork();
  if (pid == 0) {
    execl("/bin/sh", "/bin/sh", "-c", "ls", NULL);
    _exit(EXIT_FAILURE);
  } else if (pid < 0)
    status = -1;
  else if (waitpid(pid, &status, 0) != pid)
    status = -1;
  return status;
}


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    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1195 <main+0x55>
lea    0xe94(%rip),%rsi
lea    0xe95(%rip),%rdx
lea    0xe91(%rip),%rcx
xor    %eax,%eax
mov    %eax,%r8d
mov    %rsi,%rdi
call   1050 <execl@plt>
mov    0x2e52(%rip),%rax
mov    (%rax),%edi
call   1030 <_exit@plt>
cmpq   $0x0,-0x10(%rbp)
jge    11ac <main+0x6c>
movl   $0xffffffff,-0x8(%rbp)
jmp    11d1 <main+0x91>
mov    -0x10(%rbp),%rdi
lea    -0x8(%rbp),%rsi
xor    %edx,%edx
call   1040 <waitpid@plt>
cmp    -0x10(%rbp),%rax
je     11cc <main+0x8c>
movl   $0xffffffff,-0x8(%rbp)
jmp    11d1 <main+0x91>
jmp    11d6 <main+0x96>
mov    -0x8(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
xor    %eax,%eax
call   1060 <fork@plt>
test   %rax,%rax
je     1183 <main+0x43>
js     1178 <main+0x38>
mov    %rax,%rbx
lea    0xc(%rsp),%rsi
mov    %rax,%rdi
xor    %edx,%edx
call   1040 <waitpid@plt>
mov    %rax,%rcx
mov    $0xffffffff,%eax
cmp    %rbx,%rcx
jne    117d <main+0x3d>
mov    0xc(%rsp),%eax
jmp    117d <main+0x3d>
mov    $0xffffffff,%eax
add    $0x10,%rsp
pop    %rbx
ret
lea    0xe76(%rip),%rdi
lea    0xe77(%rip),%rdx
lea    0xe73(%rip),%rcx
mov    %rdi,%rsi
xor    %r8d,%r8d
call   1050 <execl@plt>
mov    0x2e36(%rip),%rax
mov    (%rax),%edi
call   1030 <_exit@plt>

LLVM IR (-O0):
@.str = [8 x i8] c"/bin/sh\00"
@.str.1 = [3 x i8] c"-c\00"
@.str.2 = [3 x i8] c"ls\00"
@EXIT_FAILURE = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i64
store i32 0, i32* %1
%4 = call i64 (...) @fork()
store i64 %4, i64* %3
%5 = load i64, i64* %3
%6 = icmp eq i64 %5, 0
br i1 %6, label %7, label %11
7: ; preds = %0
%8 = call i32 @execl(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* null)
%9 = load i32, i32* @EXIT_FAILURE
%10 = call i32 @_exit(i32 %9)
unreachable
11: ; preds = %0
%12 = load i64, i64* %3
%13 = icmp slt i64 %12, 0
br i1 %13, label %14, label %15
14: ; preds = %11
store i32 -1, i32* %2
br label %22
15: ; preds = %11
%16 = load i64, i64* %3
%17 = call i64 @waitpid(i64 %16, i32* %2, i32 0)
%18 = load i64, i64* %3
%19 = icmp ne i64 %17, %18
br i1 %19, label %20, label %21
20: ; preds = %15
store i32 -1, i32* %2
br label %21
21: ; preds = %20, %15
br label %22
22: ; preds = %21, %14
br label %23
23: ; preds = %22
%24 = load i32, i32* %2
ret i32 %24
}

LLVM IR (-O2):
@.str = [8 x i8] c"/bin/sh\00"
@.str.1 = [3 x i8] c"-c\00"
@.str.2 = [3 x i8] c"ls\00"
@EXIT_FAILURE = global i32 0
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 @execl(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* null)
%7 = load i32, i32* @EXIT_FAILURE
%8 = tail call i32 @_exit(i32 %7)
unreachable
9: ; preds = %0
%10 = icmp slt i64 %3, 0
br i1 %10, label %16, label %11
11: ; preds = %9
%12 = call i64 @waitpid(i64 %3, i32* %1, i32 0)
%13 = icmp eq i64 %12, %3
%14 = load i32, i32* %1
%15 = select i1 %13, i32 %14, i32 -1
br label %16
16: ; preds = %11, %9
%17 = phi i32 [ -1, %9 ], [ %15, %11 ]
ret i32 %17
}