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

/* Variables and functions */
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
unsigned int fread(unsigned char *, int, unsigned int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, long, int /*<<< orphan*/);
int ftell(int /*<<< orphan*/ *);
int fwrite(unsigned char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ memset(unsigned char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char *argv[]) {
  FILE *fp;
  unsigned char buffer[(8 * 1024)];
  unsigned char header[(16)];
  unsigned int checksum, count;
  int i, len;
  if (argc != 2) {
    printf("Usage: mk4412 <file>\n");
    return -1;
  }
  fp = fopen(argv[1], "r+b");
  if (fp == NULL) {
    printf("Can not open file '%s'\n", argv[1]);
    return -1;
  }
  fseek(fp, 0L, SEEK_END);
  len = ftell(fp);
  count = (len < (8 * 1024)) ? len : (8 * 1024);
  fseek(fp, 0L, SEEK_SET);
  memset(buffer, 0, sizeof(buffer));
  if (fread(buffer, 1, count, fp) != count) {
    printf("Can't read %s\n", argv[1]);
    fclose(fp);
    return -1;
  }
  for (i = 16, checksum = 0; i < count; i++) {
    checksum += buffer[i] & 0xff;
  }
  memset(header, 0, sizeof(header));
  header[3] = (0x1f >> 24) & 0xff;
  header[2] = (0x1f >> 16) & 0xff;
  header[1] = (0x1f >> 8) & 0xff;
  header[0] = (0x1f >> 0) & 0xff;
  header[7] = (checksum >> 24) & 0xff;
  header[6] = (checksum >> 16) & 0xff;
  header[5] = (checksum >> 8) & 0xff;
  header[4] = (checksum >> 0) & 0xff;
  header[0] ^= 0xbc;
  header[1] ^= 0xca;
  header[2] ^= 0xba;
  header[3] ^= 0xcb;
  header[4] ^= 0xcb;
  header[5] ^= 0xce;
  header[6] ^= 0xcd;
  header[7] ^= 0xdf;
  header[8] ^= 0xb7;
  header[9] ^= 0xba;
  header[10] ^= 0xbe;
  header[11] ^= 0xbb;
  header[12] ^= 0xba;
  header[13] ^= 0xad;
  header[14] ^= 0xdf;
  header[15] ^= 0xdf;
  for (i = 1; i < (16); i++) {
    header[i] ^= header[i - 1];
  }
  fseek(fp, 0L, SEEK_SET);
  if (fwrite(header, 1, sizeof(header), fp) != sizeof(header)) {
    printf("Write header error %s\n", argv[1]);
    fclose(fp);
    return -1;
  }
  fclose(fp);
  printf("The checksum is 0x%08x for %ld bytes [0x%08x ~ 0x%08x]\n", checksum,
         (count - sizeof(header)), sizeof(header), (count - 1));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2050,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11bd <main+0x3d>
lea    0xe56(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    15d5 <main+0x455>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe4a(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1202 <main+0x82>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe2b(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    15d5 <main+0x455>
mov    -0x18(%rbp),%rdi
mov    0x2ddb(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
call   1080 <fseek@plt>
mov    -0x18(%rbp),%rdi
call   1070 <ftell@plt>
mov    %eax,-0x2040(%rbp)
cmpl   $0x2000,-0x2040(%rbp)
jge    1248 <main+0xc8>
mov    -0x2040(%rbp),%eax
mov    %eax,-0x2044(%rbp)
jmp    1258 <main+0xd8>
mov    $0x2000,%eax
mov    %eax,-0x2044(%rbp)
jmp    1258 <main+0xd8>
mov    -0x2044(%rbp),%eax
mov    %eax,-0x2038(%rbp)
mov    -0x18(%rbp),%rdi
mov    0x2d69(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
call   1080 <fseek@plt>
lea    -0x2020(%rbp),%rdi
xor    %esi,%esi
mov    $0x2000,%edx
call   1060 <memset@plt>
lea    -0x2020(%rbp),%rdi
mov    -0x2038(%rbp),%edx
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
call   1030 <fread@plt>
cmp    -0x2038(%rbp),%eax
je     12df <main+0x15f>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xd6f(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    15d5 <main+0x455>
movl   $0x10,-0x203c(%rbp)
movl   $0x0,-0x2034(%rbp)
mov    -0x203c(%rbp),%eax
cmp    -0x2038(%rbp),%eax
jae    1339 <main+0x1b9>
movslq -0x203c(%rbp),%rax
movzbl -0x2020(%rbp,%rax,1),%eax
ff
and    $0xff,%eax
add    -0x2034(%rbp),%eax
mov    %eax,-0x2034(%rbp)
mov    -0x203c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x203c(%rbp)
jmp    12f3 <main+0x173>
lea    -0x2030(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1060 <memset@plt>
movb   $0x0,-0x202d(%rbp)
movb   $0x0,-0x202e(%rbp)
movb   $0x0,-0x202f(%rbp)
movb   $0x1f,-0x2030(%rbp)
mov    -0x2034(%rbp),%eax
shr    $0x18,%eax
and    $0xff,%eax
mov    %al,-0x2029(%rbp)
mov    -0x2034(%rbp),%eax
shr    $0x10,%eax
and    $0xff,%eax
mov    %al,-0x202a(%rbp)
mov    -0x2034(%rbp),%eax
shr    $0x8,%eax
and    $0xff,%eax
mov    %al,-0x202b(%rbp)
mov    -0x2034(%rbp),%eax
shr    $0x0,%eax
and    $0xff,%eax
mov    %al,-0x202c(%rbp)
movzbl -0x2030(%rbp),%eax
xor    $0xbc,%eax
mov    %al,-0x2030(%rbp)
movzbl -0x202f(%rbp),%eax
xor    $0xca,%eax
mov    %al,-0x202f(%rbp)
movzbl -0x202e(%rbp),%eax
xor    $0xba,%eax
mov    %al,-0x202e(%rbp)
movzbl -0x202d(%rbp),%eax
xor    $0xcb,%eax
mov    %al,-0x202d(%rbp)
movzbl -0x202c(%rbp),%eax
xor    $0xcb,%eax
mov    %al,-0x202c(%rbp)
movzbl -0x202b(%rbp),%eax
xor    $0xce,%eax
mov    %al,-0x202b(%rbp)
movzbl -0x202a(%rbp),%eax
xor    $0xcd,%eax
mov    %al,-0x202a(%rbp)
movzbl -0x2029(%rbp),%eax
xor    $0xdf,%eax
mov    %al,-0x2029(%rbp)
movzbl -0x2028(%rbp),%eax
xor    $0xb7,%eax
mov    %al,-0x2028(%rbp)
movzbl -0x2027(%rbp),%eax
xor    $0xba,%eax
mov    %al,-0x2027(%rbp)
movzbl -0x2026(%rbp),%eax
xor    $0xbe,%eax
mov    %al,-0x2026(%rbp)
movzbl -0x2025(%rbp),%eax
xor    $0xbb,%eax
mov    %al,-0x2025(%rbp)
movzbl -0x2024(%rbp),%eax
xor    $0xba,%eax
mov    %al,-0x2024(%rbp)
movzbl -0x2023(%rbp),%eax
xor    $0xad,%eax
mov    %al,-0x2023(%rbp)
movzbl -0x2022(%rbp),%eax
xor    $0xdf,%eax
mov    %al,-0x2022(%rbp)
movzbl -0x2021(%rbp),%eax
xor    $0xdf,%eax
mov    %al,-0x2021(%rbp)
movl   $0x1,-0x203c(%rbp)
cmpl   $0x10,-0x203c(%rbp)
jge    152e <main+0x3ae>
mov    -0x203c(%rbp),%eax
sub    $0x1,%eax
cltq
movzbl -0x2030(%rbp,%rax,1),%edx
ff
movslq -0x203c(%rbp),%rax
movzbl -0x2030(%rbp,%rax,1),%ecx
ff
xor    %edx,%ecx
mov    %cl,-0x2030(%rbp,%rax,1)
mov    -0x203c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x203c(%rbp)
jmp    14e2 <main+0x362>
mov    -0x18(%rbp),%rdi
mov    0x2a9f(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
call   1080 <fseek@plt>
lea    -0x2030(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
mov    $0x10,%edx
call   10a0 <fwrite@plt>
cltq
cmp    $0x10,%rax
je     1595 <main+0x415>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xac8(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    15d5 <main+0x455>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x2034(%rbp),%esi
mov    -0x2038(%rbp),%eax
mov    %eax,%edx
sub    $0x10,%rdx
mov    -0x2038(%rbp),%r8d
sub    $0x1,%r8d
lea    0xa96(%rip),%rdi
mov    $0x10,%ecx
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x2050,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x2018,%rsp
cmp    $0x2,%edi
jne    1259 <main+0xc9>
mov    %rsi,%r14
mov    0x8(%rsi),%rdi
lea    0xe48(%rip),%rsi
call   10a0 <fopen@plt>
test   %rax,%rax
je     126a <main+0xda>
mov    %rax,%r12
mov    0x2e18(%rip),%rax
mov    (%rax),%edx
xor    %ebp,%ebp
mov    %r12,%rdi
xor    %esi,%esi
call   1090 <fseek@plt>
mov    %r12,%rdi
call   1080 <ftell@plt>
mov    %eax,%r15d
cmp    $0x2000,%eax
mov    $0x2000,%eax
cmovge %eax,%r15d
mov    0x2dda(%rip),%rax
mov    (%rax),%edx
mov    %r12,%rdi
xor    %esi,%esi
call   1090 <fseek@plt>
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x2000,%edx
call   1070 <memset@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %r15d,%edx
mov    %r12,%rcx
call   1040 <fread@plt>
cmp    %r15d,%eax
jne    1281 <main+0xf1>
cmp    $0x11,%r15d
jb     13a0 <main+0x210>
mov    %r15d,%eax
lea    -0x10(%rax),%rdx
cmp    $0x8,%rdx
jae    1291 <main+0x101>
xor    %ebp,%ebp
mov    $0x10,%ecx
jmp    1390 <main+0x200>
lea    0xe1a(%rip),%rdi
call   1030 <puts@plt>
jmp    14b5 <main+0x325>
mov    0x8(%r14),%rsi
lea    0xd8f(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
jmp    14b5 <main+0x325>
mov    0x8(%r14),%rsi
lea    0xd90(%rip),%rdi
jmp    14a6 <main+0x316>
mov    %rdx,%rcx
and    $0xfffffffffffffff8,%rcx
lea    -0x8(%rcx),%rsi
mov    %rsi,%rbp
shr    $0x3,%rbp
add    $0x1,%rbp
test   %rsi,%rsi
je     1324 <main+0x194>
mov    %rbp,%rsi
and    $0xfffffffffffffffe,%rsi
pxor   %xmm2,%xmm2
mov    $0x10,%edi
pxor   %xmm0,%xmm0
pxor   %xmm1,%xmm1
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movdqa 0x10(%rsp,%rdi,1),%xmm3
movd   0x14(%rsp,%rdi,1),%xmm4
punpcklbw %xmm2,%xmm3
punpcklwd %xmm2,%xmm3
paddd  %xmm0,%xmm3
punpcklbw %xmm2,%xmm4
punpcklwd %xmm2,%xmm4
paddd  %xmm1,%xmm4
movq   0x18(%rsp,%rdi,1),%xmm0
movd   0x1c(%rsp,%rdi,1),%xmm1
punpcklbw %xmm2,%xmm0
punpcklwd %xmm2,%xmm0
paddd  %xmm3,%xmm0
punpcklbw %xmm2,%xmm1
punpcklwd %xmm2,%xmm1
paddd  %xmm4,%xmm1
add    $0x10,%rdi
add    $0xfffffffffffffffe,%rsi
jne    12d0 <main+0x140>
jmp    1331 <main+0x1a1>
pxor   %xmm0,%xmm0
mov    $0x10,%edi
pxor   %xmm1,%xmm1
test   $0x1,%bpl
je     135f <main+0x1cf>
movq   0x10(%rsp,%rdi,1),%xmm2
movd   0x14(%rsp,%rdi,1),%xmm3
pxor   %xmm4,%xmm4
punpcklbw %xmm4,%xmm2
punpcklwd %xmm4,%xmm2
paddd  %xmm2,%xmm0
punpcklbw %xmm4,%xmm3
punpcklwd %xmm4,%xmm3
paddd  %xmm3,%xmm1
paddd  %xmm1,%xmm0
pshufd $0xee,%xmm0,%xmm1
paddd  %xmm0,%xmm1
pshufd $0x55,%xmm1,%xmm0
paddd  %xmm1,%xmm0
movd   %xmm0,%ebp
cmp    %rcx,%rdx
je     13a0 <main+0x210>
add    $0x10,%rcx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movzbl 0x10(%rsp,%rcx,1),%edx
add    %edx,%ebp
add    $0x1,%rcx
cmp    %rcx,%rax
jne    1390 <main+0x200>
mov    %rsp,%r13
xor    %ebx,%ebx
mov    %r13,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1070 <memset@plt>
mov    %ebp,%ecx
shr    $0x18,%ecx
mov    %ebp,%edx
shr    $0x10,%edx
mov    %ebp,%esi
shr    $0x8,%esi
movb   $0xa3,(%rsp)
movw   $0xd369,0x1(%rsp)
movb   $0x18,0x3(%rsp)
mov    %ebp,%eax
xor    $0xd3,%al
mov    %al,0x4(%rsp)
xor    %sil,%al
xor    $0xce,%al
mov    %al,0x5(%rsp)
xor    %dl,%al
xor    $0xcd,%al
mov    %al,0x6(%rsp)
xor    %cl,%al
xor    $0xdf,%al
mov    %al,0x7(%rsp)
xor    0x8(%rsp),%al
xor    $0xb7,%al
mov    %al,0x8(%rsp)
xor    0x9(%rsp),%al
xor    $0xba,%al
mov    %al,0x9(%rsp)
xor    0xa(%rsp),%al
xor    $0xbe,%al
mov    %al,0xa(%rsp)
xor    0xb(%rsp),%al
xor    $0xbb,%al
mov    %al,0xb(%rsp)
xor    0xc(%rsp),%al
xor    $0xba,%al
mov    %al,0xc(%rsp)
xor    0xd(%rsp),%al
xor    $0xad,%al
mov    %al,0xd(%rsp)
xor    0xe(%rsp),%al
mov    %eax,%ecx
xor    $0xdf,%cl
mov    %cl,0xe(%rsp)
xor    %al,0xf(%rsp)
mov    0x2b90(%rip),%rax
mov    (%rax),%edx
mov    %r12,%rdi
xor    %esi,%esi
call   1090 <fseek@plt>
mov    %r13,%rdi
mov    $0x1,%esi
mov    $0x10,%edx
mov    %r12,%rcx
call   10b0 <fwrite@plt>
cmp    $0x10,%eax
jne    149b <main+0x30b>
mov    %r12,%rdi
call   1050 <fclose@plt>
mov    %r15d,%edx
add    $0xfffffffffffffff0,%rdx
add    $0xffffffff,%r15d
lea    0xbba(%rip),%rdi
mov    $0x10,%ecx
mov    %ebp,%esi
mov    %r15d,%r8d
xor    %eax,%eax
call   1060 <printf@plt>
jmp    14ba <main+0x32a>
mov    0x8(%r14),%rsi
lea    0xb85(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r12,%rdi
call   1050 <fclose@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x2018,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [22 x i8] c"Usage: mk4412 <file>\0A\00"
@.str.1 = [4 x i8] c"r+b\00"
@.str.2 = [24 x i8] c"Can not open file '%s'\0A\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@.str.3 = [15 x i8] c"Can't read %s\0A\00"
@.str.4 = [23 x i8] c"Write header error %s\0A\00"
@.str.5 = [56 x i8] c"The checksum is 0x%08x for %ld bytes [0x%08x ~ 0x%08x]\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca [8192 x i8]
%8 = alloca [16 x i8]
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
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 %17
15: ; preds = %2
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %230
17: ; preds = %2
%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 ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
store i32* %21, i32** %6
%22 = load i32*, i32** %6
%23 = icmp eq i32* %22, null
br i1 %23, label %24, label %29
24: ; preds = %17
%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 ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i8* %27)
store i32 -1, i32* %3
br label %230
29: ; preds = %17
%30 = load i32*, i32** %6
%31 = load i32, i32* @SEEK_END
%32 = call i32 @fseek(i32* %30, i64 0, i32 %31)
%33 = load i32*, i32** %6
%34 = call i32 @ftell(i32* %33)
store i32 %34, i32* %12
%35 = load i32, i32* %12
%36 = icmp slt i32 %35, 8192
br i1 %36, label %37, label %39
37: ; preds = %29
%38 = load i32, i32* %12
br label %40
39: ; preds = %29
br label %40
40: ; preds = %39, %37
%41 = phi i32 [ %38, %37 ], [ 8192, %39 ]
store i32 %41, i32* %10
%42 = load i32*, i32** %6
%43 = load i32, i32* @SEEK_SET
%44 = call i32 @fseek(i32* %42, i64 0, i32 %43)
%45 = getelementptr inbounds [8192 x i8], [8192 x i8]* %7, i64 0, i64 0
%46 = call i32 @memset(i8* %45, i32 0, i32 8192)
%47 = getelementptr inbounds [8192 x i8], [8192 x i8]* %7, i64 0, i64 0
%48 = load i32, i32* %10
%49 = load i32*, i32** %6
%50 = call i32 @fread(i8* %47, i32 1, i32 %48, i32* %49)
%51 = load i32, i32* %10
%52 = icmp ne i32 %50, %51
br i1 %52, label %53, label %60
53: ; preds = %40
%54 = load i8**, i8*** %5
%55 = getelementptr inbounds i8*, i8** %54, i64 1
%56 = load i8*, i8** %55
%57 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i8* %56)
%58 = load i32*, i32** %6
%59 = call i32 @fclose(i32* %58)
store i32 -1, i32* %3
br label %230
60: ; preds = %40
store i32 16, i32* %11
store i32 0, i32* %9
br label %61
61: ; preds = %74, %60
%62 = load i32, i32* %11
%63 = load i32, i32* %10
%64 = icmp ult i32 %62, %63
br i1 %64, label %65, label %77
65: ; preds = %61
%66 = load i32, i32* %11
%67 = sext i32 %66 to i64
%68 = getelementptr inbounds [8192 x i8], [8192 x i8]* %7, i64 0, i64 %67
%69 = load i8, i8* %68
%70 = zext i8 %69 to i32
%71 = and i32 %70, 255
%72 = load i32, i32* %9
%73 = add i32 %72, %71
store i32 %73, i32* %9
br label %74
74: ; preds = %65
%75 = load i32, i32* %11
%76 = add nsw i32 %75, 1
store i32 %76, i32* %11
br label %61
77: ; preds = %61
%78 = getelementptr inbounds [16 x i8], [16 x i8]* %8, i64 0, i64 0
%79 = call i32 @memset(i8* %78, i32 0, i32 16)
%80 = getelementptr inbounds [16 x i8], [16 x i8]* %8, i64 0, i64 3
store i8 0, i8* %80
%81 = getelementptr inbounds [16 x i8], [16 x i8]* %8, i64 0, i64 2
store i8 0, i8* %81
%82 = getelementptr inbounds [16 x i8], [16 x i8]* %8, i64 0, i64 1
store i8 0, i8* %82
%83 = getelementptr inbounds [16 x i8], [16 x i8]* %8, i64 0, i64 0
store i8 31, i8* %83
%84 = load i32, i32* %9
%85 = lshr i32 %84, 24
%86 = and i32 %85, 255
%87 = trunc i32 %86 to i8
%88 = getelementptr inbounds [16 x i8], [16 x i8]* %8, i64 0, i64 7
store i8 %87, i8* %88
%89 = load i32, i32* %9
%90 = lshr i32 %89, 16
%91 = and i32 %90, 255
%92 = trunc i32 %91 to i8
%93 = getelementptr inbounds [16 x i8], [16 x i8]* %8, i64 0, i64 6
store i8 %92, i8* %93
%94 = load i32, i32* %9
%95 = lshr i32 %94, 8
%96 = and i32 %95, 255
%97 = trunc i32 %96 to i8
%98 = getelementptr inbounds [16 x i8], [16 x i8]* %8, i64 0, i64 5
store i8 %97, i8* %98
%99 = load i32, i32* %9
%100 = lshr i32 %99, 0
%101 = and i32 %100, 255
%102 = trunc i32 %101 to i8
%103 = getelementptr inbounds [16 x i8], [16 x i8]* %8, i64 0, i64 4
store i8 %102, i8* %103
%104 = getelementptr inbounds [16 x i8], [16 x i8]* %8, i64 0, i64 0
%105 = load i8, i8* %104
%106 = zext i8 %105 to i32
%107 = xor i32 %106, 188
%108 = trunc i32 %107 to i8
store i8 %108, i8* %104
%109 = getelementptr inbounds [16 x i8], [16 x i8]* %8, i64 0, i64 1
%110 = load i8, i8* %109
%111 = zext i8 %110 to i32
%112 = xor i32 %111, 202
%113 = trunc i32 %112 to i8
store i8 %113, i8* %109
%114 = getelementptr inbounds [16 x i8], [16 x i8]* %8, i64 0, i64 2
%115 = load i8, i8* %114
%116 = zext i8 %115 to i32
%117 = xor i32 %116, 186
%118 = trunc i32 %117 to i8
store i8 %118, i8* %114
%119 = getelementptr inbounds [16 x i8], [16 x i8]* %8, i64 0, i64 3
%120 = load i8, i8* %119
%121 = zext i8 %120 to i32
%122 = xor i32 %121, 203
%123 = trunc i32 %122 to i8
store i8 %123, i8* %119
%124 = getelementptr inbounds [16 x i8], [16 x i8]* %8, i64 0, i64 4
%125 = load i8, i8* %124
%126 = zext i8 %125 to i32
%127 = xor i32 %126, 203
%128 = trunc i32 %127 to i8
store i8 %128, i8* %124
%129 = getelementptr inbounds [16 x i8], [16 x i8]* %8, i64 0, i64 5
%130 = load i8, i8* %129
%131 = zext i8 %130 to i32
%132 = xor i32 %131, 206
%133 = trunc i32 %132 to i8
store i8 %133, i8* %129
%134 = getelementptr inbounds [16 x i8], [16 x i8]* %8, i64 0, i64 6
%135 = load i8, i8* %134
%136 = zext i8 %135 to i32
%137 = xor i32 %136, 205
%138 = trunc i32 %137 to i8
store i8 %138, i8* %134
%139 = getelementptr inbounds [16 x i8], [16 x i8]* %8, i64 0, i64 7
%140 = load i8, i8* %139
%141 = zext i8 %140 to i32
%142 = xor i32 %141, 223
%143 = trunc i32 %142 to i8
store i8 %143, i8* %139
%144 = getelementptr inbounds [16 x i8], [16 x i8]* %8, i64 0, i64 8
%145 = load i8, i8* %144
%146 = zext i8 %145 to i32
%147 = xor i32 %146, 183
%148 = trunc i32 %147 to i8
store i8 %148, i8* %144
%149 = getelementptr inbounds [16 x i8], [16 x i8]* %8, i64 0, i64 9
%150 = load i8, i8* %149
%151 = zext i8 %150 to i32
%152 = xor i32 %151, 186
%153 = trunc i32 %152 to i8
store i8 %153, i8* %149
%154 = getelementptr inbounds [16 x i8], [16 x i8]* %8, i64 0, i64 10
%155 = load i8, i8* %154
%156 = zext i8 %155 to i32
%157 = xor i32 %156, 190
%158 = trunc i32 %157 to i8
store i8 %158, i8* %154
%159 = getelementptr inbounds [16 x i8], [16 x i8]* %8, i64 0, i64 11
%160 = load i8, i8* %159
%161 = zext i8 %160 to i32
%162 = xor i32 %161, 187
%163 = trunc i32 %162 to i8
store i8 %163, i8* %159
%164 = getelementptr inbounds [16 x i8], [16 x i8]* %8, i64 0, i64 12
%165 = load i8, i8* %164
%166 = zext i8 %165 to i32
%167 = xor i32 %166, 186
%168 = trunc i32 %167 to i8
store i8 %168, i8* %164
%169 = getelementptr inbounds [16 x i8], [16 x i8]* %8, i64 0, i64 13
%170 = load i8, i8* %169
%171 = zext i8 %170 to i32
%172 = xor i32 %171, 173
%173 = trunc i32 %172 to i8
store i8 %173, i8* %169
%174 = getelementptr inbounds [16 x i8], [16 x i8]* %8, i64 0, i64 14
%175 = load i8, i8* %174
%176 = zext i8 %175 to i32
%177 = xor i32 %176, 223
%178 = trunc i32 %177 to i8
store i8 %178, i8* %174
%179 = getelementptr inbounds [16 x i8], [16 x i8]* %8, i64 0, i64 15
%180 = load i8, i8* %179
%181 = zext i8 %180 to i32
%182 = xor i32 %181, 223
%183 = trunc i32 %182 to i8
store i8 %183, i8* %179
store i32 1, i32* %11
br label %184
184: ; preds = %201, %77
%185 = load i32, i32* %11
%186 = icmp slt i32 %185, 16
br i1 %186, label %187, label %204
187: ; preds = %184
%188 = load i32, i32* %11
%189 = sub nsw i32 %188, 1
%190 = sext i32 %189 to i64
%191 = getelementptr inbounds [16 x i8], [16 x i8]* %8, i64 0, i64 %190
%192 = load i8, i8* %191
%193 = zext i8 %192 to i32
%194 = load i32, i32* %11
%195 = sext i32 %194 to i64
%196 = getelementptr inbounds [16 x i8], [16 x i8]* %8, i64 0, i64 %195
%197 = load i8, i8* %196
%198 = zext i8 %197 to i32
%199 = xor i32 %198, %193
%200 = trunc i32 %199 to i8
store i8 %200, i8* %196
br label %201
201: ; preds = %187
%202 = load i32, i32* %11
%203 = add nsw i32 %202, 1
store i32 %203, i32* %11
br label %184
204: ; preds = %184
%205 = load i32*, i32** %6
%206 = load i32, i32* @SEEK_SET
%207 = call i32 @fseek(i32* %205, i64 0, i32 %206)
%208 = getelementptr inbounds [16 x i8], [16 x i8]* %8, i64 0, i64 0
%209 = load i32*, i32** %6
%210 = call i32 @fwrite(i8* %208, i32 1, i32 16, i32* %209)
%211 = sext i32 %210 to i64
%212 = icmp ne i64 %211, 16
br i1 %212, label %213, label %220
213: ; preds = %204
%214 = load i8**, i8*** %5
%215 = getelementptr inbounds i8*, i8** %214, i64 1
%216 = load i8*, i8** %215
%217 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), i8* %216)
%218 = load i32*, i32** %6
%219 = call i32 @fclose(i32* %218)
store i32 -1, i32* %3
br label %230
220: ; preds = %204
%221 = load i32*, i32** %6
%222 = call i32 @fclose(i32* %221)
%223 = load i32, i32* %9
%224 = load i32, i32* %10
%225 = zext i32 %224 to i64
%226 = sub i64 %225, 16
%227 = load i32, i32* %10
%228 = sub i32 %227, 1
%229 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.5, i64 0, i64 0), i32 %223, i64 %226, i64 16, i32 %228)
store i32 0, i32* %3
br label %230
230: ; preds = %220, %213, %53, %24, %15
%231 = load i32, i32* %3
ret i32 %231
}

LLVM IR (-O2):
@.str.1 = [4 x i8] c"r+b\00"
@.str.2 = [24 x i8] c"Can not open file '%s'\0A\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@.str.3 = [15 x i8] c"Can't read %s\0A\00"
@.str.4 = [23 x i8] c"Write header error %s\0A\00"
@.str.5 = [56 x i8] c"The checksum is 0x%08x for %ld bytes [0x%08x ~ 0x%08x]\0A\00"
@str = [21 x i8] c"Usage: mk4412 <file>\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [8192 x i8]
%4 = alloca [16 x i8]
%5 = getelementptr inbounds [8192 x i8], [8192 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 0
%7 = icmp eq i32 %0, 2
br i1 %7, label %10, label %8
8: ; preds = %2
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str, i64 0, i64 0))
br label %186
10: ; preds = %2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = tail call i32* @fopen(i8* %12, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %18
15: ; preds = %10
%16 = load i8*, i8** %11
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i8* %16)
br label %186
18: ; preds = %10
%19 = load i32, i32* @SEEK_END
%20 = tail call i32 @fseek(i32* %13, i64 0, i32 %19)
%21 = tail call i32 @ftell(i32* %13)
%22 = icmp slt i32 %21, 8192
%23 = select i1 %22, i32 %21, i32 8192
%24 = load i32, i32* @SEEK_SET
%25 = tail call i32 @fseek(i32* %13, i64 0, i32 %24)
%26 = call i32 @memset(i8* %5, i32 0, i32 8192)
%27 = call i32 @fread(i8* %5, i32 1, i32 %23, i32* %13)
%28 = icmp eq i32 %27, %23
br i1 %28, label %29, label %104
29: ; preds = %18
%30 = icmp ugt i32 %23, 16
br i1 %30, label %31, label %117
31: ; preds = %29
%32 = zext i32 %23 to i64
%33 = add nsw i64 %32, -16
%34 = icmp ult i64 %33, 8
br i1 %34, label %101, label %35
35: ; preds = %31
%36 = and i64 %33, -8
%37 = add nsw i64 %36, 16
%38 = add nsw i64 %36, -8
%39 = lshr exact i64 %38, 3
%40 = add nuw nsw i64 %39, 1
%41 = and i64 %40, 1
%42 = icmp eq i64 %38, 0
br i1 %42, label %77, label %43
43: ; preds = %35
%44 = and i64 %40, 4611686018427387902
br label %45
45: ; preds = %45, %43
%46 = phi i64 [ 0, %43 ], [ %72, %45 ]
%47 = phi <4 x i32> [ zeroinitializer, %43 ], [ %70, %45 ]
%48 = phi <4 x i32> [ zeroinitializer, %43 ], [ %71, %45 ]
%49 = phi i64 [ 0, %43 ], [ %73, %45 ]
%50 = add i64 %46, 16
%51 = getelementptr inbounds [8192 x i8], [8192 x i8]* %3, i64 0, i64 %50
%52 = bitcast i8* %51 to <4 x i8>*
%53 = load <4 x i8>, <4 x i8>* %52
%54 = getelementptr inbounds i8, i8* %51, i64 4
%55 = bitcast i8* %54 to <4 x i8>*
%56 = load <4 x i8>, <4 x i8>* %55
%57 = zext <4 x i8> %53 to <4 x i32>
%58 = zext <4 x i8> %56 to <4 x i32>
%59 = add <4 x i32> %47, %57
%60 = add <4 x i32> %48, %58
%61 = add i64 %46, 24
%62 = getelementptr inbounds [8192 x i8], [8192 x i8]* %3, i64 0, i64 %61
%63 = bitcast i8* %62 to <4 x i8>*
%64 = load <4 x i8>, <4 x i8>* %63
%65 = getelementptr inbounds i8, i8* %62, i64 4
%66 = bitcast i8* %65 to <4 x i8>*
%67 = load <4 x i8>, <4 x i8>* %66
%68 = zext <4 x i8> %64 to <4 x i32>
%69 = zext <4 x i8> %67 to <4 x i32>
%70 = add <4 x i32> %59, %68
%71 = add <4 x i32> %60, %69
%72 = add nuw i64 %46, 16
%73 = add i64 %49, 2
%74 = icmp eq i64 %73, %44
br i1 %74, label %75, label %45
75: ; preds = %45
%76 = add i64 %46, 32
br label %77
77: ; preds = %75, %35
%78 = phi <4 x i32> [ undef, %35 ], [ %70, %75 ]
%79 = phi <4 x i32> [ undef, %35 ], [ %71, %75 ]
%80 = phi i64 [ 16, %35 ], [ %76, %75 ]
%81 = phi <4 x i32> [ zeroinitializer, %35 ], [ %70, %75 ]
%82 = phi <4 x i32> [ zeroinitializer, %35 ], [ %71, %75 ]
%83 = icmp eq i64 %41, 0
br i1 %83, label %95, label %84
84: ; preds = %77
%85 = getelementptr inbounds [8192 x i8], [8192 x i8]* %3, i64 0, i64 %80
%86 = bitcast i8* %85 to <4 x i8>*
%87 = load <4 x i8>, <4 x i8>* %86
%88 = getelementptr inbounds i8, i8* %85, i64 4
%89 = bitcast i8* %88 to <4 x i8>*
%90 = load <4 x i8>, <4 x i8>* %89
%91 = zext <4 x i8> %87 to <4 x i32>
%92 = zext <4 x i8> %90 to <4 x i32>
%93 = add <4 x i32> %81, %91
%94 = add <4 x i32> %82, %92
br label %95
95: ; preds = %77, %84
%96 = phi <4 x i32> [ %78, %77 ], [ %93, %84 ]
%97 = phi <4 x i32> [ %79, %77 ], [ %94, %84 ]
%98 = add <4 x i32> %97, %96
%99 = call i32 @llvm.vector.reduce.add.v4i32(<4 x i32> %98)
%100 = icmp eq i64 %33, %36
br i1 %100, label %117, label %101
101: ; preds = %31, %95
%102 = phi i64 [ 16, %31 ], [ %37, %95 ]
%103 = phi i32 [ 0, %31 ], [ %99, %95 ]
br label %108
104: ; preds = %18
%105 = load i8*, i8** %11
%106 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i8* %105)
%107 = call i32 @fclose(i32* %13)
br label %186
108: ; preds = %101, %108
%109 = phi i64 [ %115, %108 ], [ %102, %101 ]
%110 = phi i32 [ %114, %108 ], [ %103, %101 ]
%111 = getelementptr inbounds [8192 x i8], [8192 x i8]* %3, i64 0, i64 %109
%112 = load i8, i8* %111
%113 = zext i8 %112 to i32
%114 = add i32 %110, %113
%115 = add nuw nsw i64 %109, 1
%116 = icmp eq i64 %115, %32
br i1 %116, label %117, label %108
117: ; preds = %108, %95, %29
%118 = phi i32 [ 0, %29 ], [ %99, %95 ], [ %114, %108 ]
%119 = call i32 @memset(i8* %6, i32 0, i32 16)
%120 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 3
%121 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 2
%122 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 1
%123 = lshr i32 %118, 24
%124 = trunc i32 %123 to i8
%125 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 7
%126 = lshr i32 %118, 16
%127 = trunc i32 %126 to i8
%128 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 6
%129 = lshr i32 %118, 8
%130 = trunc i32 %129 to i8
%131 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 5
%132 = trunc i32 %118 to i8
%133 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 4
store i8 -93, i8* %6
%134 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 8
%135 = load i8, i8* %134
%136 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 9
%137 = load i8, i8* %136
%138 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 10
%139 = load i8, i8* %138
%140 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 11
%141 = load i8, i8* %140
%142 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 12
%143 = load i8, i8* %142
%144 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 13
%145 = load i8, i8* %144
%146 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 14
%147 = load i8, i8* %146
%148 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 15
%149 = load i8, i8* %148
store i8 105, i8* %122
store i8 -45, i8* %121
store i8 24, i8* %120
%150 = xor i8 %132, -45
store i8 %150, i8* %133
%151 = xor i8 %150, %130
%152 = xor i8 %151, -50
store i8 %152, i8* %131
%153 = xor i8 %152, %127
%154 = xor i8 %153, -51
store i8 %154, i8* %128
%155 = xor i8 %154, %124
%156 = xor i8 %155, -33
store i8 %156, i8* %125
%157 = xor i8 %135, %156
%158 = xor i8 %157, -73
store i8 %158, i8* %134
%159 = xor i8 %137, %158
%160 = xor i8 %159, -70
store i8 %160, i8* %136
%161 = xor i8 %139, %160
%162 = xor i8 %161, -66
store i8 %162, i8* %138
%163 = xor i8 %141, %162
%164 = xor i8 %163, -69
store i8 %164, i8* %140
%165 = xor i8 %143, %164
%166 = xor i8 %165, -70
store i8 %166, i8* %142
%167 = xor i8 %145, %166
%168 = xor i8 %167, -83
store i8 %168, i8* %144
%169 = xor i8 %147, %168
%170 = xor i8 %169, -33
store i8 %170, i8* %146
%171 = xor i8 %149, %169
store i8 %171, i8* %148
%172 = load i32, i32* @SEEK_SET
%173 = call i32 @fseek(i32* %13, i64 0, i32 %172)
%174 = call i32 @fwrite(i8* %6, i32 1, i32 16, i32* %13)
%175 = icmp eq i32 %174, 16
br i1 %175, label %180, label %176
176: ; preds = %117
%177 = load i8*, i8** %11
%178 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), i8* %177)
%179 = call i32 @fclose(i32* %13)
br label %186
180: ; preds = %117
%181 = call i32 @fclose(i32* %13)
%182 = zext i32 %23 to i64
%183 = add nsw i64 %182, -16
%184 = add i32 %23, -1
%185 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([56 x i8], [56 x i8]* @.str.5, i64 0, i64 0), i32 %118, i64 %183, i64 16, i32 %184)
br label %186
186: ; preds = %180, %176, %104, %15, %8
%187 = phi i32 [ -1, %8 ], [ -1, %15 ], [ -1, %104 ], [ -1, %176 ], [ 0, %180 ]
ret i32 %187
}