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

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ O_WRONLY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ lseek(int, long, int /*<<< orphan*/);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ puts(char *);
int read(int, char *, int);
int /*<<< orphan*/ write(int, char *, int);
int main(void) {
  unsigned char header[3];
  unsigned char sector[128];
  register int i;
  int fd, drivea, readed;
  if ((drivea = open("../disks/drivea.cpm", O_WRONLY)) == -1) {
    perror("file ../disks/drivea.cpm");
    exit(1);
  }
  if ((fd = open("boot.bin", O_RDONLY)) == -1) {
    perror("file boot.bin");
    exit(1);
  }
  if ((readed = read(fd, (char *)header, 3)) != 3) {
    perror("file boot.bin");
    exit(1);
  }
  if (header[0] != 0xff || header[1] != 0 || header[2] != 0) {
    puts("start address of boot.bin <> 0");
    exit(0);
  }
  memset((char *)sector, 0, 128);
  read(fd, (char *)sector, 128);
  close(fd);
  write(drivea, (char *)sector, 128);
  if ((fd = open("cpm.bin", O_RDONLY)) == -1) {
    perror("file cpm.bin");
    exit(1);
  }
  lseek(fd, (long)17 * 128, 0);
  for (i = 0; i < 44; i++) {
    if ((readed = read(fd, (char *)sector, 128)) != 128) {
      perror("file cpm.bin");
      exit(1);
    }
    write(drivea, (char *)sector, 128);
  }
  close(fd);
  if ((fd = open("bios.bin", O_RDONLY)) == -1) {
    perror("file bios.bin");
    exit(1);
  }
  if ((readed = read(fd, (char *)header, 3)) != 3) {
    perror("file bios.bin");
    exit(1);
  }
  if (header[0] != 0xff) {
    puts("unknown format of bios.bin");
    exit(0);
  }
  i = 0;
  while ((readed = read(fd, (char *)sector, 128)) == 128) {
    write(drivea, (char *)sector, 128);
    i++;
    if (i == 6) {
      puts("6 sectors written, can't write any more!");
      goto stop;
    }
  }
  if (readed > 0) {
    write(drivea, (char *)sector, 128);
  }
stop:
  close(fd);
  close(drivea);
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e27(%rip),%rax
mov    (%rax),%esi
lea    0xe53(%rip),%rdi
call   1090 <open@plt>
mov    %eax,-0x9c(%rbp)
cmp    $0xffffffff,%eax
jne    11dc <main+0x4c>
lea    0xe33(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    0x2e05(%rip),%rax
mov    (%rax),%esi
lea    0xe32(%rip),%rdi
call   1090 <open@plt>
mov    %eax,-0x98(%rbp)
cmp    $0xffffffff,%eax
jne    1216 <main+0x86>
lea    0xe12(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x98(%rbp),%edi
lea    -0x7(%rbp),%rsi
mov    $0x3,%edx
call   1080 <read@plt>
mov    %eax,-0xa0(%rbp)
cmp    $0x3,%eax
je     124f <main+0xbf>
lea    0xdd9(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
movzbl -0x7(%rbp),%eax
cmp    $0xff,%eax
jne    1278 <main+0xe8>
movzbl -0x6(%rbp),%eax
cmp    $0x0,%eax
jne    1278 <main+0xe8>
movzbl -0x5(%rbp),%eax
cmp    $0x0,%eax
je     128b <main+0xfb>
lea    0xda8(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   10b0 <exit@plt>
lea    -0x90(%rbp),%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   1060 <memset@plt>
mov    -0x98(%rbp),%edi
lea    -0x90(%rbp),%rsi
mov    $0x80,%edx
call   1080 <read@plt>
mov    -0x98(%rbp),%edi
call   1070 <close@plt>
mov    -0x9c(%rbp),%edi
lea    -0x90(%rbp),%rsi
mov    $0x80,%edx
call   1040 <write@plt>
mov    0x2d0a(%rip),%rax
mov    (%rax),%esi
lea    0xd64(%rip),%rdi
call   1090 <open@plt>
mov    %eax,-0x98(%rbp)
cmp    $0xffffffff,%eax
jne    1311 <main+0x181>
lea    0xd44(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x98(%rbp),%edi
mov    $0x880,%esi
xor    %edx,%edx
call   1050 <lseek@plt>
movl   $0x0,-0x94(%rbp)
cmpl   $0x2c,-0x94(%rbp)
jge    13a3 <main+0x213>
mov    -0x98(%rbp),%edi
lea    -0x90(%rbp),%rsi
mov    $0x80,%edx
call   1080 <read@plt>
mov    %eax,-0xa0(%rbp)
cmp    $0x80,%eax
je     1378 <main+0x1e8>
lea    0xcdd(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x9c(%rbp),%edi
lea    -0x90(%rbp),%rsi
mov    $0x80,%edx
call   1040 <write@plt>
mov    -0x94(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x94(%rbp)
jmp    132d <main+0x19d>
mov    -0x98(%rbp),%edi
call   1070 <close@plt>
mov    0x2c33(%rip),%rax
mov    (%rax),%esi
lea    0xc9a(%rip),%rdi
call   1090 <open@plt>
mov    %eax,-0x98(%rbp)
cmp    $0xffffffff,%eax
jne    13e8 <main+0x258>
lea    0xc7a(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x98(%rbp),%edi
lea    -0x7(%rbp),%rsi
mov    $0x3,%edx
call   1080 <read@plt>
mov    %eax,-0xa0(%rbp)
cmp    $0x3,%eax
je     1421 <main+0x291>
lea    0xc41(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
movzbl -0x7(%rbp),%eax
cmp    $0xff,%eax
je     1443 <main+0x2b3>
lea    0xc2a(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   10b0 <exit@plt>
movl   $0x0,-0x94(%rbp)
mov    -0x98(%rbp),%edi
lea    -0x90(%rbp),%rsi
mov    $0x80,%edx
call   1080 <read@plt>
mov    %eax,-0xa0(%rbp)
cmp    $0x80,%eax
jne    14be <main+0x32e>
mov    -0x9c(%rbp),%edi
lea    -0x90(%rbp),%rsi
mov    $0x80,%edx
call   1040 <write@plt>
mov    -0x94(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x94(%rbp)
cmpl   $0x6,-0x94(%rbp)
jne    14b9 <main+0x329>
lea    0xbcd(%rip),%rdi
call   1030 <puts@plt>
jmp    14e7 <main+0x357>
jmp    144d <main+0x2bd>
cmpl   $0x0,-0xa0(%rbp)
jle    14e2 <main+0x352>
mov    -0x9c(%rbp),%edi
lea    -0x90(%rbp),%rsi
mov    $0x80,%edx
call   1040 <write@plt>
jmp    14e7 <main+0x357>
mov    -0x98(%rbp),%edi
call   1070 <close@plt>
mov    -0x9c(%rbp),%edi
call   1070 <close@plt>
xor    %eax,%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x90,%rsp
mov    0x2e2a(%rip),%rax
mov    (%rax),%esi
lea    0xe56(%rip),%rdi
call   1090 <open@plt>
cmp    $0xffffffff,%eax
je     1481 <main+0x2f1>
mov    %eax,%r14d
mov    0x2e21(%rip),%r15
mov    (%r15),%esi
lea    0xe4d(%rip),%rdi
call   1090 <open@plt>
cmp    $0xffffffff,%eax
je     146f <main+0x2df>
mov    %eax,%ebp
lea    0xd(%rsp),%rsi
mov    %eax,%edi
mov    $0x3,%edx
call   1080 <read@plt>
cmp    $0x3,%eax
jne    146f <main+0x2df>
cmpb   $0xff,0xd(%rsp)
jne    148a <main+0x2fa>
cmpb   $0x0,0xe(%rsp)
jne    148a <main+0x2fa>
cmpb   $0x0,0xf(%rsp)
jne    148a <main+0x2fa>
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   1060 <memset@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x80,%edx
call   1080 <read@plt>
mov    %ebp,%edi
call   1070 <close@plt>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    $0x80,%edx
call   1040 <write@plt>
mov    (%r15),%esi
lea    0xdeb(%rip),%rdi
call   1090 <open@plt>
cmp    $0xffffffff,%eax
je     1459 <main+0x2c9>
mov    %eax,%r12d
mov    $0x880,%esi
mov    %eax,%edi
xor    %edx,%edx
call   1050 <lseek@plt>
mov    $0x2c,%ebp
lea    0x10(%rsp),%rbx
nopl   0x0(%rax)
mov    %r12d,%edi
mov    %rbx,%rsi
mov    $0x80,%edx
call   1080 <read@plt>
cmp    $0x80,%eax
jne    1459 <main+0x2c9>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    $0x80,%edx
call   1040 <write@plt>
add    $0xffffffff,%ebp
jne    1290 <main+0x100>
mov    %r12d,%edi
call   1070 <close@plt>
mov    (%r15),%esi
lea    0xd86(%rip),%rdi
call   1090 <open@plt>
cmp    $0xffffffff,%eax
je     1478 <main+0x2e8>
mov    %eax,%ebp
lea    0xd(%rsp),%rsi
mov    %eax,%edi
mov    $0x3,%edx
call   1080 <read@plt>
cmp    $0x3,%eax
jne    1478 <main+0x2e8>
cmpb   $0xff,0xd(%rsp)
jne    1493 <main+0x303>
lea    0x10(%rsp),%rsi
mov    %ebp,%edi
mov    $0x80,%edx
call   1080 <read@plt>
cmp    $0x80,%eax
jne    1422 <main+0x292>
lea    0x10(%rsp),%rbx
mov    %r14d,%edi
mov    %rbx,%rsi
mov    $0x80,%edx
call   1040 <write@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x80,%edx
call   1080 <read@plt>
cmp    $0x80,%eax
jne    1422 <main+0x292>
lea    0x10(%rsp),%rbx
mov    %r14d,%edi
mov    %rbx,%rsi
mov    $0x80,%edx
call   1040 <write@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x80,%edx
call   1080 <read@plt>
cmp    $0x80,%eax
jne    1422 <main+0x292>
lea    0x10(%rsp),%rbx
mov    %r14d,%edi
mov    %rbx,%rsi
mov    $0x80,%edx
call   1040 <write@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x80,%edx
call   1080 <read@plt>
cmp    $0x80,%eax
jne    1422 <main+0x292>
lea    0x10(%rsp),%rbx
mov    %r14d,%edi
mov    %rbx,%rsi
mov    $0x80,%edx
call   1040 <write@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x80,%edx
call   1080 <read@plt>
cmp    $0x80,%eax
jne    1422 <main+0x292>
lea    0x10(%rsp),%rbx
mov    %r14d,%edi
mov    %rbx,%rsi
mov    $0x80,%edx
call   1040 <write@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x80,%edx
call   1080 <read@plt>
cmp    $0x80,%eax
jne    1422 <main+0x292>
lea    0x10(%rsp),%rsi
mov    %r14d,%edi
mov    $0x80,%edx
call   1040 <write@plt>
lea    0xc61(%rip),%rdi
call   1030 <puts@plt>
jmp    1438 <main+0x2a8>
test   %eax,%eax
jle    1438 <main+0x2a8>
lea    0x10(%rsp),%rsi
mov    %r14d,%edi
mov    $0x80,%edx
call   1040 <write@plt>
mov    %ebp,%edi
call   1070 <close@plt>
mov    %r14d,%edi
call   1070 <close@plt>
xor    %eax,%eax
add    $0x90,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xbe6(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
lea    0xba3(%rip),%rdi
jmp    1460 <main+0x2d0>
lea    0xbd4(%rip),%rdi
jmp    1460 <main+0x2d0>
lea    0xb78(%rip),%rdi
jmp    1460 <main+0x2d0>
lea    0xb96(%rip),%rdi
jmp    149a <main+0x30a>
lea    0xbc7(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@.str = [20 x i8] c"../disks/drivea.cpm\00"
@O_WRONLY = global i32 0
@.str.1 = [25 x i8] c"file ../disks/drivea.cpm\00"
@.str.2 = [9 x i8] c"boot.bin\00"
@O_RDONLY = global i32 0
@.str.3 = [14 x i8] c"file boot.bin\00"
@.str.4 = [31 x i8] c"start address of boot.bin <> 0\00"
@.str.5 = [8 x i8] c"cpm.bin\00"
@.str.6 = [13 x i8] c"file cpm.bin\00"
@.str.7 = [9 x i8] c"bios.bin\00"
@.str.8 = [14 x i8] c"file bios.bin\00"
@.str.9 = [27 x i8] c"unknown format of bios.bin\00"
@.str.10 = [41 x i8] c"6 sectors written, can't write any more!\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [3 x i8]
%3 = alloca [128 x i8]
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %1
%8 = load i32, i32* @O_WRONLY
%9 = call i32 @open(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 %8)
store i32 %9, i32* %6
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %14
11: ; preds = %0
%12 = call i32 @perror(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
%13 = call i32 @exit(i32 1)
unreachable
14: ; preds = %0
%15 = load i32, i32* @O_RDONLY
%16 = call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 %15)
store i32 %16, i32* %5
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %21
18: ; preds = %14
%19 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
%20 = call i32 @exit(i32 1)
unreachable
21: ; preds = %14
%22 = load i32, i32* %5
%23 = getelementptr inbounds [3 x i8], [3 x i8]* %2, i64 0, i64 0
%24 = call i32 @read(i32 %22, i8* %23, i32 3)
store i32 %24, i32* %7
%25 = icmp ne i32 %24, 3
br i1 %25, label %26, label %29
26: ; preds = %21
%27 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
%28 = call i32 @exit(i32 1)
unreachable
29: ; preds = %21
%30 = getelementptr inbounds [3 x i8], [3 x i8]* %2, i64 0, i64 0
%31 = load i8, i8* %30
%32 = zext i8 %31 to i32
%33 = icmp ne i32 %32, 255
br i1 %33, label %44, label %34
34: ; preds = %29
%35 = getelementptr inbounds [3 x i8], [3 x i8]* %2, i64 0, i64 1
%36 = load i8, i8* %35
%37 = zext i8 %36 to i32
%38 = icmp ne i32 %37, 0
br i1 %38, label %44, label %39
39: ; preds = %34
%40 = getelementptr inbounds [3 x i8], [3 x i8]* %2, i64 0, i64 2
%41 = load i8, i8* %40
%42 = zext i8 %41 to i32
%43 = icmp ne i32 %42, 0
br i1 %43, label %44, label %47
44: ; preds = %39, %34, %29
%45 = call i32 @puts(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0))
%46 = call i32 @exit(i32 0)
unreachable
47: ; preds = %39
%48 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%49 = call i32 @memset(i8* %48, i32 0, i32 128)
%50 = load i32, i32* %5
%51 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%52 = call i32 @read(i32 %50, i8* %51, i32 128)
%53 = load i32, i32* %5
%54 = call i32 @close(i32 %53)
%55 = load i32, i32* %6
%56 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%57 = call i32 @write(i32 %55, i8* %56, i32 128)
%58 = load i32, i32* @O_RDONLY
%59 = call i32 @open(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i32 %58)
store i32 %59, i32* %5
%60 = icmp eq i32 %59, -1
br i1 %60, label %61, label %64
61: ; preds = %47
%62 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0))
%63 = call i32 @exit(i32 1)
unreachable
64: ; preds = %47
%65 = load i32, i32* %5
%66 = call i32 @lseek(i32 %65, i64 2176, i32 0)
store i32 0, i32* %4
br label %67
67: ; preds = %82, %64
%68 = load i32, i32* %4
%69 = icmp slt i32 %68, 44
br i1 %69, label %70, label %85
70: ; preds = %67
%71 = load i32, i32* %5
%72 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%73 = call i32 @read(i32 %71, i8* %72, i32 128)
store i32 %73, i32* %7
%74 = icmp ne i32 %73, 128
br i1 %74, label %75, label %78
75: ; preds = %70
%76 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0))
%77 = call i32 @exit(i32 1)
unreachable
78: ; preds = %70
%79 = load i32, i32* %6
%80 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%81 = call i32 @write(i32 %79, i8* %80, i32 128)
br label %82
82: ; preds = %78
%83 = load i32, i32* %4
%84 = add nsw i32 %83, 1
store i32 %84, i32* %4
br label %67
85: ; preds = %67
%86 = load i32, i32* %5
%87 = call i32 @close(i32 %86)
%88 = load i32, i32* @O_RDONLY
%89 = call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.7, i64 0, i64 0), i32 %88)
store i32 %89, i32* %5
%90 = icmp eq i32 %89, -1
br i1 %90, label %91, label %94
91: ; preds = %85
%92 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.8, i64 0, i64 0))
%93 = call i32 @exit(i32 1)
unreachable
94: ; preds = %85
%95 = load i32, i32* %5
%96 = getelementptr inbounds [3 x i8], [3 x i8]* %2, i64 0, i64 0
%97 = call i32 @read(i32 %95, i8* %96, i32 3)
store i32 %97, i32* %7
%98 = icmp ne i32 %97, 3
br i1 %98, label %99, label %102
99: ; preds = %94
%100 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.8, i64 0, i64 0))
%101 = call i32 @exit(i32 1)
unreachable
102: ; preds = %94
%103 = getelementptr inbounds [3 x i8], [3 x i8]* %2, i64 0, i64 0
%104 = load i8, i8* %103
%105 = zext i8 %104 to i32
%106 = icmp ne i32 %105, 255
br i1 %106, label %107, label %110
107: ; preds = %102
%108 = call i32 @puts(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.9, i64 0, i64 0))
%109 = call i32 @exit(i32 0)
unreachable
110: ; preds = %102
store i32 0, i32* %4
br label %111
111: ; preds = %126, %110
%112 = load i32, i32* %5
%113 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%114 = call i32 @read(i32 %112, i8* %113, i32 128)
store i32 %114, i32* %7
%115 = icmp eq i32 %114, 128
br i1 %115, label %116, label %127
116: ; preds = %111
%117 = load i32, i32* %6
%118 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%119 = call i32 @write(i32 %117, i8* %118, i32 128)
%120 = load i32, i32* %4
%121 = add nsw i32 %120, 1
store i32 %121, i32* %4
%122 = load i32, i32* %4
%123 = icmp eq i32 %122, 6
br i1 %123, label %124, label %126
124: ; preds = %116
%125 = call i32 @puts(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.10, i64 0, i64 0))
br label %135
126: ; preds = %116
br label %111
127: ; preds = %111
%128 = load i32, i32* %7
%129 = icmp sgt i32 %128, 0
br i1 %129, label %130, label %134
130: ; preds = %127
%131 = load i32, i32* %6
%132 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%133 = call i32 @write(i32 %131, i8* %132, i32 128)
br label %134
134: ; preds = %130, %127
br label %135
135: ; preds = %134, %124
%136 = load i32, i32* %5
%137 = call i32 @close(i32 %136)
%138 = load i32, i32* %6
%139 = call i32 @close(i32 %138)
ret i32 0
}

