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

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int fread(unsigned char *, int, int, int /*<<< orphan*/ *);
scalar_t__ fwrite(unsigned char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ writetestfile();
int main(int argc, char **argv) {
  if (strcmp(argv[1], "-test") == 0) {
    writetestfile();
    printf("Written test file data to \"testfile\"\n");
    return (0);
  }
  if (argc != 3) {
    printf("Invalid command specified.  Please use:\n");
    printf("fixbadftp INPUTFILE OUTPUTFILE\n");
    return (1);
  }
  FILE *ifh;
  FILE *ofh;
  unsigned char inbox[(1024 * 4)];
  unsigned char outbox[(1024 * 4)];
  unsigned char lastchar;
  unsigned char firstloop = 1;
  long int numdetections = 0;
  long int totalread = 0;
  long int totalwritten = 0;
  int numbytesread = 0;
  int i, j;
  ifh = fopen(argv[1], "r");
  if (!ifh) {
    printf("Unable to open input file (%s).\n", argv[1]);
    return (2);
  }
  ofh = fopen(argv[2], "w");
  if (!ofh) {
    printf("Unable to open output file (%s).\n", argv[2]);
    fclose(ifh);
    return (2);
  }
  while (!feof(ifh)) {
    numbytesread = fread(inbox, sizeof(char), sizeof(inbox), ifh);
    totalread += numbytesread;
    for (i = 0, j = 0; i < numbytesread; ++i) {
      if (firstloop && i == 0) {
        lastchar = inbox[0];
        firstloop = 0;
        continue;
      } else {
        if (lastchar != '\r') {
          outbox[j] = lastchar;
          ++j;
        } else {
          if (inbox[i] != '\n') {
            outbox[j] = lastchar;
            ++j;
          } else {
            ++numdetections;
          }
        }
      }
      lastchar = inbox[i];
    }
    totalwritten += fwrite(outbox, sizeof(char), (j), ofh);
  }
  outbox[0] = lastchar;
  totalwritten += fwrite(outbox, sizeof(char), 1, ofh);
  fclose(ifh);
  fclose(ofh);
  printf("Processing results for input file \"%s\":\n", argv[1]);
  printf("Total Bytes Read:    %ld\n", totalread);
  printf("Total Bytes Written: %ld\n", totalwritten);
  printf("Read - Written:      %ld\n", (totalread - totalwritten));
  printf("CRLFs Detected:      %ld\n", numdetections);
  printf("Sane? (0=yes):       %d\n",
         ((totalread - totalwritten) - numdetections));
  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)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe58(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    11d8 <main+0x58>
mov    $0x0,%al
call   1090 <writetestfile@plt>
lea    0xe41(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    154a <main+0x3ca>
cmpl   $0x3,-0x8(%rbp)
je     120a <main+0x8a>
lea    0xe43(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe5e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    154a <main+0x3ca>
movb   $0x1,-0x2022(%rbp)
movq   $0x0,-0x2030(%rbp)
movq   $0x0,-0x2038(%rbp)
movq   $0x0,-0x2040(%rbp)
movl   $0x0,-0x2044(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe2a(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1281 <main+0x101>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe09(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x2,-0x4(%rbp)
jmp    154a <main+0x3ca>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe08(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    12cf <main+0x14f>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
lea    0xde7(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x2,-0x4(%rbp)
jmp    154a <main+0x3ca>
jmp    12d4 <main+0x154>
mov    -0x18(%rbp),%rdi
call   1070 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    12f2 <main+0x172>
jmp    146c <main+0x2ec>
lea    -0x1020(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
mov    $0x1000,%edx
call   1030 <fread@plt>
mov    %eax,-0x2044(%rbp)
movslq -0x2044(%rbp),%rax
add    -0x2038(%rbp),%rax
mov    %rax,-0x2038(%rbp)
movl   $0x0,-0x2048(%rbp)
movl   $0x0,-0x204c(%rbp)
mov    -0x2048(%rbp),%eax
cmp    -0x2044(%rbp),%eax
jge    143e <main+0x2be>
movzbl -0x2022(%rbp),%eax
cmp    $0x0,%eax
je     1382 <main+0x202>
cmpl   $0x0,-0x2048(%rbp)
jne    1382 <main+0x202>
mov    -0x1020(%rbp),%al
mov    %al,-0x2021(%rbp)
movb   $0x0,-0x2022(%rbp)
jmp    142a <main+0x2aa>
movzbl -0x2021(%rbp),%eax
cmp    $0xd,%eax
je     13ba <main+0x23a>
mov    -0x2021(%rbp),%cl
movslq -0x204c(%rbp),%rax
mov    %cl,-0x2020(%rbp,%rax,1)
mov    -0x204c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x204c(%rbp)
jmp    1411 <main+0x291>
movslq -0x2048(%rbp),%rax
movzbl -0x1020(%rbp,%rax,1),%eax
ff
cmp    $0xa,%eax
je     13fa <main+0x27a>
mov    -0x2021(%rbp),%cl
movslq -0x204c(%rbp),%rax
mov    %cl,-0x2020(%rbp,%rax,1)
mov    -0x204c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x204c(%rbp)
jmp    140c <main+0x28c>
mov    -0x2030(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x2030(%rbp)
jmp    1411 <main+0x291>
jmp    1416 <main+0x296>
movslq -0x2048(%rbp),%rax
mov    -0x1020(%rbp,%rax,1),%al
mov    %al,-0x2021(%rbp)
mov    -0x2048(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2048(%rbp)
jmp    133b <main+0x1bb>
lea    -0x2020(%rbp),%rdi
mov    -0x204c(%rbp),%edx
mov    -0x20(%rbp),%rcx
mov    $0x1,%esi
call   10a0 <fwrite@plt>
add    -0x2040(%rbp),%rax
mov    %rax,-0x2040(%rbp)
jmp    12d4 <main+0x154>
mov    -0x2021(%rbp),%al
mov    %al,-0x2020(%rbp)
lea    -0x2020(%rbp),%rdi
mov    -0x20(%rbp),%rcx
mov    $0x1,%edx
mov    %edx,%esi
call   10a0 <fwrite@plt>
add    -0x2040(%rbp),%rax
mov    %rax,-0x2040(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xbfe(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x2038(%rbp),%rsi
lea    0xc12(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x2040(%rbp),%rsi
lea    0xc17(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x2038(%rbp),%rsi
sub    -0x2040(%rbp),%rsi
lea    0xc15(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x2030(%rbp),%rsi
lea    0xc1a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x2038(%rbp),%rsi
sub    -0x2040(%rbp),%rsi
sub    -0x2030(%rbp),%rsi
lea    0xc11(%rip),%rdi
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    $0x2028,%rsp
mov    %rsi,%rbp
mov    %edi,%ebx
mov    0x8(%rsi),%rdi
lea    0xe4f(%rip),%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
je     12d7 <main+0x147>
cmp    $0x3,%ebx
jne    12ee <main+0x15e>
mov    0x8(%rbp),%rdi
lea    0xe33(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     130d <main+0x17d>
mov    %rax,%rbx
mov    0x10(%rbp),%rdi
lea    0xe3a(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,0x10(%rsp)
test   %rax,%rax
je     1321 <main+0x191>
mov    %rbp,0x18(%rsp)
mov    %rbx,0x8(%rsp)
mov    %rbx,%rdi
call   1080 <feof@plt>
test   %eax,%eax
je     1354 <main+0x1c4>
xor    %r13d,%r13d
xor    %r14d,%r14d
xor    %r12d,%r12d
mov    0x8(%rsp),%rbp
mov    %r15b,0x20(%rsp)
lea    0x20(%rsp),%rdi
mov    $0x1,%esi
mov    $0x1,%edx
mov    0x10(%rsp),%r15
mov    %r15,%rcx
call   10b0 <fwrite@plt>
mov    %rax,%rbx
add    %r12,%rbx
mov    %rbp,%rdi
call   1050 <fclose@plt>
mov    %r15,%rdi
call   1050 <fclose@plt>
mov    0x18(%rsp),%rax
mov    0x8(%rax),%rsi
lea    0xddc(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xdf7(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe00(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
sub    %rbx,%r14
lea    0xe06(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe0f(%rip),%rdi
mov    %r13,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
sub    %r13,%r14
lea    0xe15(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %ebx,%ebx
jmp    1340 <main+0x1b0>
xor    %ebx,%ebx
xor    %eax,%eax
call   10a0 <writetestfile@plt>
lea    0xe57(%rip),%rdi
call   1030 <puts@plt>
jmp    1340 <main+0x1b0>
lea    0xe02(%rip),%rdi
call   1030 <puts@plt>
lea    0xe1e(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%ebx
jmp    1340 <main+0x1b0>
mov    0x8(%rbp),%rsi
lea    0xcf0(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
jmp    133b <main+0x1ab>
mov    0x10(%rbp),%rsi
lea    0xcff(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
mov    $0x2,%ebx
mov    %ebx,%eax
add    $0x2028,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0x1,%bl
xor    %r12d,%r12d
xor    %r14d,%r14d
xor    %r13d,%r13d
mov    0x8(%rsp),%rbp
jmp    13a3 <main+0x213>
cs nopw 0x0(%rax,%rax,1)
xor    %edx,%edx
cltq
add    %rax,%r14
lea    0x20(%rsp),%rdi
mov    $0x1,%esi
mov    0x10(%rsp),%rcx
call   10b0 <fwrite@plt>
add    %rax,%r12
mov    0x8(%rsp),%rbp
mov    %rbp,%rdi
call   1080 <feof@plt>
test   %eax,%eax
jne    122a <main+0x9a>
lea    0x1020(%rsp),%rdi
mov    $0x1,%esi
mov    $0x1000,%edx
mov    %rbp,%rcx
call   1040 <fread@plt>
test   %eax,%eax
jle    1370 <main+0x1e0>
mov    0x1020(%rsp),%cl
mov    %eax,%esi
xor    %edi,%edi
xor    %edx,%edx
jmp    13ed <main+0x25d>
movslq %edx,%rdx
mov    %r15b,0x20(%rsp,%rdx,1)
add    $0x1,%edx
movzbl 0x1020(%rsp,%rdi,1),%r15d
add    $0x1,%rdi
cmp    %rdi,%rsi
je     1372 <main+0x1e2>
test   %bl,%bl
je     1400 <main+0x270>
test   %rdi,%rdi
jne    1400 <main+0x270>
xor    %ebx,%ebx
mov    %ecx,%r15d
jmp    13e4 <main+0x254>
nopl   (%rax)
cmp    $0xd,%r15b
jne    13d0 <main+0x240>
movzbl 0x1020(%rsp,%rdi,1),%r15d
cmp    $0xa,%r15b
jne    141e <main+0x28e>
add    $0x1,%r13
mov    $0xa,%r15b
jmp    13e4 <main+0x254>
movslq %edx,%rbp
movb   $0xd,0x20(%rsp,%rbp,1)
add    $0x1,%edx
jmp    13e4 <main+0x254>

LLVM IR (-O0):
@.str = [6 x i8] c"-test\00"
@.str.1 = [38 x i8] c"Written test file data to \22testfile\22\0A\00"
@.str.2 = [41 x i8] c"Invalid command specified. Please use:\0A\00"
@.str.3 = [32 x i8] c"fixbadftp INPUTFILE OUTPUTFILE\0A\00"
@.str.4 = [2 x i8] c"r\00"
@.str.5 = [33 x i8] c"Unable to open input file (%s).\0A\00"
@.str.6 = [2 x i8] c"w\00"
@.str.7 = [34 x i8] c"Unable to open output file (%s).\0A\00"
@.str.8 = [41 x i8] c"Processing results for input file \22%s\22:\0A\00"
@.str.9 = [26 x i8] c"Total Bytes Read: %ld\0A\00"
@.str.10 = [26 x i8] c"Total Bytes Written: %ld\0A\00"
@.str.11 = [26 x i8] c"Read - Written: %ld\0A\00"
@.str.12 = [26 x i8] c"CRLFs Detected: %ld\0A\00"
@.str.13 = [25 x i8] c"Sane? (0=yes): %d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca [4096 x i8]
%9 = alloca [4096 x i8]
%10 = alloca i8
%11 = alloca i8
%12 = alloca i64
%13 = alloca i64
%14 = alloca i64
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = call i64 @strcmp(i8* %20, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %2
%24 = call i32 (...) @writetestfile()
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %3
br label %163
26: ; preds = %2
%27 = load i32, i32* %4
%28 = icmp ne i32 %27, 3
br i1 %28, label %29, label %32
29: ; preds = %26
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.2, i64 0, i64 0))
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0))
store i32 1, i32* %3
br label %163
32: ; preds = %26
store i8 1, i8* %11
store i64 0, i64* %12
store i64 0, i64* %13
store i64 0, i64* %14
store i32 0, i32* %15
%33 = load i8**, i8*** %5
%34 = getelementptr inbounds i8*, i8** %33, i64 1
%35 = load i8*, i8** %34
%36 = call i32* @fopen(i8* %35, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32* %36, i32** %6
%37 = load i32*, i32** %6
%38 = icmp ne i32* %37, null
br i1 %38, label %44, label %39
39: ; preds = %32
%40 = load i8**, i8*** %5
%41 = getelementptr inbounds i8*, i8** %40, i64 1
%42 = load i8*, i8** %41
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.5, i64 0, i64 0), i8* %42)
store i32 2, i32* %3
br label %163
44: ; preds = %32
%45 = load i8**, i8*** %5
%46 = getelementptr inbounds i8*, i8** %45, i64 2
%47 = load i8*, i8** %46
%48 = call i32* @fopen(i8* %47, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
store i32* %48, i32** %7
%49 = load i32*, i32** %7
%50 = icmp ne i32* %49, null
br i1 %50, label %58, label %51
51: ; preds = %44
%52 = load i8**, i8*** %5
%53 = getelementptr inbounds i8*, i8** %52, i64 2
%54 = load i8*, i8** %53
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.7, i64 0, i64 0), i8* %54)
%56 = load i32*, i32** %6
%57 = call i32 @fclose(i32* %56)
store i32 2, i32* %3
br label %163
58: ; preds = %44
br label %59
59: ; preds = %124, %58
%60 = load i32*, i32** %6
%61 = call i32 @feof(i32* %60)
%62 = icmp ne i32 %61, 0
%63 = xor i1 %62, true
br i1 %63, label %64, label %131
64: ; preds = %59
%65 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 0
%66 = load i32*, i32** %6
%67 = call i32 @fread(i8* %65, i32 1, i32 4096, i32* %66)
store i32 %67, i32* %15
%68 = load i32, i32* %15
%69 = sext i32 %68 to i64
%70 = load i64, i64* %13
%71 = add nsw i64 %70, %69
store i64 %71, i64* %13
store i32 0, i32* %16
store i32 0, i32* %17
br label %72
72: ; preds = %121, %64
%73 = load i32, i32* %16
%74 = load i32, i32* %15
%75 = icmp slt i32 %73, %74
br i1 %75, label %76, label %124
76: ; preds = %72
%77 = load i8, i8* %11
%78 = zext i8 %77 to i32
%79 = icmp ne i32 %78, 0
br i1 %79, label %80, label %86
80: ; preds = %76
%81 = load i32, i32* %16
%82 = icmp eq i32 %81, 0
br i1 %82, label %83, label %86
83: ; preds = %80
%84 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 0
%85 = load i8, i8* %84
store i8 %85, i8* %10
store i8 0, i8* %11
br label %121
86: ; preds = %80, %76
%87 = load i8, i8* %10
%88 = zext i8 %87 to i32
%89 = icmp ne i32 %88, 13
br i1 %89, label %90, label %97
90: ; preds = %86
%91 = load i8, i8* %10
%92 = load i32, i32* %17
%93 = sext i32 %92 to i64
%94 = getelementptr inbounds [4096 x i8], [4096 x i8]* %9, i64 0, i64 %93
store i8 %91, i8* %94
%95 = load i32, i32* %17
%96 = add nsw i32 %95, 1
store i32 %96, i32* %17
br label %115
97: ; preds = %86
%98 = load i32, i32* %16
%99 = sext i32 %98 to i64
%100 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 %99
%101 = load i8, i8* %100
%102 = zext i8 %101 to i32
%103 = icmp ne i32 %102, 10
br i1 %103, label %104, label %111
104: ; preds = %97
%105 = load i8, i8* %10
%106 = load i32, i32* %17
%107 = sext i32 %106 to i64
%108 = getelementptr inbounds [4096 x i8], [4096 x i8]* %9, i64 0, i64 %107
store i8 %105, i8* %108
%109 = load i32, i32* %17
%110 = add nsw i32 %109, 1
store i32 %110, i32* %17
br label %114
111: ; preds = %97
%112 = load i64, i64* %12
%113 = add nsw i64 %112, 1
store i64 %113, i64* %12
br label %114
114: ; preds = %111, %104
br label %115
115: ; preds = %114, %90
br label %116
116: ; preds = %115
%117 = load i32, i32* %16
%118 = sext i32 %117 to i64
%119 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 %118
%120 = load i8, i8* %119
store i8 %120, i8* %10
br label %121
121: ; preds = %116, %83
%122 = load i32, i32* %16
%123 = add nsw i32 %122, 1
store i32 %123, i32* %16
br label %72
124: ; preds = %72
%125 = getelementptr inbounds [4096 x i8], [4096 x i8]* %9, i64 0, i64 0
%126 = load i32, i32* %17
%127 = load i32*, i32** %7
%128 = call i64 @fwrite(i8* %125, i32 1, i32 %126, i32* %127)
%129 = load i64, i64* %14
%130 = add nsw i64 %129, %128
store i64 %130, i64* %14
br label %59
131: ; preds = %59
%132 = load i8, i8* %10
%133 = getelementptr inbounds [4096 x i8], [4096 x i8]* %9, i64 0, i64 0
store i8 %132, i8* %133
%134 = getelementptr inbounds [4096 x i8], [4096 x i8]* %9, i64 0, i64 0
%135 = load i32*, i32** %7
%136 = call i64 @fwrite(i8* %134, i32 1, i32 1, i32* %135)
%137 = load i64, i64* %14
%138 = add nsw i64 %137, %136
store i64 %138, i64* %14
%139 = load i32*, i32** %6
%140 = call i32 @fclose(i32* %139)
%141 = load i32*, i32** %7
%142 = call i32 @fclose(i32* %141)
%143 = load i8**, i8*** %5
%144 = getelementptr inbounds i8*, i8** %143, i64 1
%145 = load i8*, i8** %144
%146 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.8, i64 0, i64 0), i8* %145)
%147 = load i64, i64* %13
%148 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.9, i64 0, i64 0), i64 %147)
%149 = load i64, i64* %14
%150 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.10, i64 0, i64 0), i64 %149)
%151 = load i64, i64* %13
%152 = load i64, i64* %14
%153 = sub nsw i64 %151, %152
%154 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.11, i64 0, i64 0), i64 %153)
%155 = load i64, i64* %12
%156 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.12, i64 0, i64 0), i64 %155)
%157 = load i64, i64* %13
%158 = load i64, i64* %14
%159 = sub nsw i64 %157, %158
%160 = load i64, i64* %12
%161 = sub nsw i64 %159, %160
%162 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.13, i64 0, i64 0), i64 %161)
store i32 0, i32* %3
br label %163
163: ; preds = %131, %51, %39, %29, %23
%164 = load i32, i32* %3
ret i32 %164
}

LLVM IR (-O2):
@.str = [6 x i8] c"-test\00"
@.str.4 = [2 x i8] c"r\00"
@.str.5 = [33 x i8] c"Unable to open input file (%s).\0A\00"
@.str.6 = [2 x i8] c"w\00"
@.str.7 = [34 x i8] c"Unable to open output file (%s).\0A\00"
@.str.8 = [41 x i8] c"Processing results for input file \22%s\22:\0A\00"
@.str.9 = [26 x i8] c"Total Bytes Read: %ld\0A\00"
@.str.10 = [26 x i8] c"Total Bytes Written: %ld\0A\00"
@.str.11 = [26 x i8] c"Read - Written: %ld\0A\00"
@.str.12 = [26 x i8] c"CRLFs Detected: %ld\0A\00"
@.str.13 = [25 x i8] c"Sane? (0=yes): %d\0A\00"
@str = [40 x i8] c"Invalid command specified. Please use:\00"
@str.14 = [31 x i8] c"fixbadftp INPUTFILE OUTPUTFILE\00"
@str.15 = [37 x i8] c"Written test file data to \22testfile\22\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [4096 x i8]
%4 = alloca [4096 x i8]
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = tail call i64 @strcmp(i8* %6, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %12
9: ; preds = %2
%10 = tail call i32 (...) @writetestfile()
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @str.15, i64 0, i64 0))
br label %114
12: ; preds = %2
%13 = icmp eq i32 %0, 3
br i1 %13, label %17, label %14
14: ; preds = %12
%15 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @str, i64 0, i64 0))
%16 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str.14, i64 0, i64 0))
br label %114
17: ; preds = %12
%18 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%19 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 0
%20 = load i8*, i8** %5
%21 = tail call i32* @fopen(i8* %20, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%22 = icmp eq i32* %21, null
br i1 %22, label %23, label %26
23: ; preds = %17
%24 = load i8*, i8** %5
%25 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.5, i64 0, i64 0), i8* %24)
br label %112
26: ; preds = %17
%27 = getelementptr inbounds i8*, i8** %1, i64 2
%28 = load i8*, i8** %27
%29 = tail call i32* @fopen(i8* %28, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%30 = icmp eq i32* %29, null
br i1 %30, label %34, label %31
31: ; preds = %26
%32 = tail call i32 @feof(i32* %21)
%33 = icmp eq i32 %32, 0
br i1 %33, label %38, label %94
34: ; preds = %26
%35 = load i8*, i8** %27
%36 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.7, i64 0, i64 0), i8* %35)
%37 = tail call i32 @fclose(i32* %21)
br label %112
38: ; preds = %31, %85
%39 = phi i64 [ %91, %85 ], [ 0, %31 ]
%40 = phi i64 [ %46, %85 ], [ 0, %31 ]
%41 = phi i64 [ %88, %85 ], [ 0, %31 ]
%42 = phi i8 [ %87, %85 ], [ 1, %31 ]
%43 = phi i8 [ %86, %85 ], [ undef, %31 ]
%44 = call i32 @fread(i8* %18, i32 1, i32 4096, i32* %21)
%45 = sext i32 %44 to i64
%46 = add nsw i64 %40, %45
%47 = icmp sgt i32 %44, 0
br i1 %47, label %48, label %85
48: ; preds = %38
%49 = load i8, i8* %18
%50 = zext i32 %44 to i64
br label %51
51: ; preds = %48, %78
%52 = phi i64 [ 0, %48 ], [ %83, %78 ]
%53 = phi i32 [ 0, %48 ], [ %82, %78 ]
%54 = phi i64 [ %41, %48 ], [ %81, %78 ]
%55 = phi i8 [ %42, %48 ], [ %80, %78 ]
%56 = phi i8 [ %43, %48 ], [ %79, %78 ]
%57 = icmp ne i8 %55, 0
%58 = icmp eq i64 %52, 0
%59 = select i1 %57, i1 %58, i1 false
br i1 %59, label %78, label %60
60: ; preds = %51
%61 = icmp eq i8 %56, 13
br i1 %61, label %68, label %62
62: ; preds = %60
%63 = sext i32 %53 to i64
%64 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 %63
store i8 %56, i8* %64
%65 = add nsw i32 %53, 1
%66 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 %52
%67 = load i8, i8* %66
br label %78
68: ; preds = %60
%69 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 %52
%70 = load i8, i8* %69
%71 = icmp eq i8 %70, 10
br i1 %71, label %76, label %72
72: ; preds = %68
%73 = sext i32 %53 to i64
%74 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 %73
store i8 13, i8* %74
%75 = add nsw i32 %53, 1
br label %78
76: ; preds = %68
%77 = add nsw i64 %54, 1
br label %78
78: ; preds = %72, %76, %62, %51
%79 = phi i8 [ %49, %51 ], [ %67, %62 ], [ %70, %72 ], [ 10, %76 ]
%80 = phi i8 [ 0, %51 ], [ %55, %62 ], [ %55, %72 ], [ %55, %76 ]
%81 = phi i64 [ %54, %51 ], [ %54, %62 ], [ %54, %72 ], [ %77, %76 ]
%82 = phi i32 [ %53, %51 ], [ %65, %62 ], [ %75, %72 ], [ %53, %76 ]
%83 = add nuw nsw i64 %52, 1
%84 = icmp eq i64 %83, %50
br i1 %84, label %85, label %51
85: ; preds = %78, %38
%86 = phi i8 [ %43, %38 ], [ %79, %78 ]
%87 = phi i8 [ %42, %38 ], [ %80, %78 ]
%88 = phi i64 [ %41, %38 ], [ %81, %78 ]
%89 = phi i32 [ 0, %38 ], [ %82, %78 ]
%90 = call i64 @fwrite(i8* %19, i32 1, i32 %89, i32* %29)
%91 = add nsw i64 %90, %39
%92 = tail call i32 @feof(i32* %21)
%93 = icmp eq i32 %92, 0
br i1 %93, label %38, label %94
94: ; preds = %85, %31
%95 = phi i8 [ undef, %31 ], [ %86, %85 ]
%96 = phi i64 [ 0, %31 ], [ %88, %85 ]
%97 = phi i64 [ 0, %31 ], [ %46, %85 ]
%98 = phi i64 [ 0, %31 ], [ %91, %85 ]
store i8 %95, i8* %19
%99 = call i64 @fwrite(i8* %19, i32 1, i32 1, i32* %29)
%100 = add nsw i64 %99, %98
%101 = tail call i32 @fclose(i32* %21)
%102 = tail call i32 @fclose(i32* %29)
%103 = load i8*, i8** %5
%104 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @.str.8, i64 0, i64 0), i8* %103)
%105 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.9, i64 0, i64 0), i64 %97)
%106 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.10, i64 0, i64 0), i64 %100)
%107 = sub nsw i64 %97, %100
%108 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.11, i64 0, i64 0), i64 %107)
%109 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.12, i64 0, i64 0), i64 %96)
%110 = sub nsw i64 %107, %96
%111 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.13, i64 0, i64 0), i64 %110)
br label %112
112: ; preds = %94, %34, %23
%113 = phi i32 [ 0, %94 ], [ 2, %34 ], [ 2, %23 ]
br label %114
114: ; preds = %112, %14, %9
%115 = phi i32 [ 0, %9 ], [ 1, %14 ], [ %113, %112 ]
ret i32 %115
}