#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 /*<<< orphan*/ exit(int);
void *fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ fread(unsigned char *, unsigned char, int,
                         int /*<<< orphan*/ *);
int /*<<< orphan*/ *open_file(char *, char *);
int /*<<< orphan*/ usage(char *);
main(int argc, char **argv) {
  FILE *ifile, *ofile;
  char *myname = argv[0];
  char c;
  unsigned char block_count = 0;
  int block_address = 0;
  unsigned char block_data_buffer[512];
  if (argc < 3) {
    usage(myname);
    exit(1);
  }
  ifile = open_file(argv[1], "r");
  ofile = open_file(argv[2], "w");
  c = fgetc(ifile);
  if (c == 0x01) {
    block_count = fgetc(ifile);
    if (block_count == 0)
      block_count = 256;
    c = fgetc(ifile);
    block_address = fgetc(ifile);
    block_address = ((block_address <<= 8) & 0xf0) + (c & 0x0f);
    fread(block_data_buffer, block_count - 2, 1, ifile);
  } else if (c == 0x02) {
  } else if (c < 0x20) {
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x230,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
movb   $0x0,-0x2a(%rbp)
movl   $0x0,-0x30(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    119c <main+0x4c>
mov    -0x28(%rbp),%rdi
call   1060 <usage@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe55(%rip),%rsi
call   1040 <open_file@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe3f(%rip),%rsi
call   1040 <open_file@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %al,-0x29(%rbp)
movsbl -0x29(%rbp),%eax
cmp    $0x1,%eax
jne    1258 <main+0x108>
mov    -0x18(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %al,-0x2a(%rbp)
movzbl -0x2a(%rbp),%eax
cmp    $0x0,%eax
jne    1202 <main+0xb2>
movb   $0x0,-0x2a(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %al,-0x29(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %eax,-0x30(%rbp)
mov    -0x30(%rbp),%eax
shl    $0x8,%eax
mov    %eax,-0x30(%rbp)
and    $0xf0,%eax
movsbl -0x29(%rbp),%ecx
and    $0xf,%ecx
add    %ecx,%eax
mov    %eax,-0x30(%rbp)
lea    -0x230(%rbp),%rdi
movzbl -0x2a(%rbp),%eax
sub    $0x2,%eax
mov    -0x18(%rbp),%rcx
mov    $0x1,%edx
movzbl %al,%esi
call   1030 <fread@plt>
jmp    1286 <main+0x136>
movsbl -0x29(%rbp),%eax
cmp    $0x2,%eax
jne    126a <main+0x11a>
jmp    1281 <main+0x131>
movsbl -0x29(%rbp),%eax
cmp    $0x20,%eax
jge    127c <main+0x12c>
jmp    127c <main+0x12c>
jmp    1281 <main+0x131>
jmp    1286 <main+0x136>
mov    -0x4(%rbp),%eax
add    $0x230,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x208,%rsp
mov    %rsi,%rbx
cmp    $0x2,%edi
jle    11dc <main+0x8c>
mov    0x8(%rbx),%rdi
lea    0xe93(%rip),%rsi
call   1040 <open_file@plt>
mov    %rax,%r14
mov    0x10(%rbx),%rdi
lea    0xe82(%rip),%rsi
call   1040 <open_file@plt>
mov    %r14,%rdi
call   1050 <fgetc@plt>
cmp    $0x1,%al
jne    11cf <main+0x7f>
mov    %r14,%rdi
call   1050 <fgetc@plt>
mov    %rax,%rbx
mov    %r14,%rdi
call   1050 <fgetc@plt>
mov    %r14,%rdi
call   1050 <fgetc@plt>
lea    -0x2(%rbx),%eax
test   %bl,%bl
movzbl %al,%eax
mov    $0xfe,%ecx
cmovne %eax,%ecx
movzbl %cl,%esi
mov    %rsp,%rdi
mov    $0x1,%edx
mov    %r14,%rcx
call   1030 <fread@plt>
xor    %eax,%eax
add    $0x208,%rsp
pop    %rbx
pop    %r14
ret
mov    (%rbx),%rdi
call   1060 <usage@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [2 x i8] c"w\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 i8*
%9 = alloca i8
%10 = alloca i8
%11 = alloca i32
%12 = alloca [512 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 0
%15 = load i8*, i8** %14
store i8* %15, i8** %8
store i8 0, i8* %10
store i32 0, i32* %11
%16 = load i32, i32* %4
%17 = icmp slt i32 %16, 3
br i1 %17, label %18, label %22
18: ; preds = %2
%19 = load i8*, i8** %8
%20 = call i32 @usage(i8* %19)
%21 = call i32 @exit(i32 1)
unreachable
22: ; preds = %2
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 1
%25 = load i8*, i8** %24
%26 = call i32* @open_file(i8* %25, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %26, i32** %6
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 2
%29 = load i8*, i8** %28
%30 = call i32* @open_file(i8* %29, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %30, i32** %7
%31 = load i32*, i32** %6
%32 = call i8* @fgetc(i32* %31)
%33 = ptrtoint i8* %32 to i8
store i8 %33, i8* %9
%34 = load i8, i8* %9
%35 = sext i8 %34 to i32
%36 = icmp eq i32 %35, 1
br i1 %36, label %37, label %66
37: ; preds = %22
%38 = load i32*, i32** %6
%39 = call i8* @fgetc(i32* %38)
%40 = ptrtoint i8* %39 to i8
store i8 %40, i8* %10
%41 = load i8, i8* %10
%42 = zext i8 %41 to i32
%43 = icmp eq i32 %42, 0
br i1 %43, label %44, label %45
44: ; preds = %37
store i8 0, i8* %10
br label %45
45: ; preds = %44, %37
%46 = load i32*, i32** %6
%47 = call i8* @fgetc(i32* %46)
%48 = ptrtoint i8* %47 to i8
store i8 %48, i8* %9
%49 = load i32*, i32** %6
%50 = call i8* @fgetc(i32* %49)
%51 = ptrtoint i8* %50 to i32
store i32 %51, i32* %11
%52 = load i32, i32* %11
%53 = shl i32 %52, 8
store i32 %53, i32* %11
%54 = and i32 %53, 240
%55 = load i8, i8* %9
%56 = sext i8 %55 to i32
%57 = and i32 %56, 15
%58 = add nsw i32 %54, %57
store i32 %58, i32* %11
%59 = getelementptr inbounds [512 x i8], [512 x i8]* %12, i64 0, i64 0
%60 = load i8, i8* %10
%61 = zext i8 %60 to i32
%62 = sub nsw i32 %61, 2
%63 = trunc i32 %62 to i8
%64 = load i32*, i32** %6
%65 = call i32 @fread(i8* %59, i8 zeroext %63, i32 1, i32* %64)
br label %78
66: ; preds = %22
%67 = load i8, i8* %9
%68 = sext i8 %67 to i32
%69 = icmp eq i32 %68, 2
br i1 %69, label %70, label %71
70: ; preds = %66
br label %77
71: ; preds = %66
%72 = load i8, i8* %9
%73 = sext i8 %72 to i32
%74 = icmp slt i32 %73, 32
br i1 %74, label %75, label %76
75: ; preds = %71
br label %76
76: ; preds = %75, %71
br label %77
77: ; preds = %76, %70
br label %78
78: ; preds = %77, %45
%79 = load i32, i32* %3
ret i32 %79
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [2 x i8] c"w\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [512 x i8]
%4 = load i8*, i8** %1
%5 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%6 = icmp slt i32 %0, 3
br i1 %6, label %7, label %10
7: ; preds = %2
%8 = tail call i32 @usage(i8* %4)
%9 = tail call i32 @exit(i32 1)
unreachable
10: ; preds = %2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = tail call i32* @open_file(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%14 = getelementptr inbounds i8*, i8** %1, i64 2
%15 = load i8*, i8** %14
%16 = tail call i32* @open_file(i8* %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%17 = tail call i8* @fgetc(i32* %13)
%18 = ptrtoint i8* %17 to i64
%19 = and i64 %18, 255
%20 = icmp eq i64 %19, 1
br i1 %20, label %21, label %32
21: ; preds = %10
%22 = tail call i8* @fgetc(i32* %13)
%23 = ptrtoint i8* %22 to i64
%24 = trunc i64 %23 to i8
%25 = and i64 %23, 255
%26 = icmp eq i64 %25, 0
%27 = tail call i8* @fgetc(i32* %13)
%28 = tail call i8* @fgetc(i32* %13)
%29 = add i8 %24, -2
%30 = select i1 %26, i8 -2, i8 %29
%31 = call i32 @fread(i8* %5, i8 zeroext %30, i32 1, i32* %13)
br label %32
32: ; preds = %10, %21
ret i32 0
}