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

/* Variables and functions */
int /*<<< orphan*/ apply_changes(unsigned char *, char *, size_t);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ free(unsigned char *);
int /*<<< orphan*/ get_data(char *, unsigned char **, int /*<<< orphan*/ *,
                            size_t *);
scalar_t__ make_changes(unsigned char *, int, int, size_t, int *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ sscanf(char *, char *, int *);
int strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
int not_main(char *rom_name, char *offset, char *bytes, int apply_or_check) {
  FILE *file = fopen(rom_name, "rb");
  if (file) {
    size_t size;
    unsigned char *buf;
    get_data("rom.smc", &buf, file, &size);
    fclose(file);
    char to_use[30];
    int num = strlen(bytes);
    int offset_to_apply, bytes_to_apply, new_offset;
    int c = 0;
    int check_tweak = 0;
    sscanf(offset, "%x", &offset_to_apply);
    while (c < num) {
      strncpy(to_use, bytes + c, 2);
      sscanf(to_use, "%x", &bytes_to_apply);
      if ((make_changes(buf, offset_to_apply, bytes_to_apply, size,
                        &check_tweak) == 0)) {
        if (apply_or_check == 0) {
          apply_changes(buf, rom_name, size);
        }
      }
      c += 2;
      offset_to_apply++;
    }
    free(buf);
    if (apply_or_check > 0)
      if (check_tweak == (c / 2))
        return 1;
      else
        return 0;
    return 1;
  } else {
    fclose(file);
    printf("no such file???\n");
    return 0;
  }
}


x86 assembly (clang, -O0):
<not_main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe3b(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     130e <not_main+0x16e>
mov    -0x30(%rbp),%rdx
lea    0xe1f(%rip),%rdi
lea    -0x40(%rbp),%rsi
lea    -0x38(%rbp),%rcx
call   10c0 <get_data@plt>
mov    -0x30(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,-0x64(%rbp)
movl   $0x0,-0x74(%rbp)
movl   $0x0,-0x78(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xdec(%rip),%rsi
lea    -0x68(%rbp),%rdx
call   1090 <sscanf@plt>
mov    -0x74(%rbp),%eax
cmp    -0x64(%rbp),%eax
jge    12b9 <not_main+0x119>
lea    -0x60(%rbp),%rdi
mov    -0x20(%rbp),%rsi
movslq -0x74(%rbp),%rax
add    %rax,%rsi
mov    $0x2,%edx
call   1040 <strncpy@plt>
lea    -0x60(%rbp),%rdi
lea    0xdb3(%rip),%rsi
lea    -0x6c(%rbp),%rdx
call   1090 <sscanf@plt>
mov    -0x40(%rbp),%rdi
mov    -0x68(%rbp),%esi
mov    -0x6c(%rbp),%edx
mov    -0x38(%rbp),%rcx
lea    -0x78(%rbp),%r8
call   10b0 <make_changes@plt>
cmp    $0x0,%rax
jne    12a2 <not_main+0x102>
cmpl   $0x0,-0x24(%rbp)
jne    129d <not_main+0xfd>
mov    -0x40(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x38(%rbp),%rdx
call   1080 <apply_changes@plt>
jmp    12a2 <not_main+0x102>
mov    -0x74(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x74(%rbp)
mov    -0x68(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x68(%rbp)
jmp    1228 <not_main+0x88>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
cmpl   $0x0,-0x24(%rbp)
jle    1302 <not_main+0x162>
mov    -0x78(%rbp),%eax
mov    %eax,-0x7c(%rbp)
mov    -0x74(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x7c(%rbp),%eax
cmp    %ecx,%eax
jne    12f6 <not_main+0x156>
movl   $0x1,-0x4(%rbp)
jmp    132a <not_main+0x18a>
movl   $0x0,-0x4(%rbp)
jmp    132a <not_main+0x18a>
movl   $0x1,-0x4(%rbp)
jmp    132a <not_main+0x18a>
mov    -0x30(%rbp),%rdi
call   1050 <fclose@plt>
lea    0xcf0(%rip),%rdi
call   1070 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<not_main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x58,%rsp
mov    %ecx,%r15d
mov    %rdx,%r12
mov    %rsi,%rbx
lea    0xe42(%rip),%rsi
mov    %rdi,0x28(%rsp)
call   10a0 <fopen@plt>
test   %rax,%rax
je     12ad <not_main+0x10d>
mov    %rax,%rbp
lea    0xe28(%rip),%rdi
lea    0x10(%rsp),%rsi
lea    0x20(%rsp),%rcx
mov    %rax,%rdx
call   10c0 <get_data@plt>
mov    %rbp,%rdi
call   1060 <fclose@plt>
mov    %r12,%rdi
call   1070 <strlen@plt>
mov    %eax,%ebp
movl   $0x0,0x8(%rsp)
lea    0xdfd(%rip),%rsi
lea    0xc(%rsp),%rdx
mov    %rbx,%rdi
call   1090 <sscanf@plt>
xor    %r14d,%r14d
test   %ebp,%ebp
jle    12c7 <not_main+0x127>
lea    0x30(%rsp),%rbx
lea    0x8(%rsp),%r13
jmp    124e <not_main+0xae>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
add    $0x2,%r14
addl   $0x1,0xc(%rsp)
cmp    %r14d,%ebp
jle    12c4 <not_main+0x124>
lea    (%r12,%r14,1),%rsi
mov    %rbx,%rdi
mov    $0x2,%edx
call   1040 <strncpy@plt>
mov    %rbx,%rdi
lea    0xda2(%rip),%rsi
lea    0x1c(%rsp),%rdx
call   1090 <sscanf@plt>
mov    0x10(%rsp),%rdi
mov    0xc(%rsp),%esi
mov    0x1c(%rsp),%edx
mov    0x20(%rsp),%rcx
mov    %r13,%r8
call   10b0 <make_changes@plt>
test   %r15d,%r15d
jne    1240 <not_main+0xa0>
test   %rax,%rax
jne    1240 <not_main+0xa0>
mov    0x10(%rsp),%rdi
mov    0x20(%rsp),%rdx
mov    0x28(%rsp),%rsi
call   1080 <apply_changes@plt>
jmp    1240 <not_main+0xa0>
xor    %ebx,%ebx
xor    %edi,%edi
call   1060 <fclose@plt>
lea    0xd51(%rip),%rdi
call   1050 <puts@plt>
jmp    12e4 <not_main+0x144>
shr    %r14d
mov    0x10(%rsp),%rdi
call   1030 <free@plt>
cmp    %r14d,0x8(%rsp)
sete   %al
test   %r15d,%r15d
setle  %cl
or     %al,%cl
movzbl %cl,%ebx
mov    %ebx,%eax
add    $0x58,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
@.str.1 = [8 x i8] c"rom.smc\00"
@.str.2 = [3 x i8] c"%x\00"
@.str.3 = [17 x i8] c"no such file???\0A\00"
define i32 @not_main(i8* %0, i8* %1, i8* %2, i32 %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32*
%11 = alloca i64
%12 = alloca i8*
%13 = alloca [30 x i8]
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32
%19 = alloca i32
store i8* %0, i8** %6
store i8* %1, i8** %7
store i8* %2, i8** %8
store i32 %3, i32* %9
%20 = load i8*, i8** %6
%21 = call i32* @fopen(i8* %20, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %21, i32** %10
%22 = load i32*, i32** %10
%23 = icmp ne i32* %22, null
br i1 %23, label %24, label %79
24: ; preds = %4
%25 = load i32*, i32** %10
%26 = call i32 @get_data(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8** %12, i32* %25, i64* %11)
%27 = load i32*, i32** %10
%28 = call i32 @fclose(i32* %27)
%29 = load i8*, i8** %8
%30 = call i32 @strlen(i8* %29)
store i32 %30, i32* %14
store i32 0, i32* %18
store i32 0, i32* %19
%31 = load i8*, i8** %7
%32 = call i32 @sscanf(i8* %31, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %15)
br label %33
33: ; preds = %61, %24
%34 = load i32, i32* %18
%35 = load i32, i32* %14
%36 = icmp slt i32 %34, %35
br i1 %36, label %37, label %66
37: ; preds = %33
%38 = getelementptr inbounds [30 x i8], [30 x i8]* %13, i64 0, i64 0
%39 = load i8*, i8** %8
%40 = load i32, i32* %18
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i8, i8* %39, i64 %41
%43 = call i32 @strncpy(i8* %38, i8* %42, i32 2)
%44 = getelementptr inbounds [30 x i8], [30 x i8]* %13, i64 0, i64 0
%45 = call i32 @sscanf(i8* %44, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %16)
%46 = load i8*, i8** %12
%47 = load i32, i32* %15
%48 = load i32, i32* %16
%49 = load i64, i64* %11
%50 = call i64 @make_changes(i8* %46, i32 %47, i32 %48, i64 %49, i32* %19)
%51 = icmp eq i64 %50, 0
br i1 %51, label %52, label %61
52: ; preds = %37
%53 = load i32, i32* %9
%54 = icmp eq i32 %53, 0
br i1 %54, label %55, label %60
55: ; preds = %52
%56 = load i8*, i8** %12
%57 = load i8*, i8** %6
%58 = load i64, i64* %11
%59 = call i32 @apply_changes(i8* %56, i8* %57, i64 %58)
br label %60
60: ; preds = %55, %52
br label %61
61: ; preds = %60, %37
%62 = load i32, i32* %18
%63 = add nsw i32 %62, 2
store i32 %63, i32* %18
%64 = load i32, i32* %15
%65 = add nsw i32 %64, 1
store i32 %65, i32* %15
br label %33
66: ; preds = %33
%67 = load i8*, i8** %12
%68 = call i32 @free(i8* %67)
%69 = load i32, i32* %9
%70 = icmp sgt i32 %69, 0
br i1 %70, label %71, label %78
71: ; preds = %66
%72 = load i32, i32* %19
%73 = load i32, i32* %18
%74 = sdiv i32 %73, 2
%75 = icmp eq i32 %72, %74
br i1 %75, label %76, label %77
76: ; preds = %71
store i32 1, i32* %5
br label %83
77: ; preds = %71
store i32 0, i32* %5
br label %83
78: ; preds = %66
store i32 1, i32* %5
br label %83
79: ; preds = %4
%80 = load i32*, i32** %10
%81 = call i32 @fclose(i32* %80)
%82 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %5
br label %83
83: ; preds = %79, %78, %77, %76
%84 = load i32, i32* %5
ret i32 %84
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@.str.1 = [8 x i8] c"rom.smc\00"
@.str.2 = [3 x i8] c"%x\00"
@str = [16 x i8] c"no such file???\00"
define i32 @not_main(i8* %0, i8* nocapture %1, i8* %2, i32 %3) {
%5 = alloca i64
%6 = alloca i8*
%7 = alloca [30 x i8]
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%12 = icmp eq i32* %11, null
br i1 %12, label %61, label %13
13: ; preds = %4
%14 = bitcast i64* %5 to i8*
%15 = bitcast i8** %6 to i8*
%16 = call i32 @get_data(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8** %6, i32* %11, i64* %5)
%17 = call i32 @fclose(i32* %11)
%18 = getelementptr inbounds [30 x i8], [30 x i8]* %7, i64 0, i64 0
%19 = call i32 @strlen(i8* %2)
%20 = bitcast i32* %8 to i8*
%21 = bitcast i32* %9 to i8*
%22 = bitcast i32* %10 to i8*
store i32 0, i32* %10
%23 = call i32 @sscanf(i8* %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %8)
%24 = icmp sgt i32 %19, 0
br i1 %24, label %25, label %52
25: ; preds = %13
%26 = icmp eq i32 %3, 0
br label %27
27: ; preds = %25, %43
%28 = phi i64 [ 0, %25 ], [ %44, %43 ]
%29 = getelementptr inbounds i8, i8* %2, i64 %28
%30 = call i32 @strncpy(i8* %18, i8* %29, i32 2)
%31 = call i32 @sscanf(i8* %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %9)
%32 = load i8*, i8** %6
%33 = load i32, i32* %8
%34 = load i32, i32* %9
%35 = load i64, i64* %5
%36 = call i64 @make_changes(i8* %32, i32 %33, i32 %34, i64 %35, i32* %10)
%37 = icmp eq i64 %36, 0
%38 = and i1 %26, %37
br i1 %38, label %39, label %43
39: ; preds = %27
%40 = load i8*, i8** %6
%41 = load i64, i64* %5
%42 = call i32 @apply_changes(i8* %40, i8* %0, i64 %41)
br label %43
43: ; preds = %39, %27
%44 = add nuw i64 %28, 2
%45 = load i32, i32* %8
%46 = add nsw i32 %45, 1
store i32 %46, i32* %8
%47 = trunc i64 %44 to i32
%48 = icmp sgt i32 %19, %47
br i1 %48, label %27, label %49
49: ; preds = %43
%50 = trunc i64 %44 to i32
%51 = lshr exact i32 %50, 1
br label %52
52: ; preds = %49, %13
%53 = phi i32 [ 0, %13 ], [ %51, %49 ]
%54 = load i8*, i8** %6
%55 = call i32 @free(i8* %54)
%56 = load i32, i32* %10
%57 = icmp eq i32 %56, %53
%58 = icmp slt i32 %3, 1
%59 = select i1 %58, i1 true, i1 %57
%60 = zext i1 %59 to i32
br label %64
61: ; preds = %4
%62 = tail call i32 @fclose(i32* null)
%63 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str, i64 0, i64 0))
br label %64
64: ; preds = %61, %52
%65 = phi i32 [ %60, %52 ], [ 0, %61 ]
ret i32 %65
}