#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*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ close(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
scalar_t__ ferror(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
size_t fread(void *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(unsigned int *);
size_t fwrite(unsigned int *, int, size_t, int /*<<< orphan*/ *);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char *argv[]) {
  FILE *fp = NULL;
  char *input_file, *output_file;
  int i;
  unsigned int checksum, *buffer;
  size_t file_size;
  if (argc < 2) {
    printf("Error: Input file required\n");
    printf("Usage:\n\tLPC-Checksum-Inseter "
           "InputFile.bin\nor\n\tLPC-Checksum-Inseter InputFile.bin "
           "OutputFile.bin");
    return (1);
  }
  input_file = (char *)argv[1];
  if (argc == 2) {
    output_file = input_file;
  } else {
    output_file = (char *)argv[2];
  }
  buffer = (unsigned int *)malloc((1024 * 1024));
  if (!buffer) {
    printf("Error: unable to allocate memory for buffer\n");
    return (1);
  }
  fp = fopen((const char *)input_file, "rb");
  if (fp == NULL) {
    printf("Error: unable to open file %s for input\n", input_file);
    free(buffer);
    return (1);
  }
  file_size = fread((void *)buffer, 1, (1024 * 1024), fp);
  if (ferror(fp)) {
    printf("Error: failed to read file: %s\n", input_file);
    close(fp);
    free(buffer);
    return (1);
  }
  if (!feof(fp)) {
    printf("The input file %s is too large for this application. The maximum "
           "size supported is %d bytes\n",
           input_file, (1024 * 1024));
    close(fp);
    free(buffer);
    return (1);
  }
  printf("Input file %s has been read. Size %d bytes\n", input_file,
         (int)file_size);
  close(fp);
  checksum = 0;
  for (i = 0; i < 7; i++) {
    checksum += buffer[i];
    printf("%d: 0x%08x\n", i, buffer[i]);
  }
  if (buffer[7] == (0xFFFFFFFF - checksum) + 1) {
    printf("Checksum already set to correct value.  Exiting without changing "
           "file\n");
    free(buffer);
    return (1);
  }
  buffer[7] = (0xFFFFFFFF - checksum) + 1;
  printf("7: 0x%08x\n", buffer[7]);
  printf("checksum total: 0x%08x\n", checksum + buffer[7]);
  fp = fopen(output_file, "wb");
  if (!fp) {
    printf("Error: unable to open file %s for output\n", output_file);
    free(buffer);
    return (1);
  }
  if (fwrite(buffer, 1, file_size, fp) != file_size) {
    printf("Error: unable to write to file %s\n", output_file);
    close(fp);
    free(buffer);
    return (1);
  }
  printf("File %s written with %d bytes\n", output_file, (int)file_size);
  free(buffer);
  close(fp);
  return (1);
}


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)
movq   $0x0,-0x18(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    11e0 <main+0x50>
lea    0xe41(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xe4f(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    14e4 <main+0x354>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x20(%rbp)
cmpl   $0x2,-0x8(%rbp)
jne    1203 <main+0x73>
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
jmp    120f <main+0x7f>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x28(%rbp)
mov    $0x100000,%edi
call   1090 <malloc@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    1242 <main+0xb2>
lea    0xe4e(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    14e4 <main+0x354>
mov    -0x20(%rbp),%rdi
lea    0xe5d(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1288 <main+0xf8>
mov    -0x20(%rbp),%rsi
lea    0xe41(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
movl   $0x1,-0x4(%rbp)
jmp    14e4 <main+0x354>
mov    -0x38(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
mov    $0x100000,%edx
call   1050 <fread@plt>
mov    %rax,-0x40(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <ferror@plt>
cmp    $0x0,%rax
je     12e6 <main+0x156>
mov    -0x20(%rbp),%rsi
lea    0xe15(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1070 <close@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
movl   $0x1,-0x4(%rbp)
jmp    14e4 <main+0x354>
mov    -0x18(%rbp),%rdi
call   1080 <feof@plt>
cmp    $0x0,%eax
jne    132d <main+0x19d>
mov    -0x20(%rbp),%rsi
lea    0xdf3(%rip),%rdi
mov    $0x100000,%edx
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1070 <close@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
movl   $0x1,-0x4(%rbp)
jmp    14e4 <main+0x354>
mov    -0x20(%rbp),%rsi
mov    -0x40(%rbp),%rax
mov    %eax,%edx
lea    0xe15(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1070 <close@plt>
movl   $0x0,-0x30(%rbp)
movl   $0x0,-0x2c(%rbp)
cmpl   $0x7,-0x2c(%rbp)
jge    13a1 <main+0x211>
mov    -0x38(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
add    -0x30(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x2c(%rbp),%esi
mov    -0x38(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
lea    0xdf3(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    135c <main+0x1cc>
mov    -0x38(%rbp),%rax
mov    0x1c(%rax),%eax
mov    $0xffffffff,%ecx
sub    -0x30(%rbp),%ecx
add    $0x1,%ecx
cmp    %ecx,%eax
jne    13de <main+0x24e>
lea    0xdc9(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
movl   $0x1,-0x4(%rbp)
jmp    14e4 <main+0x354>
mov    $0xffffffff,%ecx
sub    -0x30(%rbp),%ecx
add    $0x1,%ecx
mov    -0x38(%rbp),%rax
mov    %ecx,0x1c(%rax)
mov    -0x38(%rbp),%rax
mov    0x1c(%rax),%esi
lea    0xdd4(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x30(%rbp),%esi
mov    -0x38(%rbp),%rax
add    0x1c(%rax),%esi
lea    0xdc7(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x28(%rbp),%rdi
lea    0xdcd(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1463 <main+0x2d3>
mov    -0x28(%rbp),%rsi
lea    0xdb1(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
movl   $0x1,-0x4(%rbp)
jmp    14e4 <main+0x354>
mov    -0x38(%rbp),%rdi
mov    -0x40(%rbp),%rdx
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
call   10b0 <fwrite@plt>
cmp    -0x40(%rbp),%rax
je     14b3 <main+0x323>
mov    -0x28(%rbp),%rsi
lea    0xd94(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1070 <close@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
movl   $0x1,-0x4(%rbp)
jmp    14e4 <main+0x354>
mov    -0x28(%rbp),%rsi
mov    -0x40(%rbp),%rax
mov    %eax,%edx
lea    0xd81(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rdi
call   1070 <close@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
cmp    $0x1,%edi
jg     11cc <main+0x2c>
lea    0x1092(%rip),%rdi
call   1040 <puts@plt>
lea    0xe40(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
jmp    126c <main+0xcc>
mov    0x8(%rsi),%rbp
mov    %rbp,%r14
cmp    $0x2,%edi
je     11dc <main+0x3c>
mov    0x10(%rsi),%r14
mov    $0x100000,%edi
call   10a0 <malloc@plt>
test   %rax,%rax
je     1245 <main+0xa5>
mov    %rax,%r12
lea    0xe6c(%rip),%rsi
mov    %rbp,%rdi
call   10b0 <fopen@plt>
test   %rax,%rax
je     1253 <main+0xb3>
mov    %rax,%rbx
mov    %r12,%rdi
mov    $0x1,%esi
mov    $0x100000,%edx
mov    %rax,%rcx
call   1060 <fread@plt>
mov    %rax,%r15
mov    %rbx,%rdi
call   1050 <ferror@plt>
test   %rax,%rax
je     127a <main+0xda>
lea    0xe5c(%rip),%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %rbx,%rdi
call   1080 <close@plt>
jmp    1264 <main+0xc4>
lea    0xf88(%rip),%rdi
call   1040 <puts@plt>
jmp    126c <main+0xcc>
lea    0xe0a(%rip),%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %r12,%rdi
call   1030 <free@plt>
mov    $0x1,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %rbx,%rdi
call   1090 <feof@plt>
test   %eax,%eax
je     135f <main+0x1bf>
lea    0xe79(%rip),%rdi
mov    %rbp,%rsi
mov    %r15d,%edx
xor    %eax,%eax
call   1070 <printf@plt>
mov    %rbx,%rdi
call   1080 <close@plt>
mov    (%r12),%ebp
lea    0xe85(%rip),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    %ebp,%edx
xor    %eax,%eax
call   1070 <printf@plt>
mov    0x4(%r12),%edx
add    %edx,%ebp
mov    %rbx,%rdi
mov    $0x1,%esi
xor    %eax,%eax
call   1070 <printf@plt>
mov    0x8(%r12),%edx
add    %edx,%ebp
mov    %rbx,%rdi
mov    $0x2,%esi
xor    %eax,%eax
call   1070 <printf@plt>
mov    0xc(%r12),%edx
add    %edx,%ebp
mov    %rbx,%rdi
mov    $0x3,%esi
xor    %eax,%eax
call   1070 <printf@plt>
mov    0x10(%r12),%edx
add    %edx,%ebp
mov    %rbx,%rdi
mov    $0x4,%esi
xor    %eax,%eax
call   1070 <printf@plt>
mov    0x14(%r12),%edx
add    %edx,%ebp
mov    %rbx,%rdi
mov    $0x5,%esi
xor    %eax,%eax
call   1070 <printf@plt>
mov    0x18(%r12),%edx
add    %edx,%ebp
mov    %rbx,%rdi
mov    $0x6,%esi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %ebp,%esi
neg    %esi
cmp    %esi,0x1c(%r12)
jne    137a <main+0x1da>
lea    0xeab(%rip),%rdi
call   1040 <puts@plt>
jmp    1264 <main+0xc4>
lea    0xd47(%rip),%rdi
mov    %rbp,%rsi
mov    $0x100000,%edx
xor    %eax,%eax
call   1070 <printf@plt>
jmp    123b <main+0x9b>
mov    %esi,0x1c(%r12)
lea    0xdbc(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
add    0x1c(%r12),%ebp
lea    0xdb4(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xdbc(%rip),%rsi
mov    %r14,%rdi
call   10b0 <fopen@plt>
test   %rax,%rax
je     13fa <main+0x25a>
mov    %rax,%rbx
mov    %r12,%rdi
mov    $0x1,%esi
mov    %r15,%rdx
mov    %rax,%rcx
call   10c0 <fwrite@plt>
cmp    %r15,%rax
jne    1409 <main+0x269>
lea    0xddd(%rip),%rdi
mov    %r14,%rsi
mov    %r15d,%edx
xor    %eax,%eax
call   1070 <printf@plt>
mov    %r12,%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
call   1080 <close@plt>
jmp    126c <main+0xcc>
lea    0xd67(%rip),%rdi
mov    %r14,%rsi
jmp    125d <main+0xbd>
lea    0xd82(%rip),%rdi
mov    %r14,%rsi
jmp    1234 <main+0x94>

LLVM IR (-O0):
@.str = [28 x i8] c"Error: Input file required\0A\00"
@.str.1 = [97 x i8] c"Usage:\0A\09LPC-Checksum-Inseter InputFile.bin\0Aor\0A\09LPC-Checksum-Inseter InputFile.bin OutputFile.bin\00"
@.str.2 = [45 x i8] c"Error: unable to allocate memory for buffer\0A\00"
@.str.3 = [3 x i8] c"rb\00"
@.str.4 = [41 x i8] c"Error: unable to open file %s for input\0A\00"
@.str.5 = [32 x i8] c"Error: failed to read file: %s\0A\00"
@.str.6 = [93 x i8] c"The input file %s is too large for this application. The maximum size supported is %d bytes\0A\00"
@.str.7 = [44 x i8] c"Input file %s has been read. Size %d bytes\0A\00"
@.str.8 = [12 x i8] c"%d: 0x%08x\0A\00"
@.str.9 = [71 x i8] c"Checksum already set to correct value. Exiting without changing file\0A\00"
@.str.10 = [11 x i8] c"7: 0x%08x\0A\00"
@.str.11 = [24 x i8] c"checksum total: 0x%08x\0A\00"
@.str.12 = [3 x i8] c"wb\00"
@.str.13 = [42 x i8] c"Error: unable to open file %s for output\0A\00"
@.str.14 = [35 x i8] c"Error: unable to write to file %s\0A\00"
@.str.15 = [31 x i8] c"File %s written with %d bytes\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32*
%12 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32* null, i32** %6
%13 = load i32, i32* %4
%14 = icmp slt i32 %13, 2
br i1 %14, label %15, label %18
15: ; preds = %2
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([97 x i8], [97 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %3
br label %161
18: ; preds = %2
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 1
%21 = load i8*, i8** %20
store i8* %21, i8** %7
%22 = load i32, i32* %4
%23 = icmp eq i32 %22, 2
br i1 %23, label %24, label %26
24: ; preds = %18
%25 = load i8*, i8** %7
store i8* %25, i8** %8
br label %30
26: ; preds = %18
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 2
%29 = load i8*, i8** %28
store i8* %29, i8** %8
br label %30
30: ; preds = %26, %24
%31 = call i64 @malloc(i32 1048576)
%32 = inttoptr i64 %31 to i32*
store i32* %32, i32** %11
%33 = load i32*, i32** %11
%34 = icmp ne i32* %33, null
br i1 %34, label %37, label %35
35: ; preds = %30
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %3
br label %161
37: ; preds = %30
%38 = load i8*, i8** %7
%39 = call i32* @fopen(i8* %38, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
store i32* %39, i32** %6
%40 = load i32*, i32** %6
%41 = icmp eq i32* %40, null
br i1 %41, label %42, label %47
42: ; preds = %37
%43 = load i8*, i8** %7
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.4, i64 0, i64 0), i8* %43)
%45 = load i32*, i32** %11
%46 = call i32 @free(i32* %45)
store i32 1, i32* %3
br label %161
47: ; preds = %37
%48 = load i32*, i32** %11
%49 = bitcast i32* %48 to i8*
%50 = load i32*, i32** %6
%51 = call i64 @fread(i8* %49, i32 1, i32 1048576, i32* %50)
store i64 %51, i64* %12
%52 = load i32*, i32** %6
%53 = call i64 @ferror(i32* %52)
%54 = icmp ne i64 %53, 0
br i1 %54, label %55, label %62
55: ; preds = %47
%56 = load i8*, i8** %7
%57 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.5, i64 0, i64 0), i8* %56)
%58 = load i32*, i32** %6
%59 = call i32 @close(i32* %58)
%60 = load i32*, i32** %11
%61 = call i32 @free(i32* %60)
store i32 1, i32* %3
br label %161
62: ; preds = %47
%63 = load i32*, i32** %6
%64 = call i32 @feof(i32* %63)
%65 = icmp ne i32 %64, 0
br i1 %65, label %73, label %66
66: ; preds = %62
%67 = load i8*, i8** %7
%68 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([93 x i8], [93 x i8]* @.str.6, i64 0, i64 0), i8* %67, i32 1048576)
%69 = load i32*, i32** %6
%70 = call i32 @close(i32* %69)
%71 = load i32*, i32** %11
%72 = call i32 @free(i32* %71)
store i32 1, i32* %3
br label %161
73: ; preds = %62
%74 = load i8*, i8** %7
%75 = load i64, i64* %12
%76 = trunc i64 %75 to i32
%77 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.7, i64 0, i64 0), i8* %74, i32 %76)
%78 = load i32*, i32** %6
%79 = call i32 @close(i32* %78)
store i32 0, i32* %10
store i32 0, i32* %9
br label %80
80: ; preds = %98, %73
%81 = load i32, i32* %9
%82 = icmp slt i32 %81, 7
br i1 %82, label %83, label %101
83: ; preds = %80
%84 = load i32*, i32** %11
%85 = load i32, i32* %9
%86 = sext i32 %85 to i64
%87 = getelementptr inbounds i32, i32* %84, i64 %86
%88 = load i32, i32* %87
%89 = load i32, i32* %10
%90 = add i32 %89, %88
store i32 %90, i32* %10
%91 = load i32, i32* %9
%92 = load i32*, i32** %11
%93 = load i32, i32* %9
%94 = sext i32 %93 to i64
%95 = getelementptr inbounds i32, i32* %92, i64 %94
%96 = load i32, i32* %95
%97 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.8, i64 0, i64 0), i32 %91, i32 %96)
br label %98
98: ; preds = %83
%99 = load i32, i32* %9
%100 = add nsw i32 %99, 1
store i32 %100, i32* %9
br label %80
101: ; preds = %80
%102 = load i32*, i32** %11
%103 = getelementptr inbounds i32, i32* %102, i64 7
%104 = load i32, i32* %103
%105 = load i32, i32* %10
%106 = sub i32 -1, %105
%107 = add i32 %106, 1
%108 = icmp eq i32 %104, %107
br i1 %108, label %109, label %113
109: ; preds = %101
%110 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([71 x i8], [71 x i8]* @.str.9, i64 0, i64 0))
%111 = load i32*, i32** %11
%112 = call i32 @free(i32* %111)
store i32 1, i32* %3
br label %161
113: ; preds = %101
%114 = load i32, i32* %10
%115 = sub i32 -1, %114
%116 = add i32 %115, 1
%117 = load i32*, i32** %11
%118 = getelementptr inbounds i32, i32* %117, i64 7
store i32 %116, i32* %118
%119 = load i32*, i32** %11
%120 = getelementptr inbounds i32, i32* %119, i64 7
%121 = load i32, i32* %120
%122 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.10, i64 0, i64 0), i32 %121)
%123 = load i32, i32* %10
%124 = load i32*, i32** %11
%125 = getelementptr inbounds i32, i32* %124, i64 7
%126 = load i32, i32* %125
%127 = add i32 %123, %126
%128 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.11, i64 0, i64 0), i32 %127)
%129 = load i8*, i8** %8
%130 = call i32* @fopen(i8* %129, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.12, i64 0, i64 0))
store i32* %130, i32** %6
%131 = load i32*, i32** %6
%132 = icmp ne i32* %131, null
br i1 %132, label %138, label %133
133: ; preds = %113
%134 = load i8*, i8** %8
%135 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.13, i64 0, i64 0), i8* %134)
%136 = load i32*, i32** %11
%137 = call i32 @free(i32* %136)
store i32 1, i32* %3
br label %161
138: ; preds = %113
%139 = load i32*, i32** %11
%140 = load i64, i64* %12
%141 = load i32*, i32** %6
%142 = call i64 @fwrite(i32* %139, i32 1, i64 %140, i32* %141)
%143 = load i64, i64* %12
%144 = icmp ne i64 %142, %143
br i1 %144, label %145, label %152
145: ; preds = %138
%146 = load i8*, i8** %8
%147 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.14, i64 0, i64 0), i8* %146)
%148 = load i32*, i32** %6
%149 = call i32 @close(i32* %148)
%150 = load i32*, i32** %11
%151 = call i32 @free(i32* %150)
store i32 1, i32* %3
br label %161
152: ; preds = %138
%153 = load i8*, i8** %8
%154 = load i64, i64* %12
%155 = trunc i64 %154 to i32
%156 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.15, i64 0, i64 0), i8* %153, i32 %155)
%157 = load i32*, i32** %11
%158 = call i32 @free(i32* %157)
%159 = load i32*, i32** %6
%160 = call i32 @close(i32* %159)
store i32 1, i32* %3
br label %161
161: ; preds = %152, %145, %133, %109, %66, %55, %42, %35, %15
%162 = load i32, i32* %3
ret i32 %162
}

LLVM IR (-O2):
@.str.1 = [97 x i8] c"Usage:\0A\09LPC-Checksum-Inseter InputFile.bin\0Aor\0A\09LPC-Checksum-Inseter InputFile.bin OutputFile.bin\00"
@.str.3 = [3 x i8] c"rb\00"
@.str.4 = [41 x i8] c"Error: unable to open file %s for input\0A\00"
@.str.5 = [32 x i8] c"Error: failed to read file: %s\0A\00"
@.str.6 = [93 x i8] c"The input file %s is too large for this application. The maximum size supported is %d bytes\0A\00"
@.str.7 = [44 x i8] c"Input file %s has been read. Size %d bytes\0A\00"
@.str.8 = [12 x i8] c"%d: 0x%08x\0A\00"
@.str.10 = [11 x i8] c"7: 0x%08x\0A\00"
@.str.11 = [24 x i8] c"checksum total: 0x%08x\0A\00"
@.str.12 = [3 x i8] c"wb\00"
@.str.13 = [42 x i8] c"Error: unable to open file %s for output\0A\00"
@.str.14 = [35 x i8] c"Error: unable to write to file %s\0A\00"
@.str.15 = [31 x i8] c"File %s written with %d bytes\0A\00"
@str = [44 x i8] c"Error: unable to allocate memory for buffer\00"
@str.16 = [70 x i8] c"Checksum already set to correct value. Exiting without changing file\00"
@str.17 = [27 x i8] c"Error: Input file required\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %4, label %7
4: ; preds = %2
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str.17, i64 0, i64 0))
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([97 x i8], [97 x i8]* @.str.1, i64 0, i64 0))
br label %101
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = icmp eq i32 %0, 2
br i1 %10, label %14, label %11
11: ; preds = %7
%12 = getelementptr inbounds i8*, i8** %1, i64 2
%13 = load i8*, i8** %12
br label %14
14: ; preds = %7, %11
%15 = phi i8* [ %13, %11 ], [ %9, %7 ]
%16 = tail call i64 @malloc(i32 1048576)
%17 = inttoptr i64 %16 to i32*
%18 = icmp eq i64 %16, 0
br i1 %18, label %19, label %21
19: ; preds = %14
%20 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @str, i64 0, i64 0))
br label %101
21: ; preds = %14
%22 = tail call i32* @fopen(i8* %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%23 = icmp eq i32* %22, null
br i1 %23, label %24, label %27
24: ; preds = %21
%25 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @.str.4, i64 0, i64 0), i8* %9)
%26 = tail call i32 @free(i32* %17)
br label %101
27: ; preds = %21
%28 = inttoptr i64 %16 to i8*
%29 = tail call i64 @fread(i8* %28, i32 1, i32 1048576, i32* %22)
%30 = tail call i64 @ferror(i32* %22)
%31 = icmp eq i64 %30, 0
br i1 %31, label %36, label %32
32: ; preds = %27
%33 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.5, i64 0, i64 0), i8* %9)
%34 = tail call i32 @close(i32* %22)
%35 = tail call i32 @free(i32* %17)
br label %101
36: ; preds = %27
%37 = tail call i32 @feof(i32* %22)
%38 = icmp eq i32 %37, 0
br i1 %38, label %39, label %43
39: ; preds = %36
%40 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([93 x i8], [93 x i8]* @.str.6, i64 0, i64 0), i8* %9, i32 1048576)
%41 = tail call i32 @close(i32* %22)
%42 = tail call i32 @free(i32* %17)
br label %101
43: ; preds = %36
%44 = trunc i64 %29 to i32
%45 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @.str.7, i64 0, i64 0), i8* %9, i32 %44)
%46 = tail call i32 @close(i32* %22)
%47 = load i32, i32* %17
%48 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.8, i64 0, i64 0), i32 0, i32 %47)
%49 = getelementptr inbounds i32, i32* %17, i64 1
%50 = load i32, i32* %49
%51 = add i32 %50, %47
%52 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.8, i64 0, i64 0), i32 1, i32 %50)
%53 = getelementptr inbounds i32, i32* %17, i64 2
%54 = load i32, i32* %53
%55 = add i32 %54, %51
%56 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.8, i64 0, i64 0), i32 2, i32 %54)
%57 = getelementptr inbounds i32, i32* %17, i64 3
%58 = load i32, i32* %57
%59 = add i32 %58, %55
%60 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.8, i64 0, i64 0), i32 3, i32 %58)
%61 = getelementptr inbounds i32, i32* %17, i64 4
%62 = load i32, i32* %61
%63 = add i32 %62, %59
%64 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.8, i64 0, i64 0), i32 4, i32 %62)
%65 = getelementptr inbounds i32, i32* %17, i64 5
%66 = load i32, i32* %65
%67 = add i32 %66, %63
%68 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.8, i64 0, i64 0), i32 5, i32 %66)
%69 = getelementptr inbounds i32, i32* %17, i64 6
%70 = load i32, i32* %69
%71 = add i32 %70, %67
%72 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.8, i64 0, i64 0), i32 6, i32 %70)
%73 = getelementptr inbounds i32, i32* %17, i64 7
%74 = load i32, i32* %73
%75 = sub i32 0, %71
%76 = icmp eq i32 %74, %75
br i1 %76, label %77, label %80
77: ; preds = %43
%78 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([70 x i8], [70 x i8]* @str.16, i64 0, i64 0))
%79 = tail call i32 @free(i32* %17)
br label %101
80: ; preds = %43
store i32 %75, i32* %73
%81 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.10, i64 0, i64 0), i32 %75)
%82 = load i32, i32* %73
%83 = add i32 %82, %71
%84 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.11, i64 0, i64 0), i32 %83)
%85 = tail call i32* @fopen(i8* %15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.12, i64 0, i64 0))
%86 = icmp eq i32* %85, null
br i1 %86, label %87, label %90
87: ; preds = %80
%88 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str.13, i64 0, i64 0), i8* %15)
%89 = tail call i32 @free(i32* %17)
br label %101
90: ; preds = %80
%91 = tail call i64 @fwrite(i32* %17, i32 1, i64 %29, i32* %85)
%92 = icmp eq i64 %91, %29
br i1 %92, label %97, label %93
93: ; preds = %90
%94 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.14, i64 0, i64 0), i8* %15)
%95 = tail call i32 @close(i32* %85)
%96 = tail call i32 @free(i32* %17)
br label %101
97: ; preds = %90
%98 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.15, i64 0, i64 0), i8* %15, i32 %44)
%99 = tail call i32 @free(i32* %17)
%100 = tail call i32 @close(i32* %85)
br label %101
101: ; preds = %97, %93, %87, %77, %39, %32, %24, %19, %4
ret i32 1
}