#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 /*<<< orphan*/ old_path;

/* Variables and functions */
int /*<<< orphan*/ chdir(char const *);
int /*<<< orphan*/ debug(char *);
int /*<<< orphan*/ *getcwd(char *, int);
int /*<<< orphan*/ injector(char const *);
int /*<<< orphan*/ setenv(char *, char const *, int);
int /*<<< orphan*/ strcpy(char *, char *);
int Game_Main(const char *path, const char *udn __attribute__((unused))) {
  debug("Game_Main() started");
  char old_path[256];
  if (getcwd(old_path, sizeof(old_path)) == NULL)
    strcpy(old_path, "/mtd_exe/");
  chdir(path);
  setenv("HOME", path, 1);
  injector(path);
  chdir(old_path);
  setenv("HOME", old_path, 1);
  return 1;
}


x86 assembly (clang, -O0):
<Game_Main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x110,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe86(%rip),%rdi
call   1050 <debug@plt>
lea    -0x110(%rbp),%rdi
mov    $0x100,%esi
call   1070 <getcwd@plt>
cmp    $0x0,%rax
jne    11ad <Game_Main+0x4d>
lea    -0x110(%rbp),%rdi
lea    0xe6c(%rip),%rsi
call   1030 <strcpy@plt>
mov    -0x8(%rbp),%rdi
call   1060 <chdir@plt>
mov    -0x8(%rbp),%rsi
lea    0xe5d(%rip),%rdi
mov    $0x1,%edx
call   1040 <setenv@plt>
mov    -0x8(%rbp),%rdi
call   1080 <injector@plt>
lea    -0x110(%rbp),%rdi
call   1060 <chdir@plt>
lea    -0x110(%rbp),%rsi
lea    0xe30(%rip),%rdi
mov    $0x1,%edx
call   1040 <setenv@plt>
mov    $0x1,%eax
add    $0x110,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Game_Main>:
push   %r14
push   %rbx
sub    $0x108,%rsp
mov    %rdi,%rbx
lea    0xe8c(%rip),%rdi
call   1050 <debug@plt>
mov    %rsp,%rdi
mov    $0x100,%esi
call   1070 <getcwd@plt>
test   %rax,%rax
jne    119a <Game_Main+0x3a>
lea    0xe82(%rip),%rsi
mov    %rsp,%rdi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
call   1060 <chdir@plt>
lea    0xe75(%rip),%r14
mov    %r14,%rdi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1040 <setenv@plt>
mov    %rbx,%rdi
call   1080 <injector@plt>
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1060 <chdir@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1040 <setenv@plt>
mov    $0x1,%eax
add    $0x108,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [20 x i8] c"Game_Main() started\00"
@.str.1 = [10 x i8] c"/mtd_exe/\00"
@.str.2 = [5 x i8] c"HOME\00"
define i32 @Game_Main(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca [256 x i8]
store i8* %0, i8** %3
store i8* %1, i8** %4
%6 = call i32 @debug(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%7 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%8 = call i32* @getcwd(i8* %7, i32 256)
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %13
10: ; preds = %2
%11 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%12 = call i32 @strcpy(i8* %11, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
br label %13
13: ; preds = %10, %2
%14 = load i8*, i8** %3
%15 = call i32 @chdir(i8* %14)
%16 = load i8*, i8** %3
%17 = call i32 @setenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %16, i32 1)
%18 = load i8*, i8** %3
%19 = call i32 @injector(i8* %18)
%20 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%21 = call i32 @chdir(i8* %20)
%22 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%23 = call i32 @setenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %22, i32 1)
ret i32 1
}

LLVM IR (-O2):
@.str = [20 x i8] c"Game_Main() started\00"
@.str.1 = [10 x i8] c"/mtd_exe/\00"
@.str.2 = [5 x i8] c"HOME\00"
define i32 @Game_Main(i8* %0, i8* nocapture readnone %1) {
%3 = alloca [256 x i8]
%4 = tail call i32 @debug(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%5 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%6 = call i32* @getcwd(i8* %5, i32 256)
%7 = icmp eq i32* %6, null
br i1 %7, label %8, label %10
8: ; preds = %2
%9 = call i32 @strcpy(i8* %5, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
br label %10
10: ; preds = %8, %2
%11 = call i32 @chdir(i8* %0)
%12 = call i32 @setenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %0, i32 1)
%13 = call i32 @injector(i8* %0)
%14 = call i32 @chdir(i8* %5)
%15 = call i32 @setenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %5, i32 1)
ret i32 1
}