#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 EOF;
int /*<<< orphan*/ SEEK_CUR;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fputc(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fread(unsigned char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int, int /*<<< orphan*/);
int /*<<< orphan*/ fwrite(unsigned char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ memcpy(unsigned char *, unsigned char *, int);
int /*<<< orphan*/ memset(unsigned char *, int /*<<< orphan*/, int);
int open_error(char *, char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ strncmp(unsigned char *, char *, int);
int main(int argc, char **argv) {
  int c;
  int section_count;
  FILE *in, *out;
  unsigned char section_header[40];
  if (argc < 2 || argc > 3) {
    printf("Fixes MS Win32 object files to be compatible with the incorrect\n");
    printf(" implementation in MinGW32.\n");
    printf("Usage: objfix infile [outfile]\n");
    return 1;
  }
  in = fopen(argv[1], (argc == 2 ? "rb+" : "rb"));
  if (!in)
    return open_error(argv[1], (argc == 2 ? "read" : "update"));
  if (argc == 3) {
    out = fopen(argv[2], "wb");
    if (!out)
      return open_error(argv[1], (argc == 2 ? "read" : "update"));
  } else {
    out = NULL;
  }
  if (out) {
    fputc(fgetc(in), out);
    fputc(fgetc(in), out);
    fputc(section_count = fgetc(in), out);
    fputc(c = fgetc(in), out);
    section_count += c << 8;
    for (c = 4; c < 0x14; c++) {
      fputc(fgetc(in), out);
    }
    for (c = 0; c < section_count; c++) {
      fread(section_header, 1, 40, in);
      if (!strncmp(section_header, ".bss", 8)) {
        memcpy(section_header + 8, section_header + 16, 4);
        memset(section_header + 16, 0, 4);
      } else {
        memset(section_header + 8, 0, 4);
      }
      fwrite(section_header, 1, 40, out);
    }
    while ((c = fgetc(in)) != EOF) {
      fputc(c, out);
    }
  } else {
    fgetc(in);
    fgetc(in);
    section_count = fgetc(in);
    section_count += fgetc(in) << 8;
    fseek(in, 0x14, SEEK_SET);
    for (c = 0; c < section_count; c++) {
      fread(section_header, 1, 40, in);
      fseek(in, -40, SEEK_CUR);
      if (!strncmp(section_header, ".bss", 8)) {
        memcpy(section_header + 8, section_header + 16, 4);
        memset(section_header + 16, 0, 4);
      } else {
        memset(section_header + 8, 0, 4);
      }
      fwrite(section_header, 1, 40, in);
      fseek(in, 0, SEEK_CUR);
    }
  }
  fclose(in);
  if (out)
    fclose(out);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jl     11ea <main+0x2a>
cmpl   $0x3,-0x8(%rbp)
jle    121a <main+0x5a>
lea    0xe0f(%rip),%rdi
call   1060 <printf@plt>
lea    0xe44(%rip),%rdi
call   1060 <printf@plt>
lea    0xe55(%rip),%rdi
call   1060 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    15bb <main+0x3fb>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x8(%rbp),%ecx
lea    0xe56(%rip),%rsi
lea    0xe4b(%rip),%rax
cmp    $0x2,%ecx
cmove  %rax,%rsi
call   10d0 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    127b <main+0xbb>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x8(%rbp),%ecx
lea    0xe2a(%rip),%rsi
lea    0xe1e(%rip),%rax
cmp    $0x2,%ecx
cmove  %rax,%rsi
call   1070 <open_error@plt>
mov    %eax,-0x4(%rbp)
jmp    15bb <main+0x3fb>
cmpl   $0x3,-0x8(%rbp)
jne    12da <main+0x11a>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xdfd(%rip),%rsi
call   10d0 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    12d5 <main+0x115>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x8(%rbp),%ecx
lea    0xdd0(%rip),%rsi
lea    0xdc4(%rip),%rax
cmp    $0x2,%ecx
cmove  %rax,%rsi
call   1070 <open_error@plt>
mov    %eax,-0x4(%rbp)
jmp    15bb <main+0x3fb>
jmp    12e2 <main+0x122>
movq   $0x0,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     146c <main+0x2ac>
mov    -0x20(%rbp),%rdi
call   1090 <fgetc@plt>
mov    %eax,%edi
mov    -0x28(%rbp),%rsi
call   10a0 <fputc@plt>
mov    -0x20(%rbp),%rdi
call   1090 <fgetc@plt>
mov    %eax,%edi
mov    -0x28(%rbp),%rsi
call   10a0 <fputc@plt>
mov    -0x20(%rbp),%rdi
call   1090 <fgetc@plt>
mov    %eax,%edi
mov    %edi,-0x18(%rbp)
mov    -0x28(%rbp),%rsi
call   10a0 <fputc@plt>
mov    -0x20(%rbp),%rdi
call   1090 <fgetc@plt>
mov    %eax,%edi
mov    %edi,-0x14(%rbp)
mov    -0x28(%rbp),%rsi
call   10a0 <fputc@plt>
mov    -0x14(%rbp),%eax
shl    $0x8,%eax
add    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
movl   $0x4,-0x14(%rbp)
cmpl   $0x14,-0x14(%rbp)
jge    1382 <main+0x1c2>
mov    -0x20(%rbp),%rdi
call   1090 <fgetc@plt>
mov    %eax,%edi
mov    -0x28(%rbp),%rsi
call   10a0 <fputc@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1356 <main+0x196>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    1436 <main+0x276>
lea    -0x50(%rbp),%rdi
mov    -0x20(%rbp),%rcx
mov    $0x1,%esi
mov    $0x28,%edx
call   1040 <fread@plt>
lea    -0x50(%rbp),%rdi
lea    0xcdd(%rip),%rsi
mov    $0x8,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    13fd <main+0x23d>
lea    -0x50(%rbp),%rdi
add    $0x8,%rdi
lea    -0x50(%rbp),%rsi
add    $0x10,%rsi
mov    $0x4,%edx
call   10b0 <memcpy@plt>
lea    -0x50(%rbp),%rdi
add    $0x10,%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1080 <memset@plt>
jmp    1411 <main+0x251>
lea    -0x50(%rbp),%rdi
add    $0x8,%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1080 <memset@plt>
lea    -0x50(%rbp),%rdi
mov    -0x28(%rbp),%rcx
mov    $0x1,%esi
mov    $0x28,%edx
call   10e0 <fwrite@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1389 <main+0x1c9>
jmp    143b <main+0x27b>
mov    -0x20(%rbp),%rdi
call   1090 <fgetc@plt>
mov    %eax,-0x14(%rbp)
mov    0x2b92(%rip),%rcx
cmp    (%rcx),%eax
je     1467 <main+0x2a7>
mov    -0x14(%rbp),%edi
mov    -0x28(%rbp),%rsi
call   10a0 <fputc@plt>
jmp    143b <main+0x27b>
jmp    1597 <main+0x3d7>
mov    -0x20(%rbp),%rdi
call   1090 <fgetc@plt>
mov    -0x20(%rbp),%rdi
call   1090 <fgetc@plt>
mov    -0x20(%rbp),%rdi
call   1090 <fgetc@plt>
mov    %eax,-0x18(%rbp)
mov    -0x20(%rbp),%rdi
call   1090 <fgetc@plt>
shl    $0x8,%eax
add    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x20(%rbp),%rdi
mov    0x2b29(%rip),%rax
mov    (%rax),%edx
mov    $0x14,%esi
call   10c0 <fseek@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    1592 <main+0x3d2>
lea    -0x50(%rbp),%rdi
mov    -0x20(%rbp),%rcx
mov    $0x1,%esi
mov    $0x28,%edx
call   1040 <fread@plt>
mov    -0x20(%rbp),%rdi
mov    0x2b00(%rip),%rax
mov    (%rax),%edx
mov    $0xffffffd8,%esi
call   10c0 <fseek@plt>
lea    -0x50(%rbp),%rdi
lea    0xb95(%rip),%rsi
mov    $0x8,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    1545 <main+0x385>
lea    -0x50(%rbp),%rdi
add    $0x8,%rdi
lea    -0x50(%rbp),%rsi
add    $0x10,%rsi
mov    $0x4,%edx
call   10b0 <memcpy@plt>
lea    -0x50(%rbp),%rdi
add    $0x10,%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1080 <memset@plt>
jmp    1559 <main+0x399>
lea    -0x50(%rbp),%rdi
add    $0x8,%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1080 <memset@plt>
lea    -0x50(%rbp),%rdi
mov    -0x20(%rbp),%rcx
mov    $0x1,%esi
mov    $0x28,%edx
call   10e0 <fwrite@plt>
mov    -0x20(%rbp),%rdi
mov    0x2a6d(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   10c0 <fseek@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    14ba <main+0x2fa>
jmp    1597 <main+0x3d7>
mov    -0x20(%rbp),%rdi
call   1050 <fclose@plt>
cmpq   $0x0,-0x28(%rbp)
je     15b4 <main+0x3f4>
mov    -0x28(%rbp),%rdi
call   1050 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %edi,%ebp
lea    -0x4(%rbp),%eax
cmp    $0xfffffffd,%eax
ja     1206 <main+0x46>
lea    0xe3c(%rip),%rdi
call   1040 <puts@plt>
lea    0xe70(%rip),%rdi
call   1040 <puts@plt>
lea    0xe80(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%eax
jmp    1618 <main+0x458>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
cmp    $0x2,%ebp
lea    0xde9(%rip),%rax
lea    0xde6(%rip),%rsi
cmove  %rax,%rsi
call   10d0 <fopen@plt>
test   %rax,%rax
je     1496 <main+0x2d6>
mov    %rax,%r12
cmp    $0x3,%ebp
jne    14c2 <main+0x302>
mov    0x10(%rbx),%rdi
lea    0xdcc(%rip),%rsi
call   10d0 <fopen@plt>
test   %rax,%rax
je     1496 <main+0x2d6>
mov    %rax,%r14
mov    %r12,%rdi
call   1090 <fgetc@plt>
mov    %eax,%edi
mov    %r14,%rsi
call   10a0 <fputc@plt>
mov    %r12,%rdi
call   1090 <fgetc@plt>
mov    %eax,%edi
mov    %r14,%rsi
call   10a0 <fputc@plt>
mov    %r12,%rdi
call   1090 <fgetc@plt>
mov    %r14,0x8(%rsp)
mov    %eax,%r15d
mov    %eax,%edi
mov    0x8(%rsp),%rsi
call   10a0 <fputc@plt>
mov    %r12,%rdi
call   1090 <fgetc@plt>
mov    %eax,%r14d
mov    %eax,%edi
mov    0x8(%rsp),%rsi
call   10a0 <fputc@plt>
shl    $0x8,%r14d
mov    %r12,%rdi
call   1090 <fgetc@plt>
mov    %eax,%edi
mov    0x8(%rsp),%rsi
call   10a0 <fputc@plt>
mov    %r12,%rdi
call   1090 <fgetc@plt>
mov    %eax,%edi
mov    0x8(%rsp),%rsi
call   10a0 <fputc@plt>
mov    %r12,%rdi
call   1090 <fgetc@plt>
mov    %eax,%edi
mov    0x8(%rsp),%rsi
call   10a0 <fputc@plt>
mov    %r12,%rdi
call   1090 <fgetc@plt>
mov    %eax,%edi
mov    0x8(%rsp),%rsi
call   10a0 <fputc@plt>
mov    %r12,%rdi
call   1090 <fgetc@plt>
mov    %eax,%edi
mov    0x8(%rsp),%rsi
call   10a0 <fputc@plt>
mov    %r12,%rdi
call   1090 <fgetc@plt>
mov    %eax,%edi
mov    0x8(%rsp),%rsi
call   10a0 <fputc@plt>
mov    %r12,%rdi
call   1090 <fgetc@plt>
mov    %eax,%edi
mov    0x8(%rsp),%rsi
call   10a0 <fputc@plt>
mov    %r12,%rdi
call   1090 <fgetc@plt>
mov    %eax,%edi
mov    0x8(%rsp),%rsi
call   10a0 <fputc@plt>
mov    %r12,%rdi
call   1090 <fgetc@plt>
mov    %eax,%edi
mov    0x8(%rsp),%rsi
call   10a0 <fputc@plt>
mov    %r12,%rdi
call   1090 <fgetc@plt>
mov    %eax,%edi
mov    0x8(%rsp),%rsi
call   10a0 <fputc@plt>
mov    %r12,%rdi
call   1090 <fgetc@plt>
mov    %eax,%edi
mov    0x8(%rsp),%rsi
call   10a0 <fputc@plt>
mov    %r12,%rdi
call   1090 <fgetc@plt>
mov    %eax,%edi
mov    0x8(%rsp),%rsi
call   10a0 <fputc@plt>
mov    %r12,%rdi
call   1090 <fgetc@plt>
mov    %eax,%edi
mov    0x8(%rsp),%rsi
call   10a0 <fputc@plt>
mov    %r12,%rdi
call   1090 <fgetc@plt>
mov    %eax,%edi
mov    0x8(%rsp),%rsi
call   10a0 <fputc@plt>
mov    %r12,%rdi
call   1090 <fgetc@plt>
mov    %eax,%edi
mov    0x8(%rsp),%rsi
call   10a0 <fputc@plt>
mov    %r12,%rdi
call   1090 <fgetc@plt>
mov    %eax,%edi
mov    0x8(%rsp),%rsi
call   10a0 <fputc@plt>
add    %r15d,%r14d
mov    0x8(%rsp),%r15
test   %r14d,%r14d
jle    15d8 <main+0x418>
lea    0x18(%rsp),%rbp
lea    0x10(%rsp),%r13
lea    0xc01(%rip),%rbx
jmp    144b <main+0x28b>
nopw   0x0(%rax,%rax,1)
xor    %esi,%esi
mov    $0x4,%edx
call   1080 <memset@plt>
mov    %r13,%rdi
mov    $0x1,%esi
mov    $0x28,%edx
mov    %r15,%rcx
call   10e0 <fwrite@plt>
add    $0xffffffff,%r14d
je     15d8 <main+0x418>
mov    %r13,%rdi
mov    $0x1,%esi
mov    $0x28,%edx
mov    %r12,%rcx
call   1050 <fread@plt>
mov    %r13,%rdi
mov    %rbx,%rsi
mov    $0x8,%edx
call   1030 <strncmp@plt>
mov    %rbp,%rdi
test   %eax,%eax
jne    1420 <main+0x260>
mov    %rbp,%rdi
lea    0x20(%rsp),%r15
mov    %r15,%rsi
mov    $0x4,%edx
call   10b0 <memcpy@plt>
mov    %r15,%rdi
mov    0x8(%rsp),%r15
jmp    1420 <main+0x260>
cmp    $0x2,%ebp
mov    0x8(%rbx),%rdi
lea    0xb63(%rip),%rax
lea    0xb61(%rip),%rsi
cmove  %rax,%rsi
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1070 <open_error@plt>
mov    %r12,%rdi
call   1090 <fgetc@plt>
mov    %r12,%rdi
call   1090 <fgetc@plt>
mov    %r12,%rdi
call   1090 <fgetc@plt>
mov    %eax,%ebx
mov    %r12,%rdi
call   1090 <fgetc@plt>
mov    %eax,%ebp
shl    $0x8,%ebp
add    %ebx,%ebp
mov    0x2ade(%rip),%rax
mov    (%rax),%edx
mov    %r12,%rdi
mov    $0x14,%esi
call   10c0 <fseek@plt>
test   %ebp,%ebp
jle    15d3 <main+0x413>
lea    0x18(%rsp),%r13
lea    0x10(%rsp),%r14
mov    0x2ace(%rip),%r15
lea    0xaf5(%rip),%rbx
jmp    1563 <main+0x3a3>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
xor    %esi,%esi
mov    $0x4,%edx
call   1080 <memset@plt>
mov    %r14,%rdi
mov    $0x1,%esi
mov    $0x28,%edx
mov    %r12,%rcx
call   10e0 <fwrite@plt>
mov    (%r15),%edx
mov    %r12,%rdi
xor    %esi,%esi
call   10c0 <fseek@plt>
add    $0xffffffff,%ebp
je     15d3 <main+0x413>
mov    %r14,%rdi
mov    $0x1,%esi
mov    $0x28,%edx
mov    %r12,%rcx
call   1050 <fread@plt>
mov    (%r15),%edx
mov    %r12,%rdi
mov    $0xffffffd8,%esi
call   10c0 <fseek@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    $0x8,%edx
call   1030 <strncmp@plt>
mov    %r13,%rdi
test   %eax,%eax
jne    1530 <main+0x370>
mov    %r13,%rdi
mov    %r12,%r14
mov    %r15,%r12
mov    %r13,%r15
lea    0x20(%rsp),%r13
mov    %r13,%rsi
mov    $0x4,%edx
call   10b0 <memcpy@plt>
mov    %r13,%rdi
mov    %r15,%r13
mov    %r12,%r15
mov    %r14,%r12
lea    0x10(%rsp),%r14
jmp    1530 <main+0x370>
mov    %r12,%rdi
jmp    1611 <main+0x451>
mov    %r12,%rdi
call   1090 <fgetc@plt>
mov    0x29f9(%rip),%rbx
cmp    (%rbx),%eax
je     1606 <main+0x446>
nopl   0x0(%rax,%rax,1)
mov    %eax,%edi
mov    %r15,%rsi
call   10a0 <fputc@plt>
mov    %r12,%rdi
call   1090 <fgetc@plt>
cmp    (%rbx),%eax
jne    15f0 <main+0x430>
mov    %r12,%rdi
call   1060 <fclose@plt>
mov    %r15,%rdi
call   1060 <fclose@plt>
xor    %eax,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [65 x i8] c"Fixes MS Win32 object files to be compatible with the incorrect\0A\00"
@.str.1 = [29 x i8] c" implementation in MinGW32.\0A\00"
@.str.2 = [32 x i8] c"Usage: objfix infile [outfile]\0A\00"
@.str.3 = [4 x i8] c"rb+\00"
@.str.4 = [3 x i8] c"rb\00"
@.str.5 = [5 x i8] c"read\00"
@.str.6 = [7 x i8] c"update\00"
@.str.7 = [3 x i8] c"wb\00"
@.str.8 = [5 x i8] c".bss\00"
@EOF = global i32 0
@SEEK_SET = global i32 0
@SEEK_CUR = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca [40 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* %4
%12 = icmp slt i32 %11, 2
br i1 %12, label %16, label %13
13: ; preds = %2
%14 = load i32, i32* %4
%15 = icmp sgt i32 %14, 3
br i1 %15, label %16, label %20
16: ; preds = %13, %2
%17 = call i32 @printf(i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str, i64 0, i64 0))
%18 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0))
%19 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %3
br label %201
20: ; preds = %13
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 1
%23 = load i8*, i8** %22
%24 = load i32, i32* %4
%25 = icmp eq i32 %24, 2
%26 = zext i1 %25 to i64
%27 = select i1 %25, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0)
%28 = call i32* @fopen(i8* %23, i8* %27)
store i32* %28, i32** %8
%29 = load i32*, i32** %8
%30 = icmp ne i32* %29, null
br i1 %30, label %40, label %31
31: ; preds = %20
%32 = load i8**, i8*** %5
%33 = getelementptr inbounds i8*, i8** %32, i64 1
%34 = load i8*, i8** %33
%35 = load i32, i32* %4
%36 = icmp eq i32 %35, 2
%37 = zext i1 %36 to i64
%38 = select i1 %36, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0)
%39 = call i32 @open_error(i8* %34, i8* %38)
store i32 %39, i32* %3
br label %201
40: ; preds = %20
%41 = load i32, i32* %4
%42 = icmp eq i32 %41, 3
br i1 %42, label %43, label %60
43: ; preds = %40
%44 = load i8**, i8*** %5
%45 = getelementptr inbounds i8*, i8** %44, i64 2
%46 = load i8*, i8** %45
%47 = call i32* @fopen(i8* %46, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0))
store i32* %47, i32** %9
%48 = load i32*, i32** %9
%49 = icmp ne i32* %48, null
br i1 %49, label %59, label %50
50: ; preds = %43
%51 = load i8**, i8*** %5
%52 = getelementptr inbounds i8*, i8** %51, i64 1
%53 = load i8*, i8** %52
%54 = load i32, i32* %4
%55 = icmp eq i32 %54, 2
%56 = zext i1 %55 to i64
%57 = select i1 %55, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0)
%58 = call i32 @open_error(i8* %53, i8* %57)
store i32 %58, i32* %3
br label %201
59: ; preds = %43
br label %61
60: ; preds = %40
store i32* null, i32** %9
br label %61
61: ; preds = %60, %59
%62 = load i32*, i32** %9
%63 = icmp ne i32* %62, null
br i1 %63, label %64, label %139
64: ; preds = %61
%65 = load i32*, i32** %8
%66 = call i32 @fgetc(i32* %65)
%67 = load i32*, i32** %9
%68 = call i32 @fputc(i32 %66, i32* %67)
%69 = load i32*, i32** %8
%70 = call i32 @fgetc(i32* %69)
%71 = load i32*, i32** %9
%72 = call i32 @fputc(i32 %70, i32* %71)
%73 = load i32*, i32** %8
%74 = call i32 @fgetc(i32* %73)
store i32 %74, i32* %7
%75 = load i32*, i32** %9
%76 = call i32 @fputc(i32 %74, i32* %75)
%77 = load i32*, i32** %8
%78 = call i32 @fgetc(i32* %77)
store i32 %78, i32* %6
%79 = load i32*, i32** %9
%80 = call i32 @fputc(i32 %78, i32* %79)
%81 = load i32, i32* %6
%82 = shl i32 %81, 8
%83 = load i32, i32* %7
%84 = add nsw i32 %83, %82
store i32 %84, i32* %7
store i32 4, i32* %6
br label %85
85: ; preds = %93, %64
%86 = load i32, i32* %6
%87 = icmp slt i32 %86, 20
br i1 %87, label %88, label %96
88: ; preds = %85
%89 = load i32*, i32** %8
%90 = call i32 @fgetc(i32* %89)
%91 = load i32*, i32** %9
%92 = call i32 @fputc(i32 %90, i32* %91)
br label %93
93: ; preds = %88
%94 = load i32, i32* %6
%95 = add nsw i32 %94, 1
store i32 %95, i32* %6
br label %85
96: ; preds = %85
store i32 0, i32* %6
br label %97
97: ; preds = %125, %96
%98 = load i32, i32* %6
%99 = load i32, i32* %7
%100 = icmp slt i32 %98, %99
br i1 %100, label %101, label %128
101: ; preds = %97
%102 = getelementptr inbounds [40 x i8], [40 x i8]* %10, i64 0, i64 0
%103 = load i32*, i32** %8
%104 = call i32 @fread(i8* %102, i32 1, i32 40, i32* %103)
%105 = getelementptr inbounds [40 x i8], [40 x i8]* %10, i64 0, i64 0
%106 = call i32 @strncmp(i8* %105, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0), i32 8)
%107 = icmp ne i32 %106, 0
br i1 %107, label %117, label %108
108: ; preds = %101
%109 = getelementptr inbounds [40 x i8], [40 x i8]* %10, i64 0, i64 0
%110 = getelementptr inbounds i8, i8* %109, i64 8
%111 = getelementptr inbounds [40 x i8], [40 x i8]* %10, i64 0, i64 0
%112 = getelementptr inbounds i8, i8* %111, i64 16
%113 = call i32 @memcpy(i8* %110, i8* %112, i32 4)
%114 = getelementptr inbounds [40 x i8], [40 x i8]* %10, i64 0, i64 0
%115 = getelementptr inbounds i8, i8* %114, i64 16
%116 = call i32 @memset(i8* %115, i32 0, i32 4)
br label %121
117: ; preds = %101
%118 = getelementptr inbounds [40 x i8], [40 x i8]* %10, i64 0, i64 0
%119 = getelementptr inbounds i8, i8* %118, i64 8
%120 = call i32 @memset(i8* %119, i32 0, i32 4)
br label %121
121: ; preds = %117, %108
%122 = getelementptr inbounds [40 x i8], [40 x i8]* %10, i64 0, i64 0
%123 = load i32*, i32** %9
%124 = call i32 @fwrite(i8* %122, i32 1, i32 40, i32* %123)
br label %125
125: ; preds = %121
%126 = load i32, i32* %6
%127 = add nsw i32 %126, 1
store i32 %127, i32* %6
br label %97
128: ; preds = %97
br label %129
129: ; preds = %134, %128
%130 = load i32*, i32** %8
%131 = call i32 @fgetc(i32* %130)
store i32 %131, i32* %6
%132 = load i32, i32* @EOF
%133 = icmp ne i32 %131, %132
br i1 %133, label %134, label %138
134: ; preds = %129
%135 = load i32, i32* %6
%136 = load i32*, i32** %9
%137 = call i32 @fputc(i32 %135, i32* %136)
br label %129
138: ; preds = %129
br label %192
139: ; preds = %61
%140 = load i32*, i32** %8
%141 = call i32 @fgetc(i32* %140)
%142 = load i32*, i32** %8
%143 = call i32 @fgetc(i32* %142)
%144 = load i32*, i32** %8
%145 = call i32 @fgetc(i32* %144)
store i32 %145, i32* %7
%146 = load i32*, i32** %8
%147 = call i32 @fgetc(i32* %146)
%148 = shl i32 %147, 8
%149 = load i32, i32* %7
%150 = add nsw i32 %149, %148
store i32 %150, i32* %7
%151 = load i32*, i32** %8
%152 = load i32, i32* @SEEK_SET
%153 = call i32 @fseek(i32* %151, i32 20, i32 %152)
store i32 0, i32* %6
br label %154
154: ; preds = %188, %139
%155 = load i32, i32* %6
%156 = load i32, i32* %7
%157 = icmp slt i32 %155, %156
br i1 %157, label %158, label %191
158: ; preds = %154
%159 = getelementptr inbounds [40 x i8], [40 x i8]* %10, i64 0, i64 0
%160 = load i32*, i32** %8
%161 = call i32 @fread(i8* %159, i32 1, i32 40, i32* %160)
%162 = load i32*, i32** %8
%163 = load i32, i32* @SEEK_CUR
%164 = call i32 @fseek(i32* %162, i32 -40, i32 %163)
%165 = getelementptr inbounds [40 x i8], [40 x i8]* %10, i64 0, i64 0
%166 = call i32 @strncmp(i8* %165, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0), i32 8)
%167 = icmp ne i32 %166, 0
br i1 %167, label %177, label %168
168: ; preds = %158
%169 = getelementptr inbounds [40 x i8], [40 x i8]* %10, i64 0, i64 0
%170 = getelementptr inbounds i8, i8* %169, i64 8
%171 = getelementptr inbounds [40 x i8], [40 x i8]* %10, i64 0, i64 0
%172 = getelementptr inbounds i8, i8* %171, i64 16
%173 = call i32 @memcpy(i8* %170, i8* %172, i32 4)
%174 = getelementptr inbounds [40 x i8], [40 x i8]* %10, i64 0, i64 0
%175 = getelementptr inbounds i8, i8* %174, i64 16
%176 = call i32 @memset(i8* %175, i32 0, i32 4)
br label %181
177: ; preds = %158
%178 = getelementptr inbounds [40 x i8], [40 x i8]* %10, i64 0, i64 0
%179 = getelementptr inbounds i8, i8* %178, i64 8
%180 = call i32 @memset(i8* %179, i32 0, i32 4)
br label %181
181: ; preds = %177, %168
%182 = getelementptr inbounds [40 x i8], [40 x i8]* %10, i64 0, i64 0
%183 = load i32*, i32** %8
%184 = call i32 @fwrite(i8* %182, i32 1, i32 40, i32* %183)
%185 = load i32*, i32** %8
%186 = load i32, i32* @SEEK_CUR
%187 = call i32 @fseek(i32* %185, i32 0, i32 %186)
br label %188
188: ; preds = %181
%189 = load i32, i32* %6
%190 = add nsw i32 %189, 1
store i32 %190, i32* %6
br label %154
191: ; preds = %154
br label %192
192: ; preds = %191, %138
%193 = load i32*, i32** %8
%194 = call i32 @fclose(i32* %193)
%195 = load i32*, i32** %9
%196 = icmp ne i32* %195, null
br i1 %196, label %197, label %200
197: ; preds = %192
%198 = load i32*, i32** %9
%199 = call i32 @fclose(i32* %198)
br label %200
200: ; preds = %197, %192
store i32 0, i32* %3
br label %201
201: ; preds = %200, %50, %31, %16
%202 = load i32, i32* %3
ret i32 %202
}

