#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*/ execvp(char *, char **);
scalar_t__ fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ wait(int *);
int main(int argc, char *argv[]) {
  if (argc < 2) {
    fprintf(stderr, "Usage: %s CMD [ARGS...]\n", argv[0]);
    return 255;
  }
  if (fork()) {
    int retval;
    wait(&retval);
    return !retval;
  } else {
    execvp(argv[1], argv + 1);
    perror(argv[1]);
    return 255;
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    1198 <main+0x48>
mov    0x2e69(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe79(%rip),%rsi
call   1030 <fprintf@plt>
movl   $0xff,-0x4(%rbp)
jmp    11f1 <main+0xa1>
mov    $0x0,%al
call   1070 <fork@plt>
cmp    $0x0,%rax
je     11c8 <main+0x78>
lea    -0x14(%rbp),%rdi
call   1060 <wait@plt>
cmpl   $0x0,-0x14(%rbp)
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
jmp    11f1 <main+0xa1>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x10(%rbp),%rsi
add    $0x8,%rsi
call   1050 <execvp@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1040 <perror@plt>
movl   $0xff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
cmp    $0x1,%edi
jg     117c <main+0x2c>
mov    0x2e7c(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xe90(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0xff,%eax
jmp    119c <main+0x4c>
xor    %eax,%eax
call   1070 <fork@plt>
test   %rax,%rax
je     11a2 <main+0x52>
lea    0xc(%rsp),%rdi
call   1060 <wait@plt>
xor    %eax,%eax
cmpl   $0x0,0xc(%rsp)
sete   %al
add    $0x10,%rsp
pop    %rbx
ret
lea    0x8(%rbx),%rsi
mov    0x8(%rbx),%rdi
call   1050 <execvp@plt>
mov    0x8(%rbx),%rdi
call   1040 <perror@plt>
jmp    1175 <main+0x25>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [25 x i8] c"Usage: %s CMD [ARGS...]\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = load i32, i32* %4
%8 = icmp slt i32 %7, 2
br i1 %8, label %9, label %15
9: ; preds = %2
%10 = load i32, i32* @stderr
%11 = load i8**, i8*** %5
%12 = getelementptr inbounds i8*, i8** %11, i64 0
%13 = load i8*, i8** %12
%14 = call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %13)
store i32 255, i32* %3
br label %35
15: ; preds = %2
%16 = call i64 (...) @fork()
%17 = icmp ne i64 %16, 0
br i1 %17, label %18, label %24
18: ; preds = %15
%19 = call i32 @wait(i32* %6)
%20 = load i32, i32* %6
%21 = icmp ne i32 %20, 0
%22 = xor i1 %21, true
%23 = zext i1 %22 to i32
store i32 %23, i32* %3
br label %35
24: ; preds = %15
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 1
%27 = load i8*, i8** %26
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 1
%30 = call i32 @execvp(i8* %27, i8** %29)
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i64 1
%33 = load i8*, i8** %32
%34 = call i32 @perror(i8* %33)
store i32 255, i32* %3
br label %35
35: ; preds = %24, %18, %9
%36 = load i32, i32* %3
ret i32 %36
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [25 x i8] c"Usage: %s CMD [ARGS...]\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = icmp slt i32 %0, 2
br i1 %4, label %5, label %9
5: ; preds = %2
%6 = load i32, i32* @stderr
%7 = load i8*, i8** %1
%8 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %7)
br label %24
9: ; preds = %2
%10 = tail call i64 (...) @fork()
%11 = icmp eq i64 %10, 0
br i1 %11, label %18, label %12
12: ; preds = %9
%13 = bitcast i32* %3 to i8*
%14 = call i32 @wait(i32* %3)
%15 = load i32, i32* %3
%16 = icmp eq i32 %15, 0
%17 = zext i1 %16 to i32
br label %24
18: ; preds = %9
%19 = getelementptr inbounds i8*, i8** %1, i64 1
%20 = load i8*, i8** %19
%21 = tail call i32 @execvp(i8* %20, i8** %19)
%22 = load i8*, i8** %19
%23 = tail call i32 @perror(i8* %22)
br label %24
24: ; preds = %18, %12, %5
%25 = phi i32 [ 255, %5 ], [ %17, %12 ], [ 255, %18 ]
ret i32 %25
}