#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*/ close(int);
int /*<<< orphan*/ exit(int);
int open(char *, int /*<<< orphan*/);
int read(int, char **, int);
int /*<<< orphan*/ sprintf(char *, char *, char *);
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ write(int, ...);
int main(int argc, char *argv[]) {
  char buf1[2];
  char buf2[2];
  int f1, f2, c1, c2;
  char err[50];
  if (argc != 3) {
    sprintf(err, "Usage: %s hd.img bios.img\n", argv[0]);
    write(2, &err, strlen(err));
    exit(1);
  }
  f1 = open(argv[1], O_RDONLY);
  if (f1 < 0) {
    sprintf(err, "Could not open file %s\n", argv[1]);
    write(2, &err, strlen(err));
    exit(1);
  }
  f2 = open(argv[2], O_RDONLY);
  if (f2 < 0) {
    sprintf(err, "Could not open file %s\n", argv[2]);
    write(2, &err, strlen(err));
    exit(1);
  }
  while (1) {
    c1 = read(f1, &buf1, 2);
    c2 = read(f2, &buf2, 2);
    if (c1 < 2 && c2 < 2)
      break;
    else {
      if (c1 < 2) {
        buf1[0] = 0xff;
        buf1[1] = 0xff;
      }
      if (c2 < 2) {
        buf2[0] = 0xff;
        buf2[1] = 0xff;
      }
    }
    write(1, &buf1[1], 1);
    write(1, &buf1[0], 1);
    write(1, &buf2[1], 1);
    write(1, &buf2[0], 1);
  }
  close(f1);
  close(f2);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     11cc <main+0x5c>
lea    -0x60(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe5e(%rip),%rsi
call   1080 <sprintf@plt>
lea    -0x60(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%edx
mov    $0x2,%edi
lea    -0x60(%rbp),%rsi
mov    $0x0,%al
call   1030 <write@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e0d(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    122c <main+0xbc>
lea    -0x60(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xe19(%rip),%rsi
call   1080 <sprintf@plt>
lea    -0x60(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%edx
mov    $0x2,%edi
lea    -0x60(%rbp),%rsi
mov    $0x0,%al
call   1030 <write@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
mov    0x2dad(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    128c <main+0x11c>
lea    -0x60(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdx
lea    0xdb9(%rip),%rsi
call   1080 <sprintf@plt>
lea    -0x60(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%edx
mov    $0x2,%edi
lea    -0x60(%rbp),%rsi
mov    $0x0,%al
call   1030 <write@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
jmp    1291 <main+0x121>
mov    -0x18(%rbp),%edi
lea    -0x12(%rbp),%rsi
mov    $0x2,%edx
call   1060 <read@plt>
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%edi
lea    -0x14(%rbp),%rsi
mov    $0x2,%edx
call   1060 <read@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x2,-0x20(%rbp)
jge    12d2 <main+0x162>
cmpl   $0x2,-0x24(%rbp)
jge    12d2 <main+0x162>
jmp    1350 <main+0x1e0>
cmpl   $0x2,-0x20(%rbp)
jge    12e4 <main+0x174>
movb   $0xff,-0x12(%rbp)
movb   $0xff,-0x11(%rbp)
cmpl   $0x2,-0x24(%rbp)
jge    12f6 <main+0x186>
movb   $0xff,-0x14(%rbp)
movb   $0xff,-0x13(%rbp)
jmp    12fb <main+0x18b>
lea    -0x12(%rbp),%rsi
add    $0x1,%rsi
mov    $0x1,%edx
mov    %edx,%edi
mov    $0x0,%al
call   1030 <write@plt>
lea    -0x12(%rbp),%rsi
mov    $0x1,%edx
mov    %edx,%edi
mov    $0x0,%al
call   1030 <write@plt>
lea    -0x14(%rbp),%rsi
add    $0x1,%rsi
mov    $0x1,%edx
mov    %edx,%edi
mov    $0x0,%al
call   1030 <write@plt>
lea    -0x14(%rbp),%rsi
mov    $0x1,%edx
mov    %edx,%edi
mov    $0x0,%al
call   1030 <write@plt>
jmp    1291 <main+0x121>
mov    -0x18(%rbp),%edi
call   1050 <close@plt>
mov    -0x1c(%rbp),%edi
call   1050 <close@plt>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %rsi,%rbx
cmp    $0x3,%edi
jne    12de <main+0x16e>
mov    0x8(%rbx),%rdi
mov    0x2e53(%rip),%rbp
mov    0x0(%rbp),%esi
call   1070 <open@plt>
test   %eax,%eax
js     12ea <main+0x17a>
mov    %eax,%r12d
mov    0x10(%rbx),%rdi
mov    0x0(%rbp),%esi
call   1070 <open@plt>
test   %eax,%eax
js     12f0 <main+0x180>
mov    %eax,%r13d
lea    0x10(%rsp),%rsi
mov    %r12d,%edi
mov    $0x2,%edx
call   1060 <read@plt>
mov    %eax,%ebx
lea    0xe(%rsp),%rsi
mov    %r13d,%edi
mov    $0x2,%edx
call   1060 <read@plt>
cmp    $0x2,%ebx
setl   %dl
cmp    $0x2,%eax
setl   %cl
cmp    $0x1,%ebx
jg     11ff <main+0x8f>
cmp    $0x2,%eax
jl     12bd <main+0x14d>
lea    0xf(%rsp),%r15
lea    0x10(%rsp),%rbx
lea    0xe(%rsp),%rbp
xchg   %ax,%ax
test   $0x1,%dl
je     121c <main+0xac>
movw   $0xffff,0x10(%rsp)
test   $0x1,%cl
je     1228 <main+0xb8>
movw   $0xffff,0xe(%rsp)
mov    $0x1,%edi
lea    0x11(%rsp),%rsi
mov    $0x1,%edx
xor    %eax,%eax
call   1030 <write@plt>
mov    $0x1,%edi
mov    %rbx,%rsi
mov    $0x1,%edx
xor    %eax,%eax
call   1030 <write@plt>
mov    $0x1,%edi
mov    %r15,%rsi
mov    $0x1,%edx
xor    %eax,%eax
call   1030 <write@plt>
mov    $0x1,%edi
mov    %rbp,%rsi
mov    $0x1,%edx
xor    %eax,%eax
call   1030 <write@plt>
mov    %r12d,%edi
mov    %rbx,%rsi
mov    $0x2,%edx
call   1060 <read@plt>
mov    %eax,%r14d
mov    %r13d,%edi
mov    %rbp,%rsi
mov    $0x2,%edx
call   1060 <read@plt>
cmp    $0x2,%r14d
setl   %dl
cmp    $0x2,%eax
setl   %cl
cmp    $0x1,%r14d
jg     1210 <main+0xa0>
cmp    $0x1,%eax
jg     1210 <main+0xa0>
mov    %r12d,%edi
call   1050 <close@plt>
mov    %r13d,%edi
call   1050 <close@plt>
xor    %eax,%eax
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    (%rbx),%rdx
lea    0xd18(%rip),%rsi
jmp    12fb <main+0x18b>
mov    0x8(%rbx),%rdx
jmp    12f4 <main+0x184>
mov    0x10(%rbx),%rdx
lea    0xd20(%rip),%rsi
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
call   1080 <sprintf@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    $0x2,%edi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1030 <write@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [27 x i8] c"Usage: %s hd.img bios.img\0A\00"
@O_RDONLY = global i32 0
@.str.1 = [24 x i8] c"Could not open file %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [2 x i8]
%7 = alloca [2 x i8]
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca [50 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = load i32, i32* %4
%14 = icmp ne i32 %13, 3
br i1 %14, label %15, label %25
15: ; preds = %2
%16 = getelementptr inbounds [50 x i8], [50 x i8]* %12, i64 0, i64 0
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 0
%19 = load i8*, i8** %18
%20 = call i32 @sprintf(i8* %16, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* %19)
%21 = getelementptr inbounds [50 x i8], [50 x i8]* %12, i64 0, i64 0
%22 = call i32 @strlen(i8* %21)
%23 = call i32 (i32, ...) @write(i32 2, [50 x i8]* %12, i32 %22)
%24 = call i32 @exit(i32 1)
unreachable
25: ; preds = %2
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 1
%28 = load i8*, i8** %27
%29 = load i32, i32* @O_RDONLY
%30 = call i32 @open(i8* %28, i32 %29)
store i32 %30, i32* %8
%31 = load i32, i32* %8
%32 = icmp slt i32 %31, 0
br i1 %32, label %33, label %43
33: ; preds = %25
%34 = getelementptr inbounds [50 x i8], [50 x i8]* %12, i64 0, i64 0
%35 = load i8**, i8*** %5
%36 = getelementptr inbounds i8*, i8** %35, i64 1
%37 = load i8*, i8** %36
%38 = call i32 @sprintf(i8* %34, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* %37)
%39 = getelementptr inbounds [50 x i8], [50 x i8]* %12, i64 0, i64 0
%40 = call i32 @strlen(i8* %39)
%41 = call i32 (i32, ...) @write(i32 2, [50 x i8]* %12, i32 %40)
%42 = call i32 @exit(i32 1)
unreachable
43: ; preds = %25
%44 = load i8**, i8*** %5
%45 = getelementptr inbounds i8*, i8** %44, i64 2
%46 = load i8*, i8** %45
%47 = load i32, i32* @O_RDONLY
%48 = call i32 @open(i8* %46, i32 %47)
store i32 %48, i32* %9
%49 = load i32, i32* %9
%50 = icmp slt i32 %49, 0
br i1 %50, label %51, label %61
51: ; preds = %43
%52 = getelementptr inbounds [50 x i8], [50 x i8]* %12, i64 0, i64 0
%53 = load i8**, i8*** %5
%54 = getelementptr inbounds i8*, i8** %53, i64 2
%55 = load i8*, i8** %54
%56 = call i32 @sprintf(i8* %52, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* %55)
%57 = getelementptr inbounds [50 x i8], [50 x i8]* %12, i64 0, i64 0
%58 = call i32 @strlen(i8* %57)
%59 = call i32 (i32, ...) @write(i32 2, [50 x i8]* %12, i32 %58)
%60 = call i32 @exit(i32 1)
unreachable
61: ; preds = %43
br label %62
62: ; preds = %61, %88
%63 = load i32, i32* %8
%64 = bitcast [2 x i8]* %6 to i8**
%65 = call i32 @read(i32 %63, i8** %64, i32 2)
store i32 %65, i32* %10
%66 = load i32, i32* %9
%67 = bitcast [2 x i8]* %7 to i8**
%68 = call i32 @read(i32 %66, i8** %67, i32 2)
store i32 %68, i32* %11
%69 = load i32, i32* %10
%70 = icmp slt i32 %69, 2
br i1 %70, label %71, label %75
71: ; preds = %62
%72 = load i32, i32* %11
%73 = icmp slt i32 %72, 2
br i1 %73, label %74, label %75
74: ; preds = %71
br label %97
75: ; preds = %71, %62
%76 = load i32, i32* %10
%77 = icmp slt i32 %76, 2
br i1 %77, label %78, label %81
78: ; preds = %75
%79 = getelementptr inbounds [2 x i8], [2 x i8]* %6, i64 0, i64 0
store i8 -1, i8* %79
%80 = getelementptr inbounds [2 x i8], [2 x i8]* %6, i64 0, i64 1
store i8 -1, i8* %80
br label %81
81: ; preds = %78, %75
%82 = load i32, i32* %11
%83 = icmp slt i32 %82, 2
br i1 %83, label %84, label %87
84: ; preds = %81
%85 = getelementptr inbounds [2 x i8], [2 x i8]* %7, i64 0, i64 0
store i8 -1, i8* %85
%86 = getelementptr inbounds [2 x i8], [2 x i8]* %7, i64 0, i64 1
store i8 -1, i8* %86
br label %87
87: ; preds = %84, %81
br label %88
88: ; preds = %87
%89 = getelementptr inbounds [2 x i8], [2 x i8]* %6, i64 0, i64 1
%90 = call i32 (i32, ...) @write(i32 1, i8* %89, i32 1)
%91 = getelementptr inbounds [2 x i8], [2 x i8]* %6, i64 0, i64 0
%92 = call i32 (i32, ...) @write(i32 1, i8* %91, i32 1)
%93 = getelementptr inbounds [2 x i8], [2 x i8]* %7, i64 0, i64 1
%94 = call i32 (i32, ...) @write(i32 1, i8* %93, i32 1)
%95 = getelementptr inbounds [2 x i8], [2 x i8]* %7, i64 0, i64 0
%96 = call i32 (i32, ...) @write(i32 1, i8* %95, i32 1)
br label %62
97: ; preds = %74
%98 = load i32, i32* %8
%99 = call i32 @close(i32 %98)
%100 = load i32, i32* %9
%101 = call i32 @close(i32 %100)
ret i32 0
}

LLVM IR (-O2):
@.str = [27 x i8] c"Usage: %s hd.img bios.img\0A\00"
@O_RDONLY = global i32 0
@.str.1 = [24 x i8] c"Could not open file %s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [2 x i8]
%4 = alloca [2 x i8]
%5 = alloca [50 x i8]
%6 = getelementptr inbounds [2 x i8], [2 x i8]* %3, i64 0, i64 0
%7 = getelementptr inbounds [2 x i8], [2 x i8]* %4, i64 0, i64 0
%8 = getelementptr inbounds [50 x i8], [50 x i8]* %5, i64 0, i64 0
%9 = icmp eq i32 %0, 3
br i1 %9, label %16, label %10
10: ; preds = %2
%11 = load i8*, i8** %1
%12 = call i32 @sprintf(i8* %8, i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* %11)
%13 = call i32 @strlen(i8* %8)
%14 = call i32 (i32, ...) @write(i32 2, [50 x i8]* %5, i32 %13)
%15 = call i32 @exit(i32 1)
unreachable
16: ; preds = %2
%17 = getelementptr inbounds i8*, i8** %1, i64 1
%18 = load i8*, i8** %17
%19 = load i32, i32* @O_RDONLY
%20 = tail call i32 @open(i8* %18, i32 %19)
%21 = icmp slt i32 %20, 0
br i1 %21, label %22, label %28
22: ; preds = %16
%23 = load i8*, i8** %17
%24 = call i32 @sprintf(i8* %8, i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* %23)
%25 = call i32 @strlen(i8* %8)
%26 = call i32 (i32, ...) @write(i32 2, [50 x i8]* %5, i32 %25)
%27 = call i32 @exit(i32 1)
unreachable
28: ; preds = %16
%29 = getelementptr inbounds i8*, i8** %1, i64 2
%30 = load i8*, i8** %29
%31 = load i32, i32* @O_RDONLY
%32 = tail call i32 @open(i8* %30, i32 %31)
%33 = icmp slt i32 %32, 0
br i1 %33, label %45, label %34
34: ; preds = %28
%35 = bitcast [2 x i8]* %3 to i8**
%36 = call i32 @read(i32 %20, i8** %35, i32 2)
%37 = bitcast [2 x i8]* %4 to i8**
%38 = call i32 @read(i32 %32, i8** %37, i32 2)
%39 = icmp slt i32 %36, 2
%40 = icmp slt i32 %38, 2
%41 = and i1 %39, %40
br i1 %41, label %67, label %42
42: ; preds = %34
%43 = getelementptr inbounds [2 x i8], [2 x i8]* %3, i64 0, i64 1
%44 = getelementptr inbounds [2 x i8], [2 x i8]* %4, i64 0, i64 1
br label %51
45: ; preds = %28
%46 = load i8*, i8** %29
%47 = call i32 @sprintf(i8* %8, i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* %46)
%48 = call i32 @strlen(i8* %8)
%49 = call i32 (i32, ...) @write(i32 2, [50 x i8]* %5, i32 %48)
%50 = call i32 @exit(i32 1)
unreachable
51: ; preds = %42, %57
%52 = phi i1 [ %40, %42 ], [ %65, %57 ]
%53 = phi i1 [ %39, %42 ], [ %64, %57 ]
br i1 %53, label %54, label %55
54: ; preds = %51
store i8 -1, i8* %6
store i8 -1, i8* %43
br label %55
55: ; preds = %54, %51
br i1 %52, label %56, label %57
56: ; preds = %55
store i8 -1, i8* %7
store i8 -1, i8* %44
br label %57
57: ; preds = %55, %56
%58 = call i32 (i32, ...) @write(i32 1, i8* %43, i32 1)
%59 = call i32 (i32, ...) @write(i32 1, i8* %6, i32 1)
%60 = call i32 (i32, ...) @write(i32 1, i8* %44, i32 1)
%61 = call i32 (i32, ...) @write(i32 1, i8* %7, i32 1)
%62 = call i32 @read(i32 %20, i8** %35, i32 2)
%63 = call i32 @read(i32 %32, i8** %37, i32 2)
%64 = icmp slt i32 %62, 2
%65 = icmp slt i32 %63, 2
%66 = and i1 %64, %65
br i1 %66, label %67, label %51
67: ; preds = %57, %34
%68 = call i32 @close(i32 %20)
%69 = call i32 @close(i32 %32)
ret i32 0
}