#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 patchSMBX(char const *, char const *);
int /*<<< orphan*/ wprintf(char *, char const *);
int main() {
  const char *oldEXE = "smbx.exe";
  const char *newEXE = "lunaengine.exe";
  int err = patchSMBX(oldEXE, newEXE);
  if (err == 0) {
    wprintf(L"SMBX has been PATCHED!\nTo start LunaLUA-SMBX, open the %s\n",
            newEXE);
  } else {
    switch (err) {
    case 1:
      wprintf(L"FAILED TO PATCH: CAN'T OPEN SOURCE FILE %s FOR READ!\n",
              oldEXE);
      break;
    case 2:
      wprintf(L"FAILED TO PATCH: CAN'T OPEN TARGET FILE %s FOR WRITE!\n",
              newEXE);
      break;
    }
  }
  return err;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeca(%rip),%rax
mov    %rax,-0x10(%rbp)
lea    0xec8(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <patchSMBX@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jne    1174 <main+0x54>
mov    -0x18(%rbp),%rsi
lea    0xeae(%rip),%rdi
call   1030 <wprintf@plt>
jmp    11c3 <main+0xa3>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x20(%rbp)
sub    $0x1,%eax
je     1199 <main+0x79>
jmp    1188 <main+0x68>
mov    -0x20(%rbp),%eax
sub    $0x2,%eax
je     11ae <main+0x8e>
jmp    11be <main+0x9e>
mov    -0x10(%rbp),%rsi
lea    0xf60(%rip),%rdi
call   1030 <wprintf@plt>
jmp    11be <main+0x9e>
mov    -0x18(%rbp),%rsi
lea    0x1023(%rip),%rdi
call   1030 <wprintf@plt>
jmp    11c3 <main+0xa3>
mov    -0x1c(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
lea    0xed8(%rip),%rdi
lea    0xeda(%rip),%rsi
call   1040 <patchSMBX@plt>
mov    %eax,%ebx
cmp    $0x2,%eax
je     114d <main+0x2d>
cmp    $0x1,%ebx
je     115d <main+0x3d>
test   %ebx,%ebx
jne    1170 <main+0x50>
lea    0xecd(%rip),%rdi
jmp    1154 <main+0x34>
lea    0x1088(%rip),%rdi
lea    0xeae(%rip),%rsi
jmp    116b <main+0x4b>
lea    0xfa0(%rip),%rdi
lea    0xe95(%rip),%rsi
call   1030 <wprintf@plt>
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [9 x i8] c"smbx.exe\00"
@.str.1 = [15 x i8] c"lunaengine.exe\00"
@.str.2 = [59 x i32] [i32 83, i32 77, i32 66, i32 88, i32 32, i32 104, i32 97, i32 115, i32 32, i32 98, i32 101, i32 101, i32 110, i32 32, i32 80, i32 65, i32 84, i32 67, i32 72, i32 69, i32 68, i32 33, i32 10, i32 84, i32 111, i32 32, i32 115, i32 116, i32 97, i32 114, i32 116, i32 32, i32 76, i32 117, i32 110, i32 97, i32 76, i32 85, i32 65, i32 45, i32 83, i32 77, i32 66, i32 88, i32 44, i32 32, i32 111, i32 112, i32 101, i32 110, i32 32, i32 116, i32 104, i32 101, i32 32, i32 37, i32 115, i32 10, i32 0]
@.str.3 = [54 x i32] [i32 70, i32 65, i32 73, i32 76, i32 69, i32 68, i32 32, i32 84, i32 79, i32 32, i32 80, i32 65, i32 84, i32 67, i32 72, i32 58, i32 32, i32 67, i32 65, i32 78, i32 39, i32 84, i32 32, i32 79, i32 80, i32 69, i32 78, i32 32, i32 83, i32 79, i32 85, i32 82, i32 67, i32 69, i32 32, i32 70, i32 73, i32 76, i32 69, i32 32, i32 37, i32 115, i32 32, i32 70, i32 79, i32 82, i32 32, i32 82, i32 69, i32 65, i32 68, i32 33, i32 10, i32 0]
@.str.4 = [55 x i32] [i32 70, i32 65, i32 73, i32 76, i32 69, i32 68, i32 32, i32 84, i32 79, i32 32, i32 80, i32 65, i32 84, i32 67, i32 72, i32 58, i32 32, i32 67, i32 65, i32 78, i32 39, i32 84, i32 32, i32 79, i32 80, i32 69, i32 78, i32 32, i32 84, i32 65, i32 82, i32 71, i32 69, i32 84, i32 32, i32 70, i32 73, i32 76, i32 69, i32 32, i32 37, i32 115, i32 32, i32 70, i32 79, i32 82, i32 32, i32 87, i32 82, i32 73, i32 84, i32 69, i32 33, i32 10, i32 0]
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
store i32 0, i32* %1
store i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8** %2
store i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8** %3
%5 = load i8*, i8** %2
%6 = load i8*, i8** %3
%7 = call i32 @patchSMBX(i8* %5, i8* %6)
store i32 %7, i32* %4
%8 = load i32, i32* %4
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %0
%11 = load i8*, i8** %3
%12 = call i32 @wprintf(i8* bitcast ([59 x i32]* @.str.2 to i8*), i8* %11)
br label %22
13: ; preds = %0
%14 = load i32, i32* %4
switch i32 %14, label %21 [
i32 1, label %15
i32 2, label %18
]
15: ; preds = %13
%16 = load i8*, i8** %2
%17 = call i32 @wprintf(i8* bitcast ([54 x i32]* @.str.3 to i8*), i8* %16)
br label %21
18: ; preds = %13
%19 = load i8*, i8** %3
%20 = call i32 @wprintf(i8* bitcast ([55 x i32]* @.str.4 to i8*), i8* %19)
br label %21
21: ; preds = %13, %18, %15
br label %22
22: ; preds = %21, %10
%23 = load i32, i32* %4
ret i32 %23
}

LLVM IR (-O2):
@.str = [9 x i8] c"smbx.exe\00"
@.str.1 = [15 x i8] c"lunaengine.exe\00"
@.str.2 = [59 x i32] [i32 83, i32 77, i32 66, i32 88, i32 32, i32 104, i32 97, i32 115, i32 32, i32 98, i32 101, i32 101, i32 110, i32 32, i32 80, i32 65, i32 84, i32 67, i32 72, i32 69, i32 68, i32 33, i32 10, i32 84, i32 111, i32 32, i32 115, i32 116, i32 97, i32 114, i32 116, i32 32, i32 76, i32 117, i32 110, i32 97, i32 76, i32 85, i32 65, i32 45, i32 83, i32 77, i32 66, i32 88, i32 44, i32 32, i32 111, i32 112, i32 101, i32 110, i32 32, i32 116, i32 104, i32 101, i32 32, i32 37, i32 115, i32 10, i32 0]
@.str.3 = [54 x i32] [i32 70, i32 65, i32 73, i32 76, i32 69, i32 68, i32 32, i32 84, i32 79, i32 32, i32 80, i32 65, i32 84, i32 67, i32 72, i32 58, i32 32, i32 67, i32 65, i32 78, i32 39, i32 84, i32 32, i32 79, i32 80, i32 69, i32 78, i32 32, i32 83, i32 79, i32 85, i32 82, i32 67, i32 69, i32 32, i32 70, i32 73, i32 76, i32 69, i32 32, i32 37, i32 115, i32 32, i32 70, i32 79, i32 82, i32 32, i32 82, i32 69, i32 65, i32 68, i32 33, i32 10, i32 0]
@.str.4 = [55 x i32] [i32 70, i32 65, i32 73, i32 76, i32 69, i32 68, i32 32, i32 84, i32 79, i32 32, i32 80, i32 65, i32 84, i32 67, i32 72, i32 58, i32 32, i32 67, i32 65, i32 78, i32 39, i32 84, i32 32, i32 79, i32 80, i32 69, i32 78, i32 32, i32 84, i32 65, i32 82, i32 71, i32 69, i32 84, i32 32, i32 70, i32 73, i32 76, i32 69, i32 32, i32 37, i32 115, i32 32, i32 70, i32 79, i32 82, i32 32, i32 87, i32 82, i32 73, i32 84, i32 69, i32 33, i32 10, i32 0]
define i32 @main() {
%1 = tail call i32 @patchSMBX(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
switch i32 %1, label %8 [
i32 0, label %2
i32 1, label %4
i32 2, label %6
]
2: ; preds = %0
%3 = tail call i32 @wprintf(i8* bitcast ([59 x i32]* @.str.2 to i8*), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
br label %8
4: ; preds = %0
%5 = tail call i32 @wprintf(i8* bitcast ([54 x i32]* @.str.3 to i8*), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
br label %8
6: ; preds = %0
%7 = tail call i32 @wprintf(i8* bitcast ([55 x i32]* @.str.4 to i8*), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
br label %8
8: ; preds = %0, %4, %6, %2
ret i32 %1
}