#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 ulong;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int EXIT_SUCCESS;
int O_CREAT;
int /*<<< orphan*/ O_RDONLY;
int O_TRUNC;
int O_WRONLY;
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);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, char *, char *);
int lseek(int, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ memcpy(unsigned char *, char *, int);
int open(char *, int, ...);
int /*<<< orphan*/ printf(char *, int);
unsigned int read(int, unsigned char *, unsigned int);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int write(int, unsigned char *, int);
int main(int argc, char **argv) {
  int i, len;
  unsigned char buffer[(8 * 1024)] = {0};
  int ifd, ofd;
  unsigned int checksum = 0, count;
  if (argc != 3) {
    printf(" %d Wrong number of arguments\n", argc);
    exit(EXIT_FAILURE);
  }
  ifd = open(argv[1], O_RDONLY);
  if (ifd < 0) {
    fprintf(stderr, "%s: Can't open %s: %s\n", argv[0], argv[1],
            strerror(errno));
    exit(EXIT_FAILURE);
  }
  ofd = open(argv[2], O_WRONLY | O_CREAT | O_TRUNC,
             (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH));
  if (ifd < 0) {
    fprintf(stderr, "%s: Can't open %s: %s\n", argv[0], argv[2],
            strerror(errno));
    if (ifd)
      close(ifd);
    exit(EXIT_FAILURE);
  }
  len = lseek(ifd, 0, SEEK_END);
  lseek(ifd, 0, SEEK_SET);
  memcpy(&buffer[0], "S3C6410 HEADER  ", 8);
  count = (len < ((8 * 1024) - 8)) ? len : ((8 * 1024) - 8);
  if (read(ifd, buffer + 8, count) != count) {
    fprintf(stderr, "%s: Can't read %s: %s\n", argv[0], argv[1],
            strerror(errno));
    if (ifd)
      close(ifd);
    if (ofd)
      close(ofd);
    exit(EXIT_FAILURE);
  }
  for (i = 0; i < (8 * 1024) - 8; i++)
    checksum += buffer[i + 16];
  *(ulong *)buffer ^= 0x1f;
  *(ulong *)(buffer + 4) ^= checksum;
  for (i = 1; i < 8; i++)
    buffer[i] ^= buffer[i - 1];
  if (write(ofd, buffer, (8 * 1024)) != (8 * 1024)) {
    fprintf(stderr, "%s: Can't write %s: %s\n", argv[0], argv[2],
            strerror(errno));
    if (ifd)
      close(ifd);
    if (ofd)
      close(ofd);
    exit(EXIT_FAILURE);
  }
  if (ifd)
    close(ifd);
  if (ofd)
    close(ofd);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2090,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x2020(%rbp),%rdi
xor    %esi,%esi
mov    $0x2000,%edx
call   1060 <memset@plt>
movl   $0x0,-0x202c(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     120d <main+0x5d>
mov    -0x8(%rbp),%esi
lea    0xe06(%rip),%rdi
call   1040 <printf@plt>
mov    0x2d82(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2db4(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   10b0 <open@plt>
mov    %eax,-0x2024(%rbp)
cmpl   $0x0,-0x2024(%rbp)
jge    12a3 <main+0xf3>
mov    0x2d71(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2044(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x2040(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x2038(%rbp)
mov    0x2d3d(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
mov    -0x2044(%rbp),%edi
mov    -0x2040(%rbp),%rdx
mov    -0x2038(%rbp),%rcx
mov    %rax,%r8
lea    0xd8f(%rip),%rsi
call   1090 <fprintf@plt>
mov    0x2cec(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
mov    0x2cb6(%rip),%rax
mov    (%rax),%esi
mov    0x2d3d(%rip),%rax
or     (%rax),%esi
mov    0x2d2c(%rip),%rax
or     (%rax),%esi
mov    0x2cb3(%rip),%rax
mov    (%rax),%edx
mov    0x2cea(%rip),%rax
or     (%rax),%edx
mov    0x2cb9(%rip),%rax
or     (%rax),%edx
mov    0x2ce0(%rip),%rax
or     (%rax),%edx
mov    0x2c9f(%rip),%rax
or     (%rax),%edx
mov    0x2c66(%rip),%rax
or     (%rax),%edx
mov    $0x0,%al
call   10b0 <open@plt>
mov    %eax,-0x2028(%rbp)
cmpl   $0x0,-0x2024(%rbp)
jge    1399 <main+0x1e9>
mov    0x2c93(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x205c(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x2058(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x2050(%rbp)
mov    0x2c5f(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
mov    -0x205c(%rbp),%edi
mov    -0x2058(%rbp),%rdx
mov    -0x2050(%rbp),%rcx
mov    %rax,%r8
lea    0xcb1(%rip),%rsi
call   1090 <fprintf@plt>
cmpl   $0x0,-0x2024(%rbp)
je     138b <main+0x1db>
mov    -0x2024(%rbp),%edi
call   1070 <close@plt>
mov    0x2bf6(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
mov    -0x2024(%rbp),%edi
mov    0x2c32(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1050 <lseek@plt>
mov    %eax,-0x18(%rbp)
mov    -0x2024(%rbp),%edi
mov    0x2be1(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1050 <lseek@plt>
lea    -0x2020(%rbp),%rdi
lea    0xc60(%rip),%rsi
mov    $0x8,%edx
call   10a0 <memcpy@plt>
cmpl   $0x1ff8,-0x18(%rbp)
jge    13fb <main+0x24b>
mov    -0x18(%rbp),%eax
mov    %eax,-0x2060(%rbp)
jmp    140b <main+0x25b>
mov    $0x1ff8,%eax
mov    %eax,-0x2060(%rbp)
jmp    140b <main+0x25b>
mov    -0x2060(%rbp),%eax
mov    %eax,-0x2030(%rbp)
mov    -0x2024(%rbp),%edi
lea    -0x2020(%rbp),%rsi
add    $0x8,%rsi
mov    -0x2030(%rbp),%edx
call   1080 <read@plt>
cmp    -0x2030(%rbp),%eax
je     14da <main+0x32a>
mov    0x2b6a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2074(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x2070(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x2068(%rbp)
mov    0x2b36(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
mov    -0x2074(%rbp),%edi
mov    -0x2070(%rbp),%rdx
mov    -0x2068(%rbp),%rcx
mov    %rax,%r8
lea    0xbb0(%rip),%rsi
call   1090 <fprintf@plt>
cmpl   $0x0,-0x2024(%rbp)
je     14b4 <main+0x304>
mov    -0x2024(%rbp),%edi
call   1070 <close@plt>
cmpl   $0x0,-0x2028(%rbp)
je     14cc <main+0x31c>
mov    -0x2028(%rbp),%edi
call   1070 <close@plt>
mov    0x2ab5(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
movl   $0x0,-0x14(%rbp)
cmpl   $0x1ff8,-0x14(%rbp)
jge    1518 <main+0x368>
mov    -0x14(%rbp),%eax
add    $0x10,%eax
cltq
movzbl -0x2020(%rbp,%rax,1),%eax
ff
add    -0x202c(%rbp),%eax
mov    %eax,-0x202c(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    14e1 <main+0x331>
mov    -0x2020(%rbp),%eax
xor    $0x1f,%eax
mov    %eax,-0x2020(%rbp)
mov    -0x202c(%rbp),%eax
xor    -0x201c(%rbp),%eax
mov    %eax,-0x201c(%rbp)
movl   $0x1,-0x14(%rbp)
cmpl   $0x8,-0x14(%rbp)
jge    157d <main+0x3cd>
mov    -0x14(%rbp),%eax
sub    $0x1,%eax
cltq
movzbl -0x2020(%rbp,%rax,1),%edx
ff
movslq -0x14(%rbp),%rax
movzbl -0x2020(%rbp,%rax,1),%ecx
ff
xor    %edx,%ecx
mov    %cl,-0x2020(%rbp,%rax,1)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1540 <main+0x390>
mov    -0x2028(%rbp),%edi
lea    -0x2020(%rbp),%rsi
mov    $0x2000,%edx
call   1030 <write@plt>
cmp    $0x2000,%eax
je     163a <main+0x48a>
mov    0x2a0a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x208c(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x2088(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x2080(%rbp)
mov    0x29d6(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
mov    -0x208c(%rbp),%edi
mov    -0x2088(%rbp),%rdx
mov    -0x2080(%rbp),%rcx
mov    %rax,%r8
lea    0xa67(%rip),%rsi
call   1090 <fprintf@plt>
cmpl   $0x0,-0x2024(%rbp)
je     1614 <main+0x464>
mov    -0x2024(%rbp),%edi
call   1070 <close@plt>
cmpl   $0x0,-0x2028(%rbp)
je     162c <main+0x47c>
mov    -0x2028(%rbp),%edi
call   1070 <close@plt>
mov    0x2955(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
cmpl   $0x0,-0x2024(%rbp)
je     1652 <main+0x4a2>
mov    -0x2024(%rbp),%edi
call   1070 <close@plt>
cmpl   $0x0,-0x2028(%rbp)
je     166a <main+0x4ba>
mov    -0x2028(%rbp),%edi
call   1070 <close@plt>
mov    0x2907(%rip),%rax
mov    (%rax),%eax
add    $0x2090,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x2000,%rsp
mov    %rsi,%r14
mov    %edi,%ebx
mov    %rsp,%rdi
mov    $0x2000,%edx
xor    %esi,%esi
call   1060 <memset@plt>
cmp    $0x3,%ebx
jne    1404 <main+0x254>
mov    0x8(%r14),%rdi
mov    0x2de9(%rip),%rax
mov    (%rax),%esi
xor    %eax,%eax
call   10b0 <open@plt>
test   %eax,%eax
js     1417 <main+0x267>
mov    %eax,%r12d
mov    0x2d66(%rip),%rax
mov    0x2def(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2ddc(%rip),%rax
or     (%rax),%esi
mov    0x2d63(%rip),%rax
mov    0x2d9c(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    0x2d69(%rip),%rax
or     (%rax),%edx
mov    0x2d90(%rip),%rax
or     (%rax),%edx
mov    0x2d4f(%rip),%rax
or     (%rax),%edx
mov    0x10(%r14),%rdi
mov    0x2d12(%rip),%rax
or     (%rax),%edx
xor    %eax,%eax
call   10b0 <open@plt>
mov    %eax,%r15d
mov    0x2d77(%rip),%rax
mov    (%rax),%edx
mov    %r12d,%edi
xor    %esi,%esi
call   1050 <lseek@plt>
mov    %eax,%ebp
mov    0x2d2a(%rip),%rax
mov    (%rax),%edx
mov    %r12d,%edi
xor    %esi,%esi
call   1050 <lseek@plt>
lea    0xdad(%rip),%rsi
mov    %rsp,%rdi
mov    $0x8,%edx
call   10a0 <memcpy@plt>
cmp    $0x1ff8,%ebp
mov    $0x1ff8,%ebx
cmovl  %ebp,%ebx
lea    0x8(%rsp),%rsi
mov    %r12d,%edi
mov    %ebx,%edx
call   1080 <read@plt>
cmp    %ebx,%eax
jne    144e <main+0x29e>
pxor   %xmm0,%xmm0
xor    %eax,%eax
pxor   %xmm2,%xmm2
pxor   %xmm1,%xmm1
nopl   0x0(%rax)
movq   0x10(%rsp,%rax,1),%xmm4
movd   0x14(%rsp,%rax,1),%xmm3
punpcklbw %xmm0,%xmm4
punpcklwd %xmm0,%xmm4
paddd  %xmm2,%xmm4
punpcklbw %xmm0,%xmm3
punpcklwd %xmm0,%xmm3
paddd  %xmm1,%xmm3
movq   0x18(%rsp,%rax,1),%xmm5
movd   0x1c(%rsp,%rax,1),%xmm6
punpcklbw %xmm0,%xmm5
punpcklwd %xmm0,%xmm5
punpcklbw %xmm0,%xmm6
punpcklwd %xmm0,%xmm6
movq   0x20(%rsp,%rax,1),%xmm2
movd   0x24(%rsp,%rax,1),%xmm1
punpcklbw %xmm0,%xmm2
punpcklwd %xmm0,%xmm2
paddd  %xmm5,%xmm2
paddd  %xmm4,%xmm2
punpcklbw %xmm0,%xmm1
punpcklwd %xmm0,%xmm1
paddd  %xmm6,%xmm1
paddd  %xmm3,%xmm1
add    $0x18,%rax
cmp    $0x1ff8,%rax
jne    12d0 <main+0x120>
paddd  %xmm2,%xmm1
pshufd $0xee,%xmm1,%xmm0
paddd  %xmm1,%xmm0
pshufd $0x55,%xmm0,%xmm1
paddd  %xmm0,%xmm1
movd   %xmm1,%eax
mov    (%rsp),%ecx
mov    %ecx,%edx
xor    $0x1f,%edx
mov    %edx,(%rsp)
xor    0x4(%rsp),%eax
mov    %ecx,%esi
shr    $0x8,%esi
xor    %edx,%esi
mov    %sil,0x1(%rsp)
mov    %ecx,%edx
shr    $0x10,%edx
xor    %esi,%edx
mov    %dl,0x2(%rsp)
shr    $0x18,%ecx
xor    %edx,%ecx
mov    %cl,0x3(%rsp)
xor    %eax,%ecx
mov    %cl,0x4(%rsp)
mov    %eax,%edx
shr    $0x8,%edx
xor    %ecx,%edx
mov    %dl,0x5(%rsp)
mov    %eax,%ecx
shr    $0x10,%ecx
xor    %edx,%ecx
mov    %cl,0x6(%rsp)
shr    $0x18,%eax
xor    %ecx,%eax
mov    %al,0x7(%rsp)
mov    %rsp,%rsi
mov    %r15d,%edi
mov    $0x2000,%edx
call   1030 <write@plt>
cmp    $0x2000,%eax
jne    1475 <main+0x2c5>
test   %r12d,%r12d
je     13de <main+0x22e>
mov    %r12d,%edi
call   1070 <close@plt>
test   %r15d,%r15d
je     13eb <main+0x23b>
mov    %r15d,%edi
call   1070 <close@plt>
mov    0x2b86(%rip),%rax
mov    (%rax),%eax
add    $0x2000,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xbf5(%rip),%rdi
mov    %ebx,%esi
call   1040 <printf@plt>
jmp    14c4 <main+0x314>
mov    0x2b92(%rip),%rax
mov    (%rax),%ebx
mov    (%r14),%rbp
mov    0x8(%r14),%r14
mov    0x2b7a(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
lea    0xbe3(%rip),%rsi
mov    %ebx,%edi
mov    %rbp,%rdx
mov    %r14,%rcx
mov    %rax,%r8
call   1090 <fprintf@plt>
jmp    14c4 <main+0x314>
mov    0x2b5b(%rip),%rax
mov    (%rax),%ebx
mov    (%r14),%rbp
mov    0x8(%r14),%r14
mov    0x2b43(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
lea    0xbd4(%rip),%rsi
jmp    149a <main+0x2ea>
mov    0x2b34(%rip),%rax
mov    (%rax),%ebx
mov    (%r14),%rbp
mov    0x10(%r14),%r14
mov    0x2b1c(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
lea    0xbc4(%rip),%rsi
mov    %ebx,%edi
mov    %rbp,%rdx
mov    %r14,%rcx
mov    %rax,%r8
call   1090 <fprintf@plt>
test   %r12d,%r12d
je     14b7 <main+0x307>
mov    %r12d,%edi
call   1070 <close@plt>
test   %r15d,%r15d
je     14c4 <main+0x314>
mov    %r15d,%edi
call   1070 <close@plt>
mov    0x2abd(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>

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

LLVM IR (-O2):
@.str = [31 x i8] c" %d Wrong number of arguments\0A\00"
@EXIT_FAILURE = global i32 0
@O_RDONLY = global i32 0
@stderr = global i32 0
@.str.1 = [23 x i8] c"%s: Can't open %s: %s\0A\00"
@errno = global i32 0
@O_WRONLY = 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
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@.str.2 = [17 x i8] c"S3C6410 HEADER \00"
@.str.3 = [23 x i8] c"%s: Can't read %s: %s\0A\00"
@.str.4 = [24 x i8] c"%s: Can't write %s: %s\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [8192 x i8]
%4 = getelementptr inbounds [8192 x i8], [8192 x i8]* %3, i64 0, i64 0
%5 = icmp eq i32 %0, 3
br i1 %5, label %10, label %6
6: ; preds = %2
%7 = tail call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i32 %0)
%8 = load i32, i32* @EXIT_FAILURE
%9 = tail call i32 @exit(i32 %8)
unreachable
10: ; preds = %2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = load i32, i32* @O_RDONLY
%14 = tail call i32 (i8*, i32, ...) @open(i8* %12, i32 %13)
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %25
16: ; preds = %10
%17 = load i32, i32* @stderr
%18 = load i8*, i8** %1
%19 = load i8*, i8** %11
%20 = load i32, i32* @errno
%21 = tail call i8* @strerror(i32 %20)
%22 = tail call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %18, i8* %19, i8* %21)
%23 = load i32, i32* @EXIT_FAILURE
%24 = tail call i32 @exit(i32 %23)
unreachable
25: ; preds = %10
%26 = getelementptr inbounds i8*, i8** %1, i64 2
%27 = load i8*, i8** %26
%28 = load i32, i32* @O_WRONLY
%29 = load i32, i32* @O_CREAT
%30 = or i32 %29, %28
%31 = load i32, i32* @O_TRUNC
%32 = or i32 %30, %31
%33 = load i32, i32* @S_IRUSR
%34 = load i32, i32* @S_IWUSR
%35 = or i32 %34, %33
%36 = load i32, i32* @S_IRGRP
%37 = or i32 %35, %36
%38 = load i32, i32* @S_IWGRP
%39 = or i32 %37, %38
%40 = load i32, i32* @S_IROTH
%41 = or i32 %39, %40
%42 = load i32, i32* @S_IWOTH
%43 = or i32 %41, %42
%44 = tail call i32 (i8*, i32, ...) @open(i8* %27, i32 %32, i32 %43)
%45 = load i32, i32* @SEEK_END
%46 = tail call i32 @lseek(i32 %14, i32 0, i32 %45)
%47 = load i32, i32* @SEEK_SET
%48 = tail call i32 @lseek(i32 %14, i32 0, i32 %47)
%49 = call i32 @memcpy(i8* %4, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i32 8)
%50 = icmp slt i32 %46, 8184
%51 = select i1 %50, i32 %46, i32 8184
%52 = getelementptr inbounds [8192 x i8], [8192 x i8]* %3, i64 0, i64 8
%53 = call i32 @read(i32 %14, i8* %52, i32 %51)
%54 = icmp eq i32 %53, %51
br i1 %54, label %55, label %132
55: ; preds = %25, %55
%56 = phi i64 [ %92, %55 ], [ 0, %25 ]
%57 = phi <4 x i32> [ %90, %55 ], [ zeroinitializer, %25 ]
%58 = phi <4 x i32> [ %91, %55 ], [ zeroinitializer, %25 ]
%59 = add nuw nsw i64 %56, 16
%60 = getelementptr inbounds [8192 x i8], [8192 x i8]* %3, i64 0, i64 %59
%61 = bitcast i8* %60 to <4 x i8>*
%62 = load <4 x i8>, <4 x i8>* %61
%63 = getelementptr inbounds i8, i8* %60, i64 4
%64 = bitcast i8* %63 to <4 x i8>*
%65 = load <4 x i8>, <4 x i8>* %64
%66 = zext <4 x i8> %62 to <4 x i32>
%67 = zext <4 x i8> %65 to <4 x i32>
%68 = add <4 x i32> %57, %66
%69 = add <4 x i32> %58, %67
%70 = add nuw nsw i64 %56, 24
%71 = getelementptr inbounds [8192 x i8], [8192 x i8]* %3, i64 0, i64 %70
%72 = bitcast i8* %71 to <4 x i8>*
%73 = load <4 x i8>, <4 x i8>* %72
%74 = getelementptr inbounds i8, i8* %71, i64 4
%75 = bitcast i8* %74 to <4 x i8>*
%76 = load <4 x i8>, <4 x i8>* %75
%77 = zext <4 x i8> %73 to <4 x i32>
%78 = zext <4 x i8> %76 to <4 x i32>
%79 = add <4 x i32> %68, %77
%80 = add <4 x i32> %69, %78
%81 = add nuw nsw i64 %56, 32
%82 = getelementptr inbounds [8192 x i8], [8192 x i8]* %3, i64 0, i64 %81
%83 = bitcast i8* %82 to <4 x i8>*
%84 = load <4 x i8>, <4 x i8>* %83
%85 = getelementptr inbounds i8, i8* %82, i64 4
%86 = bitcast i8* %85 to <4 x i8>*
%87 = load <4 x i8>, <4 x i8>* %86
%88 = zext <4 x i8> %84 to <4 x i32>
%89 = zext <4 x i8> %87 to <4 x i32>
%90 = add <4 x i32> %79, %88
%91 = add <4 x i32> %80, %89
%92 = add nuw nsw i64 %56, 24
%93 = icmp eq i64 %92, 8184
br i1 %93, label %94, label %55
94: ; preds = %55
%95 = add <4 x i32> %91, %90
%96 = call i32 @llvm.vector.reduce.add.v4i32(<4 x i32> %95)
%97 = bitcast [8192 x i8]* %3 to i32*
%98 = load i32, i32* %97
%99 = xor i32 %98, 31
store i32 %99, i32* %97
%100 = getelementptr inbounds [8192 x i8], [8192 x i8]* %3, i64 0, i64 4
%101 = bitcast i8* %100 to i32*
%102 = load i32, i32* %101
%103 = xor i32 %102, %96
%104 = getelementptr inbounds [8192 x i8], [8192 x i8]* %3, i64 0, i64 1
%105 = lshr i32 %98, 8
%106 = xor i32 %105, %99
%107 = trunc i32 %106 to i8
store i8 %107, i8* %104
%108 = getelementptr inbounds [8192 x i8], [8192 x i8]* %3, i64 0, i64 2
%109 = lshr i32 %98, 16
%110 = xor i32 %109, %106
%111 = trunc i32 %110 to i8
store i8 %111, i8* %108
%112 = getelementptr inbounds [8192 x i8], [8192 x i8]* %3, i64 0, i64 3
%113 = lshr i32 %98, 24
%114 = xor i32 %113, %110
%115 = trunc i32 %114 to i8
store i8 %115, i8* %112
%116 = xor i32 %103, %114
%117 = trunc i32 %116 to i8
store i8 %117, i8* %100
%118 = getelementptr inbounds [8192 x i8], [8192 x i8]* %3, i64 0, i64 5
%119 = lshr i32 %103, 8
%120 = xor i32 %119, %116
%121 = trunc i32 %120 to i8
store i8 %121, i8* %118
%122 = getelementptr inbounds [8192 x i8], [8192 x i8]* %3, i64 0, i64 6
%123 = lshr i32 %103, 16
%124 = xor i32 %123, %120
%125 = trunc i32 %124 to i8
store i8 %125, i8* %122
%126 = getelementptr inbounds [8192 x i8], [8192 x i8]* %3, i64 0, i64 7
%127 = lshr i32 %103, 24
%128 = xor i32 %127, %124
%129 = trunc i32 %128 to i8
store i8 %129, i8* %126
%130 = call i32 @write(i32 %44, i8* %4, i32 8192)
%131 = icmp eq i32 %130, 8192
br i1 %131, label %166, label %149
132: ; preds = %25
%133 = load i32, i32* @stderr
%134 = load i8*, i8** %1
%135 = load i8*, i8** %11
%136 = load i32, i32* @errno
%137 = call i8* @strerror(i32 %136)
%138 = call i32 @fprintf(i32 %133, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i8* %134, i8* %135, i8* %137)
%139 = icmp eq i32 %14, 0
br i1 %139, label %142, label %140
140: ; preds = %132
%141 = call i32 @close(i32 %14)
br label %142
142: ; preds = %140, %132
%143 = icmp eq i32 %44, 0
br i1 %143, label %146, label %144
144: ; preds = %142
%145 = call i32 @close(i32 %44)
br label %146
146: ; preds = %144, %142
%147 = load i32, i32* @EXIT_FAILURE
%148 = call i32 @exit(i32 %147)
unreachable
149: ; preds = %94
%150 = load i32, i32* @stderr
%151 = load i8*, i8** %1
%152 = load i8*, i8** %26
%153 = load i32, i32* @errno
%154 = call i8* @strerror(i32 %153)
%155 = call i32 @fprintf(i32 %150, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0), i8* %151, i8* %152, i8* %154)
%156 = icmp eq i32 %14, 0
br i1 %156, label %159, label %157
157: ; preds = %149
%158 = call i32 @close(i32 %14)
br label %159
159: ; preds = %157, %149
%160 = icmp eq i32 %44, 0
br i1 %160, label %163, label %161
161: ; preds = %159
%162 = call i32 @close(i32 %44)
br label %163
163: ; preds = %161, %159
%164 = load i32, i32* @EXIT_FAILURE
%165 = call i32 @exit(i32 %164)
unreachable
166: ; preds = %94
%167 = icmp eq i32 %14, 0
br i1 %167, label %170, label %168
168: ; preds = %166
%169 = call i32 @close(i32 %14)
br label %170
170: ; preds = %168, %166
%171 = icmp eq i32 %44, 0
br i1 %171, label %174, label %172
172: ; preds = %170
%173 = call i32 @close(i32 %44)
br label %174
174: ; preds = %172, %170
%175 = load i32, i32* @EXIT_SUCCESS
ret i32 %175
}