#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 /*<<< orphan*/ MAP_SHARED;
int O_APPEND;
int O_CREAT;
int /*<<< orphan*/ O_RDONLY;
int O_TRUNC;
int O_WRONLY;
int /*<<< orphan*/ PROT_READ;
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ SEEK_SET;
int S_IRGRP;
int S_IROTH;
int S_IRUSR;
int S_IWGRP;
int S_IWOTH;
int S_IWUSR;
int /*<<< orphan*/ close(int);
unsigned int crc32(unsigned char *, unsigned int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
unsigned int lseek(int, int /*<<< orphan*/, int /*<<< orphan*/);
unsigned char *mmap(int /*<<< orphan*/ *, unsigned int, int /*<<< orphan*/,
                    int /*<<< orphan*/, int, int /*<<< orphan*/);
int /*<<< orphan*/ munmap(unsigned char *, unsigned int);
int open(char *, int, ...);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *, unsigned int);
int /*<<< orphan*/ stderr;
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ write(int, ...);
int main(int argc, char *argv[]) {
  int fd, fd_out;
  unsigned char *buffer;
  unsigned int length;
  unsigned int crc;
  if (((argc != 2) && (argc != 3) && (argc != 4)) ||
      ((argc > 2) &&
       (strcmp(argv[2], "write") && (strcmp(argv[2], "writelzma"))))) {
    fprintf(stderr, "Usage: mkmmimg <filename> [write[lzma]] [dest]\n");
    return 1;
  }
  fd = open(argv[1], O_RDONLY);
  if (fd == -1) {
    perror("open");
    return 1;
  }
  length = lseek(fd, 0, SEEK_END);
  lseek(fd, 0, SEEK_SET);
  buffer = mmap(NULL, length, PROT_READ, MAP_SHARED, fd, 0);
  if (!buffer) {
    perror("mmap");
    close(fd);
    return 1;
  }
  crc = crc32(buffer, length);
  printf("CRC32 (%s): %08x\n", argv[1], crc);
  if (argc == 3) {
    char b[4];
    fd_out = open(argv[1], O_WRONLY | O_APPEND);
    if (fd_out == -1) {
      perror("open");
      return 1;
    }
    b[0] = (crc & 0xff000000) >> 24;
    b[1] = (crc & 0x00ff0000) >> 16;
    b[2] = (crc & 0x0000ff00) >> 8;
    b[3] = (crc & 0x000000ff) >> 0;
    write(fd_out, &b[0], 4);
    close(fd_out);
  }
  if (argc == 4) {
    char b[4];
    fd_out = open(argv[3], O_WRONLY | O_CREAT | O_TRUNC,
                  S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);
    if (fd_out == -1) {
      perror("open");
      return 1;
    }
    b[0] = (length & 0xff000000) >> 24;
    b[1] = (length & 0x00ff0000) >> 16;
    b[2] = (length & 0x0000ff00) >> 8;
    b[3] = (length & 0x000000ff) >> 0;
    if (strcmp(argv[2], "writelzma") == 0)
      b[0] |= 0x80;
    write(fd_out, &b[0], 4);
    b[0] = (crc & 0xff000000) >> 24;
    b[1] = (crc & 0x00ff0000) >> 16;
    b[2] = (crc & 0x0000ff00) >> 8;
    b[3] = (crc & 0x000000ff) >> 0;
    write(fd_out, &b[0], 4);
    write(fd_out, buffer, length);
    close(fd_out);
  }
  munmap(buffer, length);
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11e4 <main+0x34>
cmpl   $0x3,-0x8(%rbp)
je     11e4 <main+0x34>
cmpl   $0x4,-0x8(%rbp)
jne    122a <main+0x7a>
cmpl   $0x2,-0x8(%rbp)
jle    124b <main+0x9b>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe03(%rip),%rsi
call   1090 <strcmp@plt>
cmp    $0x0,%rax
je     124b <main+0x9b>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xdeb(%rip),%rsi
call   1090 <strcmp@plt>
cmp    $0x0,%rax
je     124b <main+0x9b>
mov    0x2d6f(%rip),%rax
mov    (%rax),%edi
lea    0xdd6(%rip),%rsi
call   10a0 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1551 <main+0x3a1>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2d66(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   10c0 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    1288 <main+0xd8>
lea    0xdc9(%rip),%rdi
call   10d0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1551 <main+0x3a1>
mov    -0x14(%rbp),%edi
mov    0x2d36(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1070 <lseek@plt>
mov    %eax,-0x24(%rbp)
mov    -0x14(%rbp),%edi
mov    0x2cf0(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1070 <lseek@plt>
mov    -0x24(%rbp),%esi
mov    0x2d2d(%rip),%rax
mov    (%rax),%edx
mov    0x2d14(%rip),%rax
mov    (%rax),%ecx
mov    -0x14(%rbp),%r8d
xor    %eax,%eax
mov    %eax,%edi
xor    %r9d,%r9d
call   1050 <mmap@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1305 <main+0x155>
lea    0xd59(%rip),%rdi
call   10d0 <perror@plt>
mov    -0x14(%rbp),%edi
call   1080 <close@plt>
movl   $0x1,-0x4(%rbp)
jmp    1551 <main+0x3a1>
mov    -0x20(%rbp),%rdi
mov    -0x24(%rbp),%esi
call   1030 <crc32@plt>
mov    %eax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
mov    -0x28(%rbp),%edx
lea    0xd24(%rip),%rdi
call   1060 <printf@plt>
cmpl   $0x3,-0x8(%rbp)
jne    13ce <main+0x21e>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2c2c(%rip),%rax
mov    (%rax),%esi
mov    0x2c1b(%rip),%rax
or     (%rax),%esi
mov    $0x0,%al
call   10c0 <open@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    137b <main+0x1cb>
lea    0xcd6(%rip),%rdi
call   10d0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1551 <main+0x3a1>
mov    -0x28(%rbp),%eax
and    $0xff000000,%eax
shr    $0x18,%eax
mov    %al,-0x2c(%rbp)
mov    -0x28(%rbp),%eax
and    $0xff0000,%eax
shr    $0x10,%eax
mov    %al,-0x2b(%rbp)
mov    -0x28(%rbp),%eax
and    $0xff00,%eax
shr    $0x8,%eax
mov    %al,-0x2a(%rbp)
mov    -0x28(%rbp),%eax
and    $0xff,%eax
shr    $0x0,%eax
mov    %al,-0x29(%rbp)
mov    -0x18(%rbp),%edi
lea    -0x2c(%rbp),%rsi
mov    $0x4,%edx
mov    $0x0,%al
call   1040 <write@plt>
mov    -0x18(%rbp),%edi
call   1080 <close@plt>
cmpl   $0x4,-0x8(%rbp)
jne    1536 <main+0x386>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
mov    0x2b89(%rip),%rax
mov    (%rax),%esi
mov    0x2c08(%rip),%rax
or     (%rax),%esi
mov    0x2bf7(%rip),%rax
or     (%rax),%esi
mov    0x2b7e(%rip),%rax
mov    (%rax),%edx
mov    0x2ba5(%rip),%rax
or     (%rax),%edx
mov    0x2b7c(%rip),%rax
or     (%rax),%edx
mov    0x2b9b(%rip),%rax
or     (%rax),%edx
mov    0x2b62(%rip),%rax
or     (%rax),%edx
mov    0x2b31(%rip),%rax
or     (%rax),%edx
mov    $0x0,%al
call   10c0 <open@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    145d <main+0x2ad>
lea    0xbf4(%rip),%rdi
call   10d0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1551 <main+0x3a1>
mov    -0x24(%rbp),%eax
and    $0xff000000,%eax
shr    $0x18,%eax
mov    %al,-0x30(%rbp)
mov    -0x24(%rbp),%eax
and    $0xff0000,%eax
shr    $0x10,%eax
mov    %al,-0x2f(%rbp)
mov    -0x24(%rbp),%eax
and    $0xff00,%eax
shr    $0x8,%eax
mov    %al,-0x2e(%rbp)
mov    -0x24(%rbp),%eax
and    $0xff,%eax
shr    $0x0,%eax
mov    %al,-0x2d(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xb62(%rip),%rsi
call   1090 <strcmp@plt>
cmp    $0x0,%rax
jne    14bf <main+0x30f>
movsbl -0x30(%rbp),%eax
or     $0x80,%eax
mov    %al,-0x30(%rbp)
mov    -0x18(%rbp),%edi
lea    -0x30(%rbp),%rsi
mov    $0x4,%edx
mov    $0x0,%al
call   1040 <write@plt>
mov    -0x28(%rbp),%eax
and    $0xff000000,%eax
shr    $0x18,%eax
mov    %al,-0x30(%rbp)
mov    -0x28(%rbp),%eax
and    $0xff0000,%eax
shr    $0x10,%eax
mov    %al,-0x2f(%rbp)
mov    -0x28(%rbp),%eax
and    $0xff00,%eax
shr    $0x8,%eax
mov    %al,-0x2e(%rbp)
mov    -0x28(%rbp),%eax
and    $0xff,%eax
shr    $0x0,%eax
mov    %al,-0x2d(%rbp)
mov    -0x18(%rbp),%edi
lea    -0x30(%rbp),%rsi
mov    $0x4,%edx
mov    $0x0,%al
call   1040 <write@plt>
mov    -0x18(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    -0x24(%rbp),%edx
mov    $0x0,%al
call   1040 <write@plt>
mov    -0x18(%rbp),%edi
call   1080 <close@plt>
mov    -0x20(%rbp),%rdi
mov    -0x24(%rbp),%esi
call   10b0 <munmap@plt>
mov    -0x14(%rbp),%edi
call   1080 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edi,%ebx
lea    -0x2(%rbx),%eax
cmp    $0x2,%eax
ja     11f7 <main+0x47>
mov    %rsi,%rbp
cmp    $0x3,%ebx
jb     1216 <main+0x66>
mov    0x10(%rbp),%rdi
lea    0xe28(%rip),%rsi
call   1090 <strcmp@plt>
test   %rax,%rax
je     1216 <main+0x66>
mov    0x10(%rbp),%rdi
lea    0xe19(%rip),%rsi
call   1090 <strcmp@plt>
test   %rax,%rax
je     1216 <main+0x66>
mov    0x2da2(%rip),%rax
mov    (%rax),%edi
lea    0xe09(%rip),%rsi
call   10a0 <fprintf@plt>
mov    $0x1,%eax
jmp    13e2 <main+0x232>
mov    0x8(%rbp),%rdi
mov    0x2d9f(%rip),%rax
mov    (%rax),%esi
xor    %eax,%eax
call   10c0 <open@plt>
cmp    $0xffffffff,%eax
je     13f1 <main+0x241>
mov    %eax,%r12d
mov    0x2d8b(%rip),%rax
mov    (%rax),%edx
mov    %r12d,%edi
xor    %esi,%esi
call   1070 <lseek@plt>
mov    %eax,%r14d
mov    0x2d45(%rip),%rax
mov    (%rax),%edx
mov    %r12d,%edi
xor    %esi,%esi
call   1070 <lseek@plt>
mov    0x2d82(%rip),%rax
mov    (%rax),%edx
mov    0x2d69(%rip),%rax
mov    (%rax),%ecx
xor    %edi,%edi
mov    %r14d,%esi
mov    %r12d,%r8d
xor    %r9d,%r9d
call   1050 <mmap@plt>
test   %rax,%rax
je     1404 <main+0x254>
mov    %rax,%r15
mov    %rax,%rdi
mov    %r14d,%esi
call   1030 <crc32@plt>
mov    %eax,%r13d
mov    0x8(%rbp),%rsi
lea    0xda4(%rip),%rdi
mov    %eax,%edx
call   1060 <printf@plt>
cmp    $0x4,%ebx
je     12fc <main+0x14c>
cmp    $0x3,%ebx
jne    13cd <main+0x21d>
mov    0x8(%rbp),%rdi
mov    0x2caa(%rip),%rax
mov    0x2c9b(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
xor    %eax,%eax
call   10c0 <open@plt>
cmp    $0xffffffff,%eax
je     13f1 <main+0x241>
mov    %eax,%ebx
bswap  %r13d
mov    %r13d,0x4(%rsp)
lea    0x4(%rsp),%rsi
mov    %eax,%edi
mov    $0x4,%edx
jmp    13bf <main+0x20f>
mov    0x2c6d(%rip),%rax
mov    0x2cee(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2cdb(%rip),%rax
or     (%rax),%esi
mov    0x2c62(%rip),%rax
mov    0x2c8b(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    0x2c60(%rip),%rax
or     (%rax),%edx
mov    0x2c7f(%rip),%rax
or     (%rax),%edx
mov    0x2c46(%rip),%rax
or     (%rax),%edx
mov    0x18(%rbp),%rdi
mov    0x2c11(%rip),%rax
or     (%rax),%edx
xor    %eax,%eax
call   10c0 <open@plt>
cmp    $0xffffffff,%eax
je     13f1 <main+0x241>
mov    %eax,%ebx
mov    %r14d,%eax
bswap  %eax
mov    %eax,(%rsp)
mov    0x10(%rbp),%rdi
lea    0xc90(%rip),%rsi
call   1090 <strcmp@plt>
test   %rax,%rax
jne    138b <main+0x1db>
mov    %r14d,%eax
shr    $0x18,%eax
or     $0x80,%al
mov    %al,(%rsp)
mov    %rsp,%rbp
mov    %ebx,%edi
mov    %rbp,%rsi
mov    $0x4,%edx
xor    %eax,%eax
call   1040 <write@plt>
bswap  %r13d
mov    %r13d,(%rsp)
mov    %ebx,%edi
mov    %rbp,%rsi
mov    $0x4,%edx
xor    %eax,%eax
call   1040 <write@plt>
mov    %ebx,%edi
mov    %r15,%rsi
mov    %r14d,%edx
xor    %eax,%eax
call   1040 <write@plt>
mov    %ebx,%edi
call   1080 <close@plt>
mov    %r15,%rdi
mov    %r14d,%esi
call   10b0 <munmap@plt>
mov    %r12d,%edi
call   1080 <close@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xc48(%rip),%rdi
call   10d0 <perror@plt>
mov    $0x1,%eax
jmp    13e2 <main+0x232>
lea    0xc3a(%rip),%rdi
call   10d0 <perror@plt>
mov    %r12d,%edi
call   1080 <close@plt>
mov    $0x1,%eax
jmp    13e2 <main+0x232>

LLVM IR (-O0):
@.str = [6 x i8] c"write\00"
@.str.1 = [10 x i8] c"writelzma\00"
@stderr = global i32 0
@.str.2 = [48 x i8] c"Usage: mkmmimg <filename> [write[lzma]] [dest]\0A\00"
@O_RDONLY = global i32 0
@.str.3 = [5 x i8] c"open\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@PROT_READ = global i32 0
@MAP_SHARED = global i32 0
@.str.4 = [5 x i8] c"mmap\00"
@.str.5 = [18 x i8] c"CRC32 (%s): %08x\0A\00"
@O_WRONLY = global i32 0
@O_APPEND = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@S_IRGRP = global i32 0
@S_IWGRP = global i32 0
@S_IROTH = global i32 0
@S_IWOTH = 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 i8*
%9 = alloca i32
%10 = alloca i32
%11 = alloca [4 x i8]
%12 = alloca [4 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = load i32, i32* %4
%14 = icmp ne i32 %13, 2
br i1 %14, label %15, label %21
15: ; preds = %2
%16 = load i32, i32* %4
%17 = icmp ne i32 %16, 3
br i1 %17, label %18, label %21
18: ; preds = %15
%19 = load i32, i32* %4
%20 = icmp ne i32 %19, 4
br i1 %20, label %36, label %21
21: ; preds = %18, %15, %2
%22 = load i32, i32* %4
%23 = icmp sgt i32 %22, 2
br i1 %23, label %24, label %39
24: ; preds = %21
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 2
%27 = load i8*, i8** %26
%28 = call i64 @strcmp(i8* %27, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%29 = icmp ne i64 %28, 0
br i1 %29, label %30, label %39
30: ; preds = %24
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i64 2
%33 = load i8*, i8** %32
%34 = call i64 @strcmp(i8* %33, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%35 = icmp ne i64 %34, 0
br i1 %35, label %36, label %39
36: ; preds = %30, %18
%37 = load i32, i32* @stderr
%38 = call i32 @fprintf(i32 %37, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %3
br label %215
39: ; preds = %30, %24, %21
%40 = load i8**, i8*** %5
%41 = getelementptr inbounds i8*, i8** %40, i64 1
%42 = load i8*, i8** %41
%43 = load i32, i32* @O_RDONLY
%44 = call i32 (i8*, i32, ...) @open(i8* %42, i32 %43)
store i32 %44, i32* %6
%45 = load i32, i32* %6
%46 = icmp eq i32 %45, -1
br i1 %46, label %47, label %49
47: ; preds = %39
%48 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
store i32 1, i32* %3
br label %215
49: ; preds = %39
%50 = load i32, i32* %6
%51 = load i32, i32* @SEEK_END
%52 = call i32 @lseek(i32 %50, i32 0, i32 %51)
store i32 %52, i32* %9
%53 = load i32, i32* %6
%54 = load i32, i32* @SEEK_SET
%55 = call i32 @lseek(i32 %53, i32 0, i32 %54)
%56 = load i32, i32* %9
%57 = load i32, i32* @PROT_READ
%58 = load i32, i32* @MAP_SHARED
%59 = load i32, i32* %6
%60 = call i8* @mmap(i32* null, i32 %56, i32 %57, i32 %58, i32 %59, i32 0)
store i8* %60, i8** %8
%61 = load i8*, i8** %8
%62 = icmp ne i8* %61, null
br i1 %62, label %67, label %63
63: ; preds = %49
%64 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%65 = load i32, i32* %6
%66 = call i32 @close(i32 %65)
store i32 1, i32* %3
br label %215
67: ; preds = %49
%68 = load i8*, i8** %8
%69 = load i32, i32* %9
%70 = call i32 @crc32(i8* %68, i32 %69)
store i32 %70, i32* %10
%71 = load i8**, i8*** %5
%72 = getelementptr inbounds i8*, i8** %71, i64 1
%73 = load i8*, i8** %72
%74 = load i32, i32* %10
%75 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0), i8* %73, i32 %74)
%76 = load i32, i32* %4
%77 = icmp eq i32 %76, 3
br i1 %77, label %78, label %116
78: ; preds = %67
%79 = load i8**, i8*** %5
%80 = getelementptr inbounds i8*, i8** %79, i64 1
%81 = load i8*, i8** %80
%82 = load i32, i32* @O_WRONLY
%83 = load i32, i32* @O_APPEND
%84 = or i32 %82, %83
%85 = call i32 (i8*, i32, ...) @open(i8* %81, i32 %84)
store i32 %85, i32* %7
%86 = load i32, i32* %7
%87 = icmp eq i32 %86, -1
br i1 %87, label %88, label %90
88: ; preds = %78
%89 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
store i32 1, i32* %3
br label %215
90: ; preds = %78
%91 = load i32, i32* %10
%92 = and i32 %91, -16777216
%93 = lshr i32 %92, 24
%94 = trunc i32 %93 to i8
%95 = getelementptr inbounds [4 x i8], [4 x i8]* %11, i64 0, i64 0
store i8 %94, i8* %95
%96 = load i32, i32* %10
%97 = and i32 %96, 16711680
%98 = lshr i32 %97, 16
%99 = trunc i32 %98 to i8
%100 = getelementptr inbounds [4 x i8], [4 x i8]* %11, i64 0, i64 1
store i8 %99, i8* %100
%101 = load i32, i32* %10
%102 = and i32 %101, 65280
%103 = lshr i32 %102, 8
%104 = trunc i32 %103 to i8
%105 = getelementptr inbounds [4 x i8], [4 x i8]* %11, i64 0, i64 2
store i8 %104, i8* %105
%106 = load i32, i32* %10
%107 = and i32 %106, 255
%108 = lshr i32 %107, 0
%109 = trunc i32 %108 to i8
%110 = getelementptr inbounds [4 x i8], [4 x i8]* %11, i64 0, i64 3
store i8 %109, i8* %110
%111 = load i32, i32* %7
%112 = getelementptr inbounds [4 x i8], [4 x i8]* %11, i64 0, i64 0
%113 = call i32 (i32, ...) @write(i32 %111, i8* %112, i32 4)
%114 = load i32, i32* %7
%115 = call i32 @close(i32 %114)
br label %116
116: ; preds = %90, %67
%117 = load i32, i32* %4
%118 = icmp eq i32 %117, 4
br i1 %118, label %119, label %209
119: ; preds = %116
%120 = load i8**, i8*** %5
%121 = getelementptr inbounds i8*, i8** %120, i64 3
%122 = load i8*, i8** %121
%123 = load i32, i32* @O_WRONLY
%124 = load i32, i32* @O_CREAT
%125 = or i32 %123, %124
%126 = load i32, i32* @O_TRUNC
%127 = or i32 %125, %126
%128 = load i32, i32* @S_IRUSR
%129 = load i32, i32* @S_IWUSR
%130 = or i32 %128, %129
%131 = load i32, i32* @S_IRGRP
%132 = or i32 %130, %131
%133 = load i32, i32* @S_IWGRP
%134 = or i32 %132, %133
%135 = load i32, i32* @S_IROTH
%136 = or i32 %134, %135
%137 = load i32, i32* @S_IWOTH
%138 = or i32 %136, %137
%139 = call i32 (i8*, i32, ...) @open(i8* %122, i32 %127, i32 %138)
store i32 %139, i32* %7
%140 = load i32, i32* %7
%141 = icmp eq i32 %140, -1
br i1 %141, label %142, label %144
142: ; preds = %119
%143 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
store i32 1, i32* %3
br label %215
144: ; preds = %119
%145 = load i32, i32* %9
%146 = and i32 %145, -16777216
%147 = lshr i32 %146, 24
%148 = trunc i32 %147 to i8
%149 = getelementptr inbounds [4 x i8], [4 x i8]* %12, i64 0, i64 0
store i8 %148, i8* %149
%150 = load i32, i32* %9
%151 = and i32 %150, 16711680
%152 = lshr i32 %151, 16
%153 = trunc i32 %152 to i8
%154 = getelementptr inbounds [4 x i8], [4 x i8]* %12, i64 0, i64 1
store i8 %153, i8* %154
%155 = load i32, i32* %9
%156 = and i32 %155, 65280
%157 = lshr i32 %156, 8
%158 = trunc i32 %157 to i8
%159 = getelementptr inbounds [4 x i8], [4 x i8]* %12, i64 0, i64 2
store i8 %158, i8* %159
%160 = load i32, i32* %9
%161 = and i32 %160, 255
%162 = lshr i32 %161, 0
%163 = trunc i32 %162 to i8
%164 = getelementptr inbounds [4 x i8], [4 x i8]* %12, i64 0, i64 3
store i8 %163, i8* %164
%165 = load i8**, i8*** %5
%166 = getelementptr inbounds i8*, i8** %165, i64 2
%167 = load i8*, i8** %166
%168 = call i64 @strcmp(i8* %167, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%169 = icmp eq i64 %168, 0
br i1 %169, label %170, label %176
170: ; preds = %144
%171 = getelementptr inbounds [4 x i8], [4 x i8]* %12, i64 0, i64 0
%172 = load i8, i8* %171
%173 = sext i8 %172 to i32
%174 = or i32 %173, 128
%175 = trunc i32 %174 to i8
store i8 %175, i8* %171
br label %176
176: ; preds = %170, %144
%177 = load i32, i32* %7
%178 = getelementptr inbounds [4 x i8], [4 x i8]* %12, i64 0, i64 0
%179 = call i32 (i32, ...) @write(i32 %177, i8* %178, i32 4)
%180 = load i32, i32* %10
%181 = and i32 %180, -16777216
%182 = lshr i32 %181, 24
%183 = trunc i32 %182 to i8
%184 = getelementptr inbounds [4 x i8], [4 x i8]* %12, i64 0, i64 0
store i8 %183, i8* %184
%185 = load i32, i32* %10
%186 = and i32 %185, 16711680
%187 = lshr i32 %186, 16
%188 = trunc i32 %187 to i8
%189 = getelementptr inbounds [4 x i8], [4 x i8]* %12, i64 0, i64 1
store i8 %188, i8* %189
%190 = load i32, i32* %10
%191 = and i32 %190, 65280
%192 = lshr i32 %191, 8
%193 = trunc i32 %192 to i8
%194 = getelementptr inbounds [4 x i8], [4 x i8]* %12, i64 0, i64 2
store i8 %193, i8* %194
%195 = load i32, i32* %10
%196 = and i32 %195, 255
%197 = lshr i32 %196, 0
%198 = trunc i32 %197 to i8
%199 = getelementptr inbounds [4 x i8], [4 x i8]* %12, i64 0, i64 3
store i8 %198, i8* %199
%200 = load i32, i32* %7
%201 = getelementptr inbounds [4 x i8], [4 x i8]* %12, i64 0, i64 0
%202 = call i32 (i32, ...) @write(i32 %200, i8* %201, i32 4)
%203 = load i32, i32* %7
%204 = load i8*, i8** %8
%205 = load i32, i32* %9
%206 = call i32 (i32, ...) @write(i32 %203, i8* %204, i32 %205)
%207 = load i32, i32* %7
%208 = call i32 @close(i32 %207)
br label %209
209: ; preds = %176, %116
%210 = load i8*, i8** %8
%211 = load i32, i32* %9
%212 = call i32 @munmap(i8* %210, i32 %211)
%213 = load i32, i32* %6
%214 = call i32 @close(i32 %213)
store i32 0, i32* %3
br label %215
215: ; preds = %209, %142, %88, %63, %47, %36
%216 = load i32, i32* %3
ret i32 %216
}

LLVM IR (-O2):
@.str = [6 x i8] c"write\00"
@.str.1 = [10 x i8] c"writelzma\00"
@stderr = global i32 0
@.str.2 = [48 x i8] c"Usage: mkmmimg <filename> [write[lzma]] [dest]\0A\00"
@O_RDONLY = global i32 0
@.str.3 = [5 x i8] c"open\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@PROT_READ = global i32 0
@MAP_SHARED = global i32 0
@.str.4 = [5 x i8] c"mmap\00"
@.str.5 = [18 x i8] c"CRC32 (%s): %08x\0A\00"
@O_WRONLY = global i32 0
@O_APPEND = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@S_IRGRP = global i32 0
@S_IWGRP = global i32 0
@S_IROTH = global i32 0
@S_IWOTH = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [4 x i8]
%4 = alloca [4 x i8]
%5 = add i32 %0, -2
%6 = icmp ult i32 %5, 3
br i1 %6, label %7, label %18
7: ; preds = %2
%8 = icmp ugt i32 %0, 2
br i1 %8, label %9, label %21
9: ; preds = %7
%10 = getelementptr inbounds i8*, i8** %1, i64 2
%11 = load i8*, i8** %10
%12 = tail call i64 @strcmp(i8* %11, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%13 = icmp eq i64 %12, 0
br i1 %13, label %21, label %14
14: ; preds = %9
%15 = load i8*, i8** %10
%16 = tail call i64 @strcmp(i8* %15, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%17 = icmp eq i64 %16, 0
br i1 %17, label %21, label %18
18: ; preds = %2, %14
%19 = load i32, i32* @stderr
%20 = tail call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.2, i64 0, i64 0))
br label %124
21: ; preds = %14, %9, %7
%22 = getelementptr inbounds i8*, i8** %1, i64 1
%23 = load i8*, i8** %22
%24 = load i32, i32* @O_RDONLY
%25 = tail call i32 (i8*, i32, ...) @open(i8* %23, i32 %24)
%26 = icmp eq i32 %25, -1
br i1 %26, label %27, label %29
27: ; preds = %21
%28 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
br label %124
29: ; preds = %21
%30 = load i32, i32* @SEEK_END
%31 = tail call i32 @lseek(i32 %25, i32 0, i32 %30)
%32 = load i32, i32* @SEEK_SET
%33 = tail call i32 @lseek(i32 %25, i32 0, i32 %32)
%34 = load i32, i32* @PROT_READ
%35 = load i32, i32* @MAP_SHARED
%36 = tail call i8* @mmap(i32* null, i32 %31, i32 %34, i32 %35, i32 %25, i32 0)
%37 = icmp eq i8* %36, null
br i1 %37, label %38, label %41
38: ; preds = %29
%39 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%40 = tail call i32 @close(i32 %25)
br label %124
41: ; preds = %29
%42 = tail call i32 @crc32(i8* %36, i32 %31)
%43 = load i8*, i8** %22
%44 = tail call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0), i8* %43, i32 %42)
switch i32 %0, label %121 [
i32 3, label %45
i32 4, label %68
]
45: ; preds = %41
%46 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 0
%47 = load i8*, i8** %22
%48 = load i32, i32* @O_WRONLY
%49 = load i32, i32* @O_APPEND
%50 = or i32 %49, %48
%51 = tail call i32 (i8*, i32, ...) @open(i8* %47, i32 %50)
%52 = icmp eq i32 %51, -1
br i1 %52, label %53, label %55
53: ; preds = %45
%54 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
br label %124
55: ; preds = %45
%56 = lshr i32 %42, 24
%57 = trunc i32 %56 to i8
store i8 %57, i8* %46
%58 = lshr i32 %42, 16
%59 = trunc i32 %58 to i8
%60 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 1
store i8 %59, i8* %60
%61 = lshr i32 %42, 8
%62 = trunc i32 %61 to i8
%63 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 2
store i8 %62, i8* %63
%64 = trunc i32 %42 to i8
%65 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 3
store i8 %64, i8* %65
%66 = call i32 (i32, ...) @write(i32 %51, i8* %46, i32 4)
%67 = call i32 @close(i32 %51)
br label %121
68: ; preds = %41
%69 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 0
%70 = getelementptr inbounds i8*, i8** %1, i64 3
%71 = load i8*, i8** %70
%72 = load i32, i32* @O_WRONLY
%73 = load i32, i32* @O_CREAT
%74 = or i32 %73, %72
%75 = load i32, i32* @O_TRUNC
%76 = or i32 %74, %75
%77 = load i32, i32* @S_IRUSR
%78 = load i32, i32* @S_IWUSR
%79 = or i32 %78, %77
%80 = load i32, i32* @S_IRGRP
%81 = or i32 %79, %80
%82 = load i32, i32* @S_IWGRP
%83 = or i32 %81, %82
%84 = load i32, i32* @S_IROTH
%85 = or i32 %83, %84
%86 = load i32, i32* @S_IWOTH
%87 = or i32 %85, %86
%88 = tail call i32 (i8*, i32, ...) @open(i8* %71, i32 %76, i32 %87)
%89 = icmp eq i32 %88, -1
br i1 %89, label %90, label %92
90: ; preds = %68
%91 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
br label %124
92: ; preds = %68
%93 = lshr i32 %31, 24
%94 = trunc i32 %93 to i8
store i8 %94, i8* %69
%95 = lshr i32 %31, 16
%96 = trunc i32 %95 to i8
%97 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 1
store i8 %96, i8* %97
%98 = lshr i32 %31, 8
%99 = trunc i32 %98 to i8
%100 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 2
store i8 %99, i8* %100
%101 = trunc i32 %31 to i8
%102 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 3
store i8 %101, i8* %102
%103 = getelementptr inbounds i8*, i8** %1, i64 2
%104 = load i8*, i8** %103
%105 = tail call i64 @strcmp(i8* %104, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%106 = icmp eq i64 %105, 0
br i1 %106, label %107, label %109
107: ; preds = %92
%108 = or i8 %94, -128
store i8 %108, i8* %69
br label %109
109: ; preds = %92, %107
%110 = call i32 (i32, ...) @write(i32 %88, i8* %69, i32 4)
%111 = lshr i32 %42, 24
%112 = trunc i32 %111 to i8
store i8 %112, i8* %69
%113 = lshr i32 %42, 16
%114 = trunc i32 %113 to i8
store i8 %114, i8* %97
%115 = lshr i32 %42, 8
%116 = trunc i32 %115 to i8
store i8 %116, i8* %100
%117 = trunc i32 %42 to i8
store i8 %117, i8* %102
%118 = call i32 (i32, ...) @write(i32 %88, i8* %69, i32 4)
%119 = call i32 (i32, ...) @write(i32 %88, i8* %36, i32 %31)
%120 = call i32 @close(i32 %88)
br label %121
121: ; preds = %41, %109, %55
%122 = call i32 @munmap(i8* %36, i32 %31)
%123 = call i32 @close(i32 %25)
br label %124
124: ; preds = %90, %53, %121, %38, %27, %18
%125 = phi i32 [ 1, %18 ], [ 1, %27 ], [ 0, %121 ], [ 1, %38 ], [ 1, %53 ], [ 1, %90 ]
ret i32 %125
}