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

/* Variables and functions */
int EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ exit(int);
scalar_t__ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
size_t fread(int *, int, int, int /*<<< orphan*/ *);
int fseeko(int /*<<< orphan*/ *, int, int /*<<< orphan*/);
int ftello(int /*<<< orphan*/ *);
int fwrite(int *, int, int, int /*<<< orphan*/);
int getopt(int, char **, char *);
int htobe32(int);
int le32toh(int);
int /*<<< orphan*/ optarg;
int optind;
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
int strtoul(int /*<<< orphan*/, int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ usage(char *);
int main(int argc, char *argv[]) {
  FILE *input;
  int opt;
  off_t pos;
  size_t size;
  uint32_t addr = 0x40200000;
  uint32_t temp;
  int chsettings = 0;
  int swap = 0;
  while ((opt = getopt(argc, argv, "a:s")) != -1) {
    switch (opt) {
    case 'a':
      addr = strtoul(optarg, NULL, 0);
      break;
    case 's':
      swap = 1;
      break;
    }
  }
  if (optind >= argc) {
    usage(argv[0]);
    exit(1);
  }
  input = fopen(argv[optind], "r");
  if (input == NULL) {
    perror("fopen");
    exit(EXIT_FAILURE);
  }
  if (fseeko(input, 0, SEEK_END) == -1) {
    perror("fseeko");
    exit(EXIT_FAILURE);
  }
  pos = ftello(input);
  if (pos == -1) {
    perror("ftello");
    exit(EXIT_FAILURE);
  }
  if (pos > 0x100000) {
    fprintf(stderr, "error: image should be smaller than 1 MiB\n");
    exit(EXIT_FAILURE);
  }
  if (fseeko(input, 0x14, SEEK_SET) == -1) {
    perror("fseeko");
    exit(EXIT_FAILURE);
  }
  size = fread(&temp, 1, sizeof(uint32_t), input);
  if (!size) {
    perror("fseeko");
    exit(EXIT_FAILURE);
  }
  if (le32toh(temp) == 0x45534843)
    chsettings = 1;
  if (fseeko(input, 0x0, SEEK_SET) == -1) {
    perror("fseeko");
    exit(EXIT_FAILURE);
  }
  pos = (pos + 3) & ~3;
  if (!chsettings) {
    temp = pos;
    if (swap)
      temp = htobe32(temp);
    fwrite(&temp, sizeof(uint32_t), 1, stdout);
    temp = addr;
    if (swap)
      temp = htobe32(temp);
    fwrite(&temp, sizeof(uint32_t), 1, stdout);
  }
  for (;;) {
    size = fread(&temp, 1, sizeof(uint32_t), input);
    if (!size)
      break;
    if (size < 4 && !feof(input)) {
      perror("fread");
      exit(EXIT_FAILURE);
    }
    if (swap)
      temp = htobe32(le32toh(temp));
    if (fwrite(&temp, 1, sizeof(uint32_t), stdout) != 4) {
      perror("fwrite");
      exit(EXIT_FAILURE);
    }
  }
  if (fclose(input) != 0) {
    perror("fclose");
    exit(EXIT_FAILURE);
  }
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x40200000,-0x2c(%rbp)
movl   $0x0,-0x34(%rbp)
movl   $0x0,-0x38(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xdd7(%rip),%rdx
call   10e0 <getopt@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0xffffffff,%eax
je     1287 <main+0x97>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x3c(%rbp)
sub    $0x61,%eax
je     125f <main+0x6f>
jmp    124e <main+0x5e>
mov    -0x3c(%rbp),%eax
sub    $0x73,%eax
je     127b <main+0x8b>
jmp    1282 <main+0x92>
mov    0x2d92(%rip),%rax
mov    (%rax),%edi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   10f0 <strtoul@plt>
mov    %eax,-0x2c(%rbp)
jmp    1282 <main+0x92>
movl   $0x1,-0x38(%rbp)
jmp    121b <main+0x2b>
mov    0x2d4a(%rip),%rax
mov    (%rax),%eax
cmp    -0x8(%rbp),%eax
jl     12af <main+0xbf>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   10a0 <usage@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x2d1e(%rip),%rcx
movslq (%rcx),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xd3c(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    12f6 <main+0x106>
lea    0xd23(%rip),%rdi
call   10d0 <perror@plt>
mov    0x2cc9(%rip),%rax
mov    (%rax),%edi
call   1100 <exit@plt>
mov    -0x18(%rbp),%rdi
mov    0x2cdf(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   10b0 <fseeko@plt>
cmp    $0xffffffff,%eax
jne    132d <main+0x13d>
lea    0xcf2(%rip),%rdi
call   10d0 <perror@plt>
mov    0x2c92(%rip),%rax
mov    (%rax),%edi
call   1100 <exit@plt>
mov    -0x18(%rbp),%rdi
call   1040 <ftello@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0xffffffff,-0x20(%rbp)
jne    135d <main+0x16d>
lea    0xcc9(%rip),%rdi
call   10d0 <perror@plt>
mov    0x2c62(%rip),%rax
mov    (%rax),%edi
call   1100 <exit@plt>
cmpl   $0x100000,-0x20(%rbp)
jle    138d <main+0x19d>
mov    0x2c57(%rip),%rax
mov    (%rax),%edi
lea    0xca0(%rip),%rsi
call   1070 <fprintf@plt>
mov    0x2c32(%rip),%rax
mov    (%rax),%edi
call   1100 <exit@plt>
mov    -0x18(%rbp),%rdi
mov    0x2c28(%rip),%rax
mov    (%rax),%edx
mov    $0x14,%esi
call   10b0 <fseeko@plt>
cmp    $0xffffffff,%eax
jne    13c7 <main+0x1d7>
lea    0xc58(%rip),%rdi
call   10d0 <perror@plt>
mov    0x2bf8(%rip),%rax
mov    (%rax),%edi
call   1100 <exit@plt>
mov    -0x18(%rbp),%rcx
lea    -0x30(%rbp),%rdi
mov    $0x1,%esi
mov    $0x4,%edx
call   1050 <fread@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1407 <main+0x217>
lea    0xc18(%rip),%rdi
call   10d0 <perror@plt>
mov    0x2bb8(%rip),%rax
mov    (%rax),%edi
call   1100 <exit@plt>
mov    -0x30(%rbp),%edi
call   1030 <le32toh@plt>
cmp    $0x45534843,%eax
jne    1421 <main+0x231>
movl   $0x1,-0x34(%rbp)
mov    -0x18(%rbp),%rdi
mov    0x2b94(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   10b0 <fseeko@plt>
cmp    $0xffffffff,%eax
jne    1458 <main+0x268>
lea    0xbc7(%rip),%rdi
call   10d0 <perror@plt>
mov    0x2b67(%rip),%rax
mov    (%rax),%edi
call   1100 <exit@plt>
mov    -0x20(%rbp),%eax
add    $0x3,%eax
and    $0xfffffffc,%eax
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x34(%rbp)
jne    14dc <main+0x2ec>
mov    -0x20(%rbp),%eax
mov    %eax,-0x30(%rbp)
cmpl   $0x0,-0x38(%rbp)
je     1489 <main+0x299>
mov    -0x30(%rbp),%edi
call   1090 <htobe32@plt>
mov    %eax,-0x30(%rbp)
mov    0x2b20(%rip),%rax
mov    (%rax),%ecx
lea    -0x30(%rbp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
call   1110 <fwrite@plt>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x30(%rbp)
cmpl   $0x0,-0x38(%rbp)
je     14c0 <main+0x2d0>
mov    -0x30(%rbp),%edi
call   1090 <htobe32@plt>
mov    %eax,-0x30(%rbp)
mov    0x2ae9(%rip),%rax
mov    (%rax),%ecx
lea    -0x30(%rbp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
call   1110 <fwrite@plt>
jmp    14e1 <main+0x2f1>
mov    -0x18(%rbp),%rcx
lea    -0x30(%rbp),%rdi
mov    $0x1,%esi
mov    $0x4,%edx
call   1050 <fread@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    150c <main+0x31c>
jmp    15a3 <main+0x3b3>
cmpq   $0x4,-0x28(%rbp)
jae    1543 <main+0x353>
mov    -0x18(%rbp),%rdi
call   1080 <feof@plt>
cmp    $0x0,%eax
jne    1543 <main+0x353>
lea    0xb15(%rip),%rdi
call   10d0 <perror@plt>
mov    0x2a7c(%rip),%rax
mov    (%rax),%edi
call   1100 <exit@plt>
cmpl   $0x0,-0x38(%rbp)
je     155f <main+0x36f>
mov    -0x30(%rbp),%edi
call   1030 <le32toh@plt>
mov    %eax,%edi
call   1090 <htobe32@plt>
mov    %eax,-0x30(%rbp)
mov    0x2a4a(%rip),%rax
mov    (%rax),%ecx
lea    -0x30(%rbp),%rdi
mov    $0x1,%esi
mov    $0x4,%edx
call   1110 <fwrite@plt>
cmp    $0x4,%eax
je     159e <main+0x3ae>
lea    0xac0(%rip),%rdi
call   10d0 <perror@plt>
mov    0x2a21(%rip),%rax
mov    (%rax),%edi
call   1100 <exit@plt>
jmp    14e1 <main+0x2f1>
mov    -0x18(%rbp),%rdi
call   1060 <fclose@plt>
cmp    $0x0,%rax
je     15d0 <main+0x3e0>
lea    0xa95(%rip),%rdi
call   10d0 <perror@plt>
mov    0x29ef(%rip),%rax
mov    (%rax),%edi
call   1100 <exit@plt>
mov    0x29d1(%rip),%rax
mov    (%rax),%edi
call   1100 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%ebp
xor    %r12d,%r12d
mov    $0x40200000,%r15d
lea    0xdf0(%rip),%r14
mov    0x2de1(%rip),%r13
jmp    1220 <main+0x30>
mov    $0x1,%r12d
nop
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r14,%rdx
call   10e0 <getopt@plt>
cmp    $0x61,%eax
je     123e <main+0x4e>
cmp    $0x73,%eax
je     1219 <main+0x29>
cmp    $0xffffffff,%eax
jne    1220 <main+0x30>
jmp    1250 <main+0x60>
mov    0x0(%r13),%edi
xor    %esi,%esi
xor    %edx,%edx
call   10f0 <strtoul@plt>
mov    %eax,%r15d
jmp    1220 <main+0x30>
mov    0x2d81(%rip),%rax
movslq (%rax),%rax
cmp    %ebp,%eax
jge    127c <main+0x8c>
mov    (%rbx,%rax,8),%rdi
lea    0xd9b(%rip),%rsi
call   10c0 <fopen@plt>
test   %rax,%rax
jne    128e <main+0x9e>
lea    0xd8c(%rip),%rdi
jmp    12c6 <main+0xd6>
mov    (%rbx),%rdi
call   10a0 <usage@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
mov    %rax,%rbx
mov    0x2d48(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   10b0 <fseeko@plt>
cmp    $0xffffffff,%eax
jne    12b2 <main+0xc2>
lea    0xd5c(%rip),%rdi
jmp    12c6 <main+0xd6>
mov    %rbx,%rdi
call   1040 <ftello@plt>
cmp    $0xffffffff,%eax
jne    12d9 <main+0xe9>
lea    0xd4d(%rip),%rdi
call   10d0 <perror@plt>
mov    0x2ce6(%rip),%rax
mov    (%rax),%edi
call   1100 <exit@plt>
mov    %eax,%r14d
cmp    $0x100001,%eax
jl     12fa <main+0x10a>
mov    0x2cde(%rip),%rax
mov    (%rax),%edi
lea    0xd27(%rip),%rsi
call   1070 <fprintf@plt>
jmp    12cb <main+0xdb>
mov    0x2cbf(%rip),%rbp
mov    0x0(%rbp),%edx
mov    %rbx,%rdi
mov    $0x14,%esi
call   10b0 <fseeko@plt>
cmp    $0xffffffff,%eax
je     12a9 <main+0xb9>
lea    0x4(%rsp),%rdi
mov    $0x1,%esi
mov    $0x4,%edx
mov    %rbx,%rcx
call   1050 <fread@plt>
test   %rax,%rax
je     12a9 <main+0xb9>
mov    0x4(%rsp),%edi
call   1030 <le32toh@plt>
mov    %eax,%r13d
mov    0x0(%rbp),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   10b0 <fseeko@plt>
cmp    $0xffffffff,%eax
je     12a9 <main+0xb9>
cmp    $0x45534843,%r13d
je     13f1 <main+0x201>
add    $0x3,%r14d
and    $0xfffffffc,%r14d
mov    %r14d,0x4(%rsp)
test   %r12d,%r12d
jne    1396 <main+0x1a6>
mov    0x2c32(%rip),%rax
mov    (%rax),%ecx
lea    0x4(%rsp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
call   1110 <fwrite@plt>
jmp    13cf <main+0x1df>
mov    %r14d,%edi
call   1090 <htobe32@plt>
mov    %eax,0x4(%rsp)
mov    0x2c07(%rip),%rax
mov    (%rax),%ecx
lea    0x4(%rsp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
call   1110 <fwrite@plt>
mov    %r15d,0x4(%rsp)
mov    %r15d,%edi
call   1090 <htobe32@plt>
mov    %eax,%r15d
mov    %r15d,0x4(%rsp)
mov    0x2bd5(%rip),%rax
mov    (%rax),%ecx
lea    0x4(%rsp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
call   1110 <fwrite@plt>
lea    0x4(%rsp),%rbp
mov    0x2bb3(%rip),%r14
jmp    141a <main+0x22a>
nop
mov    (%r14),%ecx
mov    %rbp,%rdi
mov    $0x1,%esi
mov    $0x4,%edx
call   1110 <fwrite@plt>
cmp    $0x4,%eax
jne    147c <main+0x28c>
mov    %rbp,%rdi
mov    $0x1,%esi
mov    $0x4,%edx
mov    %rbx,%rcx
call   1050 <fread@plt>
test   %rax,%rax
je     1461 <main+0x271>
cmp    $0x3,%rax
ja     1446 <main+0x256>
mov    %rbx,%rdi
call   1080 <feof@plt>
test   %eax,%eax
je     1494 <main+0x2a4>
test   %r12d,%r12d
je     1400 <main+0x210>
mov    0x4(%rsp),%edi
call   1030 <le32toh@plt>
mov    %eax,%edi
call   1090 <htobe32@plt>
mov    %eax,0x4(%rsp)
jmp    1400 <main+0x210>
mov    %rbx,%rdi
call   1060 <fclose@plt>
test   %rax,%rax
jne    1488 <main+0x298>
mov    0x2b33(%rip),%rax
mov    (%rax),%edi
call   1100 <exit@plt>
lea    0xbc8(%rip),%rdi
jmp    12c6 <main+0xd6>
lea    0xbc3(%rip),%rdi
jmp    12c6 <main+0xd6>
lea    0xbaa(%rip),%rdi
jmp    12c6 <main+0xd6>

LLVM IR (-O0):
@.str = [4 x i8] c"a:s\00"
@optarg = global i32 0
@optind = global i32 0
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [6 x i8] c"fopen\00"
@EXIT_FAILURE = global i32 0
@SEEK_END = global i32 0
@.str.3 = [7 x i8] c"fseeko\00"
@.str.4 = [7 x i8] c"ftello\00"
@stderr = global i32 0
@.str.5 = [43 x i8] c"error: image should be smaller than 1 MiB\0A\00"
@SEEK_SET = global i32 0
@stdout = global i32 0
@.str.6 = [6 x i8] c"fread\00"
@.str.7 = [7 x i8] c"fwrite\00"
@.str.8 = [7 x i8] c"fclose\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i64
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 1075838976, i32* %10
store i32 0, i32* %12
store i32 0, i32* %13
br label %14
14: ; preds = %25, %2
%15 = load i32, i32* %4
%16 = load i8**, i8*** %5
%17 = call i32 @getopt(i32 %15, i8** %16, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
store i32 %17, i32* %7
%18 = icmp ne i32 %17, -1
br i1 %18, label %19, label %26
19: ; preds = %14
%20 = load i32, i32* %7
switch i32 %20, label %25 [
i32 97, label %21
i32 115, label %24
]
21: ; preds = %19
%22 = load i32, i32* @optarg
%23 = call i32 @strtoul(i32 %22, i32* null, i32 0)
store i32 %23, i32* %10
br label %25
24: ; preds = %19
store i32 1, i32* %13
br label %25
25: ; preds = %19, %24, %21
br label %14
26: ; preds = %14
%27 = load i32, i32* @optind
%28 = load i32, i32* %4
%29 = icmp sge i32 %27, %28
br i1 %29, label %30, label %36
30: ; preds = %26
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i64 0
%33 = load i8*, i8** %32
%34 = call i32 @usage(i8* %33)
%35 = call i32 @exit(i32 1)
unreachable
36: ; preds = %26
%37 = load i8**, i8*** %5
%38 = load i32, i32* @optind
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i8*, i8** %37, i64 %39
%41 = load i8*, i8** %40
%42 = call i32* @fopen(i8* %41, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %42, i32** %6
%43 = load i32*, i32** %6
%44 = icmp eq i32* %43, null
br i1 %44, label %45, label %49
45: ; preds = %36
%46 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%47 = load i32, i32* @EXIT_FAILURE
%48 = call i32 @exit(i32 %47)
unreachable
49: ; preds = %36
%50 = load i32*, i32** %6
%51 = load i32, i32* @SEEK_END
%52 = call i32 @fseeko(i32* %50, i32 0, i32 %51)
%53 = icmp eq i32 %52, -1
br i1 %53, label %54, label %58
54: ; preds = %49
%55 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%56 = load i32, i32* @EXIT_FAILURE
%57 = call i32 @exit(i32 %56)
unreachable
58: ; preds = %49
%59 = load i32*, i32** %6
%60 = call i32 @ftello(i32* %59)
store i32 %60, i32* %8
%61 = load i32, i32* %8
%62 = icmp eq i32 %61, -1
br i1 %62, label %63, label %67
63: ; preds = %58
%64 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
%65 = load i32, i32* @EXIT_FAILURE
%66 = call i32 @exit(i32 %65)
unreachable
67: ; preds = %58
%68 = load i32, i32* %8
%69 = icmp sgt i32 %68, 1048576
br i1 %69, label %70, label %75
70: ; preds = %67
%71 = load i32, i32* @stderr
%72 = call i32 @fprintf(i32 %71, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.5, i64 0, i64 0))
%73 = load i32, i32* @EXIT_FAILURE
%74 = call i32 @exit(i32 %73)
unreachable
75: ; preds = %67
%76 = load i32*, i32** %6
%77 = load i32, i32* @SEEK_SET
%78 = call i32 @fseeko(i32* %76, i32 20, i32 %77)
%79 = icmp eq i32 %78, -1
br i1 %79, label %80, label %84
80: ; preds = %75
%81 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%82 = load i32, i32* @EXIT_FAILURE
%83 = call i32 @exit(i32 %82)
unreachable
84: ; preds = %75
%85 = load i32*, i32** %6
%86 = call i64 @fread(i32* %11, i32 1, i32 4, i32* %85)
store i64 %86, i64* %9
%87 = load i64, i64* %9
%88 = icmp ne i64 %87, 0
br i1 %88, label %93, label %89
89: ; preds = %84
%90 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%91 = load i32, i32* @EXIT_FAILURE
%92 = call i32 @exit(i32 %91)
unreachable
93: ; preds = %84
%94 = load i32, i32* %11
%95 = call i32 @le32toh(i32 %94)
%96 = icmp eq i32 %95, 1163085891
br i1 %96, label %97, label %98
97: ; preds = %93
store i32 1, i32* %12
br label %98
98: ; preds = %97, %93
%99 = load i32*, i32** %6
%100 = load i32, i32* @SEEK_SET
%101 = call i32 @fseeko(i32* %99, i32 0, i32 %100)
%102 = icmp eq i32 %101, -1
br i1 %102, label %103, label %107
103: ; preds = %98
%104 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%105 = load i32, i32* @EXIT_FAILURE
%106 = call i32 @exit(i32 %105)
unreachable
107: ; preds = %98
%108 = load i32, i32* %8
%109 = add nsw i32 %108, 3
%110 = and i32 %109, -4
store i32 %110, i32* %8
%111 = load i32, i32* %12
%112 = icmp ne i32 %111, 0
br i1 %112, label %132, label %113
113: ; preds = %107
%114 = load i32, i32* %8
store i32 %114, i32* %11
%115 = load i32, i32* %13
%116 = icmp ne i32 %115, 0
br i1 %116, label %117, label %120
117: ; preds = %113
%118 = load i32, i32* %11
%119 = call i32 @htobe32(i32 %118)
store i32 %119, i32* %11
br label %120
120: ; preds = %117, %113
%121 = load i32, i32* @stdout
%122 = call i32 @fwrite(i32* %11, i32 4, i32 1, i32 %121)
%123 = load i32, i32* %10
store i32 %123, i32* %11
%124 = load i32, i32* %13
%125 = icmp ne i32 %124, 0
br i1 %125, label %126, label %129
126: ; preds = %120
%127 = load i32, i32* %11
%128 = call i32 @htobe32(i32 %127)
store i32 %128, i32* %11
br label %129
129: ; preds = %126, %120
%130 = load i32, i32* @stdout
%131 = call i32 @fwrite(i32* %11, i32 4, i32 1, i32 %130)
br label %132
132: ; preds = %129, %107
br label %133
133: ; preds = %165, %132
%134 = load i32*, i32** %6
%135 = call i64 @fread(i32* %11, i32 1, i32 4, i32* %134)
store i64 %135, i64* %9
%136 = load i64, i64* %9
%137 = icmp ne i64 %136, 0
br i1 %137, label %139, label %138
138: ; preds = %133
br label %166
139: ; preds = %133
%140 = load i64, i64* %9
%141 = icmp ult i64 %140, 4
br i1 %141, label %142, label %150
142: ; preds = %139
%143 = load i32*, i32** %6
%144 = call i32 @feof(i32* %143)
%145 = icmp ne i32 %144, 0
br i1 %145, label %150, label %146
146: ; preds = %142
%147 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0))
%148 = load i32, i32* @EXIT_FAILURE
%149 = call i32 @exit(i32 %148)
unreachable
150: ; preds = %142, %139
%151 = load i32, i32* %13
%152 = icmp ne i32 %151, 0
br i1 %152, label %153, label %157
153: ; preds = %150
%154 = load i32, i32* %11
%155 = call i32 @le32toh(i32 %154)
%156 = call i32 @htobe32(i32 %155)
store i32 %156, i32* %11
br label %157
157: ; preds = %153, %150
%158 = load i32, i32* @stdout
%159 = call i32 @fwrite(i32* %11, i32 1, i32 4, i32 %158)
%160 = icmp ne i32 %159, 4
br i1 %160, label %161, label %165
161: ; preds = %157
%162 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0))
%163 = load i32, i32* @EXIT_FAILURE
%164 = call i32 @exit(i32 %163)
unreachable
165: ; preds = %157
br label %133
166: ; preds = %138
%167 = load i32*, i32** %6
%168 = call i64 @fclose(i32* %167)
%169 = icmp ne i64 %168, 0
br i1 %169, label %170, label %174
170: ; preds = %166
%171 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.8, i64 0, i64 0))
%172 = load i32, i32* @EXIT_FAILURE
%173 = call i32 @exit(i32 %172)
unreachable
174: ; preds = %166
%175 = load i32, i32* @EXIT_SUCCESS
%176 = call i32 @exit(i32 %175)
unreachable
}

LLVM IR (-O2):
@.str = [4 x i8] c"a:s\00"
@optarg = global i32 0
@optind = global i32 0
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [6 x i8] c"fopen\00"
@EXIT_FAILURE = global i32 0
@SEEK_END = global i32 0
@.str.3 = [7 x i8] c"fseeko\00"
@.str.4 = [7 x i8] c"ftello\00"
@stderr = global i32 0
@.str.5 = [43 x i8] c"error: image should be smaller than 1 MiB\0A\00"
@SEEK_SET = global i32 0
@stdout = global i32 0
@.str.6 = [6 x i8] c"fread\00"
@.str.7 = [7 x i8] c"fwrite\00"
@.str.8 = [7 x i8] c"fclose\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
br label %5
5: ; preds = %12, %2
%6 = phi i32 [ %14, %12 ], [ 1075838976, %2 ]
%7 = phi i32 [ %9, %12 ], [ 0, %2 ]
br label %8
8: ; preds = %10, %5
%9 = phi i32 [ %7, %5 ], [ 1, %10 ]
br label %10
10: ; preds = %8, %10
%11 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
switch i32 %11, label %10 [
i32 -1, label %15
i32 97, label %12
i32 115, label %8
]
12: ; preds = %10
%13 = load i32, i32* @optarg
%14 = tail call i32 @strtoul(i32 %13, i32* null, i32 0)
br label %5
15: ; preds = %10
%16 = load i32, i32* @optind
%17 = icmp slt i32 %16, %0
br i1 %17, label %22, label %18
18: ; preds = %15
%19 = load i8*, i8** %1
%20 = tail call i32 @usage(i8* %19)
%21 = tail call i32 @exit(i32 1)
unreachable
22: ; preds = %15
%23 = sext i32 %16 to i64
%24 = getelementptr inbounds i8*, i8** %1, i64 %23
%25 = load i8*, i8** %24
%26 = tail call i32* @fopen(i8* %25, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%27 = icmp eq i32* %26, null
br i1 %27, label %28, label %32
28: ; preds = %22
%29 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%30 = load i32, i32* @EXIT_FAILURE
%31 = tail call i32 @exit(i32 %30)
unreachable
32: ; preds = %22
%33 = load i32, i32* @SEEK_END
%34 = tail call i32 @fseeko(i32* %26, i32 0, i32 %33)
%35 = icmp eq i32 %34, -1
br i1 %35, label %36, label %40
36: ; preds = %32
%37 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%38 = load i32, i32* @EXIT_FAILURE
%39 = tail call i32 @exit(i32 %38)
unreachable
40: ; preds = %32
%41 = tail call i32 @ftello(i32* %26)
%42 = icmp eq i32 %41, -1
br i1 %42, label %43, label %47
43: ; preds = %40
%44 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
%45 = load i32, i32* @EXIT_FAILURE
%46 = tail call i32 @exit(i32 %45)
unreachable
47: ; preds = %40
%48 = icmp sgt i32 %41, 1048576
br i1 %48, label %49, label %54
49: ; preds = %47
%50 = load i32, i32* @stderr
%51 = tail call i32 @fprintf(i32 %50, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.5, i64 0, i64 0))
%52 = load i32, i32* @EXIT_FAILURE
%53 = tail call i32 @exit(i32 %52)
unreachable
54: ; preds = %47
%55 = load i32, i32* @SEEK_SET
%56 = tail call i32 @fseeko(i32* %26, i32 20, i32 %55)
%57 = icmp eq i32 %56, -1
br i1 %57, label %58, label %62
58: ; preds = %54
%59 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%60 = load i32, i32* @EXIT_FAILURE
%61 = tail call i32 @exit(i32 %60)
unreachable
62: ; preds = %54
%63 = call i64 @fread(i32* %3, i32 1, i32 4, i32* %26)
%64 = icmp eq i64 %63, 0
br i1 %64, label %65, label %69
65: ; preds = %62
%66 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%67 = load i32, i32* @EXIT_FAILURE
%68 = tail call i32 @exit(i32 %67)
unreachable
69: ; preds = %62
%70 = load i32, i32* %3
%71 = tail call i32 @le32toh(i32 %70)
%72 = load i32, i32* @SEEK_SET
%73 = tail call i32 @fseeko(i32* %26, i32 0, i32 %72)
%74 = icmp eq i32 %73, -1
br i1 %74, label %75, label %79
75: ; preds = %69
%76 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%77 = load i32, i32* @EXIT_FAILURE
%78 = tail call i32 @exit(i32 %77)
unreachable
79: ; preds = %69
%80 = icmp eq i32 %71, 1163085891
%81 = add nsw i32 %41, 3
%82 = and i32 %81, -4
br i1 %80, label %97, label %83
83: ; preds = %79
store i32 %82, i32* %3
%84 = icmp eq i32 %9, 0
br i1 %84, label %90, label %85
85: ; preds = %83
%86 = tail call i32 @htobe32(i32 %82)
store i32 %86, i32* %3
%87 = load i32, i32* @stdout
%88 = call i32 @fwrite(i32* %3, i32 4, i32 1, i32 %87)
store i32 %6, i32* %3
%89 = call i32 @htobe32(i32 %6)
br label %93
90: ; preds = %83
%91 = load i32, i32* @stdout
%92 = call i32 @fwrite(i32* %3, i32 4, i32 1, i32 %91)
br label %93
93: ; preds = %90, %85
%94 = phi i32 [ %89, %85 ], [ %6, %90 ]
store i32 %94, i32* %3
%95 = load i32, i32* @stdout
%96 = call i32 @fwrite(i32* %3, i32 4, i32 1, i32 %95)
br label %97
97: ; preds = %93, %79
%98 = icmp eq i32 %9, 0
br label %99
99: ; preds = %116, %97
%100 = call i64 @fread(i32* %3, i32 1, i32 4, i32* %26)
%101 = icmp eq i64 %100, 0
br i1 %101, label %124, label %102
102: ; preds = %99
%103 = icmp ult i64 %100, 4
br i1 %103, label %104, label %111
104: ; preds = %102
%105 = call i32 @feof(i32* %26)
%106 = icmp eq i32 %105, 0
br i1 %106, label %107, label %111
107: ; preds = %104
%108 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0))
%109 = load i32, i32* @EXIT_FAILURE
%110 = call i32 @exit(i32 %109)
unreachable
111: ; preds = %104, %102
br i1 %98, label %116, label %112
112: ; preds = %111
%113 = load i32, i32* %3
%114 = call i32 @le32toh(i32 %113)
%115 = call i32 @htobe32(i32 %114)
store i32 %115, i32* %3
br label %116
116: ; preds = %112, %111
%117 = load i32, i32* @stdout
%118 = call i32 @fwrite(i32* %3, i32 1, i32 4, i32 %117)
%119 = icmp eq i32 %118, 4
br i1 %119, label %99, label %120
120: ; preds = %116
%121 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0))
%122 = load i32, i32* @EXIT_FAILURE
%123 = call i32 @exit(i32 %122)
unreachable
124: ; preds = %99
%125 = call i64 @fclose(i32* %26)
%126 = icmp eq i64 %125, 0
br i1 %126, label %131, label %127
127: ; preds = %124
%128 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.8, i64 0, i64 0))
%129 = load i32, i32* @EXIT_FAILURE
%130 = call i32 @exit(i32 %129)
unreachable
131: ; preds = %124
%132 = load i32, i32* @EXIT_SUCCESS
%133 = call i32 @exit(i32 %132)
unreachable
}