#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*/ _exit(int);
scalar_t__ execv(char *, char **);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  char *new_argv[] = {NULL, "3", NULL};
  if (argc != 2) {
    fprintf(stderr, "Usage: %s exepath\n", argv[0]);
    return -1;
  }
  new_argv[0] = argv[1];
  if (execv(new_argv[0], new_argv) < 0)
    perror("execv");
  _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    0x2ca3(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0x2ca0(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0x2c9d(%rip),%rax
mov    %rax,-0x20(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11a8 <main+0x68>
mov    0x2e58(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe6a(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0xffffffff,%eax
add    $0x30,%rsp
pop    %rbp
ret
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1060 <execv@plt>
cmp    $0x0,%rax
jge    11d7 <main+0x97>
lea    0xe43(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%edi
call   1030 <_exit@plt>

x86 assembly (clang, -O2):
<main>:
sub    $0x18,%rsp
mov    0x2cc5(%rip),%rax
mov    %rax,0x10(%rsp)
movaps 0x2ca9(%rip),%xmm0
movaps %xmm0,(%rsp)
cmp    $0x2,%edi
je     1182 <main+0x42>
mov    0x2e79(%rip),%rax
mov    (%rax),%edi
mov    (%rsi),%rdx
lea    0xe8f(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0xffffffff,%eax
add    $0x18,%rsp
ret
mov    0x8(%rsi),%rdi
mov    %rdi,(%rsp)
mov    %rsp,%rsi
call   1060 <execv@plt>
test   %rax,%rax
jns    11a3 <main+0x63>
lea    0xe77(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%edi
call   1030 <_exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"3\00"
@__const.main.new_argv = [3 x i8*] [i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i32 0, i32 0), i8* null]
@stderr = global i32 0
@.str.1 = [19 x i8] c"Usage: %s exepath\0A\00"
@.str.2 = [6 x i8] c"execv\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [3 x i8*]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = bitcast [3 x i8*]* %6 to i8*
%8 = load i32, i32* %4
%9 = icmp ne i32 %8, 2
br i1 %9, label %10, label %16
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 ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* %14)
ret i32 -1
16: ; preds = %2
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
%20 = getelementptr inbounds [3 x i8*], [3 x i8*]* %6, i64 0, i64 0
store i8* %19, i8** %20
%21 = getelementptr inbounds [3 x i8*], [3 x i8*]* %6, i64 0, i64 0
%22 = load i8*, i8** %21
%23 = getelementptr inbounds [3 x i8*], [3 x i8*]* %6, i64 0, i64 0
%24 = call i64 @execv(i8* %22, i8** %23)
%25 = icmp slt i64 %24, 0
br i1 %25, label %26, label %28
26: ; preds = %16
%27 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
br label %28
28: ; preds = %26, %16
%29 = call i32 @_exit(i32 1)
unreachable
}

LLVM IR (-O2):
@.str = [2 x i8] c"3\00"
@__const.main.new_argv = [3 x i8*] [i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i32 0, i32 0), i8* null]
@stderr = global i32 0
@.str.1 = [19 x i8] c"Usage: %s exepath\0A\00"
@.str.2 = [6 x i8] c"execv\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [3 x i8*]
%4 = bitcast [3 x i8*]* %3 to i8*
%5 = icmp eq i32 %0, 2
br i1 %5, label %10, label %6
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = load i8*, i8** %1
%9 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* %8)
ret i32 -1
10: ; preds = %2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = getelementptr inbounds [3 x i8*], [3 x i8*]* %3, i64 0, i64 0
store i8* %12, i8** %13
%14 = call i64 @execv(i8* %12, i8** %13)
%15 = icmp slt i64 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %10
%17 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
br label %18
18: ; preds = %16, %10
%19 = call i32 @_exit(i32 1)
unreachable
}