#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 */
typedef int pid_t;

/* Variables and functions */
int /*<<< orphan*/ abort();
int /*<<< orphan*/ execvp(char *, char **);
int fork();
int /*<<< orphan*/ *getenv(char *);
int /*<<< orphan*/ ignore_children();
int /*<<< orphan*/ rye(int);
scalar_t__ setenv(char *, char *, int);
int /*<<< orphan*/ simplify_env();
void launch(char *argv[]) {
  if (getenv("LIBSITU_SYNC") == NULL) {
    ignore_children();
  }
  pid_t pid = fork();
  if (pid == -1) {
    abort();
  }
  if (pid == 0) {
    simplify_env();
    if (setenv("LD_PRELOAD", "./libsitu.so", 1) != 0) {
      abort();
    }
    execvp(argv[0], argv);
    abort();
  }
  rye(pid);
}


x86 assembly (clang, -O0):
<launch>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
lea    0xe6d(%rip),%rdi
call   1030 <getenv@plt>
cmp    $0x0,%rax
jne    11a9 <launch+0x29>
mov    $0x0,%al
call   1040 <ignore_children@plt>
mov    $0x0,%al
call   10a0 <fork@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0xffffffff,-0xc(%rbp)
jne    11c4 <launch+0x44>
mov    $0x0,%al
call   1050 <abort@plt>
cmpl   $0x0,-0xc(%rbp)
jne    1215 <launch+0x95>
mov    $0x0,%al
call   1060 <simplify_env@plt>
lea    0xe31(%rip),%rdi
lea    0xe35(%rip),%rsi
mov    $0x1,%edx
call   1070 <setenv@plt>
cmp    $0x0,%rax
je     11fe <launch+0x7e>
mov    $0x0,%al
call   1050 <abort@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
mov    -0x8(%rbp),%rsi
call   1090 <execvp@plt>
mov    $0x0,%al
call   1050 <abort@plt>
mov    -0xc(%rbp),%edi
call   1080 <rye@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<launch>:
push   %rbx
mov    %rdi,%rbx
lea    0xe75(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
jne    119c <launch+0x1c>
xor    %eax,%eax
call   1040 <ignore_children@plt>
xor    %eax,%eax
call   10a0 <fork@plt>
test   %eax,%eax
je     11b4 <launch+0x34>
cmp    $0xffffffff,%eax
je     11e3 <launch+0x63>
mov    %eax,%edi
pop    %rbx
jmp    1080 <rye@plt>
xor    %eax,%eax
call   1060 <simplify_env@plt>
lea    0xe4b(%rip),%rdi
lea    0xe4f(%rip),%rsi
mov    $0x1,%edx
call   1070 <setenv@plt>
test   %rax,%rax
jne    11e3 <launch+0x63>
mov    (%rbx),%rdi
mov    %rbx,%rsi
call   1090 <execvp@plt>
xor    %eax,%eax
call   1050 <abort@plt>

LLVM IR (-O0):
@.str = [13 x i8] c"LIBSITU_SYNC\00"
@.str.1 = [11 x i8] c"LD_PRELOAD\00"
@.str.2 = [13 x i8] c"./libsitu.so\00"
define void @launch(i8** %0) {
%2 = alloca i8**
%3 = alloca i32
store i8** %0, i8*** %2
%4 = call i32* @getenv(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %8
6: ; preds = %1
%7 = call i32 (...) @ignore_children()
br label %8
8: ; preds = %6, %1
%9 = call i32 (...) @fork()
store i32 %9, i32* %3
%10 = load i32, i32* %3
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %14
12: ; preds = %8
%13 = call i32 (...) @abort()
unreachable
14: ; preds = %8
%15 = load i32, i32* %3
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %30
17: ; preds = %14
%18 = call i32 (...) @simplify_env()
%19 = call i64 @setenv(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i32 1)
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %17
%22 = call i32 (...) @abort()
unreachable
23: ; preds = %17
%24 = load i8**, i8*** %2
%25 = getelementptr inbounds i8*, i8** %24, i64 0
%26 = load i8*, i8** %25
%27 = load i8**, i8*** %2
%28 = call i32 @execvp(i8* %26, i8** %27)
%29 = call i32 (...) @abort()
unreachable
30: ; preds = %14
%31 = load i32, i32* %3
%32 = call i32 @rye(i32 %31)
ret void
}

LLVM IR (-O2):
@.str = [13 x i8] c"LIBSITU_SYNC\00"
@.str.1 = [11 x i8] c"LD_PRELOAD\00"
@.str.2 = [13 x i8] c"./libsitu.so\00"
define void @launch(i8** %0) {
%2 = tail call i32* @getenv(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i32* %2, null
br i1 %3, label %4, label %6
4: ; preds = %1
%5 = tail call i32 (...) @ignore_children()
br label %6
6: ; preds = %4, %1
%7 = tail call i32 (...) @fork()
switch i32 %7, label %20 [
i32 -1, label %8
i32 0, label %10
]
8: ; preds = %6
%9 = tail call i32 (...) @abort()
unreachable
10: ; preds = %6
%11 = tail call i32 (...) @simplify_env()
%12 = tail call i64 @setenv(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i32 1)
%13 = icmp eq i64 %12, 0
br i1 %13, label %16, label %14
14: ; preds = %10
%15 = tail call i32 (...) @abort()
unreachable
16: ; preds = %10
%17 = load i8*, i8** %0
%18 = tail call i32 @execvp(i8* %17, i8** %0)
%19 = tail call i32 (...) @abort()
unreachable
20: ; preds = %6
%21 = tail call i32 @rye(i32 %7)
ret void
}