#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*/);
scalar_t__ fork();
char *getenv(char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ sprintf(char *, char *, char *);
int stat(char *, struct stat *);
int /*<<< orphan*/ strcpy(char *, char *);
void ExecCfg(char *arg) {
  char cfg[256];
  struct stat buf;
  strcpy(cfg, "./cfgDFXVideo");
  if (stat(cfg, &buf) != -1) {
    if (fork() == 0) {
      execl(cfg, "cfgDFXVideo", arg, NULL);
      exit(0);
    }
    return;
  }
  strcpy(cfg, "./cfg/cfgDFXVideo");
  if (stat(cfg, &buf) != -1) {
    if (fork() == 0) {
      execl(cfg, "cfgDFXVideo", arg, NULL);
      exit(0);
    }
    return;
  }
  sprintf(cfg, "%s/.pcsx/plugins/cfg/cfgDFXVideo", getenv("HOME"));
  if (stat(cfg, &buf) != -1) {
    if (fork() == 0) {
      execl(cfg, "cfgDFXVideo", arg, NULL);
      exit(0);
    }
    return;
  }
  printf("ERROR: cfgDFXVideo 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    0xe63(%rip),%rsi
call   1040 <strcpy@plt>
lea    -0x110(%rbp),%rdi
lea    -0x118(%rbp),%rsi
call   1060 <stat@plt>
cmp    $0xffffffff,%eax
je     11f6 <ExecCfg+0x76>
mov    $0x0,%al
call   10a0 <fork@plt>
cmp    $0x0,%rax
jne    11f1 <ExecCfg+0x71>
lea    -0x110(%rbp),%rdi
mov    -0x8(%rbp),%rdx
lea    0xe21(%rip),%rsi
xor    %eax,%eax
mov    %eax,%ecx
call   1090 <execl@plt>
xor    %edi,%edi
call   1080 <exit@plt>
jmp    12ed <ExecCfg+0x16d>
lea    -0x110(%rbp),%rdi
lea    0xe0a(%rip),%rsi
call   1040 <strcpy@plt>
lea    -0x110(%rbp),%rdi
lea    -0x118(%rbp),%rsi
call   1060 <stat@plt>
cmp    $0xffffffff,%eax
je     125d <ExecCfg+0xdd>
mov    $0x0,%al
call   10a0 <fork@plt>
cmp    $0x0,%rax
jne    1258 <ExecCfg+0xd8>
lea    -0x110(%rbp),%rdi
mov    -0x8(%rbp),%rdx
lea    0xdba(%rip),%rsi
xor    %eax,%eax
mov    %eax,%ecx
call   1090 <execl@plt>
xor    %edi,%edi
call   1080 <exit@plt>
jmp    12ed <ExecCfg+0x16d>
lea    -0x110(%rbp),%rax
mov    %rax,-0x120(%rbp)
lea    0xdcf(%rip),%rdi
call   1030 <getenv@plt>
mov    -0x120(%rbp),%rdi
mov    %rax,%rdx
lea    0xd98(%rip),%rsi
call   1070 <sprintf@plt>
lea    -0x110(%rbp),%rdi
lea    -0x118(%rbp),%rsi
call   1060 <stat@plt>
cmp    $0xffffffff,%eax
je     12e1 <ExecCfg+0x161>
mov    $0x0,%al
call   10a0 <fork@plt>
cmp    $0x0,%rax
jne    12dc <ExecCfg+0x15c>
lea    -0x110(%rbp),%rdi
mov    -0x8(%rbp),%rdx
lea    0xd36(%rip),%rsi
xor    %eax,%eax
mov    %eax,%ecx
call   1090 <execl@plt>
xor    %edi,%edi
call   1080 <exit@plt>
jmp    12ed <ExecCfg+0x16d>
lea    0xd5e(%rip),%rdi
call   1050 <printf@plt>
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ExecCfg>:
push   %r14
push   %rbx
sub    $0x118,%rsp
mov    %rdi,%r14
lea    0xe6c(%rip),%rsi
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
call   1040 <strcpy@plt>
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
call   1060 <stat@plt>
cmp    $0xffffffff,%eax
jne    120e <ExecCfg+0x8e>
lea    0xe54(%rip),%rsi
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
call   1040 <strcpy@plt>
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
call   1060 <stat@plt>
cmp    $0xffffffff,%eax
jne    120e <ExecCfg+0x8e>
lea    0xe61(%rip),%rdi
call   1030 <getenv@plt>
lea    0xe34(%rip),%rsi
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    %rax,%rdx
call   1070 <sprintf@plt>
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
call   1060 <stat@plt>
cmp    $0xffffffff,%eax
je     1225 <ExecCfg+0xa5>
xor    %eax,%eax
call   10a0 <fork@plt>
test   %rax,%rax
je     1233 <ExecCfg+0xb3>
add    $0x118,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe1a(%rip),%rdi
call   1050 <puts@plt>
jmp    121a <ExecCfg+0x9a>
lea    0xdc8(%rip),%rsi
lea    0x10(%rsp),%rdi
mov    %r14,%rdx
xor    %ecx,%ecx
call   1090 <execl@plt>
xor    %edi,%edi
call   1080 <exit@plt>

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

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [14 x i8] c"./cfgDFXVideo\00"
@.str.1 = [12 x i8] c"cfgDFXVideo\00"
@.str.2 = [18 x i8] c"./cfg/cfgDFXVideo\00"
@.str.3 = [33 x i8] c"%s/.pcsx/plugins/cfg/cfgDFXVideo\00"
@.str.4 = [5 x i8] c"HOME\00"
@str = [35 x i8] c"ERROR: cfgDFXVideo file not found!\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 ([14 x i8], [14 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 %15, label %9
9: ; preds = %1
%10 = call i64 (...) @fork()
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %38
12: ; preds = %9
%13 = call i32 @execl(i8* %4, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* %0, i32* null)
%14 = call i32 @exit(i32 0)
unreachable
15: ; preds = %1
%16 = call i32 @strcpy(i8* %4, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
%17 = call i32 @stat(i8* %4, %struct.stat* %3)
%18 = icmp eq i32 %17, -1
br i1 %18, label %25, label %19
19: ; preds = %15
%20 = call i64 (...) @fork()
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %38
22: ; preds = %19
%23 = call i32 @execl(i8* %4, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* %0, i32* null)
%24 = call i32 @exit(i32 0)
unreachable
25: ; preds = %15
%26 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%27 = call i32 @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0), i8* %26)
%28 = call i32 @stat(i8* %4, %struct.stat* %3)
%29 = icmp eq i32 %28, -1
br i1 %29, label %36, label %30
30: ; preds = %25
%31 = call i64 (...) @fork()
%32 = icmp eq i64 %31, 0
br i1 %32, label %33, label %38
33: ; preds = %30
%34 = call i32 @execl(i8* %4, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* %0, i32* null)
%35 = call i32 @exit(i32 0)
unreachable
36: ; preds = %25
%37 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @str, i64 0, i64 0))
br label %38
38: ; preds = %30, %19, %9, %36
ret void
}