#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 BUFSIZ;
scalar_t__ findInterposeLibrary(char *, int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int, char *, int);
int /*<<< orphan*/ *getenv(char *);
int getpid();
int /*<<< orphan*/ setenv(char *, char *, int);
int /*<<< orphan*/ snprintf(char *, int, char *, char const *, char const *);
int /*<<< orphan*/ stderr;
void set_tracing_environment(const char *tempdir,
                             const char *trace_file_prefix) {
  if (getenv("KICKSTART_PREFIX") != NULL || getenv("LD_PRELOAD") != NULL) {
    return;
  }
  char ld_preload[BUFSIZ];
  if (findInterposeLibrary(ld_preload, BUFSIZ) < 0) {
    fprintf(stderr,
            "kickstart[%d]: %s[%d]: "
            "Cannot locate libinterpose.so\n",
            getpid(),
            "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
            "2022-01-22/02-19-57/repos/pegasus-isi/pegasus/refs/heads/master/"
            "src/tools/pegasus-kickstart/mysystem.c",
            419);
    return;
  }
  setenv("LD_PRELOAD", ld_preload, 1);
  char kickstart_prefix[BUFSIZ];
  snprintf(kickstart_prefix, BUFSIZ, "%s/%s", tempdir, trace_file_prefix);
  setenv("KICKSTART_PREFIX", kickstart_prefix, 1);
}


