#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 */
char *basename(char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ free(char *);
char *getenv(char *);
int /*<<< orphan*/ stderr;
char *strdup(char *);
char *strtok(char *, char *);
void show_preload() {
  char *current_env = NULL;
  char *module_list = NULL;
  char *token = NULL;
  int num_modules = 0;
  current_env = getenv("LD_PRELOAD");
  if (current_env != NULL) {
    module_list = strdup(current_env);
    token = strtok(module_list, ":");
    fprintf(stderr, "extrae-loader: The following modules will be loaded:\n");
    while (token) {
      num_modules++;
      char *library_name = basename(token);
      fprintf(stderr, "#%d: %s [%s]\n", num_modules, library_name, token);
      token = strtok(NULL, ":");
    }
    free(module_list);
  } else {
    fprintf(stderr, "extrae-loader: WARNING: Any module loaded!\n");
  }
}


x86 assembly (clang, -O0):
<show_preload>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movq   $0x0,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
lea    0xe72(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     1244 <show_preload+0xe4>
mov    -0x8(%rbp),%rdi
call   1080 <strdup@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe51(%rip),%rsi
call   1070 <strtok@plt>
mov    %rax,-0x18(%rbp)
mov    0x2e16(%rip),%rax
mov    (%rax),%edi
lea    0xe3a(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
cmpq   $0x0,-0x18(%rbp)
je     1236 <show_preload+0xd6>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
call   1060 <basename@plt>
mov    %rax,-0x28(%rbp)
mov    0x2dde(%rip),%rax
mov    (%rax),%edi
mov    -0x1c(%rbp),%edx
mov    -0x28(%rbp),%rcx
mov    -0x18(%rbp),%r8
lea    0xe2d(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
xor    %eax,%eax
mov    %eax,%edi
lea    0xde3(%rip),%rsi
call   1070 <strtok@plt>
mov    %rax,-0x18(%rbp)
jmp    11da <show_preload+0x7a>
mov    -0x10(%rbp),%rdi
call   1040 <free@plt>
jmp    125b <show_preload+0xfb>
mov    0x2d95(%rip),%rax
mov    (%rax),%edi
lea    0xdfd(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<show_preload>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xe8e(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     1219 <show_preload+0xb9>
mov    %rax,%rdi
call   1080 <strdup@plt>
mov    %rax,%r14
lea    0xe79(%rip),%rsi
mov    %rax,%rdi
call   1070 <strtok@plt>
mov    %rax,%rbx
mov    0x2e3c(%rip),%r13
mov    0x0(%r13),%edi
lea    0xe5e(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
test   %rbx,%rbx
je     1203 <show_preload+0xa3>
mov    $0x1,%ebp
lea    0xe7c(%rip),%r15
lea    0xe3d(%rip),%r12
xchg   %ax,%ax
mov    %rbx,%rdi
call   1060 <basename@plt>
mov    0x0(%r13),%edi
mov    %r15,%rsi
mov    %ebp,%edx
mov    %rax,%rcx
mov    %rbx,%r8
xor    %eax,%eax
call   1050 <fprintf@plt>
xor    %edi,%edi
mov    %r12,%rsi
call   1070 <strtok@plt>
mov    %rax,%rbx
add    $0x1,%ebp
test   %rax,%rax
jne    11d0 <show_preload+0x70>
mov    %r14,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <free@plt>
mov    0x2dc0(%rip),%rax
mov    (%rax),%edi
lea    0xe28(%rip),%rsi
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <fprintf@plt>

LLVM IR (-O0):
@.str = [11 x i8] c"LD_PRELOAD\00"
@.str.1 = [2 x i8] c":\00"
@stderr = global i32 0
@.str.2 = [54 x i8] c"extrae-loader: The following modules will be loaded:\0A\00"
@.str.3 = [14 x i8] c"#%d: %s [%s]\0A\00"
@.str.4 = [44 x i8] c"extrae-loader: WARNING: Any module loaded!\0A\00"
define void @show_preload() {
%1 = alloca i8*
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8*
store i8* null, i8** %1
store i8* null, i8** %2
store i8* null, i8** %3
store i32 0, i32* %4
%6 = call i8* @getenv(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
store i8* %6, i8** %1
%7 = load i8*, i8** %1
%8 = icmp ne i8* %7, null
br i1 %8, label %9, label %33
9: ; preds = %0
%10 = load i8*, i8** %1
%11 = call i8* @strdup(i8* %10)
store i8* %11, i8** %2
%12 = load i8*, i8** %2
%13 = call i8* @strtok(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i8* %13, i8** %3
%14 = load i32, i32* @stderr
%15 = call i32 (i32, i8*, ...) @fprintf(i32 %14, i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.2, i64 0, i64 0))
br label %16
16: ; preds = %19, %9
%17 = load i8*, i8** %3
%18 = icmp ne i8* %17, null
br i1 %18, label %19, label %30
19: ; preds = %16
%20 = load i32, i32* %4
%21 = add nsw i32 %20, 1
store i32 %21, i32* %4
%22 = load i8*, i8** %3
%23 = call i8* @basename(i8* %22)
store i8* %23, i8** %5
%24 = load i32, i32* @stderr
%25 = load i32, i32* %4
%26 = load i8*, i8** %5
%27 = load i8*, i8** %3
%28 = call i32 (i32, i8*, ...) @fprintf(i32 %24, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i32 %25, i8* %26, i8* %27)
%29 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i8* %29, i8** %3
br label %16
30: ; preds = %16
%31 = load i8*, i8** %2
%32 = call i32 @free(i8* %31)
br label %36
33: ; preds = %0
%34 = load i32, i32* @stderr
%35 = call i32 (i32, i8*, ...) @fprintf(i32 %34, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.4, i64 0, i64 0))
br label %36
36: ; preds = %33, %30
ret void
}

LLVM IR (-O2):
@.str = [11 x i8] c"LD_PRELOAD\00"
@.str.1 = [2 x i8] c":\00"
@stderr = global i32 0
@.str.2 = [54 x i8] c"extrae-loader: The following modules will be loaded:\0A\00"
@.str.3 = [14 x i8] c"#%d: %s [%s]\0A\00"
@.str.4 = [44 x i8] c"extrae-loader: WARNING: Any module loaded!\0A\00"
define void @show_preload() {
%1 = tail call i8* @getenv(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%2 = icmp eq i8* %1, null
br i1 %2, label %20, label %3
3: ; preds = %0
%4 = tail call i8* @strdup(i8* %1)
%5 = tail call i8* @strtok(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%6 = load i32, i32* @stderr
%7 = tail call i32 (i32, i8*, ...) @fprintf(i32 %6, i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.2, i64 0, i64 0))
%8 = icmp eq i8* %5, null
br i1 %8, label %18, label %9
9: ; preds = %3, %9
%10 = phi i32 [ %12, %9 ], [ 0, %3 ]
%11 = phi i8* [ %16, %9 ], [ %5, %3 ]
%12 = add nuw nsw i32 %10, 1
%13 = tail call i8* @basename(i8* %11)
%14 = load i32, i32* @stderr
%15 = tail call i32 (i32, i8*, ...) @fprintf(i32 %14, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i32 %12, i8* %13, i8* %11)
%16 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%17 = icmp eq i8* %16, null
br i1 %17, label %18, label %9
18: ; preds = %9, %3
%19 = tail call i32 @free(i8* %4)
br label %23
20: ; preds = %0
%21 = load i32, i32* @stderr
%22 = tail call i32 (i32, i8*, ...) @fprintf(i32 %21, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.4, i64 0, i64 0))
br label %23
23: ; preds = %20, %18
ret void
}