#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 */
struct stat {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ execl(char *, char *, char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int stat(char *, struct stat *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcpy(char *, char *);
int /*<<< orphan*/ waitpid(int, int /*<<< orphan*/ *, int /*<<< orphan*/);
void ExecCfg(char *arg) {
  char cfg[256];
  struct stat buf;
  strcpy(cfg, "./cfgBladeSio1");
  if (stat(cfg, &buf) != -1) {
    int pid = fork();
    if (pid == 0) {
      if (fork() == 0) {
        execl(cfg, "cfgBladeSio1", arg, NULL);
      }
      exit(0);
    } else if (pid > 0) {
      waitpid(pid, NULL, 0);
    }
    return;
  }
  strcpy(cfg, "./cfg/cfgBladeSio1");
  if (stat(cfg, &buf) != -1) {
    int pid = fork();
    if (pid == 0) {
      if (fork() == 0) {
        execl(cfg, "cfgBladeSio1", arg, NULL);
      }
      exit(0);
    } else if (pid > 0) {
      waitpid(pid, NULL, 0);
    }
    return;
  }
  fprintf(stderr, "cfgBladeSio1 file not found!\n");
}


x86 assembly (clang, -O0):
<ExecCfg>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0x110(%rbp),%rdi
lea    0xe73(%rip),%rsi
call   1030 <strcpy@plt>
lea    -0x110(%rbp),%rdi
lea    -0x118(%rbp),%rsi
call   1050 <stat@plt>
cmp    $0xffffffff,%eax
je     1222 <ExecCfg+0xb2>
mov    $0x0,%al
call   1090 <fork@plt>
mov    %eax,-0x11c(%rbp)
cmpl   $0x0,-0x11c(%rbp)
jne    11fa <ExecCfg+0x8a>
mov    $0x0,%al
call   1090 <fork@plt>
cmp    $0x0,%eax
jne    11f3 <ExecCfg+0x83>
lea    -0x110(%rbp),%rdi
mov    -0x8(%rbp),%rdx
lea    0xe18(%rip),%rsi
xor    %eax,%eax
mov    %eax,%ecx
call   1080 <execl@plt>
xor    %edi,%edi
call   1070 <exit@plt>
cmpl   $0x0,-0x11c(%rbp)
jle    1218 <ExecCfg+0xa8>
mov    -0x11c(%rbp),%edi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1060 <waitpid@plt>
jmp    121d <ExecCfg+0xad>
jmp    12da <ExecCfg+0x16a>
lea    -0x110(%rbp),%rdi
lea    0xddf(%rip),%rsi
call   1030 <strcpy@plt>
lea    -0x110(%rbp),%rdi
lea    -0x118(%rbp),%rsi
call   1050 <stat@plt>
cmp    $0xffffffff,%eax
je     12c5 <ExecCfg+0x155>
mov    $0x0,%al
call   1090 <fork@plt>
mov    %eax,-0x120(%rbp)
cmpl   $0x0,-0x120(%rbp)
jne    129d <ExecCfg+0x12d>
mov    $0x0,%al
call   1090 <fork@plt>
cmp    $0x0,%eax
jne    1296 <ExecCfg+0x126>
lea    -0x110(%rbp),%rdi
mov    -0x8(%rbp),%rdx
lea    0xd75(%rip),%rsi
xor    %eax,%eax
mov    %eax,%ecx
call   1080 <execl@plt>
xor    %edi,%edi
call   1070 <exit@plt>
cmpl   $0x0,-0x120(%rbp)
jle    12bb <ExecCfg+0x14b>
mov    -0x120(%rbp),%edi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1060 <waitpid@plt>
jmp    12c0 <ExecCfg+0x150>
jmp    12da <ExecCfg+0x16a>
mov    0x2d14(%rip),%rax
mov    (%rax),%edi
lea    0xd4d(%rip),%rsi
call   1040 <fprintf@plt>
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ExecCfg>:
push   %r14
push   %rbx
sub    $0x118,%rsp
mov    %rdi,%r14
lea    0xe7c(%rip),%rsi
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
call   1030 <strcpy@plt>
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
call   1050 <stat@plt>
cmp    $0xffffffff,%eax
jne    11c9 <ExecCfg+0x59>
lea    0xe65(%rip),%rsi
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
call   1030 <strcpy@plt>
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
call   1050 <stat@plt>
cmp    $0xffffffff,%eax
je     11e3 <ExecCfg+0x73>
xor    %eax,%eax
call   1090 <fork@plt>
test   %eax,%eax
je     1203 <ExecCfg+0x93>
jle    11f8 <ExecCfg+0x88>
mov    %eax,%edi
xor    %esi,%esi
xor    %edx,%edx
call   1060 <waitpid@plt>
jmp    11f8 <ExecCfg+0x88>
mov    0x2df6(%rip),%rax
mov    (%rax),%edi
lea    0xe2f(%rip),%rsi
call   1040 <fprintf@plt>
add    $0x118,%rsp
pop    %rbx
pop    %r14
ret
xor    %eax,%eax
call   1090 <fork@plt>
test   %eax,%eax
jne    1224 <ExecCfg+0xb4>
lea    0xded(%rip),%rsi
lea    0x10(%rsp),%rdi
mov    %r14,%rdx
xor    %ecx,%ecx
call   1080 <execl@plt>
xor    %edi,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [15 x i8] c"./cfgBladeSio1\00"
@.str.1 = [13 x i8] c"cfgBladeSio1\00"
@.str.2 = [19 x i8] c"./cfg/cfgBladeSio1\00"
@stderr = global i32 0
@.str.3 = [30 x i8] c"cfgBladeSio1 file not found!\0A\00"
define void @ExecCfg(i8* %0) {
%2 = alloca i8*
%3 = alloca [256 x i8]
%4 = alloca %struct.stat
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %2
%7 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%8 = call i32 @strcpy(i8* %7, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%9 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%10 = call i32 @stat(i8* %9, %struct.stat* %4)
%11 = icmp ne i32 %10, -1
br i1 %11, label %12, label %33
12: ; preds = %1
%13 = call i32 (...) @fork()
store i32 %13, i32* %5
%14 = load i32, i32* %5
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %25
16: ; preds = %12
%17 = call i32 (...) @fork()
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %23
19: ; preds = %16
%20 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%21 = load i8*, i8** %2
%22 = call i32 @execl(i8* %20, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* %21, i32* null)
br label %23
23: ; preds = %19, %16
%24 = call i32 @exit(i32 0)
unreachable
25: ; preds = %12
%26 = load i32, i32* %5
%27 = icmp sgt i32 %26, 0
br i1 %27, label %28, label %31
28: ; preds = %25
%29 = load i32, i32* %5
%30 = call i32 @waitpid(i32 %29, i32* null, i32 0)
br label %31
31: ; preds = %28, %25
br label %32
32: ; preds = %31
br label %63
33: ; preds = %1
%34 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%35 = call i32 @strcpy(i8* %34, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
%36 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%37 = call i32 @stat(i8* %36, %struct.stat* %4)
%38 = icmp ne i32 %37, -1
br i1 %38, label %39, label %60
39: ; preds = %33
%40 = call i32 (...) @fork()
store i32 %40, i32* %6
%41 = load i32, i32* %6
%42 = icmp eq i32 %41, 0
br i1 %42, label %43, label %52
43: ; preds = %39
%44 = call i32 (...) @fork()
%45 = icmp eq i32 %44, 0
br i1 %45, label %46, label %50
46: ; preds = %43
%47 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%48 = load i8*, i8** %2
%49 = call i32 @execl(i8* %47, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* %48, i32* null)
br label %50
50: ; preds = %46, %43
%51 = call i32 @exit(i32 0)
unreachable
52: ; preds = %39
%53 = load i32, i32* %6
%54 = icmp sgt i32 %53, 0
br i1 %54, label %55, label %58
55: ; preds = %52
%56 = load i32, i32* %6
%57 = call i32 @waitpid(i32 %56, i32* null, i32 0)
br label %58
58: ; preds = %55, %52
br label %59
59: ; preds = %58
br label %63
60: ; preds = %33
%61 = load i32, i32* @stderr
%62 = call i32 @fprintf(i32 %61, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0))
br label %63
63: ; preds = %60, %59, %32
ret void
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [15 x i8] c"./cfgBladeSio1\00"
@.str.1 = [13 x i8] c"cfgBladeSio1\00"
@.str.2 = [19 x i8] c"./cfg/cfgBladeSio1\00"
@stderr = global i32 0
@.str.3 = [30 x i8] c"cfgBladeSio1 file not found!\0A\00"
define void @ExecCfg(i8* %0) {
%2 = alloca [256 x i8]
%3 = alloca %struct.stat
%4 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%5 = bitcast %struct.stat* %3 to i8*
%6 = call i32 @strcpy(i8* %4, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%7 = call i32 @stat(i8* %4, %struct.stat* %3)
%8 = icmp eq i32 %7, -1
br i1 %8, label %23, label %9
9: ; preds = %1
%10 = call i32 (...) @fork()
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %19
12: ; preds = %9
%13 = call i32 (...) @fork()
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %12
%16 = call i32 @execl(i8* %4, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* %0, i32* null)
br label %17
17: ; preds = %15, %12
%18 = call i32 @exit(i32 0)
unreachable
19: ; preds = %9
%20 = icmp sgt i32 %10, 0
br i1 %20, label %21, label %44
21: ; preds = %19
%22 = call i32 @waitpid(i32 %10, i32* null, i32 0)
br label %44
23: ; preds = %1
%24 = call i32 @strcpy(i8* %4, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
%25 = call i32 @stat(i8* %4, %struct.stat* %3)
%26 = icmp eq i32 %25, -1
br i1 %26, label %41, label %27
27: ; preds = %23
%28 = call i32 (...) @fork()
%29 = icmp eq i32 %28, 0
br i1 %29, label %30, label %37
30: ; preds = %27
%31 = call i32 (...) @fork()
%32 = icmp eq i32 %31, 0
br i1 %32, label %33, label %35
33: ; preds = %30
%34 = call i32 @execl(i8* %4, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* %0, i32* null)
br label %35
35: ; preds = %33, %30
%36 = call i32 @exit(i32 0)
unreachable
37: ; preds = %27
%38 = icmp sgt i32 %28, 0
br i1 %38, label %39, label %44
39: ; preds = %37
%40 = call i32 @waitpid(i32 %28, i32* null, i32 0)
br label %44
41: ; preds = %23
%42 = load i32, i32* @stderr
%43 = call i32 @fprintf(i32 %42, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0))
br label %44
44: ; preds = %39, %37, %21, %19, %41
ret void
}