#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_END;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
int ftell(int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
int /*<<< orphan*/ strncpy(char *, char *, int);
int writeSector(char *);
int writeFile(char *dest, char *src, int type) {
  char buf[512];
  for (int i = 0; i < 512; i++)
    buf[i] = 0;
  strncpy(buf, dest, 8);
  buf[2] |= 0x80 & (type << 6);
  buf[3] |= 0x80 & (type << 7);
  FILE *f = fopen(src, "r");
  if (!f) {
    printf("Error: file %s not found!\n", src);
    return -1;
  }
  fseek(f, 0, SEEK_END);
  int size = ftell(f);
  if (size <= 504) {
    rewind(f);
    int c;
    int i = 8;
    while ((c = fgetc(f)) != EOF) {
      buf[i] = c;
      i++;
    }
    fclose(f);
    return writeSector(buf);
  } else {
    buf[1] |= 0x80;
    rewind(f);
    int sectorInd = 0;
    char sect[512];
    int c;
    int i = 0;
    for (int j = 0; j < 512; j++)
      sect[j] = 0;
    while ((c = fgetc(f)) != EOF) {
      sect[i] = c;
      i++;
      if (i == 512) {
        i = 0;
        int index = writeSector(sect);
        int offset = 8 + 3 * (sectorInd >> 1);
        if (sectorInd & 1) {
          buf[offset + 1] += (index >> 8) << 4;
          buf[offset + 2] = index & 0xFF;
        } else {
          buf[offset] = index >> 4;
          buf[offset + 1] += (index & 0xF) << 4;
        }
        sectorInd++;
        for (int j = 0; j < 512; j++)
          sect[j] = 0;
      }
    }
    int index = writeSector(sect);
    int offset = 8 + 3 * (sectorInd >> 1);
    if (sectorInd & 1) {
      buf[offset + 1] += (index >> 8) << 4;
      buf[offset + 2] = index & 0xFF;
    } else {
      buf[offset] = index >> 4;
      buf[offset + 1] += (index & 0xF) << 4;
    }
    fclose(f);
    return writeSector(buf);
  }
}


x86 assembly (clang, -O0):
<writeFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x460,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
movl   $0x0,-0x224(%rbp)
cmpl   $0x200,-0x224(%rbp)
jge    11e3 <writeFile+0x53>
movslq -0x224(%rbp),%rax
movb   $0x0,-0x220(%rbp,%rax,1)
mov    -0x224(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x224(%rbp)
jmp    11b0 <writeFile+0x20>
lea    -0x220(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0x8,%edx
call   1030 <strncpy@plt>
mov    -0x1c(%rbp),%ecx
shl    $0x6,%ecx
and    $0x80,%ecx
movsbl -0x21e(%rbp),%eax
or     %ecx,%eax
mov    %al,-0x21e(%rbp)
mov    -0x1c(%rbp),%ecx
shl    $0x7,%ecx
and    $0x80,%ecx
movsbl -0x21d(%rbp),%eax
or     %ecx,%eax
mov    %al,-0x21d(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xdc7(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x230(%rbp)
cmpq   $0x0,-0x230(%rbp)
jne    126f <writeFile+0xdf>
mov    -0x18(%rbp),%rsi
lea    0xda4(%rip),%rdi
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    15fa <writeFile+0x46a>
mov    -0x230(%rbp),%rdi
mov    0x2d6b(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   10a0 <fseek@plt>
mov    -0x230(%rbp),%rdi
call   1090 <ftell@plt>
mov    %eax,-0x234(%rbp)
cmpl   $0x1f8,-0x234(%rbp)
jg     1329 <writeFile+0x199>
mov    -0x230(%rbp),%rdi
call   1060 <rewind@plt>
movl   $0x8,-0x23c(%rbp)
mov    -0x230(%rbp),%rdi
call   1080 <fgetc@plt>
mov    %eax,-0x238(%rbp)
mov    0x2d09(%rip),%rcx
cmp    (%rcx),%eax
je     1309 <writeFile+0x179>
mov    -0x238(%rbp),%eax
mov    %al,%cl
movslq -0x23c(%rbp),%rax
mov    %cl,-0x220(%rbp,%rax,1)
mov    -0x23c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x23c(%rbp)
jmp    12be <writeFile+0x12e>
mov    -0x230(%rbp),%rdi
call   1040 <fclose@plt>
lea    -0x220(%rbp),%rdi
call   1070 <writeSector@plt>
mov    %eax,-0x4(%rbp)
jmp    15fa <writeFile+0x46a>
movsbl -0x21f(%rbp),%eax
or     $0x80,%eax
mov    %al,-0x21f(%rbp)
mov    -0x230(%rbp),%rdi
call   1060 <rewind@plt>
movl   $0x0,-0x240(%rbp)
movl   $0x0,-0x448(%rbp)
movl   $0x0,-0x44c(%rbp)
cmpl   $0x200,-0x44c(%rbp)
jge    1398 <writeFile+0x208>
movslq -0x44c(%rbp),%rax
movb   $0x0,-0x440(%rbp,%rax,1)
mov    -0x44c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44c(%rbp)
jmp    1365 <writeFile+0x1d5>
jmp    139d <writeFile+0x20d>
mov    -0x230(%rbp),%rdi
call   1080 <fgetc@plt>
mov    %eax,-0x444(%rbp)
mov    0x2c2a(%rip),%rcx
cmp    (%rcx),%eax
je     1519 <writeFile+0x389>
mov    -0x444(%rbp),%eax
mov    %al,%cl
movslq -0x448(%rbp),%rax
mov    %cl,-0x440(%rbp,%rax,1)
mov    -0x448(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x448(%rbp)
cmpl   $0x200,-0x448(%rbp)
jne    1514 <writeFile+0x384>
movl   $0x0,-0x448(%rbp)
lea    -0x440(%rbp),%rdi
call   1070 <writeSector@plt>
mov    %eax,-0x450(%rbp)
mov    -0x240(%rbp),%eax
sar    $0x1,%eax
imul   $0x3,%eax,%eax
add    $0x8,%eax
mov    %eax,-0x454(%rbp)
mov    -0x240(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     1482 <writeFile+0x2f2>
mov    -0x450(%rbp),%edx
sar    $0x8,%edx
shl    $0x4,%edx
mov    -0x454(%rbp),%eax
add    $0x1,%eax
cltq
movsbl -0x220(%rbp,%rax,1),%ecx
ff
add    %edx,%ecx
mov    %cl,-0x220(%rbp,%rax,1)
mov    -0x450(%rbp),%eax
and    $0xff,%eax
mov    %al,%cl
mov    -0x454(%rbp),%eax
add    $0x2,%eax
cltq
mov    %cl,-0x220(%rbp,%rax,1)
jmp    14c3 <writeFile+0x333>
mov    -0x450(%rbp),%eax
sar    $0x4,%eax
mov    %al,%cl
movslq -0x454(%rbp),%rax
mov    %cl,-0x220(%rbp,%rax,1)
mov    -0x450(%rbp),%edx
and    $0xf,%edx
shl    $0x4,%edx
mov    -0x454(%rbp),%eax
add    $0x1,%eax
cltq
movsbl -0x220(%rbp,%rax,1),%ecx
ff
add    %edx,%ecx
mov    %cl,-0x220(%rbp,%rax,1)
mov    -0x240(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x240(%rbp)
movl   $0x0,-0x458(%rbp)
cmpl   $0x200,-0x458(%rbp)
jge    150f <writeFile+0x37f>
movslq -0x458(%rbp),%rax
movb   $0x0,-0x440(%rbp,%rax,1)
mov    -0x458(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x458(%rbp)
jmp    14dc <writeFile+0x34c>
jmp    1514 <writeFile+0x384>
jmp    139d <writeFile+0x20d>
lea    -0x440(%rbp),%rdi
call   1070 <writeSector@plt>
mov    %eax,-0x45c(%rbp)
mov    -0x240(%rbp),%eax
sar    $0x1,%eax
imul   $0x3,%eax,%eax
add    $0x8,%eax
mov    %eax,-0x460(%rbp)
mov    -0x240(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     159e <writeFile+0x40e>
mov    -0x45c(%rbp),%edx
sar    $0x8,%edx
shl    $0x4,%edx
mov    -0x460(%rbp),%eax
add    $0x1,%eax
cltq
movsbl -0x220(%rbp,%rax,1),%ecx
ff
add    %edx,%ecx
mov    %cl,-0x220(%rbp,%rax,1)
mov    -0x45c(%rbp),%eax
and    $0xff,%eax
mov    %al,%cl
mov    -0x460(%rbp),%eax
add    $0x2,%eax
cltq
mov    %cl,-0x220(%rbp,%rax,1)
jmp    15df <writeFile+0x44f>
mov    -0x45c(%rbp),%eax
sar    $0x4,%eax
mov    %al,%cl
movslq -0x460(%rbp),%rax
mov    %cl,-0x220(%rbp,%rax,1)
mov    -0x45c(%rbp),%edx
and    $0xf,%edx
shl    $0x4,%edx
mov    -0x460(%rbp),%eax
add    $0x1,%eax
cltq
movsbl -0x220(%rbp,%rax,1),%ecx
ff
add    %edx,%ecx
mov    %cl,-0x220(%rbp,%rax,1)
mov    -0x230(%rbp),%rdi
call   1040 <fclose@plt>
lea    -0x220(%rbp),%rdi
call   1070 <writeSector@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x460,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<writeFile>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x408,%rsp
mov    %edx,%ebx
mov    %rsi,%r15
mov    %rdi,%r12
mov    %rsp,%r14
mov    $0x200,%edx
mov    %r14,%rdi
xor    %esi,%esi
call   1080 <memset@plt>
mov    %r14,%rdi
mov    %r12,%rsi
mov    $0x8,%edx
call   1030 <strncpy@plt>
mov    %ebx,%eax
shl    $0x6,%al
and    $0x80,%al
or     %al,0x2(%rsp)
shl    $0x7,%bl
or     %bl,0x3(%rsp)
lea    0xe0c(%rip),%rsi
mov    %r15,%rdi
call   10c0 <fopen@plt>
test   %rax,%rax
je     1268 <writeFile+0xc8>
mov    %rax,%r13
mov    0x2ddd(%rip),%rax
mov    (%rax),%edx
xor    %ebp,%ebp
mov    %r13,%rdi
xor    %esi,%esi
call   10b0 <fseek@plt>
mov    %r13,%rdi
call   10a0 <ftell@plt>
cmp    $0x1f8,%eax
jg     1281 <writeFile+0xe1>
mov    %r13,%rdi
call   1060 <rewind@plt>
mov    %r13,%rdi
call   1090 <fgetc@plt>
mov    0x2da1(%rip),%rbx
cmp    (%rbx),%eax
je     137e <writeFile+0x1de>
lea    0x8(%rsp),%rbp
nopl   0x0(%rax)
mov    %al,0x0(%rbp)
mov    %r13,%rdi
call   1090 <fgetc@plt>
add    $0x1,%rbp
cmp    (%rbx),%eax
jne    1250 <writeFile+0xb0>
jmp    137e <writeFile+0x1de>
lea    0xd93(%rip),%rdi
mov    %r15,%rsi
call   1050 <printf@plt>
mov    $0xffffffff,%eax
jmp    138e <writeFile+0x1ee>
orb    $0x80,0x1(%rsp)
mov    %r13,%rdi
call   1060 <rewind@plt>
lea    0x200(%rsp),%rdi
mov    $0x200,%edx
xor    %esi,%esi
call   1080 <memset@plt>
mov    %r13,%rdi
call   1090 <fgetc@plt>
mov    0x2d2f(%rip),%r12
cmp    (%r12),%eax
jne    12f0 <writeFile+0x150>
lea    0x200(%rsp),%rdi
call   1070 <writeSector@plt>
mov    %ebp,%ecx
sar    %ecx
movslq %ecx,%rcx
lea    (%rcx,%rcx,2),%rcx
mov    %eax,%edx
shr    $0x4,%edx
test   $0x1,%bpl
jne    1371 <writeFile+0x1d1>
mov    %dl,0x8(%rcx,%r14,1)
shl    $0x4,%al
add    %al,0x9(%rcx,%r14,1)
jmp    137e <writeFile+0x1de>
xor    %ebx,%ebx
lea    0x200(%rsp),%r15
xor    %ebp,%ebp
jmp    132f <writeFile+0x18f>
xchg   %ax,%ax
mov    %dl,0x8(%rcx,%r14,1)
shl    $0x4,%al
add    %al,0x9(%rcx,%r14,1)
xor    %ebx,%ebx
mov    $0x200,%edx
mov    %r15,%rdi
xor    %esi,%esi
call   1080 <memset@plt>
add    $0x1,%ebp
mov    %r13,%rdi
call   1090 <fgetc@plt>
cmp    (%r12),%eax
je     12b7 <writeFile+0x117>
movslq %ebx,%rbx
mov    %al,0x200(%rsp,%rbx,1)
add    $0x1,%ebx
cmp    $0x200,%ebx
jne    1321 <writeFile+0x181>
mov    %r15,%rdi
call   1070 <writeSector@plt>
mov    %ebp,%ecx
sar    %ecx
movslq %ecx,%rcx
lea    (%rcx,%rcx,2),%rcx
mov    %eax,%edx
shr    $0x4,%edx
test   $0x1,%bpl
je     1300 <writeFile+0x160>
and    $0xf0,%dl
add    %dl,0x9(%rcx,%r14,1)
mov    %al,0xa(%rcx,%r14,1)
jmp    130d <writeFile+0x16d>
and    $0xf0,%dl
add    %dl,0x9(%rcx,%r14,1)
mov    %al,0xa(%rcx,%r14,1)
mov    %r13,%rdi
call   1040 <fclose@plt>
mov    %rsp,%rdi
call   1070 <writeSector@plt>
add    $0x408,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [27 x i8] c"Error: file %s not found!\0A\00"
@SEEK_END = global i32 0
@EOF = global i32 0
define i32 @writeFile(i8* %0, i8* %1, i32 %2) {
%4 = alloca [512 x i8]
%5 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 0
%6 = alloca [512 x i8]
%7 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%8 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 0
%9 = call i32 @strncpy(i8* %8, i8* %0, i32 8)
%10 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 2
%11 = load i8, i8* %10
%12 = trunc i32 %2 to i8
%13 = shl i8 %12, 6
%14 = and i8 %13, -128
%15 = or i8 %11, %14
store i8 %15, i8* %10
%16 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 3
%17 = load i8, i8* %16
%18 = shl i8 %12, 7
%19 = or i8 %17, %18
store i8 %19, i8* %16
%20 = call i32* @fopen(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%21 = icmp eq i32* %20, null
br i1 %21, label %22, label %24
22: ; preds = %3
%23 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %1)
br label %140
24: ; preds = %3
%25 = load i32, i32* @SEEK_END
%26 = call i32 @fseek(i32* %20, i32 0, i32 %25)
%27 = call i32 @ftell(i32* %20)
%28 = icmp slt i32 %27, 505
br i1 %28, label %29, label %46
29: ; preds = %24
%30 = call i32 @rewind(i32* %20)
%31 = call i32 @fgetc(i32* %20)
%32 = load i32, i32* @EOF
%33 = icmp eq i32 %31, %32
br i1 %33, label %43, label %34
34: ; preds = %29, %34
%35 = phi i64 [ %39, %34 ], [ 8, %29 ]
%36 = phi i32 [ %40, %34 ], [ %31, %29 ]
%37 = trunc i32 %36 to i8
%38 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 %35
store i8 %37, i8* %38
%39 = add nuw i64 %35, 1
%40 = call i32 @fgetc(i32* %20)
%41 = load i32, i32* @EOF
%42 = icmp eq i32 %40, %41
br i1 %42, label %43, label %34
43: ; preds = %34, %29
%44 = call i32 @fclose(i32* %20)
%45 = call i32 @writeSector(i8* %8)
br label %140
46: ; preds = %24
%47 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 1
%48 = load i8, i8* %47
%49 = or i8 %48, -128
store i8 %49, i8* %47
%50 = call i32 @rewind(i32* %20)
%51 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%52 = call i32 @fgetc(i32* %20)
%53 = load i32, i32* @EOF
%54 = icmp eq i32 %52, %53
br i1 %54, label %104, label %55
55: ; preds = %46, %98
%56 = phi i32 [ %101, %98 ], [ %52, %46 ]
%57 = phi i32 [ %100, %98 ], [ 0, %46 ]
%58 = phi i32 [ %99, %98 ], [ 0, %46 ]
%59 = trunc i32 %56 to i8
%60 = sext i32 %57 to i64
%61 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 %60
store i8 %59, i8* %61
%62 = add nsw i32 %57, 1
%63 = icmp eq i32 %62, 512
br i1 %63, label %64, label %98
64: ; preds = %55
%65 = call i32 @writeSector(i8* %51)
%66 = ashr i32 %58, 1
%67 = mul nsw i32 %66, 3
%68 = and i32 %58, 1
%69 = icmp eq i32 %68, 0
br i1 %69, label %83, label %70
70: ; preds = %64
%71 = lshr i32 %65, 4
%72 = add nsw i32 %67, 9
%73 = sext i32 %72 to i64
%74 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 %73
%75 = load i8, i8* %74
%76 = trunc i32 %71 to i8
%77 = and i8 %76, -16
%78 = add i8 %75, %77
store i8 %78, i8* %74
%79 = trunc i32 %65 to i8
%80 = add nsw i32 %67, 10
%81 = sext i32 %80 to i64
%82 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 %81
store i8 %79, i8* %82
br label %96
83: ; preds = %64
%84 = add nsw i32 %67, 8
%85 = lshr i32 %65, 4
%86 = trunc i32 %85 to i8
%87 = sext i32 %84 to i64
%88 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 %87
store i8 %86, i8* %88
%89 = add nsw i32 %67, 9
%90 = sext i32 %89 to i64
%91 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 %90
%92 = load i8, i8* %91
%93 = trunc i32 %65 to i8
%94 = shl i8 %93, 4
%95 = add i8 %92, %94
store i8 %95, i8* %91
br label %96
96: ; preds = %83, %70
%97 = add nsw i32 %58, 1
br label %98
98: ; preds = %96, %55
%99 = phi i32 [ %58, %55 ], [ %97, %96 ]
%100 = phi i32 [ %62, %55 ], [ 0, %96 ]
%101 = call i32 @fgetc(i32* %20)
%102 = load i32, i32* @EOF
%103 = icmp eq i32 %101, %102
br i1 %103, label %104, label %55
104: ; preds = %98, %46
%105 = phi i32 [ 0, %46 ], [ %99, %98 ]
%106 = call i32 @writeSector(i8* %51)
%107 = ashr i32 %105, 1
%108 = mul nsw i32 %107, 3
%109 = and i32 %105, 1
%110 = icmp eq i32 %109, 0
br i1 %110, label %124, label %111
111: ; preds = %104
%112 = lshr i32 %106, 4
%113 = add nsw i32 %108, 9
%114 = sext i32 %113 to i64
%115 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 %114
%116 = load i8, i8* %115
%117 = trunc i32 %112 to i8
%118 = and i8 %117, -16
%119 = add i8 %116, %118
store i8 %119, i8* %115
%120 = trunc i32 %106 to i8
%121 = add nsw i32 %108, 10
%122 = sext i32 %121 to i64
%123 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 %122
store i8 %120, i8* %123
br label %137
124: ; preds = %104
%125 = add nsw i32 %108, 8
%126 = lshr i32 %106, 4
%127 = trunc i32 %126 to i8
%128 = sext i32 %125 to i64
%129 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 %128
store i8 %127, i8* %129
%130 = add nsw i32 %108, 9
%131 = sext i32 %130 to i64
%132 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 %131
%133 = load i8, i8* %132
%134 = trunc i32 %106 to i8
%135 = shl i8 %134, 4
%136 = add i8 %133, %135
store i8 %136, i8* %132
br label %137
137: ; preds = %124, %111
%138 = call i32 @fclose(i32* %20)
%139 = call i32 @writeSector(i8* %8)
br label %140
140: ; preds = %43, %137, %22
%141 = phi i32 [ -1, %22 ], [ %45, %43 ], [ %139, %137 ]
ret i32 %141
}