#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 unsigned long off_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ MAP_SHARED;
int O_RDWR;
int O_SYNC;
int PROT_READ;
int PROT_WRITE;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fread(unsigned long *, unsigned long, int,
                         int /*<<< orphan*/ *);
int /*<<< orphan*/ free(unsigned long *);
int /*<<< orphan*/ fwrite(void *, unsigned long, int, int /*<<< orphan*/ *);
scalar_t__ malloc(unsigned long);
void *mmap(int /*<<< orphan*/, unsigned long, int, int /*<<< orphan*/, int,
           unsigned long);
int /*<<< orphan*/ munmap(void *, unsigned long);
int open(char *, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sscanf(char *, char *, unsigned long *);
int /*<<< orphan*/ strcmp(char *, char *);
int main(int argc, char *argv[]) {
  off_t mfpTarget = 0x40E00000;
  void *mfp_map_base, *mfp_virt_base;
  int fd, func;
  unsigned long *buff;
  unsigned long addr;
  int i;
  FILE *dumpFile;
  if (argc < 4) {
    printf("Usage: %s set/get/cmp file addr\n", argv[0]);
    return 0;
  }
  sscanf(argv[3], "%x", &addr);
  if (!strcmp(argv[1], "set"))
    func = 0;
  else if (!strcmp(argv[1], "cmp"))
    func = 2;
  else
    func = 1;
  if (func == 1)
    dumpFile = fopen(argv[2], "wb");
  else
    dumpFile = fopen(argv[2], "rb");
  if (!dumpFile) {
    printf("'%s' open failed.\n", argv[2]);
    return 0;
  }
  fd = open("/dev/mem", O_RDWR | O_SYNC);
  if (!fd) {
    printf("/dev/mem open failed.\n");
    return 0;
  }
  mfp_map_base = mmap(0, 16384UL, PROT_READ | PROT_WRITE, MAP_SHARED, fd,
                      mfpTarget & ~(16384UL - 1));
  if (mfp_map_base == (void *)-1) {
    printf("mmap fail\n");
    return 0;
  }
  printf("MFP Memory mapped at address %p.\n", mfp_map_base);
  mfp_virt_base = mfp_map_base + (mfpTarget & (16384UL - 1));
  printf("Init, mfp virtual base at %p (phys=0x%X)\n", mfp_virt_base,
         mfpTarget);
  if (func == 0)
    fread(mfp_virt_base, 16384UL, 1, dumpFile);
  else if (func == 1)
    fwrite(mfp_virt_base, 16384UL, 1, dumpFile);
  else {
    buff = (unsigned long *)malloc(16384UL);
    if (!buff) {
      printf("alloc fail\n");
      return 0;
    }
    fread(buff, 16384UL, 1, dumpFile);
    printf("num\taddr\tfile\tMFP\n");
    for (i = 0; i < (16384UL / 4); i++)
      if (*(buff + i) != *(((unsigned long *)mfp_virt_base) + i))
        printf("%i:\t%04x\t%08x\t%08x\n", i, i * 4, *(buff + i),
               *(((unsigned long *)mfp_virt_base) + i));
    free(buff);
  }
  fclose(dumpFile);
  munmap(mfp_map_base, 16384UL);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x40e00000,-0x18(%rbp)
40
cmpl   $0x4,-0x8(%rbp)
jge    1209 <main+0x49>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe0a(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1513 <main+0x353>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
lea    0xe09(%rip),%rsi
lea    -0x40(%rbp),%rdx
call   10a0 <sscanf@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xdf4(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%eax
jne    124a <main+0x8a>
movl   $0x0,-0x30(%rbp)
jmp    127f <main+0xbf>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xdcf(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%eax
jne    1273 <main+0xb3>
movl   $0x2,-0x30(%rbp)
jmp    127a <main+0xba>
movl   $0x1,-0x30(%rbp)
jmp    127f <main+0xbf>
cmpl   $0x1,-0x30(%rbp)
jne    12a6 <main+0xe6>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xd94(%rip),%rsi
call   10d0 <fopen@plt>
mov    %rax,-0x50(%rbp)
jmp    12be <main+0xfe>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xd7a(%rip),%rsi
call   10d0 <fopen@plt>
mov    %rax,-0x50(%rbp)
cmpq   $0x0,-0x50(%rbp)
jne    12eb <main+0x12b>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
lea    0xd5a(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1513 <main+0x353>
mov    0x2ce6(%rip),%rax
mov    (%rax),%esi
mov    0x2cd5(%rip),%rax
or     (%rax),%esi
lea    0xd41(%rip),%rdi
call   10c0 <open@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jne    1330 <main+0x170>
lea    0xd31(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1513 <main+0x353>
mov    0x2cc1(%rip),%rax
mov    (%rax),%edx
mov    0x2c80(%rip),%rax
or     (%rax),%edx
mov    0x2c9f(%rip),%rax
mov    (%rax),%ecx
mov    -0x2c(%rbp),%r8d
mov    -0x18(%rbp),%r9
and    $0xffffffffffffc000,%r9
xor    %edi,%edi
mov    $0x4000,%esi
call   1060 <mmap@plt>
mov    %rax,-0x20(%rbp)
mov    $0xffffffffffffffff,%rax
cmp    %rax,-0x20(%rbp)
jne    1395 <main+0x1d5>
lea    0xce3(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1513 <main+0x353>
mov    -0x20(%rbp),%rsi
lea    0xcd0(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x20(%rbp),%rax
mov    -0x18(%rbp),%rcx
and    $0x3fff,%rcx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rsi
mov    -0x18(%rbp),%rdx
lea    0xcc6(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
cmpl   $0x0,-0x30(%rbp)
jne    13f9 <main+0x239>
mov    -0x28(%rbp),%rdi
mov    -0x50(%rbp),%rcx
mov    $0x4000,%esi
mov    $0x1,%edx
call   1040 <fread@plt>
jmp    14fc <main+0x33c>
cmpl   $0x1,-0x30(%rbp)
jne    141f <main+0x25f>
mov    -0x28(%rbp),%rdi
mov    -0x50(%rbp),%rcx
mov    $0x4000,%esi
mov    $0x1,%edx
call   10e0 <fwrite@plt>
jmp    14f7 <main+0x337>
mov    $0x4000,%edi
call   1090 <malloc@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    1452 <main+0x292>
lea    0xc7d(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1513 <main+0x353>
mov    -0x38(%rbp),%rdi
mov    -0x50(%rbp),%rcx
mov    $0x4000,%esi
mov    $0x1,%edx
call   1040 <fread@plt>
lea    0xc58(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0x0,-0x44(%rbp)
movslq -0x44(%rbp),%rax
cmp    $0x1000,%rax
jae    14ee <main+0x32e>
mov    -0x38(%rbp),%rax
movslq -0x44(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    -0x28(%rbp),%rcx
movslq -0x44(%rbp),%rdx
cmp    (%rcx,%rdx,8),%rax
je     14db <main+0x31b>
mov    -0x44(%rbp),%esi
mov    -0x44(%rbp),%edx
shl    $0x2,%edx
mov    -0x38(%rbp),%rax
movslq -0x44(%rbp),%rcx
mov    (%rax,%rcx,8),%rcx
mov    -0x28(%rbp),%rax
movslq -0x44(%rbp),%rdi
mov    (%rax,%rdi,8),%r8
lea    0xc07(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
jmp    14e0 <main+0x320>
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    147e <main+0x2be>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
jmp    14fc <main+0x33c>
mov    -0x50(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x20(%rbp),%rdi
mov    $0x4000,%esi
call   10b0 <munmap@plt>
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbx
cmp    $0x3,%edi
jg     11f2 <main+0x22>
mov    (%rbx),%rsi
lea    0xe13(%rip),%rdi
jmp    1311 <main+0x141>
mov    0x18(%rbx),%rdi
lea    0xe24(%rip),%rsi
mov    %rsp,%rdx
call   10b0 <sscanf@plt>
mov    0x8(%rbx),%rbp
lea    0xe14(%rip),%rsi
mov    %rbp,%rdi
call   1090 <strcmp@plt>
mov    %eax,%r15d
test   %eax,%eax
je     123e <main+0x6e>
lea    0xe02(%rip),%rsi
mov    %rbp,%rdi
call   1090 <strcmp@plt>
test   %eax,%eax
je     123e <main+0x6e>
mov    $0x1,%bpl
lea    0xdf0(%rip),%rsi
jmp    1247 <main+0x77>
lea    0xdea(%rip),%rsi
xor    %ebp,%ebp
mov    0x10(%rbx),%rdi
call   10e0 <fopen@plt>
test   %rax,%rax
je     1306 <main+0x136>
mov    %rax,%r14
mov    0x2d75(%rip),%rax
mov    0x2d66(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
lea    0xdd0(%rip),%rdi
call   10d0 <open@plt>
test   %eax,%eax
je     1329 <main+0x159>
mov    0x2d6f(%rip),%rcx
mov    0x2d30(%rip),%rdx
mov    (%rdx),%edx
or     (%rcx),%edx
mov    0x2d4d(%rip),%rcx
mov    (%rcx),%ecx
mov    $0x4000,%esi
mov    $0x40e00000,%r9d
xor    %edi,%edi
mov    %eax,%r8d
call   1070 <mmap@plt>
cmp    $0xffffffffffffffff,%rax
je     1337 <main+0x167>
mov    %rax,%r12
lea    0xd8c(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1080 <printf@plt>
lea    0xd9d(%rip),%rdi
mov    $0x40e00000,%edx
mov    %r12,%rsi
xor    %eax,%eax
call   1080 <printf@plt>
test   %r15d,%r15d
je     1345 <main+0x175>
test   %bpl,%bpl
je     135c <main+0x18c>
mov    $0x4000,%esi
mov    %r12,%rdi
mov    $0x1,%edx
mov    %r14,%rcx
call   10f0 <fwrite@plt>
jmp    13d6 <main+0x206>
mov    0x10(%rbx),%rsi
lea    0xd21(%rip),%rdi
xor    %eax,%eax
call   1080 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd7e(%rip),%rdi
call   1040 <puts@plt>
jmp    1318 <main+0x148>
lea    0xda3(%rip),%rdi
call   1040 <puts@plt>
jmp    1318 <main+0x148>
mov    $0x4000,%esi
mov    %r12,%rdi
mov    $0x1,%edx
mov    %r14,%rcx
call   1050 <fread@plt>
jmp    13d6 <main+0x206>
mov    $0x4000,%edi
call   10a0 <malloc@plt>
test   %rax,%rax
je     13f0 <main+0x220>
mov    %rax,%r13
mov    $0x4000,%esi
mov    %rax,%rdi
mov    $0x1,%edx
mov    %r14,%rcx
call   1050 <fread@plt>
lea    0xd41(%rip),%rdi
call   1040 <puts@plt>
lea    0xd00(%rip),%r15
xor    %ebx,%ebx
xor    %ebp,%ebp
jmp    13b0 <main+0x1e0>
add    $0x1,%rbp
add    $0x4,%ebx
cmp    $0x1000,%rbp
je     13ce <main+0x1fe>
mov    0x0(%r13,%rbp,8),%rcx
mov    (%r12,%rbp,8),%r8
cmp    %r8,%rcx
je     13a0 <main+0x1d0>
mov    %r15,%rdi
mov    %ebp,%esi
mov    %ebx,%edx
xor    %eax,%eax
call   1080 <printf@plt>
jmp    13a0 <main+0x1d0>
mov    %r13,%rdi
call   1030 <free@plt>
mov    %r14,%rdi
call   1060 <fclose@plt>
mov    $0x4000,%esi
mov    %r12,%rdi
call   10c0 <munmap@plt>
jmp    1318 <main+0x148>
lea    0xccd(%rip),%rdi
call   1040 <puts@plt>
jmp    1318 <main+0x148>

LLVM IR (-O0):
@.str = [33 x i8] c"Usage: %s set/get/cmp file addr\0A\00"
@.str.1 = [3 x i8] c"%x\00"
@.str.2 = [4 x i8] c"set\00"
@.str.3 = [4 x i8] c"cmp\00"
@.str.4 = [3 x i8] c"wb\00"
@.str.5 = [3 x i8] c"rb\00"
@.str.6 = [19 x i8] c"'%s' open failed.\0A\00"
@.str.7 = [9 x i8] c"/dev/mem\00"
@O_RDWR = global i32 0
@O_SYNC = global i32 0
@.str.8 = [23 x i8] c"/dev/mem open failed.\0A\00"
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_SHARED = global i32 0
@.str.9 = [11 x i8] c"mmap fail\0A\00"
@.str.10 = [34 x i8] c"MFP Memory mapped at address %p.\0A\00"
@.str.11 = [42 x i8] c"Init, mfp virtual base at %p (phys=0x%X)\0A\00"
@.str.12 = [12 x i8] c"alloc fail\0A\00"
@.str.13 = [19 x i8] c"num\09addr\09file\09MFP\0A\00"
@.str.14 = [20 x i8] c"%i:\09%04x\09%08x\09%08x\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i64*
%12 = alloca i64
%13 = alloca i32
%14 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i64 1088421888, i64* %6
%15 = load i32, i32* %4
%16 = icmp slt i32 %15, 4
br i1 %16, label %17, label %22
17: ; preds = %2
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 0
%20 = load i8*, i8** %19
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i8* %20)
store i32 0, i32* %3
br label %167
22: ; preds = %2
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 3
%25 = load i8*, i8** %24
%26 = call i32 @sscanf(i8* %25, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i64* %12)
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 1
%29 = load i8*, i8** %28
%30 = call i32 @strcmp(i8* %29, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%31 = icmp ne i32 %30, 0
br i1 %31, label %33, label %32
32: ; preds = %22
store i32 0, i32* %10
br label %42
33: ; preds = %22
%34 = load i8**, i8*** %5
%35 = getelementptr inbounds i8*, i8** %34, i64 1
%36 = load i8*, i8** %35
%37 = call i32 @strcmp(i8* %36, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%38 = icmp ne i32 %37, 0
br i1 %38, label %40, label %39
39: ; preds = %33
store i32 2, i32* %10
br label %41
40: ; preds = %33
store i32 1, i32* %10
br label %41
41: ; preds = %40, %39
br label %42
42: ; preds = %41, %32
%43 = load i32, i32* %10
%44 = icmp eq i32 %43, 1
br i1 %44, label %45, label %50
45: ; preds = %42
%46 = load i8**, i8*** %5
%47 = getelementptr inbounds i8*, i8** %46, i64 2
%48 = load i8*, i8** %47
%49 = call i32* @fopen(i8* %48, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
store i32* %49, i32** %14
br label %55
50: ; preds = %42
%51 = load i8**, i8*** %5
%52 = getelementptr inbounds i8*, i8** %51, i64 2
%53 = load i8*, i8** %52
%54 = call i32* @fopen(i8* %53, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
store i32* %54, i32** %14
br label %55
55: ; preds = %50, %45
%56 = load i32*, i32** %14
%57 = icmp ne i32* %56, null
br i1 %57, label %63, label %58
58: ; preds = %55
%59 = load i8**, i8*** %5
%60 = getelementptr inbounds i8*, i8** %59, i64 2
%61 = load i8*, i8** %60
%62 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.6, i64 0, i64 0), i8* %61)
store i32 0, i32* %3
br label %167
63: ; preds = %55
%64 = load i32, i32* @O_RDWR
%65 = load i32, i32* @O_SYNC
%66 = or i32 %64, %65
%67 = call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.7, i64 0, i64 0), i32 %66)
store i32 %67, i32* %9
%68 = load i32, i32* %9
%69 = icmp ne i32 %68, 0
br i1 %69, label %72, label %70
70: ; preds = %63
%71 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.8, i64 0, i64 0))
store i32 0, i32* %3
br label %167
72: ; preds = %63
%73 = load i32, i32* @PROT_READ
%74 = load i32, i32* @PROT_WRITE
%75 = or i32 %73, %74
%76 = load i32, i32* @MAP_SHARED
%77 = load i32, i32* %9
%78 = load i64, i64* %6
%79 = and i64 %78, -16384
%80 = call i8* @mmap(i32 0, i64 16384, i32 %75, i32 %76, i32 %77, i64 %79)
store i8* %80, i8** %7
%81 = load i8*, i8** %7
%82 = icmp eq i8* %81, inttoptr (i64 -1 to i8*)
br i1 %82, label %83, label %85
83: ; preds = %72
%84 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.9, i64 0, i64 0))
store i32 0, i32* %3
br label %167
85: ; preds = %72
%86 = load i8*, i8** %7
%87 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.10, i64 0, i64 0), i8* %86)
%88 = load i8*, i8** %7
%89 = load i64, i64* %6
%90 = and i64 %89, 16383
%91 = getelementptr i8, i8* %88, i64 %90
store i8* %91, i8** %8
%92 = load i8*, i8** %8
%93 = load i64, i64* %6
%94 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.11, i64 0, i64 0), i8* %92, i64 %93)
%95 = load i32, i32* %10
%96 = icmp eq i32 %95, 0
br i1 %96, label %97, label %102
97: ; preds = %85
%98 = load i8*, i8** %8
%99 = bitcast i8* %98 to i64*
%100 = load i32*, i32** %14
%101 = call i32 @fread(i64* %99, i64 16384, i32 1, i32* %100)
br label %162
102: ; preds = %85
%103 = load i32, i32* %10
%104 = icmp eq i32 %103, 1
br i1 %104, label %105, label %109
105: ; preds = %102
%106 = load i8*, i8** %8
%107 = load i32*, i32** %14
%108 = call i32 @fwrite(i8* %106, i64 16384, i32 1, i32* %107)
br label %161
109: ; preds = %102
%110 = call i64 @malloc(i64 16384)
%111 = inttoptr i64 %110 to i64*
store i64* %111, i64** %11
%112 = load i64*, i64** %11
%113 = icmp ne i64* %112, null
br i1 %113, label %116, label %114
114: ; preds = %109
%115 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.12, i64 0, i64 0))
store i32 0, i32* %3
br label %167
116: ; preds = %109
%117 = load i64*, i64** %11
%118 = load i32*, i32** %14
%119 = call i32 @fread(i64* %117, i64 16384, i32 1, i32* %118)
%120 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.13, i64 0, i64 0))
store i32 0, i32* %13
br label %121
121: ; preds = %155, %116
%122 = load i32, i32* %13
%123 = sext i32 %122 to i64
%124 = icmp ult i64 %123, 4096
br i1 %124, label %125, label %158
125: ; preds = %121
%126 = load i64*, i64** %11
%127 = load i32, i32* %13
%128 = sext i32 %127 to i64
%129 = getelementptr inbounds i64, i64* %126, i64 %128
%130 = load i64, i64* %129
%131 = load i8*, i8** %8
%132 = bitcast i8* %131 to i64*
%133 = load i32, i32* %13
%134 = sext i32 %133 to i64
%135 = getelementptr inbounds i64, i64* %132, i64 %134
%136 = load i64, i64* %135
%137 = icmp ne i64 %130, %136
br i1 %137, label %138, label %154
138: ; preds = %125
%139 = load i32, i32* %13
%140 = load i32, i32* %13
%141 = mul nsw i32 %140, 4
%142 = load i64*, i64** %11
%143 = load i32, i32* %13
%144 = sext i32 %143 to i64
%145 = getelementptr inbounds i64, i64* %142, i64 %144
%146 = load i64, i64* %145
%147 = load i8*, i8** %8
%148 = bitcast i8* %147 to i64*
%149 = load i32, i32* %13
%150 = sext i32 %149 to i64
%151 = getelementptr inbounds i64, i64* %148, i64 %150
%152 = load i64, i64* %151
%153 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.14, i64 0, i64 0), i32 %139, i32 %141, i64 %146, i64 %152)
br label %154
154: ; preds = %138, %125
br label %155
155: ; preds = %154
%156 = load i32, i32* %13
%157 = add nsw i32 %156, 1
store i32 %157, i32* %13
br label %121
158: ; preds = %121
%159 = load i64*, i64** %11
%160 = call i32 @free(i64* %159)
br label %161
161: ; preds = %158, %105
br label %162
162: ; preds = %161, %97
%163 = load i32*, i32** %14
%164 = call i32 @fclose(i32* %163)
%165 = load i8*, i8** %7
%166 = call i32 @munmap(i8* %165, i64 16384)
br label %167
167: ; preds = %162, %114, %83, %70, %58, %17
%168 = load i32, i32* %3
ret i32 %168
}

LLVM IR (-O2):
@.str = [33 x i8] c"Usage: %s set/get/cmp file addr\0A\00"
@.str.1 = [3 x i8] c"%x\00"
@.str.2 = [4 x i8] c"set\00"
@.str.3 = [4 x i8] c"cmp\00"
@.str.4 = [3 x i8] c"wb\00"
@.str.5 = [3 x i8] c"rb\00"
@.str.6 = [19 x i8] c"'%s' open failed.\0A\00"
@.str.7 = [9 x i8] c"/dev/mem\00"
@O_RDWR = global i32 0
@O_SYNC = global i32 0
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_SHARED = global i32 0
@.str.10 = [34 x i8] c"MFP Memory mapped at address %p.\0A\00"
@.str.11 = [42 x i8] c"Init, mfp virtual base at %p (phys=0x%X)\0A\00"
@.str.14 = [20 x i8] c"%i:\09%04x\09%08x\09%08x\0A\00"
@str = [22 x i8] c"/dev/mem open failed.\00"
@str.15 = [11 x i8] c"alloc fail\00"
@str.16 = [18 x i8] c"num\09addr\09file\09MFP\00"
@str.17 = [10 x i8] c"mmap fail\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i64
%4 = bitcast i64* %3 to i8*
%5 = icmp slt i32 %0, 4
br i1 %5, label %6, label %9
6: ; preds = %2
%7 = load i8*, i8** %1
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i8* %7)
br label %87
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 3
%11 = load i8*, i8** %10
%12 = call i32 @sscanf(i8* %11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i64* %3)
%13 = getelementptr inbounds i8*, i8** %1, i64 1
%14 = load i8*, i8** %13
%15 = call i32 @strcmp(i8* dereferenceable(1) %14, i8* dereferenceable(4) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%16 = icmp eq i32 %15, 0
br i1 %16, label %20, label %17
17: ; preds = %9
%18 = call i32 @strcmp(i8* dereferenceable(1) %14, i8* dereferenceable(4) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %21
20: ; preds = %9, %17
br label %21
21: ; preds = %17, %20
%22 = phi i8* [ getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), %20 ], [ getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), %17 ]
%23 = phi i1 [ false, %20 ], [ true, %17 ]
%24 = getelementptr inbounds i8*, i8** %1, i64 2
%25 = load i8*, i8** %24
%26 = call i32* @fopen(i8* %25, i8* %22)
%27 = icmp eq i32* %26, null
br i1 %27, label %28, label %32
28: ; preds = %21
%29 = getelementptr inbounds i8*, i8** %1, i64 2
%30 = load i8*, i8** %29
%31 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.6, i64 0, i64 0), i8* %30)
br label %87
32: ; preds = %21
%33 = load i32, i32* @O_RDWR
%34 = load i32, i32* @O_SYNC
%35 = or i32 %34, %33
%36 = call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.7, i64 0, i64 0), i32 %35)
%37 = icmp eq i32 %36, 0
br i1 %37, label %38, label %40
38: ; preds = %32
%39 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str, i64 0, i64 0))
br label %87
40: ; preds = %32
%41 = load i32, i32* @PROT_READ
%42 = load i32, i32* @PROT_WRITE
%43 = or i32 %42, %41
%44 = load i32, i32* @MAP_SHARED
%45 = call i8* @mmap(i32 0, i64 16384, i32 %43, i32 %44, i32 %36, i64 1088421888)
%46 = icmp eq i8* %45, inttoptr (i64 -1 to i8*)
br i1 %46, label %47, label %49
47: ; preds = %40
%48 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str.17, i64 0, i64 0))
br label %87
49: ; preds = %40
%50 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.10, i64 0, i64 0), i8* %45)
%51 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str.11, i64 0, i64 0), i8* %45, i64 1088421888)
br i1 %16, label %52, label %55
52: ; preds = %49
%53 = bitcast i8* %45 to i64*
%54 = call i32 @fread(i64* %53, i64 16384, i32 1, i32* %26)
br label %84
55: ; preds = %49
br i1 %23, label %56, label %58
56: ; preds = %55
%57 = call i32 @fwrite(i8* %45, i64 16384, i32 1, i32* %26)
br label %84
58: ; preds = %55
%59 = call i64 @malloc(i64 16384)
%60 = inttoptr i64 %59 to i64*
%61 = icmp eq i64 %59, 0
br i1 %61, label %62, label %64
62: ; preds = %58
%63 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str.15, i64 0, i64 0))
br label %87
64: ; preds = %58
%65 = call i32 @fread(i64* %60, i64 16384, i32 1, i32* %26)
%66 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.16, i64 0, i64 0))
%67 = bitcast i8* %45 to i64*
br label %68
68: ; preds = %64, %79
%69 = phi i64 [ 0, %64 ], [ %80, %79 ]
%70 = trunc i64 %69 to i32
%71 = getelementptr inbounds i64, i64* %60, i64 %69
%72 = load i64, i64* %71
%73 = getelementptr inbounds i64, i64* %67, i64 %69
%74 = load i64, i64* %73
%75 = icmp eq i64 %72, %74
br i1 %75, label %79, label %76
76: ; preds = %68
%77 = shl nuw nsw i32 %70, 2
%78 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.14, i64 0, i64 0), i32 %70, i32 %77, i64 %72, i64 %74)
br label %79
79: ; preds = %68, %76
%80 = add nuw nsw i64 %69, 1
%81 = icmp eq i64 %80, 4096
br i1 %81, label %82, label %68
82: ; preds = %79
%83 = call i32 @free(i64* %60)
br label %84
84: ; preds = %56, %82, %52
%85 = call i32 @fclose(i32* %26)
%86 = call i32 @munmap(i8* %45, i64 16384)
br label %87
87: ; preds = %84, %62, %47, %38, %28, %6
ret i32 0
}