#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*/ execv(char *, char **);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ putenv(char *);
int main(int argc, char **argv) {
  if (argc == 1) {
    printf("You must supply a program which uses readline to run\n");
    printf("\n");
    printf("Example: %s /bin/irb\n", argv[0]);
    return 1;
  }
  putenv("LD_PRELOAD=./librlundoable.so:/lib/x86_64-linux-gnu/libtinfo.so.5");
  execv(argv[1], argv + 1);
  perror("exec() failed");
  return 2;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x1,-0x8(%rbp)
jne    119d <main+0x5d>
lea    0xe99(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xed5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xeac(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    11d1 <main+0x91>
lea    0xea8(%rip),%rdi
call   1040 <putenv@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x10(%rbp),%rsi
add    $0x8,%rsi
call   1060 <execv@plt>
lea    0xec9(%rip),%rdi
call   1050 <perror@plt>
movl   $0x2,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    %rsi,%rbx
cmp    $0x1,%edi
jne    1197 <main+0x37>
lea    0xef6(%rip),%rdi
call   1040 <puts@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    (%rbx),%rsi
lea    0xe77(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x1,%eax
pop    %rbx
ret
lea    0xe78(%rip),%rdi
call   1060 <putenv@plt>
mov    0x8(%rbx),%rdi
add    $0x8,%rbx
mov    %rbx,%rsi
call   1080 <execv@plt>
lea    0xe9e(%rip),%rdi
call   1070 <perror@plt>
mov    $0x2,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [54 x i8] c"You must supply a program which uses readline to run\0A\00"
@.str.1 = [2 x i8] c"\0A\00"
@.str.2 = [22 x i8] c"Example: %s /bin/irb\0A\00"
@.str.3 = [66 x i8] c"LD_PRELOAD=./librlundoable.so:/lib/x86_64-linux-gnu/libtinfo.so.5\00"
@.str.4 = [14 x i8] c"exec() failed\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%6 = load i32, i32* %4
%7 = icmp eq i32 %6, 1
br i1 %7, label %8, label %15
8: ; preds = %2
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str, i64 0, i64 0))
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%11 = load i8**, i8*** %5
%12 = getelementptr inbounds i8*, i8** %11, i64 0
%13 = load i8*, i8** %12
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i8* %13)
store i32 1, i32* %3
br label %24
15: ; preds = %2
%16 = call i32 @putenv(i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str.3, i64 0, i64 0))
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = call i32 @execv(i8* %19, i8** %21)
%23 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0))
store i32 2, i32* %3
br label %24
24: ; preds = %15, %8
%25 = load i32, i32* %3
ret i32 %25
}

LLVM IR (-O2):
@.str.2 = [22 x i8] c"Example: %s /bin/irb\0A\00"
@.str.3 = [66 x i8] c"LD_PRELOAD=./librlundoable.so:/lib/x86_64-linux-gnu/libtinfo.so.5\00"
@.str.4 = [14 x i8] c"exec() failed\00"
@str = [53 x i8] c"You must supply a program which uses readline to run\00"
define i32 @main(i32 %0, i8** %1) {
%3 = icmp eq i32 %0, 1
br i1 %3, label %4, label %9
4: ; preds = %2
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([53 x i8], [53 x i8]* @str, i64 0, i64 0))
%6 = tail call i32 @putchar(i32 10)
%7 = load i8*, i8** %1
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i8* %7)
br label %15
9: ; preds = %2
%10 = tail call i32 @putenv(i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str.3, i64 0, i64 0))
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = tail call i32 @execv(i8* %12, i8** %11)
%14 = tail call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0))
br label %15
15: ; preds = %9, %4
%16 = phi i32 [ 1, %4 ], [ 2, %9 ]
ret i32 %16
}