#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 **);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ memcpy(char **, char **, int);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  if (argc < 2) {
    fprintf(stderr, "This program expects at least one argument.\n");
    return 1;
  }
  int arg_cnt = argc - 1;
  char *exec_argv[arg_cnt + 1];
  memcpy(exec_argv, argv + 1, sizeof(char *) * arg_cnt);
  exec_argv[arg_cnt] = NULL;
  execvp(exec_argv[0], exec_argv);
  fprintf(stderr, "Failed to execvp(): %m\n");
  return 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)
cmpl   $0x2,-0x8(%rbp)
jge    1171 <main+0x41>
mov    0x2e89(%rip),%rax
mov    (%rax),%edi
lea    0xea0(%rip),%rsi
call   1030 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    11f6 <main+0xc6>
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
lea    0xf(,%rax,8),%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x30(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rsi
add    $0x8,%rsi
movslq -0x14(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edx
call   1040 <memcpy@plt>
mov    -0x30(%rbp),%rsi
movslq -0x14(%rbp),%rax
movq   $0x0,(%rsi,%rax,8)
mov    (%rsi),%rdi
call   1050 <execvp@plt>
mov    0x2e06(%rip),%rax
mov    (%rax),%edi
lea    0xe4a(%rip),%rsi
call   1030 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
cmp    $0x1,%edi
jg     115a <main+0x2a>
mov    0x2e96(%rip),%rax
mov    (%rax),%edi
lea    0xead(%rip),%rsi
call   1030 <fprintf@plt>
jmp    11be <main+0x8e>
mov    %rsp,%r14
lea    -0x1(%rdi),%r15d
mov    %edi,%eax
mov    %rsp,%r12
lea    0xf(,%rax,8),%rbx
and    $0xfffffffffffffff0,%rbx
mov    %r12,%r13
sub    %rbx,%r13
mov    %r13,%rsp
neg    %rbx
add    $0x8,%rsi
lea    -0x8(,%rdi,8),%edx
mov    %r13,%rdi
call   1040 <memcpy@plt>
movq   $0x0,0x0(%r13,%r15,8)
mov    (%r12,%rbx,1),%rdi
mov    %r13,%rsi
call   1050 <execvp@plt>
mov    0x2e33(%rip),%rax
mov    (%rax),%edi
lea    0xe77(%rip),%rsi
call   1030 <fprintf@plt>
mov    %r14,%rsp
mov    $0x1,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [45 x i8] c"This program expects at least one argument.\0A\00"
@.str.1 = [24 x i8] c"Failed to execvp(): %m\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp slt i32 %9, 2
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %38
14: ; preds = %2
%15 = load i32, i32* %4
%16 = sub nsw i32 %15, 1
store i32 %16, i32* %6
%17 = load i32, i32* %6
%18 = add nsw i32 %17, 1
%19 = zext i32 %18 to i64
%20 = call i8* @llvm.stacksave()
store i8* %20, i8** %7
%21 = alloca i8*, i64 %19
store i64 %19, i64* %8
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i32, i32* %6
%25 = sext i32 %24 to i64
%26 = mul i64 8, %25
%27 = trunc i64 %26 to i32
%28 = call i32 @memcpy(i8** %21, i8** %23, i32 %27)
%29 = load i32, i32* %6
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i8*, i8** %21, i64 %30
store i8* null, i8** %31
%32 = getelementptr inbounds i8*, i8** %21, i64 0
%33 = load i8*, i8** %32
%34 = call i32 @execvp(i8* %33, i8** %21)
%35 = load i32, i32* @stderr
%36 = call i32 @fprintf(i32 %35, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %3
%37 = load i8*, i8** %7
br label %38
38: ; preds = %14, %11
%39 = load i32, i32* %3
ret i32 %39
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [45 x i8] c"This program expects at least one argument.\0A\00"
@.str.1 = [24 x i8] c"Failed to execvp(): %m\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %4, label %7
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0))
br label %21
7: ; preds = %2
%8 = add nsw i32 %0, -1
%9 = zext i32 %0 to i64
%10 = tail call i8* @llvm.stacksave()
%11 = alloca i8*, i64 %9
%12 = getelementptr inbounds i8*, i8** %1, i64 1
%13 = zext i32 %8 to i64
%14 = shl i32 %8, 3
%15 = call i32 @memcpy(i8** %11, i8** %12, i32 %14)
%16 = getelementptr inbounds i8*, i8** %11, i64 %13
store i8* null, i8** %16
%17 = load i8*, i8** %11
%18 = call i32 @execvp(i8* %17, i8** %11)
%19 = load i32, i32* @stderr
%20 = call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
br label %21
21: ; preds = %7, %4
ret i32 1
}