#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*/ errno;
scalar_t__ execvp(char *, char **);
int /*<<< orphan*/ exit(int);
scalar_t__ fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
scalar_t__ wait(int *);
int main(int argc, char **argv) {
  pid_t pid;
  int status;
  if (argc < 2) {
    fprintf(stderr,
            "Usage:\n\t%1$s <command>\nExamples:\n\t%1$s ls\n\t%1$s cat "
            "/etc/groups\n",
            argv[0]);
    exit(1);
  }
  if ((pid = fork()) < 0) {
    fprintf(stderr, "%s\n", strerror(errno));
    exit(1);
  } else if (pid == 0) {
    if (execvp(argv[1], &argv[1]) < 0) {
      fprintf(stderr, "%s\n", strerror(errno));
      exit(1);
    }
  } else {
    while (wait(&status) != pid)
      ;
    exit(status);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    11a6 <main+0x46>
mov    0x2e59(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe69(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
mov    $0x0,%al
call   1080 <fork@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jge    11f1 <main+0x91>
mov    0x2e1e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    0x2e0a(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    -0x20(%rbp),%edi
mov    %rax,%rdx
lea    0xe5f(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
cmpq   $0x0,-0x18(%rbp)
jne    1256 <main+0xf6>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x10(%rbp),%rsi
add    $0x8,%rsi
call   1040 <execvp@plt>
cmp    $0x0,%rax
jge    1251 <main+0xf1>
mov    0x2dbe(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    0x2daa(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    -0x24(%rbp),%edi
mov    %rax,%rdx
lea    0xdff(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
jmp    127b <main+0x11b>
jmp    125b <main+0xfb>
lea    -0x1c(%rbp),%rdi
call   1070 <wait@plt>
cmp    -0x18(%rbp),%rax
je     1273 <main+0x113>
jmp    125b <main+0xfb>
mov    -0x1c(%rbp),%edi
call   1050 <exit@plt>
jmp    1280 <main+0x120>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
cmp    $0x1,%edi
jle    11be <main+0x5e>
xor    %eax,%eax
call   1080 <fork@plt>
test   %rax,%rax
js     1199 <main+0x39>
jne    11e0 <main+0x80>
mov    0x8(%rbx),%rdi
add    $0x8,%rbx
mov    %rbx,%rsi
call   1040 <execvp@plt>
test   %rax,%rax
js     1199 <main+0x39>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    0x2e40(%rip),%rax
mov    (%rax),%ebx
mov    0x2e2f(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
lea    0xe8a(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
jmp    11d1 <main+0x71>
mov    0x2e1b(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xe2f(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
mov    %rax,%r14
lea    0x4(%rsp),%rbx
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1070 <wait@plt>
cmp    %r14,%rax
jne    11f0 <main+0x90>
mov    0x4(%rsp),%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [65 x i8] c"Usage:\0A\09%1$s <command>\0AExamples:\0A\09%1$s ls\0A\09%1$s cat /etc/groups\0A\00"
@.str.1 = [4 x i8] c"%s\0A\00"
@errno = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp slt i32 %8, 2
br i1 %9, label %10, label %17
10: ; preds = %2
%11 = load i32, i32* @stderr
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 0
%14 = load i8*, i8** %13
%15 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str, i64 0, i64 0), i8* %14)
%16 = call i32 @exit(i32 1)
unreachable
17: ; preds = %2
%18 = call i64 (...) @fork()
store i64 %18, i64* %6
%19 = icmp slt i64 %18, 0
br i1 %19, label %20, label %26
20: ; preds = %17
%21 = load i32, i32* @stderr
%22 = load i32, i32* @errno
%23 = call i8* @strerror(i32 %22)
%24 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %23)
%25 = call i32 @exit(i32 1)
unreachable
26: ; preds = %17
%27 = load i64, i64* %6
%28 = icmp eq i64 %27, 0
br i1 %28, label %29, label %44
29: ; preds = %26
%30 = load i8**, i8*** %5
%31 = getelementptr inbounds i8*, i8** %30, i64 1
%32 = load i8*, i8** %31
%33 = load i8**, i8*** %5
%34 = getelementptr inbounds i8*, i8** %33, i64 1
%35 = call i64 @execvp(i8* %32, i8** %34)
%36 = icmp slt i64 %35, 0
br i1 %36, label %37, label %43
37: ; preds = %29
%38 = load i32, i32* @stderr
%39 = load i32, i32* @errno
%40 = call i8* @strerror(i32 %39)
%41 = call i32 @fprintf(i32 %38, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %40)
%42 = call i32 @exit(i32 1)
unreachable
43: ; preds = %29
br label %53
44: ; preds = %26
br label %45
45: ; preds = %49, %44
%46 = call i64 @wait(i32* %7)
%47 = load i64, i64* %6
%48 = icmp ne i64 %46, %47
br i1 %48, label %49, label %50
49: ; preds = %45
br label %45
50: ; preds = %45
%51 = load i32, i32* %7
%52 = call i32 @exit(i32 %51)
unreachable
53: ; preds = %43
br label %54
54: ; preds = %53
ret i32 0
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [65 x i8] c"Usage:\0A\09%1$s <command>\0AExamples:\0A\09%1$s ls\0A\09%1$s cat /etc/groups\0A\00"
@.str.1 = [4 x i8] c"%s\0A\00"
@errno = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = icmp slt i32 %0, 2
br i1 %5, label %6, label %11
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = load i8*, i8** %1
%9 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str, i64 0, i64 0), i8* %8)
%10 = tail call i32 @exit(i32 1)
unreachable
11: ; preds = %2
%12 = tail call i64 (...) @fork()
%13 = icmp slt i64 %12, 0
br i1 %13, label %14, label %20
14: ; preds = %11
%15 = load i32, i32* @stderr
%16 = load i32, i32* @errno
%17 = tail call i8* @strerror(i32 %16)
%18 = tail call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %17)
%19 = tail call i32 @exit(i32 1)
unreachable
20: ; preds = %11
%21 = icmp eq i64 %12, 0
br i1 %21, label %22, label %33
22: ; preds = %20
%23 = getelementptr inbounds i8*, i8** %1, i64 1
%24 = load i8*, i8** %23
%25 = tail call i64 @execvp(i8* %24, i8** %23)
%26 = icmp slt i64 %25, 0
br i1 %26, label %27, label %39
27: ; preds = %22
%28 = load i32, i32* @stderr
%29 = load i32, i32* @errno
%30 = tail call i8* @strerror(i32 %29)
%31 = tail call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %30)
%32 = tail call i32 @exit(i32 1)
unreachable
33: ; preds = %20, %33
%34 = call i64 @wait(i32* %3)
%35 = icmp eq i64 %34, %12
br i1 %35, label %36, label %33
36: ; preds = %33
%37 = load i32, i32* %3
%38 = call i32 @exit(i32 %37)
unreachable
39: ; preds = %22
ret i32 0
}