LLVM IR (-O2):
@.str = [20 x i8] c"../disks/drivea.cpm\00"
@O_WRONLY = global i32 0
@.str.1 = [25 x i8] c"file ../disks/drivea.cpm\00"
@.str.2 = [9 x i8] c"boot.bin\00"
@O_RDONLY = global i32 0
@.str.3 = [14 x i8] c"file boot.bin\00"
@.str.4 = [31 x i8] c"start address of boot.bin <> 0\00"
@.str.5 = [8 x i8] c"cpm.bin\00"
@.str.6 = [13 x i8] c"file cpm.bin\00"
@.str.7 = [9 x i8] c"bios.bin\00"
@.str.8 = [14 x i8] c"file bios.bin\00"
@.str.9 = [27 x i8] c"unknown format of bios.bin\00"
@.str.10 = [41 x i8] c"6 sectors written, can't write any more!\00"
define i32 @main() {
%1 = alloca [3 x i8]
%2 = alloca [128 x i8]
%3 = getelementptr inbounds [3 x i8], [3 x i8]* %1, i64 0, i64 0
%4 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 0
%5 = load i32, i32* @O_WRONLY
%6 = tail call i32 @open(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 %5)
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %11
8: ; preds = %0
%9 = tail call i32 @perror(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
%10 = tail call i32 @exit(i32 1)
unreachable
11: ; preds = %0
%12 = load i32, i32* @O_RDONLY
%13 = tail call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 %12)
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %18
15: ; preds = %11
%16 = tail call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
%17 = tail call i32 @exit(i32 1)
unreachable
18: ; preds = %11
%19 = call i32 @read(i32 %13, i8* %3, i32 3)
%20 = icmp eq i32 %19, 3
br i1 %20, label %24, label %21
21: ; preds = %18
%22 = tail call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
%23 = tail call i32 @exit(i32 1)
unreachable
24: ; preds = %18
%25 = load i8, i8* %3
%26 = icmp ne i8 %25, -1
%27 = getelementptr inbounds [3 x i8], [3 x i8]* %1, i64 0, i64 1
%28 = load i8, i8* %27
%29 = icmp ne i8 %28, 0
%30 = select i1 %26, i1 true, i1 %29
%31 = getelementptr inbounds [3 x i8], [3 x i8]* %1, i64 0, i64 2
%32 = load i8, i8* %31
%33 = icmp ne i8 %32, 0
%34 = select i1 %30, i1 true, i1 %33
br i1 %34, label %35, label %38
35: ; preds = %24
%36 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0))
%37 = tail call i32 @exit(i32 0)
unreachable
38: ; preds = %24
%39 = call i32 @memset(i8* %4, i32 0, i32 128)
%40 = call i32 @read(i32 %13, i8* %4, i32 128)
%41 = call i32 @close(i32 %13)
%42 = call i32 @write(i32 %6, i8* %4, i32 128)
%43 = load i32, i32* @O_RDONLY
%44 = call i32 @open(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i32 %43)
%45 = icmp eq i32 %44, -1
br i1 %45, label %46, label %49
46: ; preds = %38
%47 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0))
%48 = call i32 @exit(i32 1)
unreachable
49: ; preds = %38
%50 = call i32 @lseek(i32 %44, i64 2176, i32 0)
br label %51
51: ; preds = %49, %58
%52 = phi i32 [ 0, %49 ], [ %60, %58 ]
%53 = call i32 @read(i32 %44, i8* %4, i32 128)
%54 = icmp eq i32 %53, 128
br i1 %54, label %58, label %55
55: ; preds = %51
%56 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0))
%57 = call i32 @exit(i32 1)
unreachable
58: ; preds = %51
%59 = call i32 @write(i32 %6, i8* %4, i32 128)
%60 = add nuw nsw i32 %52, 1
%61 = icmp eq i32 %60, 44
br i1 %61, label %62, label %51
62: ; preds = %58
%63 = call i32 @close(i32 %44)
%64 = load i32, i32* @O_RDONLY
%65 = call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.7, i64 0, i64 0), i32 %64)
%66 = icmp eq i32 %65, -1
br i1 %66, label %67, label %70
67: ; preds = %62
%68 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.8, i64 0, i64 0))
%69 = call i32 @exit(i32 1)
unreachable
70: ; preds = %62
%71 = call i32 @read(i32 %65, i8* %3, i32 3)
%72 = icmp eq i32 %71, 3
br i1 %72, label %76, label %73
73: ; preds = %70
%74 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.8, i64 0, i64 0))
%75 = call i32 @exit(i32 1)
unreachable
76: ; preds = %70
%77 = load i8, i8* %3
%78 = icmp eq i8 %77, -1
br i1 %78, label %79, label %82
79: ; preds = %76
%80 = call i32 @read(i32 %65, i8* %4, i32 128)
%81 = icmp eq i32 %80, 128
br i1 %81, label %85, label %108
82: ; preds = %76
%83 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.9, i64 0, i64 0))
%84 = call i32 @exit(i32 0)
unreachable
85: ; preds = %79
%86 = call i32 @write(i32 %6, i8* %4, i32 128)
%87 = call i32 @read(i32 %65, i8* %4, i32 128)
%88 = icmp eq i32 %87, 128
br i1 %88, label %89, label %108
89: ; preds = %85
%90 = call i32 @write(i32 %6, i8* %4, i32 128)
%91 = call i32 @read(i32 %65, i8* %4, i32 128)
%92 = icmp eq i32 %91, 128
br i1 %92, label %93, label %108
93: ; preds = %89
%94 = call i32 @write(i32 %6, i8* %4, i32 128)
%95 = call i32 @read(i32 %65, i8* %4, i32 128)
%96 = icmp eq i32 %95, 128
br i1 %96, label %97, label %108
97: ; preds = %93
%98 = call i32 @write(i32 %6, i8* %4, i32 128)
%99 = call i32 @read(i32 %65, i8* %4, i32 128)
%100 = icmp eq i32 %99, 128
br i1 %100, label %101, label %108
101: ; preds = %97
%102 = call i32 @write(i32 %6, i8* %4, i32 128)
%103 = call i32 @read(i32 %65, i8* %4, i32 128)
%104 = icmp eq i32 %103, 128
br i1 %104, label %105, label %108
105: ; preds = %101
%106 = call i32 @write(i32 %6, i8* %4, i32 128)
%107 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @.str.10, i64 0, i64 0))
br label %113
108: ; preds = %101, %97, %93, %89, %85, %79
%109 = phi i32 [ %80, %79 ], [ %87, %85 ], [ %91, %89 ], [ %95, %93 ], [ %99, %97 ], [ %103, %101 ]
%110 = icmp sgt i32 %109, 0
br i1 %110, label %111, label %113
111: ; preds = %108
%112 = call i32 @write(i32 %6, i8* %4, i32 128)
br label %113
113: ; preds = %108, %111, %105
%114 = call i32 @close(i32 %65)
%115 = call i32 @close(i32 %6)
ret i32 0
}