#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*/ execv(char *, char **);
int fork();
int /*<<< orphan*/ perror(char *);
int waitpid(int, int /*<<< orphan*/ *, int /*<<< orphan*/);
int main(int argc, char **argv) {
  int childpid = fork();
  if (childpid == 0) {
    char *newargv[3];
    newargv[0] = "sleep";
    newargv[1] = "100";
    newargv[2] = NULL;
    execv("/bin/sleep", newargv);
    perror("execv");
  } else {
    int rc;
    rc = waitpid(childpid, NULL, 0);
    if (rc == -1) {
      perror("waitpid");
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1060 <fork@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    11a9 <main+0x69>
lea    0xe98(%rip),%rax
mov    %rax,-0x30(%rbp)
lea    0xe84(%rip),%rax
mov    %rax,-0x28(%rbp)
movq   $0x0,-0x20(%rbp)
lea    -0x30(%rbp),%rsi
lea    0xe71(%rip),%rdi
call   1050 <execv@plt>
lea    0xe70(%rip),%rdi
call   1040 <perror@plt>
jmp    11d5 <main+0x95>
mov    -0x14(%rbp),%edi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1030 <waitpid@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0xffffffff,-0x34(%rbp)
jne    11d0 <main+0x90>
lea    0xe4a(%rip),%rdi
call   1040 <perror@plt>
jmp    11d5 <main+0x95>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x18,%rsp
xor    %eax,%eax
call   1060 <fork@plt>
test   %eax,%eax
je     1166 <main+0x26>
mov    %eax,%edi
xor    %esi,%esi
xor    %edx,%edx
call   1030 <waitpid@plt>
cmp    $0xffffffff,%eax
je     119e <main+0x5e>
xor    %eax,%eax
add    $0x18,%rsp
ret
lea    0xe9c(%rip),%rax
mov    %rax,(%rsp)
lea    0xe88(%rip),%rax
mov    %rax,0x8(%rsp)
movq   $0x0,0x10(%rsp)
lea    0xe77(%rip),%rdi
mov    %rsp,%rsi
call   1050 <execv@plt>
lea    0xe73(%rip),%rdi
jmp    11a5 <main+0x65>
lea    0xe70(%rip),%rdi
call   1040 <perror@plt>
jmp    115f <main+0x1f>

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

LLVM IR (-O2):
@.str = [6 x i8] c"sleep\00"
@.str.1 = [4 x i8] c"100\00"
@.str.2 = [11 x i8] c"/bin/sleep\00"
@.str.3 = [6 x i8] c"execv\00"
@.str.4 = [8 x i8] c"waitpid\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [3 x i8*]
%4 = tail call i32 (...) @fork()
%5 = icmp eq i32 %4, 0
br i1 %5, label %6, label %13
6: ; preds = %2
%7 = bitcast [3 x i8*]* %3 to i8*
%8 = getelementptr inbounds [3 x i8*], [3 x i8*]* %3, i64 0, i64 0
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8** %8
%9 = getelementptr inbounds [3 x i8*], [3 x i8*]* %3, i64 0, i64 1
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8** %9
%10 = getelementptr inbounds [3 x i8*], [3 x i8*]* %3, i64 0, i64 2
store i8* null, i8** %10
%11 = call i32 @execv(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8** %8)
%12 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
br label %18
13: ; preds = %2
%14 = tail call i32 @waitpid(i32 %4, i32* null, i32 0)
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %18
16: ; preds = %13
%17 = tail call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
br label %18
18: ; preds = %13, %16, %6
ret i32 0
}