#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*/ errno;
scalar_t__ execle(char *, char *, char *, int /*<<< orphan*/ *, char **);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int fork();
int /*<<< orphan*/ free(char *);
int get_logdir_from_config(char **, char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ strcat(char *, char *);
char *strdup(char *);
char *strstr(char *, char *);
int /*<<< orphan*/ wait(int *);
int start_tsung_player(char *prefix) {
  pid_t child;
  int status;
  int logdir_size;
  char *logdir;
  char *child_environ[] = {NULL, NULL, NULL};
  int i;
  extern char **environ;
  printf("Starting tsung player.\n");
  logdir_size = get_logdir_from_config(&logdir, prefix);
  child_environ[0] = (char *)malloc(sizeof(char) * (logdir_size + 6));
  child_environ[0][0] = '\0';
  strcat(child_environ[0], "HOME=");
  strcat(child_environ[0], logdir);
  for (i = 0; environ[i] != NULL; i++) {
    if (strstr(environ[i], "PATH=") == environ[i]) {
      child_environ[1] = strdup(environ[i]);
    }
  }
  if (!child_environ[1]) {
    child_environ[1] = strdup("PATH=/usr/bin:/bin:/usr/local/bin");
  }
  child = fork();
  if (child == 0) {
    if (execle("/opt/tsung/bin/tsung", "/opt/tsung/bin/tsung", "start", NULL,
               child_environ)) {
      perror("Exec failed");
      exit(errno);
    }
    wait(&status);
  } else if (child == -1) {
    perror("Fork failed");
    return 1;
  } else {
    free(child_environ[0]);
    free(child_environ[1]);
    return 0;
  }
  return 1;
}


x86 assembly (clang, -O0):
<start_tsung_player>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
lea    -0x40(%rbp),%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1060 <memset@plt>
lea    0xe0d(%rip),%rdi
call   1050 <printf@plt>
mov    -0x10(%rbp),%rsi
lea    -0x28(%rbp),%rdi
call   1040 <get_logdir_from_config@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x6,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x40(%rbp),%rdi
lea    0xde7(%rip),%rsi
call   1090 <strcat@plt>
mov    -0x40(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1090 <strcat@plt>
movl   $0x0,-0x44(%rbp)
mov    0x2d97(%rip),%rax
mov    (%rax),%rax
movslq -0x44(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
je     12c7 <start_tsung_player+0xf7>
mov    0x2d7e(%rip),%rax
mov    (%rax),%rax
movslq -0x44(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xda2(%rip),%rsi
call   10f0 <strstr@plt>
mov    0x2d60(%rip),%rcx
mov    (%rcx),%rcx
movslq -0x44(%rbp),%rdx
cmp    (%rcx,%rdx,8),%rax
jne    12b4 <start_tsung_player+0xe4>
mov    0x2d48(%rip),%rax
mov    (%rax),%rax
movslq -0x44(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   10c0 <strdup@plt>
mov    %rax,-0x38(%rbp)
jmp    12b9 <start_tsung_player+0xe9>
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    124a <start_tsung_player+0x7a>
cmpq   $0x0,-0x38(%rbp)
jne    12e2 <start_tsung_player+0x112>
lea    0xd4b(%rip),%rdi
call   10c0 <strdup@plt>
mov    %rax,-0x38(%rbp)
mov    $0x0,%al
call   10e0 <fork@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    1346 <start_tsung_player+0x176>
lea    -0x40(%rbp),%r8
lea    0xd45(%rip),%rsi
lea    0xd53(%rip),%rdx
xor    %eax,%eax
mov    %eax,%ecx
mov    %rsi,%rdi
call   10b0 <execle@plt>
cmp    $0x0,%rax
je     1338 <start_tsung_player+0x168>
lea    0xd3c(%rip),%rdi
call   1080 <perror@plt>
mov    0x2ca7(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
lea    -0x18(%rbp),%rdi
call   10d0 <wait@plt>
jmp    1386 <start_tsung_player+0x1b6>
cmpl   $0xffffffff,-0x14(%rbp)
jne    1368 <start_tsung_player+0x198>
lea    0xd16(%rip),%rdi
call   1080 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    138d <start_tsung_player+0x1bd>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
jmp    138d <start_tsung_player+0x1bd>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<start_tsung_player>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rdi,%rbx
xorps  %xmm0,%xmm0
movaps %xmm0,(%rsp)
movq   $0x0,0x10(%rsp)
lea    0xe7c(%rip),%rdi
call   1050 <puts@plt>
lea    0x18(%rsp),%rdi
mov    %rbx,%rsi
call   1060 <get_logdir_from_config@plt>
lea    0x6(%rax),%edi
call   1070 <malloc@plt>
mov    %rax,(%rsp)
movb   $0x0,(%rax)
mov    (%rsp),%r14
lea    0xdef(%rip),%rsi
mov    %r14,%rdi
call   1090 <strcat@plt>
mov    0x18(%rsp),%rsi
mov    %r14,%rdi
call   1090 <strcat@plt>
mov    0x2dbb(%rip),%rax
mov    (%rax),%rbx
mov    (%rbx),%r12
test   %r12,%r12
je     127f <start_tsung_player+0xbf>
add    $0x8,%rbx
lea    0xdc3(%rip),%r15
jmp    125c <start_tsung_player+0x9c>
cs nopw 0x0(%rax,%rax,1)
nop
mov    (%rbx),%r12
add    $0x8,%rbx
test   %r12,%r12
je     127f <start_tsung_player+0xbf>
mov    $0x5,%edx
mov    %r12,%rdi
mov    %r15,%rsi
call   1040 <strncmp@plt>
test   %eax,%eax
jne    1250 <start_tsung_player+0x90>
mov    %r12,%rdi
call   10c0 <strdup@plt>
mov    %rax,0x8(%rsp)
jmp    1250 <start_tsung_player+0x90>
cmpq   $0x0,0x8(%rsp)
jne    1298 <start_tsung_player+0xd8>
lea    0xd7e(%rip),%rdi
call   10c0 <strdup@plt>
mov    %rax,0x8(%rsp)
xor    %eax,%eax
call   10e0 <fork@plt>
test   %eax,%eax
je     12be <start_tsung_player+0xfe>
cmp    $0xffffffff,%eax
je     12f9 <start_tsung_player+0x139>
mov    %r14,%rdi
call   1030 <free@plt>
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
jmp    12ed <start_tsung_player+0x12d>
lea    0xd69(%rip),%rdi
lea    0xd77(%rip),%rdx
mov    %rsp,%r8
mov    %rdi,%rsi
xor    %ecx,%ecx
call   10b0 <execle@plt>
test   %rax,%rax
jne    1307 <start_tsung_player+0x147>
lea    0x24(%rsp),%rdi
call   10d0 <wait@plt>
mov    $0x1,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
lea    0xd55(%rip),%rdi
call   1080 <perror@plt>
jmp    12e8 <start_tsung_player+0x128>
lea    0xd3b(%rip),%rdi
call   1080 <perror@plt>
mov    0x2cbe(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [24 x i8] c"Starting tsung player.\0A\00"
@.str.1 = [6 x i8] c"HOME=\00"
@environ = external global i8**
@.str.2 = [6 x i8] c"PATH=\00"
@.str.3 = [34 x i8] c"PATH=/usr/bin:/bin:/usr/local/bin\00"
@.str.4 = [21 x i8] c"/opt/tsung/bin/tsung\00"
@.str.5 = [6 x i8] c"start\00"
@.str.6 = [12 x i8] c"Exec failed\00"
@errno = global i32 0
@.str.7 = [12 x i8] c"Fork failed\00"
define i32 @start_tsung_player(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca [3 x i8*]
%9 = alloca i32
store i8* %0, i8** %3
%10 = bitcast [3 x i8*]* %8 to i8*
%11 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
%12 = load i8*, i8** %3
%13 = call i32 @get_logdir_from_config(i8** %7, i8* %12)
store i32 %13, i32* %6
%14 = load i32, i32* %6
%15 = add nsw i32 %14, 6
%16 = sext i32 %15 to i64
%17 = mul i64 1, %16
%18 = trunc i64 %17 to i32
%19 = call i64 @malloc(i32 %18)
%20 = inttoptr i64 %19 to i8*
%21 = getelementptr inbounds [3 x i8*], [3 x i8*]* %8, i64 0, i64 0
store i8* %20, i8** %21
%22 = getelementptr inbounds [3 x i8*], [3 x i8*]* %8, i64 0, i64 0
%23 = load i8*, i8** %22
%24 = getelementptr inbounds i8, i8* %23, i64 0
store i8 0, i8* %24
%25 = getelementptr inbounds [3 x i8*], [3 x i8*]* %8, i64 0, i64 0
%26 = load i8*, i8** %25
%27 = call i32 @strcat(i8* %26, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%28 = getelementptr inbounds [3 x i8*], [3 x i8*]* %8, i64 0, i64 0
%29 = load i8*, i8** %28
%30 = load i8*, i8** %7
%31 = call i32 @strcat(i8* %29, i8* %30)
store i32 0, i32* %9
br label %32
32: ; preds = %61, %1
%33 = load i8**, i8*** @environ
%34 = load i32, i32* %9
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i8*, i8** %33, i64 %35
%37 = load i8*, i8** %36
%38 = icmp ne i8* %37, null
br i1 %38, label %39, label %64
39: ; preds = %32
%40 = load i8**, i8*** @environ
%41 = load i32, i32* %9
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i8*, i8** %40, i64 %42
%44 = load i8*, i8** %43
%45 = call i8* @strstr(i8* %44, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%46 = load i8**, i8*** @environ
%47 = load i32, i32* %9
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds i8*, i8** %46, i64 %48
%50 = load i8*, i8** %49
%51 = icmp eq i8* %45, %50
br i1 %51, label %52, label %60
52: ; preds = %39
%53 = load i8**, i8*** @environ
%54 = load i32, i32* %9
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds i8*, i8** %53, i64 %55
%57 = load i8*, i8** %56
%58 = call i8* @strdup(i8* %57)
%59 = getelementptr inbounds [3 x i8*], [3 x i8*]* %8, i64 0, i64 1
store i8* %58, i8** %59
br label %60
60: ; preds = %52, %39
br label %61
61: ; preds = %60
%62 = load i32, i32* %9
%63 = add nsw i32 %62, 1
store i32 %63, i32* %9
br label %32
64: ; preds = %32
%65 = getelementptr inbounds [3 x i8*], [3 x i8*]* %8, i64 0, i64 1
%66 = load i8*, i8** %65
%67 = icmp ne i8* %66, null
br i1 %67, label %71, label %68
68: ; preds = %64
%69 = call i8* @strdup(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0))
%70 = getelementptr inbounds [3 x i8*], [3 x i8*]* %8, i64 0, i64 1
store i8* %69, i8** %70
br label %71
71: ; preds = %68, %64
%72 = call i32 (...) @fork()
store i32 %72, i32* %4
%73 = load i32, i32* %4
%74 = icmp eq i32 %73, 0
br i1 %74, label %75, label %85
75: ; preds = %71
%76 = getelementptr inbounds [3 x i8*], [3 x i8*]* %8, i64 0, i64 0
%77 = call i64 @execle(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i32* null, i8** %76)
%78 = icmp ne i64 %77, 0
br i1 %78, label %79, label %83
79: ; preds = %75
%80 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0))
%81 = load i32, i32* @errno
%82 = call i32 @exit(i32 %81)
unreachable
83: ; preds = %75
%84 = call i32 @wait(i32* %5)
br label %97
85: ; preds = %71
%86 = load i32, i32* %4
%87 = icmp eq i32 %86, -1
br i1 %87, label %88, label %90
88: ; preds = %85
%89 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.7, i64 0, i64 0))
store i32 1, i32* %2
br label %98
90: ; preds = %85
%91 = getelementptr inbounds [3 x i8*], [3 x i8*]* %8, i64 0, i64 0
%92 = load i8*, i8** %91
%93 = call i32 @free(i8* %92)
%94 = getelementptr inbounds [3 x i8*], [3 x i8*]* %8, i64 0, i64 1
%95 = load i8*, i8** %94
%96 = call i32 @free(i8* %95)
store i32 0, i32* %2
br label %98
97: ; preds = %83
store i32 1, i32* %2
br label %98
98: ; preds = %97, %90, %88
%99 = load i32, i32* %2
ret i32 %99
}

LLVM IR (-O2):
@.str.1 = [6 x i8] c"HOME=\00"
@environ = external global i8**
@.str.2 = [6 x i8] c"PATH=\00"
@.str.3 = [34 x i8] c"PATH=/usr/bin:/bin:/usr/local/bin\00"
@.str.4 = [21 x i8] c"/opt/tsung/bin/tsung\00"
@.str.5 = [6 x i8] c"start\00"
@.str.6 = [12 x i8] c"Exec failed\00"
@errno = global i32 0
@.str.7 = [12 x i8] c"Fork failed\00"
@str = [23 x i8] c"Starting tsung player.\00"
define i32 @start_tsung_player(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca [3 x i8*]
%5 = bitcast i32* %2 to i8*
%6 = bitcast i8** %3 to i8*
%7 = bitcast [3 x i8*]* %4 to i8*
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str, i64 0, i64 0))
%9 = call i32 @get_logdir_from_config(i8** %3, i8* %0)
%10 = add nsw i32 %9, 6
%11 = call i64 @malloc(i32 %10)
%12 = inttoptr i64 %11 to i8*
%13 = getelementptr inbounds [3 x i8*], [3 x i8*]* %4, i64 0, i64 0
store i8* %12, i8** %13
store i8 0, i8* %12
%14 = load i8*, i8** %13
%15 = call i32 @strcat(i8* %14, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%16 = load i8*, i8** %3
%17 = call i32 @strcat(i8* %14, i8* %16)
%18 = load i8**, i8*** @environ
%19 = load i8*, i8** %18
%20 = icmp eq i8* %19, null
br i1 %20, label %35, label %21
21: ; preds = %1
%22 = getelementptr inbounds [3 x i8*], [3 x i8*]* %4, i64 0, i64 1
br label %23
23: ; preds = %21, %30
%24 = phi i64 [ 0, %21 ], [ %31, %30 ]
%25 = phi i8* [ %19, %21 ], [ %33, %30 ]
%26 = call i32 @strncmp(i8* %25, i8* dereferenceable(6) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i64 5)
%27 = icmp eq i32 %26, 0
br i1 %27, label %28, label %30
28: ; preds = %23
%29 = call i8* @strdup(i8* %25)
store i8* %29, i8** %22
br label %30
30: ; preds = %23, %28
%31 = add nuw i64 %24, 1
%32 = getelementptr inbounds i8*, i8** %18, i64 %31
%33 = load i8*, i8** %32
%34 = icmp eq i8* %33, null
br i1 %34, label %35, label %23
35: ; preds = %30, %1
%36 = getelementptr inbounds [3 x i8*], [3 x i8*]* %4, i64 0, i64 1
%37 = load i8*, i8** %36
%38 = icmp eq i8* %37, null
br i1 %38, label %39, label %41
39: ; preds = %35
%40 = call dereferenceable_or_null(34) i8* @strdup(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0))
store i8* %40, i8** %36
br label %41
41: ; preds = %39, %35
%42 = call i32 (...) @fork()
switch i32 %42, label %54 [
i32 0, label %43
i32 -1, label %52
]
43: ; preds = %41
%44 = call i64 @execle(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i32* null, i8** %13)
%45 = icmp eq i64 %44, 0
br i1 %45, label %50, label %46
46: ; preds = %43
%47 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0))
%48 = load i32, i32* @errno
%49 = call i32 @exit(i32 %48)
unreachable
50: ; preds = %43
%51 = call i32 @wait(i32* %2)
br label %58
52: ; preds = %41
%53 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.7, i64 0, i64 0))
br label %58
54: ; preds = %41
%55 = call i32 @free(i8* %14)
%56 = load i8*, i8** %36
%57 = call i32 @free(i8* %56)
br label %58
58: ; preds = %50, %54, %52
%59 = phi i32 [ 1, %50 ], [ 1, %52 ], [ 0, %54 ]
ret i32 %59
}