#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 */
scalar_t__ calloc(int const, int);
int /*<<< orphan*/ execvp(char *, char **);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stderr;
char *strdup(char const *);
int main(const int argc, const char *argv[], const char *envp[]) {
  int i;
  char *path, **args;
  if (argc < 2) {
    fprintf(stderr, "Usage: %s <path to command> (<arguments>)\n", argv[0]);
    exit(1);
  }
  path = strdup(argv[1]);
  args = (char **)calloc(argc, sizeof(char *));
  for (i = 1; i < argc; i++) {
    args[i - 1] = strdup(argv[i]);
  }
  args[i] = NULL;
  execvp(path, args);
  perror("Unable to execvp()");
  exit(-1);
}


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)
mov    %rdx,-0x18(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    11aa <main+0x4a>
mov    0x2e55(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe65(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1080 <strdup@plt>
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%edi
mov    $0x8,%esi
call   1030 <calloc@plt>
mov    %rax,-0x30(%rbp)
movl   $0x1,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1212 <main+0xb2>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1080 <strdup@plt>
mov    %rax,%rdx
mov    -0x30(%rbp),%rax
mov    -0x1c(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11d3 <main+0x73>
mov    -0x30(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movq   $0x0,(%rax,%rcx,8)
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1060 <execvp@plt>
lea    0xdf5(%rip),%rdi
call   1050 <perror@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r15
cmp    $0x1,%edi
jg     1195 <main+0x35>
mov    0x2e66(%rip),%rax
mov    (%rax),%edi
mov    (%r15),%rdx
lea    0xe7a(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    %edi,%ebp
mov    0x8(%r15),%rdi
call   1080 <strdup@plt>
mov    %rax,%r14
mov    %ebp,%edi
mov    $0x8,%esi
call   1030 <calloc@plt>
mov    %rax,%r13
mov    %ebp,%r12d
lea    -0x1(%r12),%rbp
xor    %ebx,%ebx
nopl   0x0(%rax)
mov    0x8(%r15,%rbx,8),%rdi
call   1080 <strdup@plt>
mov    %rax,0x0(%r13,%rbx,8)
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    11c0 <main+0x60>
movq   $0x0,0x0(%r13,%r12,8)
mov    %r14,%rdi
mov    %r13,%rsi
call   1060 <execvp@plt>
lea    0xe38(%rip),%rdi
call   1050 <perror@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [43 x i8] c"Usage: %s <path to command> (<arguments>)\0A\00"
@.str.1 = [19 x i8] c"Unable to execvp()\00"
define i32 @main(i32 %0, i8** %1, i8** %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8**
%7 = alloca i8**
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i8**
store i32 0, i32* %4
store i32 %0, i32* %5
store i8** %1, i8*** %6
store i8** %2, i8*** %7
%11 = load i32, i32* %5
%12 = icmp slt i32 %11, 2
br i1 %12, label %13, label %20
13: ; preds = %3
%14 = load i32, i32* @stderr
%15 = load i8**, i8*** %6
%16 = getelementptr inbounds i8*, i8** %15, i64 0
%17 = load i8*, i8** %16
%18 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), i8* %17)
%19 = call i32 @exit(i32 1)
unreachable
20: ; preds = %3
%21 = load i8**, i8*** %6
%22 = getelementptr inbounds i8*, i8** %21, i64 1
%23 = load i8*, i8** %22
%24 = call i8* @strdup(i8* %23)
store i8* %24, i8** %9
%25 = load i32, i32* %5
%26 = call i64 @calloc(i32 %25, i32 8)
%27 = inttoptr i64 %26 to i8**
store i8** %27, i8*** %10
store i32 1, i32* %8
br label %28
28: ; preds = %44, %20
%29 = load i32, i32* %8
%30 = load i32, i32* %5
%31 = icmp slt i32 %29, %30
br i1 %31, label %32, label %47
32: ; preds = %28
%33 = load i8**, i8*** %6
%34 = load i32, i32* %8
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i8*, i8** %33, i64 %35
%37 = load i8*, i8** %36
%38 = call i8* @strdup(i8* %37)
%39 = load i8**, i8*** %10
%40 = load i32, i32* %8
%41 = sub nsw i32 %40, 1
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i8*, i8** %39, i64 %42
store i8* %38, i8** %43
br label %44
44: ; preds = %32
%45 = load i32, i32* %8
%46 = add nsw i32 %45, 1
store i32 %46, i32* %8
br label %28
47: ; preds = %28
%48 = load i8**, i8*** %10
%49 = load i32, i32* %8
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds i8*, i8** %48, i64 %50
store i8* null, i8** %51
%52 = load i8*, i8** %9
%53 = load i8**, i8*** %10
%54 = call i32 @execvp(i8* %52, i8** %53)
%55 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
%56 = call i32 @exit(i32 -1)
unreachable
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [43 x i8] c"Usage: %s <path to command> (<arguments>)\0A\00"
@.str.1 = [19 x i8] c"Unable to execvp()\00"
define i32 @main(i32 %0, i8** nocapture %1, i8** nocapture readnone %2) {
%4 = icmp slt i32 %0, 2
br i1 %4, label %5, label %10
5: ; preds = %3
%6 = load i32, i32* @stderr
%7 = load i8*, i8** %1
%8 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), i8* %7)
%9 = tail call i32 @exit(i32 1)
unreachable
10: ; preds = %3
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = tail call i8* @strdup(i8* %12)
%14 = tail call i64 @calloc(i32 %0, i32 8)
%15 = inttoptr i64 %14 to i8**
%16 = zext i32 %0 to i64
br label %17
17: ; preds = %10, %17
%18 = phi i64 [ 1, %10 ], [ %24, %17 ]
%19 = getelementptr inbounds i8*, i8** %1, i64 %18
%20 = load i8*, i8** %19
%21 = tail call i8* @strdup(i8* %20)
%22 = add nsw i64 %18, -1
%23 = getelementptr inbounds i8*, i8** %15, i64 %22
store i8* %21, i8** %23
%24 = add nuw nsw i64 %18, 1
%25 = icmp eq i64 %24, %16
br i1 %25, label %26, label %17
26: ; preds = %17
%27 = getelementptr inbounds i8*, i8** %15, i64 %16
store i8* null, i8** %27
%28 = tail call i32 @execvp(i8* %13, i8** %15)
%29 = tail call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
%30 = tail call i32 @exit(i32 -1)
unreachable
}