LLVM IR (-O2):
@.str.3 = [4 x i8] c"rb+\00"
@.str.4 = [3 x i8] c"rb\00"
@.str.5 = [5 x i8] c"read\00"
@.str.6 = [7 x i8] c"update\00"
@.str.7 = [3 x i8] c"wb\00"
@.str.8 = [5 x i8] c".bss\00"
@EOF = global i32 0
@SEEK_SET = global i32 0
@SEEK_CUR = global i32 0
@str = [64 x i8] c"Fixes MS Win32 object files to be compatible with the incorrect\00"
@str.9 = [28 x i8] c" implementation in MinGW32.\00"
@str.10 = [31 x i8] c"Usage: objfix infile [outfile]\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [40 x i8]
%4 = getelementptr inbounds [40 x i8], [40 x i8]* %3, i64 0, i64 0
%5 = add i32 %0, -4
%6 = icmp ult i32 %5, -2
br i1 %6, label %7, label %11
7: ; preds = %2
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([64 x i8], [64 x i8]* @str, i64 0, i64 0))
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str.9, i64 0, i64 0))
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str.10, i64 0, i64 0))
br label %138
11: ; preds = %2
%12 = getelementptr inbounds i8*, i8** %1, i64 1
%13 = load i8*, i8** %12
%14 = icmp eq i32 %0, 2
%15 = select i1 %14, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0)
%16 = tail call i32* @fopen(i8* %13, i8* %15)
%17 = icmp eq i32* %16, null
br i1 %17, label %18, label %22
18: ; preds = %11
%19 = load i8*, i8** %12
%20 = select i1 %14, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0)
%21 = tail call i32 @open_error(i8* %19, i8* %20)
br label %138
22: ; preds = %11
%23 = icmp eq i32 %0, 3
br i1 %23, label %24, label %103
24: ; preds = %22
%25 = getelementptr inbounds i8*, i8** %1, i64 2
%26 = load i8*, i8** %25
%27 = tail call i32* @fopen(i8* %26, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0))
%28 = icmp eq i32* %27, null
br i1 %28, label %29, label %33
29: ; preds = %24
%30 = load i8*, i8** %12
%31 = select i1 %14, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0)
%32 = tail call i32 @open_error(i8* %30, i8* %31)
br label %138
33: ; preds = %24
%34 = tail call i32 @fgetc(i32* %16)
%35 = tail call i32 @fputc(i32 %34, i32* %27)
%36 = tail call i32 @fgetc(i32* %16)
%37 = tail call i32 @fputc(i32 %36, i32* %27)
%38 = tail call i32 @fgetc(i32* %16)
%39 = tail call i32 @fputc(i32 %38, i32* %27)
%40 = tail call i32 @fgetc(i32* %16)
%41 = tail call i32 @fputc(i32 %40, i32* %27)
%42 = shl i32 %40, 8
%43 = tail call i32 @fgetc(i32* %16)
%44 = tail call i32 @fputc(i32 %43, i32* %27)
%45 = tail call i32 @fgetc(i32* %16)
%46 = tail call i32 @fputc(i32 %45, i32* %27)
%47 = tail call i32 @fgetc(i32* %16)
%48 = tail call i32 @fputc(i32 %47, i32* %27)
%49 = tail call i32 @fgetc(i32* %16)
%50 = tail call i32 @fputc(i32 %49, i32* %27)
%51 = tail call i32 @fgetc(i32* %16)
%52 = tail call i32 @fputc(i32 %51, i32* %27)
%53 = tail call i32 @fgetc(i32* %16)
%54 = tail call i32 @fputc(i32 %53, i32* %27)
%55 = tail call i32 @fgetc(i32* %16)
%56 = tail call i32 @fputc(i32 %55, i32* %27)
%57 = tail call i32 @fgetc(i32* %16)
%58 = tail call i32 @fputc(i32 %57, i32* %27)
%59 = tail call i32 @fgetc(i32* %16)
%60 = tail call i32 @fputc(i32 %59, i32* %27)
%61 = tail call i32 @fgetc(i32* %16)
%62 = tail call i32 @fputc(i32 %61, i32* %27)
%63 = tail call i32 @fgetc(i32* %16)
%64 = tail call i32 @fputc(i32 %63, i32* %27)
%65 = tail call i32 @fgetc(i32* %16)
%66 = tail call i32 @fputc(i32 %65, i32* %27)
%67 = tail call i32 @fgetc(i32* %16)
%68 = tail call i32 @fputc(i32 %67, i32* %27)
%69 = tail call i32 @fgetc(i32* %16)
%70 = tail call i32 @fputc(i32 %69, i32* %27)
%71 = tail call i32 @fgetc(i32* %16)
%72 = tail call i32 @fputc(i32 %71, i32* %27)
%73 = tail call i32 @fgetc(i32* %16)
%74 = tail call i32 @fputc(i32 %73, i32* %27)
%75 = add i32 %42, %38
%76 = icmp sgt i32 %75, 0
br i1 %76, label %77, label %80
77: ; preds = %33
%78 = getelementptr inbounds [40 x i8], [40 x i8]* %3, i64 0, i64 8
%79 = getelementptr inbounds [40 x i8], [40 x i8]* %3, i64 0, i64 16
br label %84
80: ; preds = %91, %33
%81 = call i32 @fgetc(i32* %16)
%82 = load i32, i32* @EOF
%83 = icmp eq i32 %81, %82
br i1 %83, label %135, label %97
84: ; preds = %77, %91
%85 = phi i32 [ 0, %77 ], [ %95, %91 ]
%86 = call i32 @fread(i8* %4, i32 1, i32 40, i32* %16)
%87 = call i32 @strncmp(i8* %4, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0), i32 8)
%88 = icmp eq i32 %87, 0
br i1 %88, label %89, label %91
89: ; preds = %84
%90 = call i32 @memcpy(i8* %78, i8* %79, i32 4)
br label %91
91: ; preds = %84, %89
%92 = phi i8* [ %79, %89 ], [ %78, %84 ]
%93 = call i32 @memset(i8* %92, i32 0, i32 4)
%94 = call i32 @fwrite(i8* %4, i32 1, i32 40, i32* %27)
%95 = add nuw nsw i32 %85, 1
%96 = icmp eq i32 %95, %75
br i1 %96, label %80, label %84
97: ; preds = %80, %97
%98 = phi i32 [ %100, %97 ], [ %81, %80 ]
%99 = call i32 @fputc(i32 %98, i32* %27)
%100 = call i32 @fgetc(i32* %16)
%101 = load i32, i32* @EOF
%102 = icmp eq i32 %100, %101
br i1 %102, label %135, label %97
103: ; preds = %22
%104 = tail call i32 @fgetc(i32* %16)
%105 = tail call i32 @fgetc(i32* %16)
%106 = tail call i32 @fgetc(i32* %16)
%107 = tail call i32 @fgetc(i32* %16)
%108 = shl i32 %107, 8
%109 = add i32 %108, %106
%110 = load i32, i32* @SEEK_SET
%111 = tail call i32 @fseek(i32* %16, i32 20, i32 %110)
%112 = icmp sgt i32 %109, 0
br i1 %112, label %113, label %116
113: ; preds = %103
%114 = getelementptr inbounds [40 x i8], [40 x i8]* %3, i64 0, i64 8
%115 = getelementptr inbounds [40 x i8], [40 x i8]* %3, i64 0, i64 16
br label %118
116: ; preds = %127, %103
%117 = call i32 @fclose(i32* %16)
br label %138
118: ; preds = %113, %127
%119 = phi i32 [ 0, %113 ], [ %133, %127 ]
%120 = call i32 @fread(i8* %4, i32 1, i32 40, i32* %16)
%121 = load i32, i32* @SEEK_CUR
%122 = call i32 @fseek(i32* %16, i32 -40, i32 %121)
%123 = call i32 @strncmp(i8* %4, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0), i32 8)
%124 = icmp eq i32 %123, 0
br i1 %124, label %125, label %127
125: ; preds = %118
%126 = call i32 @memcpy(i8* %114, i8* %115, i32 4)
br label %127
127: ; preds = %118, %125
%128 = phi i8* [ %115, %125 ], [ %114, %118 ]
%129 = call i32 @memset(i8* %128, i32 0, i32 4)
%130 = call i32 @fwrite(i8* %4, i32 1, i32 40, i32* %16)
%131 = load i32, i32* @SEEK_CUR
%132 = call i32 @fseek(i32* %16, i32 0, i32 %131)
%133 = add nuw nsw i32 %119, 1
%134 = icmp eq i32 %133, %109
br i1 %134, label %116, label %118
135: ; preds = %97, %80
%136 = call i32 @fclose(i32* %16)
%137 = call i32 @fclose(i32* %27)
br label %138
138: ; preds = %116, %135, %29, %18, %7
%139 = phi i32 [ 1, %7 ], [ %32, %29 ], [ %21, %18 ], [ 0, %135 ], [ 0, %116 ]
ret i32 %139
}