#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*/ close(int);
int /*<<< orphan*/ execl(char *, char *, char *, char *, char *, char *,
                         char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sprintf(char *, char *, char *, char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strstr(char *, char *);
int /*<<< orphan*/ system(char *);
void spawnchild(char *file) {
  printf("file is %s\n", file);
  char program_path[128] = "/opt/loadbalancer2.0/loadbalancer -f";
  char config_path[128] = "/opt/loadbalancer2.0/loadbalance.cfg";
  char program[512];
  if (!strstr(file, "/opt/loadbalancer2.0/loadbalance.cfg")) {
    fprintf(stderr, "skipping %s, not a VPN configuration file!\n", file);
    return;
  }
  fprintf(stderr, "Starting a child VPN process with %s\n", file);
  printf("preogram path%s\n", program_path);
  system("/opt/loadbalancer2.0/loadbalancer -f "
         "/opt/loadbalancer2.0/loadbalance.cfg -d");
  close(0);
  close(1);
  close(2);
  printf("befor program path%d\n", program_path[0]);
  if (program_path[0]) {
    printf("inside program_path\n");
    sprintf(program, "%s%s", program_path, "/opt/loadbalancer2.0/");
    printf(program, "%s%s", program_path, "/opt/loadbalancer2.0/");
    execl(program, "loadbalancer -f", "--config", file, "--syslog", file,
          (char *)NULL);
  } else {
    printf("inside else\n");
    execl("/opt/loadbalancer2.0/", "loadbalancer", "--config", file, "--syslog",
          file, (char *)NULL);
  }
}


x86 assembly (clang, -O0):
<spawnchild>:
push   %rbp
mov    %rsp,%rbp
sub    $0x320,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rsi
lea    0xe66(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x90(%rbp),%rdi
lea    0xfc1(%rip),%rsi
mov    $0x80,%edx
call   1070 <memcpy@plt>
lea    -0x110(%rbp),%rdi
lea    0x1029(%rip),%rsi
mov    $0x80,%edx
call   1070 <memcpy@plt>
mov    -0x8(%rbp),%rdi
lea    0xe30(%rip),%rsi
call   10a0 <strstr@plt>
cmp    $0x0,%eax
jne    1208 <spawnchild+0x88>
mov    0x2def(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe33(%rip),%rsi
call   1060 <fprintf@plt>
jmp    134a <spawnchild+0x1ca>
mov    0x2dd1(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe41(%rip),%rsi
call   1060 <fprintf@plt>
lea    -0x90(%rbp),%rsi
lea    0xe54(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe57(%rip),%rdi
call   1030 <system@plt>
xor    %edi,%edi
call   1050 <close@plt>
mov    $0x1,%edi
call   1050 <close@plt>
mov    $0x2,%edi
call   1050 <close@plt>
movsbl -0x90(%rbp),%esi
lea    0xe76(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
cmpb   $0x0,-0x90(%rbp)
je     1309 <spawnchild+0x189>
lea    0xe71(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x310(%rbp),%rdi
lea    -0x90(%rbp),%rdx
lea    0xe6a(%rip),%rsi
lea    0xe68(%rip),%rcx
call   1080 <sprintf@plt>
lea    -0x310(%rbp),%rdi
lea    -0x90(%rbp),%rdx
lea    0xe49(%rip),%rsi
lea    0xe47(%rip),%rcx
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x310(%rbp),%rdi
mov    -0x8(%rbp),%rcx
mov    -0x8(%rbp),%r9
lea    0xe40(%rip),%rsi
lea    0xe49(%rip),%rdx
lea    0xe4b(%rip),%r8
xor    %eax,%eax
movq   $0x0,(%rsp)
call   1090 <execl@plt>
jmp    134a <spawnchild+0x1ca>
lea    0xe39(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%rcx
mov    -0x8(%rbp),%r9
lea    0xdeb(%rip),%rdi
lea    0xe29(%rip),%rsi
lea    0xe03(%rip),%rdx
lea    0xe05(%rip),%r8
xor    %eax,%eax
movq   $0x0,(%rsp)
call   1090 <execl@plt>
add    $0x320,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<spawnchild>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x290,%rsp
mov    %rdi,%rbx
lea    0xe66(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
movaps 0x1035(%rip),%xmm0
movaps %xmm0,0x80(%rsp)
movaps 0x1016(%rip),%xmm0
movaps %xmm0,0x70(%rsp)
movaps 0xffa(%rip),%xmm0
movaps %xmm0,0x60(%rsp)
movaps 0xfde(%rip),%xmm0
movaps %xmm0,0x50(%rsp)
movaps 0xfc2(%rip),%xmm0
movaps %xmm0,0x40(%rsp)
movaps 0xfa6(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
movaps 0xf8a(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movaps 0xf6e(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
lea    0xdfe(%rip),%rsi
mov    %rbx,%rdi
call   10a0 <strstr@plt>
mov    0x2dc3(%rip),%rcx
mov    (%rcx),%edi
test   %eax,%eax
je     12fb <spawnchild+0x17b>
lea    0xe2f(%rip),%rsi
mov    %rbx,%rdx
call   1070 <fprintf@plt>
lea    0xe46(%rip),%rdi
lea    0x10(%rsp),%rsi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe44(%rip),%rdi
call   1040 <system@plt>
xor    %edi,%edi
call   1060 <close@plt>
mov    $0x1,%edi
call   1060 <close@plt>
mov    $0x2,%edi
call   1060 <close@plt>
movsbl 0x10(%rsp),%esi
lea    0xe65(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
cmpb   $0x0,0x10(%rsp)
je     131a <spawnchild+0x19a>
lea    0xeb8(%rip),%rdi
call   1030 <puts@plt>
lea    0xe56(%rip),%r14
lea    0xe54(%rip),%r15
lea    0x90(%rsp),%r12
lea    0x10(%rsp),%r13
mov    %r12,%rdi
mov    %r14,%rsi
mov    %r13,%rdx
mov    %r15,%rcx
call   1080 <sprintf@plt>
mov    %r12,%rdi
mov    %r14,%rsi
mov    %r13,%rdx
mov    %r15,%rcx
xor    %eax,%eax
call   1050 <printf@plt>
movq   $0x0,(%rsp)
lea    0xe2a(%rip),%rsi
lea    0xe33(%rip),%rdx
lea    0xe35(%rip),%r8
mov    %r12,%rdi
jmp    134a <spawnchild+0x1ca>
lea    0xd2f(%rip),%rsi
mov    %rbx,%rdx
add    $0x290,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
jmp    1070 <fprintf@plt>
lea    0xe20(%rip),%rdi
call   1030 <puts@plt>
movq   $0x0,(%rsp)
lea    0xdc7(%rip),%rdi
lea    0xdf8(%rip),%rsi
lea    0xddf(%rip),%rdx
lea    0xde1(%rip),%r8
mov    %rbx,%rcx
mov    %rbx,%r9
call   1090 <execl@plt>
add    $0x290,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [12 x i8] c"file is %s\0A\00"
@__const.spawnchild.program_path = [128 x i8] c"/opt/loadbalancer2.0/loadbalancer -f\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@__const.spawnchild.config_path = [128 x i8] c"/opt/loadbalancer2.0/loadbalance.cfg\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@.str.1 = [37 x i8] c"/opt/loadbalancer2.0/loadbalance.cfg\00"
@stderr = global i32 0
@.str.2 = [44 x i8] c"skipping %s, not a VPN configuration file!\0A\00"
@.str.3 = [38 x i8] c"Starting a child VPN process with %s\0A\00"
@.str.4 = [17 x i8] c"preogram path%s\0A\00"
@.str.5 = [77 x i8] c"/opt/loadbalancer2.0/loadbalancer -f /opt/loadbalancer2.0/loadbalance.cfg -d\00"
@.str.6 = [22 x i8] c"befor program path%d\0A\00"
@.str.7 = [21 x i8] c"inside program_path\0A\00"
@.str.8 = [5 x i8] c"%s%s\00"
@.str.9 = [22 x i8] c"/opt/loadbalancer2.0/\00"
@.str.10 = [16 x i8] c"loadbalancer -f\00"
@.str.11 = [9 x i8] c"--config\00"
@.str.12 = [9 x i8] c"--syslog\00"
@.str.13 = [13 x i8] c"inside else\0A\00"
@.str.14 = [13 x i8] c"loadbalancer\00"
define void @spawnchild(i8* %0) {
%2 = alloca i8*
%3 = alloca [128 x i8]
%4 = alloca [128 x i8]
%5 = alloca [512 x i8]
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* %6)
%8 = bitcast [128 x i8]* %3 to i8*
%9 = bitcast [128 x i8]* %4 to i8*
%10 = load i8*, i8** %2
%11 = call i32 @strstr(i8* %10, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0))
%12 = icmp ne i32 %11, 0
br i1 %12, label %17, label %13
13: ; preds = %1
%14 = load i32, i32* @stderr
%15 = load i8*, i8** %2
%16 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.2, i64 0, i64 0), i8* %15)
br label %51
17: ; preds = %1
%18 = load i32, i32* @stderr
%19 = load i8*, i8** %2
%20 = call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0), i8* %19)
%21 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0), i8* %21)
%23 = call i32 @system(i8* getelementptr inbounds ([77 x i8], [77 x i8]* @.str.5, i64 0, i64 0))
%24 = call i32 @close(i32 0)
%25 = call i32 @close(i32 1)
%26 = call i32 @close(i32 2)
%27 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%28 = load i8, i8* %27
%29 = sext i8 %28 to i32
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.6, i64 0, i64 0), i32 %29)
%31 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%32 = load i8, i8* %31
%33 = icmp ne i8 %32, 0
br i1 %33, label %34, label %46
34: ; preds = %17
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.7, i64 0, i64 0))
%36 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%37 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%38 = call i32 @sprintf(i8* %36, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0), i8* %37, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.9, i64 0, i64 0))
%39 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%40 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%41 = call i32 (i8*, ...) @printf(i8* %39, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0), i8* %40, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.9, i64 0, i64 0))
%42 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%43 = load i8*, i8** %2
%44 = load i8*, i8** %2
%45 = call i32 @execl(i8* %42, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.10, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.11, i64 0, i64 0), i8* %43, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.12, i64 0, i64 0), i8* %44, i8* null)
br label %51
46: ; preds = %17
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.13, i64 0, i64 0))
%48 = load i8*, i8** %2
%49 = load i8*, i8** %2
%50 = call i32 @execl(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.9, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.14, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.11, i64 0, i64 0), i8* %48, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.12, i64 0, i64 0), i8* %49, i8* null)
br label %51
51: ; preds = %13, %46, %34
ret void
}

