#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*/ execl(char *, char *, char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ strncpy(char *, char *, int);
int main(int argc, char *argv[]) {
  if (argc < 2) {
    printf("Error: invalid arguments\n");
    return 1;
  }
  char elf_bin[256];
  strncpy(elf_bin, argv[1], 256);
  printf("<< About to exec elf: %s\n", elf_bin);
  execl(elf_bin, elf_bin, (char *)0);
  return 1;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x110,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    116d <main+0x3d>
lea    0xea6(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    11b9 <main+0x89>
lea    -0x110(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
mov    $0x100,%edx
call   1030 <strncpy@plt>
lea    -0x110(%rbp),%rsi
lea    0xe86(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x110(%rbp),%rdi
lea    -0x110(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1050 <execl@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x110,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x100,%rsp
cmp    $0x1,%edi
jg     115b <main+0x1b>
lea    0xec6(%rip),%rdi
call   1040 <puts@plt>
jmp    118d <main+0x4d>
mov    0x8(%rsi),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x100,%edx
call   1030 <strncpy@plt>
lea    0xe8a(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
mov    %rbx,%rsi
xor    %edx,%edx
call   1060 <execl@plt>
mov    $0x1,%eax
add    $0x100,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [26 x i8] c"Error: invalid arguments\0A\00"
@.str.1 = [26 x i8] c"<< About to exec elf: %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [256 x i8]
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 %11
9: ; preds = %2
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %22
11: ; preds = %2
%12 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 1
%15 = load i8*, i8** %14
%16 = call i32 @strncpy(i8* %12, i8* %15, i32 256)
%17 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* %17)
%19 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%20 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%21 = call i32 @execl(i8* %19, i8* %20, i8* null)
store i32 1, i32* %3
br label %22
22: ; preds = %11, %9
%23 = load i32, i32* %3
ret i32 %23
}

LLVM IR (-O2):
@.str.1 = [26 x i8] c"<< About to exec elf: %s\0A\00"
@str = [25 x i8] c"Error: invalid arguments\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [256 x i8]
%4 = icmp slt i32 %0, 2
br i1 %4, label %5, label %7
5: ; preds = %2
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str, i64 0, i64 0))
br label %14
7: ; preds = %2
%8 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = call i32 @strncpy(i8* %8, i8* %10, i32 256)
%12 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* %8)
%13 = call i32 @execl(i8* %8, i8* %8, i8* null)
br label %14
14: ; preds = %7, %5
ret i32 1
}