#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ get_win_offsets(int /*<<< orphan*/ *);
int /*<<< orphan*/ print_next_win_process(int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char *argv[]) {
  if (argc != 3) {
    printf("Usage: %s trusted_image monitored_image\n", argv[0]);
  } else {
    do {
    } while (0);
    printf("==================Get Process Offset from the Trusted "
           "OS=======================\n");
    FILE *trusted_dumpfile = fopen(argv[1], "rb");
    if (!trusted_dumpfile) {
      printf("Unable to open dump file: %s\n", argv[1]);
      return -1;
    }
    get_win_offsets(trusted_dumpfile);
    print_next_win_process(trusted_dumpfile);
    fclose(trusted_dumpfile);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     118a <main+0x3a>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe82(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1202 <main+0xb2>
jmp    118f <main+0x3f>
jmp    1194 <main+0x44>
lea    0xe8e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xec9(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11e7 <main+0x97>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xea9(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1209 <main+0xb9>
mov    -0x18(%rbp),%rdi
call   1060 <get_win_offsets@plt>
mov    -0x18(%rbp),%rdi
call   1050 <print_next_win_process@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
cmp    $0x3,%edi
jne    11ac <main+0x4c>
lea    0xed7(%rip),%rdi
call   1030 <puts@plt>
mov    0x8(%r14),%rdi
lea    0xea6(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     11c1 <main+0x61>
mov    %rax,%rbx
mov    %rax,%rdi
call   1070 <get_win_offsets@plt>
mov    %rbx,%rdi
call   1060 <print_next_win_process@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
xor    %ebx,%ebx
jmp    11d8 <main+0x78>
mov    (%r14),%rsi
lea    0xe4a(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1050 <printf@plt>
jmp    11d8 <main+0x78>
mov    0x8(%r14),%rsi
lea    0xe60(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [41 x i8] c"Usage: %s trusted_image monitored_image\0A\00"
@.str.1 = [81 x i8] c"==================Get Process Offset from the Trusted OS=======================\0A\00"
@.str.2 = [3 x i8] c"rb\00"
@.str.3 = [30 x i8] c"Unable to open dump file: %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = load i32, i32* %4
%8 = icmp ne i32 %7, 3
br i1 %8, label %9, label %14
9: ; preds = %2
%10 = load i8**, i8*** %5
%11 = getelementptr inbounds i8*, i8** %10, i64 0
%12 = load i8*, i8** %11
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i8* %12)
br label %36
14: ; preds = %2
br label %15
15: ; preds = %14
br label %16
16: ; preds = %15
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([81 x i8], [81 x i8]* @.str.1, i64 0, i64 0))
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = call i32* @fopen(i8* %20, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i32* %21, i32** %6
%22 = load i32*, i32** %6
%23 = icmp ne i32* %22, null
br i1 %23, label %29, label %24
24: ; preds = %16
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 1
%27 = load i8*, i8** %26
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0), i8* %27)
store i32 -1, i32* %3
br label %37
29: ; preds = %16
%30 = load i32*, i32** %6
%31 = call i32 @get_win_offsets(i32* %30)
%32 = load i32*, i32** %6
%33 = call i32 @print_next_win_process(i32* %32)
%34 = load i32*, i32** %6
%35 = call i32 @fclose(i32* %34)
br label %36
36: ; preds = %29, %9
store i32 0, i32* %3
br label %37
37: ; preds = %36, %24
%38 = load i32, i32* %3
ret i32 %38
}

LLVM IR (-O2):
@.str = [41 x i8] c"Usage: %s trusted_image monitored_image\0A\00"
@.str.2 = [3 x i8] c"rb\00"
@.str.3 = [30 x i8] c"Unable to open dump file: %s\0A\00"
@str = [80 x i8] c"==================Get Process Offset from the Trusted OS=======================\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 3
br i1 %3, label %7, label %4
4: ; preds = %2
%5 = load i8*, i8** %1
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i8* %5)
br label %20
7: ; preds = %2
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([80 x i8], [80 x i8]* @str, i64 0, i64 0))
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = tail call i32* @fopen(i8* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%12 = icmp eq i32* %11, null
br i1 %12, label %17, label %13
13: ; preds = %7
%14 = tail call i32 @get_win_offsets(i32* %11)
%15 = tail call i32 @print_next_win_process(i32* %11)
%16 = tail call i32 @fclose(i32* %11)
br label %20
17: ; preds = %7
%18 = load i8*, i8** %9
%19 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0), i8* %18)
br label %20
20: ; preds = %4, %13, %17
%21 = phi i32 [ -1, %17 ], [ 0, %13 ], [ 0, %4 ]
ret i32 %21
}