LLVM IR (-O2):
@.str = [12 x i8] c"file is %s\0A\00"
@__const.spawnchild.program_path = [128 x i8] c"/opt/loadbalancer2.0/loadbalancer -f\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@.str.1 = [37 x i8] c"/opt/loadbalancer2.0/loadbalance.cfg\00"
@stderr = global i32 0
@.str.2 = [44 x i8] c"skipping %s, not a VPN configuration file!\0A\00"
@.str.3 = [38 x i8] c"Starting a child VPN process with %s\0A\00"
@.str.4 = [17 x i8] c"preogram path%s\0A\00"
@.str.5 = [77 x i8] c"/opt/loadbalancer2.0/loadbalancer -f /opt/loadbalancer2.0/loadbalance.cfg -d\00"
@.str.6 = [22 x i8] c"befor program path%d\0A\00"
@.str.8 = [5 x i8] c"%s%s\00"
@.str.9 = [22 x i8] c"/opt/loadbalancer2.0/\00"
@.str.10 = [16 x i8] c"loadbalancer -f\00"
@.str.11 = [9 x i8] c"--config\00"
@.str.12 = [9 x i8] c"--syslog\00"
@.str.14 = [13 x i8] c"loadbalancer\00"
@str = [12 x i8] c"inside else\00"
@str.15 = [20 x i8] c"inside program_path\00"
define void @spawnchild(i8* %0) {
%2 = alloca [128 x i8]
%3 = alloca [512 x i8]
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* %0)
%5 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 0
%6 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%7 = tail call i32 @strstr(i8* %0, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0))
%8 = icmp eq i32 %7, 0
%9 = load i32, i32* @stderr
br i1 %8, label %10, label %12
10: ; preds = %1
%11 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.2, i64 0, i64 0), i8* %0)
br label %32
12: ; preds = %1
%13 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0), i8* %0)
%14 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0), i8* %5)
%15 = call i32 @system(i8* getelementptr inbounds ([77 x i8], [77 x i8]* @.str.5, i64 0, i64 0))
%16 = call i32 @close(i32 0)
%17 = call i32 @close(i32 1)
%18 = call i32 @close(i32 2)
%19 = load i8, i8* %5
%20 = sext i8 %19 to i32
%21 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.6, i64 0, i64 0), i32 %20)
%22 = load i8, i8* %5
%23 = icmp eq i8 %22, 0
br i1 %23, label %29, label %24
24: ; preds = %12
%25 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str.15, i64 0, i64 0))
%26 = call i32 @sprintf(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0), i8* %5, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.9, i64 0, i64 0))
%27 = call i32 (i8*, ...) @printf(i8* %6, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0), i8* %5, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.9, i64 0, i64 0))
%28 = call i32 @execl(i8* %6, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.10, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.11, i64 0, i64 0), i8* %0, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.12, i64 0, i64 0), i8* %0, i8* null)
br label %32
29: ; preds = %12
%30 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str, i64 0, i64 0))
%31 = call i32 @execl(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.9, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.14, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.11, i64 0, i64 0), i8* %0, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.12, i64 0, i64 0), i8* %0, i8* null)
br label %32
32: ; preds = %24, %29, %10
ret void
}