#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_FAILURE;
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ launch(char **);
int /*<<< orphan*/ memset(char **, int /*<<< orphan*/, int);
int /*<<< orphan*/ rebuild_args(size_t, char **, char **);
scalar_t__ setenv(char *, char *, int);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  assert(argc > 0);
  char *subv[argc];
  memset(subv, 0, sizeof(char *) * argc);
  rebuild_args((size_t)argc, argv, subv);
  if (setenv("LD_PRELOAD", "./libsitu.so", 1) != 0) {
    fprintf(stderr, "failed setting 'LD_PRELOAD' env var.\n");
    exit(EXIT_FAILURE);
  }
  launch(subv);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x4(%rbp),%eax
test   %eax,%eax
setg   %al
movzbl %al,%edi
call   1060 <assert@plt>
mov    -0x4(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
lea    0xf(,%rax,8),%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x28(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x20(%rbp)
movslq -0x4(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edx
xor    %esi,%esi
call   1050 <memset@plt>
mov    -0x28(%rbp),%rdx
movslq -0x4(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <rebuild_args@plt>
lea    0xe21(%rip),%rdi
lea    0xe25(%rip),%rsi
mov    $0x1,%edx
call   1030 <setenv@plt>
cmp    $0x0,%rax
je     121d <main+0xad>
mov    0x2ddf(%rip),%rax
mov    (%rax),%edi
lea    0xe0e(%rip),%rsi
call   1070 <fprintf@plt>
mov    0x2dc2(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    -0x28(%rbp),%rdi
call   1080 <launch@plt>
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
xor    %eax,%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %edi,%r15d
xor    %edi,%edi
test   %r15d,%r15d
setg   %dil
call   1060 <assert@plt>
mov    %r15d,%eax
mov    %rsp,%rbx
lea    0xf(,%rax,8),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
movslq %r15d,%r15
lea    0x0(,%r15,8),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1050 <memset@plt>
mov    %r15,%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
call   1040 <rebuild_args@plt>
lea    0xe30(%rip),%rdi
lea    0xe34(%rip),%rsi
mov    $0x1,%edx
call   1030 <setenv@plt>
test   %rax,%rax
jne    11fb <main+0x8b>
mov    %rbx,%rdi
call   1080 <launch@plt>
xor    %eax,%eax
lea    -0x18(%rbp),%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2dde(%rip),%rax
mov    (%rax),%edi
lea    0xe0d(%rip),%rsi
call   1070 <fprintf@plt>
mov    0x2dc1(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [11 x i8] c"LD_PRELOAD\00"
@.str.1 = [13 x i8] c"./libsitu.so\00"
@stderr = global i32 0
@.str.2 = [38 x i8] c"failed setting 'LD_PRELOAD' env var.\0A\00"
@EXIT_FAILURE = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i8*
%6 = alloca i64
store i32 %0, i32* %3
store i8** %1, i8*** %4
%7 = load i32, i32* %3
%8 = icmp sgt i32 %7, 0
%9 = zext i1 %8 to i32
%10 = call i32 @assert(i32 %9)
%11 = load i32, i32* %3
%12 = zext i32 %11 to i64
%13 = call i8* @llvm.stacksave()
store i8* %13, i8** %5
%14 = alloca i8*, i64 %12
store i64 %12, i64* %6
%15 = load i32, i32* %3
%16 = sext i32 %15 to i64
%17 = mul i64 8, %16
%18 = trunc i64 %17 to i32
%19 = call i32 @memset(i8** %14, i32 0, i32 %18)
%20 = load i32, i32* %3
%21 = sext i32 %20 to i64
%22 = load i8**, i8*** %4
%23 = call i32 @rebuild_args(i64 %21, i8** %22, i8** %14)
%24 = call i64 @setenv(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 1)
%25 = icmp ne i64 %24, 0
br i1 %25, label %26, label %31
26: ; preds = %2
%27 = load i32, i32* @stderr
%28 = call i32 @fprintf(i32 %27, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0))
%29 = load i32, i32* @EXIT_FAILURE
%30 = call i32 @exit(i32 %29)
unreachable
31: ; preds = %2
%32 = call i32 @launch(i8** %14)
%33 = load i8*, i8** %5
ret i32 0
}

LLVM IR (-O2):
@.str = [11 x i8] c"LD_PRELOAD\00"
@.str.1 = [13 x i8] c"./libsitu.so\00"
@stderr = global i32 0
@.str.2 = [38 x i8] c"failed setting 'LD_PRELOAD' env var.\0A\00"
@EXIT_FAILURE = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = icmp sgt i32 %0, 0
%4 = zext i1 %3 to i32
%5 = tail call i32 @assert(i32 %4)
%6 = zext i32 %0 to i64
%7 = alloca i8*, i64 %6
%8 = sext i32 %0 to i64
%9 = shl i32 %0, 3
%10 = call i32 @memset(i8** %7, i32 0, i32 %9)
%11 = call i32 @rebuild_args(i64 %8, i8** %1, i8** %7)
%12 = call i64 @setenv(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 1)
%13 = icmp eq i64 %12, 0
br i1 %13, label %19, label %14
14: ; preds = %2
%15 = load i32, i32* @stderr
%16 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0))
%17 = load i32, i32* @EXIT_FAILURE
%18 = call i32 @exit(i32 %17)
unreachable
19: ; preds = %2
%20 = call i32 @launch(i8** %7)
ret i32 0
}