x86 assembly (clang, -O0):
<set_tracing_environment>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe89(%rip),%rdi
call   1030 <getenv@plt>
cmp    $0x0,%rax
jne    119c <set_tracing_environment+0x3c>
lea    0xe84(%rip),%rdi
call   1030 <getenv@plt>
cmp    $0x0,%rax
je     11a1 <set_tracing_environment+0x41>
jmp    129c <set_tracing_environment+0x13c>
mov    0x2e30(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x38(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x20(%rbp)
mov    0x2e04(%rip),%rax
mov    (%rax),%esi
call   1040 <findInterposeLibrary@plt>
cmp    $0x0,%rax
jge    1222 <set_tracing_environment+0xc2>
mov    0x2df4(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x3c(%rbp)
mov    $0x0,%al
call   1060 <getpid@plt>
mov    -0x3c(%rbp),%edi
mov    %eax,%edx
lea    0xe18(%rip),%rsi
lea    0xe47(%rip),%rcx
mov    $0x1a3,%r8d
call   1080 <fprintf@plt>
movl   $0x1,-0x24(%rbp)
jmp    1295 <set_tracing_environment+0x135>
mov    -0x38(%rbp),%rsi
lea    0xde4(%rip),%rdi
mov    $0x1,%edx
call   1050 <setenv@plt>
mov    0x2d9a(%rip),%rax
mov    (%rax),%eax
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x48(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x30(%rbp)
mov    0x2d75(%rip),%rax
mov    (%rax),%esi
mov    -0x8(%rbp),%rcx
mov    -0x10(%rbp),%r8
lea    0xe85(%rip),%rdx
call   1070 <snprintf@plt>
mov    -0x48(%rbp),%rsi
lea    0xd7c(%rip),%rdi
mov    $0x1,%edx
call   1050 <setenv@plt>
movl   $0x0,-0x24(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_tracing_environment>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
lea    0xe85(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
jne    1255 <set_tracing_environment+0xf5>
lea    0xe81(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
jne    1255 <set_tracing_environment+0xf5>
mov    %rsp,%r12
mov    0x2e30(%rip),%r13
mov    0x0(%r13),%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    0x0(%r13),%esi
mov    %rbx,%rdi
call   1040 <findInterposeLibrary@plt>
test   %rax,%rax
js     1225 <set_tracing_environment+0xc5>
lea    0xe3c(%rip),%rdi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1050 <setenv@plt>
mov    0x0(%r13),%esi
mov    %rsp,%rbx
mov    %rsi,%rax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
lea    0xef8(%rip),%rdx
mov    %rbx,%rdi
mov    %r15,%rcx
mov    %r14,%r8
call   1070 <snprintf@plt>
lea    0xdea(%rip),%rdi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1050 <setenv@plt>
jmp    1252 <set_tracing_environment+0xf2>
mov    0x2db4(%rip),%rax
mov    (%rax),%ebx
xor    %eax,%eax
call   1060 <getpid@plt>
lea    0xde0(%rip),%rsi
lea    0xe0f(%rip),%rcx
mov    %ebx,%edi
mov    %eax,%edx
mov    $0x1a3,%r8d
call   1080 <fprintf@plt>
mov    %r12,%rsp
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [17 x i8] c"KICKSTART_PREFIX\00"
@.str.1 = [11 x i8] c"LD_PRELOAD\00"
@BUFSIZ = global i32 0
@stderr = global i32 0
@.str.2 = [54 x i8] c"kickstart[%d]: %s[%d]: Cannot locate libinterpose.so\0A\00"
@.str.3 = [167 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/pegasus-isi/pegasus/refs/heads/master/src/tools/pegasus-kickstart/mysystem.c\00"
@.str.4 = [6 x i8] c"%s/%s\00"
define void @set_tracing_environment(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i32
%8 = alloca i64
store i8* %0, i8** %3
store i8* %1, i8** %4
%9 = call i32* @getenv(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%10 = icmp ne i32* %9, null
br i1 %10, label %14, label %11
11: ; preds = %2
%12 = call i32* @getenv(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%13 = icmp ne i32* %12, null
br i1 %13, label %14, label %15
14: ; preds = %11, %2
br label %40
15: ; preds = %11
%16 = load i32, i32* @BUFSIZ
%17 = zext i32 %16 to i64
%18 = call i8* @llvm.stacksave()
store i8* %18, i8** %5
%19 = alloca i8, i64 %17
store i64 %17, i64* %6
%20 = load i32, i32* @BUFSIZ
%21 = call i64 @findInterposeLibrary(i8* %19, i32 %20)
%22 = icmp slt i64 %21, 0
br i1 %22, label %23, label %27
23: ; preds = %15
%24 = load i32, i32* @stderr
%25 = call i32 (...) @getpid()
%26 = call i32 @fprintf(i32 %24, i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.2, i64 0, i64 0), i32 %25, i8* getelementptr inbounds ([167 x i8], [167 x i8]* @.str.3, i64 0, i64 0), i32 419)
store i32 1, i32* %7
br label %37
27: ; preds = %15
%28 = call i32 @setenv(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* %19, i32 1)
%29 = load i32, i32* @BUFSIZ
%30 = zext i32 %29 to i64
%31 = alloca i8, i64 %30
store i64 %30, i64* %8
%32 = load i32, i32* @BUFSIZ
%33 = load i8*, i8** %3
%34 = load i8*, i8** %4
%35 = call i32 @snprintf(i8* %31, i32 %32, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8* %33, i8* %34)
%36 = call i32 @setenv(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %31, i32 1)
store i32 0, i32* %7
br label %37
37: ; preds = %27, %23
%38 = load i8*, i8** %5
%39 = load i32, i32* %7
switch i32 %39, label %41 [
i32 0, label %40
i32 1, label %40
]
40: ; preds = %14, %37, %37
ret void
41: ; preds = %37
unreachable
}

LLVM IR (-O2):
@.str = [17 x i8] c"KICKSTART_PREFIX\00"
@.str.1 = [11 x i8] c"LD_PRELOAD\00"
@BUFSIZ = global i32 0
@stderr = global i32 0
@.str.2 = [54 x i8] c"kickstart[%d]: %s[%d]: Cannot locate libinterpose.so\0A\00"
@.str.3 = [167 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/pegasus-isi/pegasus/refs/heads/master/src/tools/pegasus-kickstart/mysystem.c\00"
@.str.4 = [6 x i8] c"%s/%s\00"
define void @set_tracing_environment(i8* %0, i8* %1) {
%3 = tail call i32* @getenv(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %28
5: ; preds = %2
%6 = tail call i32* @getenv(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%7 = icmp eq i32* %6, null
br i1 %7, label %8, label %28
8: ; preds = %5
%9 = load i32, i32* @BUFSIZ
%10 = zext i32 %9 to i64
%11 = tail call i8* @llvm.stacksave()
%12 = alloca i8, i64 %10
%13 = load i32, i32* @BUFSIZ
%14 = call i64 @findInterposeLibrary(i8* %12, i32 %13)
%15 = icmp slt i64 %14, 0
br i1 %15, label %16, label %20
16: ; preds = %8
%17 = load i32, i32* @stderr
%18 = call i32 (...) @getpid()
%19 = call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.2, i64 0, i64 0), i32 %18, i8* getelementptr inbounds ([167 x i8], [167 x i8]* @.str.3, i64 0, i64 0), i32 419)
br label %27
20: ; preds = %8
%21 = call i32 @setenv(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* %12, i32 1)
%22 = load i32, i32* @BUFSIZ
%23 = zext i32 %22 to i64
%24 = alloca i8, i64 %23
%25 = call i32 @snprintf(i8* %24, i32 %22, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8* %0, i8* %1)
%26 = call i32 @setenv(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %24, i32 1)
br label %27
27: ; preds = %20, %16
br label %28
28: ; preds = %2, %5, %27
ret void
}