#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 /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int fread(unsigned char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ readRecordData(int /*<<< orphan*/ *, unsigned char *, int);
int main(int argc, char **argv) {
  FILE *fp;
  fp = fopen("", "r");
  if (fp == NULL) {
    printf("fopen failed");
    exit(0);
  }
  unsigned char typeBuffer[2];
  unsigned char recordType[2];
  unsigned char buffer[32];
  int result = 0;
  while (fread(typeBuffer, 2, 1, fp) > 0) {
    if (typeBuffer[0] == 0xFF) {
      if (typeBuffer[1] == 0xFF) {
        result = fread(buffer, 25, 1, fp);
        if (result == 0) {
          printf("error reading start record");
          break;
        }
        readRecordData(fp, buffer, 10);
      }
      if (typeBuffer[1] == 0xFE) {
      }
      if (typeBuffer[1] == 0xFD) {
      }
    }
  }
  fclose(fp);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe91(%rip),%rdi
lea    0xe7c(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11ab <main+0x4b>
lea    0xe63(%rip),%rdi
call   1050 <printf@plt>
xor    %edi,%edi
call   1080 <exit@plt>
movl   $0x0,-0x44(%rbp)
lea    -0x1a(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x2,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
cmp    $0x0,%eax
jle    1269 <main+0x109>
movzbl -0x1a(%rbp),%eax
cmp    $0xff,%eax
jne    1264 <main+0x104>
movzbl -0x19(%rbp),%eax
cmp    $0xff,%eax
jne    1237 <main+0xd7>
lea    -0x40(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x19,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
mov    %eax,-0x44(%rbp)
cmpl   $0x0,-0x44(%rbp)
jne    1225 <main+0xc5>
lea    0xdf4(%rip),%rdi
call   1050 <printf@plt>
jmp    1269 <main+0x109>
mov    -0x18(%rbp),%rdi
lea    -0x40(%rbp),%rsi
mov    $0xa,%edx
call   1060 <readRecordData@plt>
movzbl -0x19(%rbp),%eax
cmp    $0xfe,%eax
jne    124b <main+0xeb>
jmp    124b <main+0xeb>
movzbl -0x19(%rbp),%eax
cmp    $0xfd,%eax
jne    125f <main+0xff>
jmp    125f <main+0xff>
jmp    1264 <main+0x104>
jmp    11b2 <main+0x52>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x30,%rsp
lea    0xe9e(%rip),%rdi
lea    0xe89(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     1220 <main+0xc0>
mov    %rax,%rbx
lea    0xe(%rsp),%rdi
mov    $0x2,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   1030 <fread@plt>
test   %eax,%eax
jle    120c <main+0xac>
lea    0x10(%rsp),%r14
lea    0xe(%rsp),%r15
jmp    11d9 <main+0x79>
nop
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0xa,%edx
call   1060 <readRecordData@plt>
mov    %r15,%rdi
mov    $0x2,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1030 <fread@plt>
test   %eax,%eax
jle    120c <main+0xac>
cmpb   $0xff,0xe(%rsp)
jne    11c0 <main+0x60>
cmpb   $0xff,0xf(%rsp)
jne    11c0 <main+0x60>
mov    %r14,%rdi
mov    $0x19,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1030 <fread@plt>
test   %eax,%eax
jne    11b0 <main+0x50>
lea    0xe08(%rip),%rdi
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xddb(%rip),%rdi
call   1050 <printf@plt>
xor    %edi,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [1 x i8] zeroinitializer
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [13 x i8] c"fopen failed\00"
@.str.3 = [27 x i8] c"error reading start record\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca [2 x i8]
%8 = alloca [2 x i8]
%9 = alloca [32 x i8]
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = call i32* @fopen(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %11, i32** %6
%12 = load i32*, i32** %6
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %17
14: ; preds = %2
%15 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%16 = call i32 @exit(i32 0)
unreachable
17: ; preds = %2
store i32 0, i32* %10
br label %18
18: ; preds = %58, %17
%19 = getelementptr inbounds [2 x i8], [2 x i8]* %7, i64 0, i64 0
%20 = load i32*, i32** %6
%21 = call i32 @fread(i8* %19, i32 2, i32 1, i32* %20)
%22 = icmp sgt i32 %21, 0
br i1 %22, label %23, label %59
23: ; preds = %18
%24 = getelementptr inbounds [2 x i8], [2 x i8]* %7, i64 0, i64 0
%25 = load i8, i8* %24
%26 = zext i8 %25 to i32
%27 = icmp eq i32 %26, 255
br i1 %27, label %28, label %58
28: ; preds = %23
%29 = getelementptr inbounds [2 x i8], [2 x i8]* %7, i64 0, i64 1
%30 = load i8, i8* %29
%31 = zext i8 %30 to i32
%32 = icmp eq i32 %31, 255
br i1 %32, label %33, label %45
33: ; preds = %28
%34 = getelementptr inbounds [32 x i8], [32 x i8]* %9, i64 0, i64 0
%35 = load i32*, i32** %6
%36 = call i32 @fread(i8* %34, i32 25, i32 1, i32* %35)
store i32 %36, i32* %10
%37 = load i32, i32* %10
%38 = icmp eq i32 %37, 0
br i1 %38, label %39, label %41
39: ; preds = %33
%40 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0))
br label %59
41: ; preds = %33
%42 = load i32*, i32** %6
%43 = getelementptr inbounds [32 x i8], [32 x i8]* %9, i64 0, i64 0
%44 = call i32 @readRecordData(i32* %42, i8* %43, i32 10)
br label %45
45: ; preds = %41, %28
%46 = getelementptr inbounds [2 x i8], [2 x i8]* %7, i64 0, i64 1
%47 = load i8, i8* %46
%48 = zext i8 %47 to i32
%49 = icmp eq i32 %48, 254
br i1 %49, label %50, label %51
50: ; preds = %45
br label %51
51: ; preds = %50, %45
%52 = getelementptr inbounds [2 x i8], [2 x i8]* %7, i64 0, i64 1
%53 = load i8, i8* %52
%54 = zext i8 %53 to i32
%55 = icmp eq i32 %54, 253
br i1 %55, label %56, label %57
56: ; preds = %51
br label %57
57: ; preds = %56, %51
br label %58
58: ; preds = %57, %23
br label %18
59: ; preds = %39, %18
%60 = load i32*, i32** %6
%61 = call i32 @fclose(i32* %60)
ret i32 0
}

LLVM IR (-O2):
@.str = [1 x i8] zeroinitializer
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [13 x i8] c"fopen failed\00"
@.str.3 = [27 x i8] c"error reading start record\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [2 x i8]
%4 = alloca [32 x i8]
%5 = tail call i32* @fopen(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %10
7: ; preds = %2
%8 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%9 = tail call i32 @exit(i32 0)
unreachable
10: ; preds = %2
%11 = getelementptr inbounds [2 x i8], [2 x i8]* %3, i64 0, i64 0
%12 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 0
%13 = call i32 @fread(i8* %11, i32 2, i32 1, i32* %5)
%14 = icmp sgt i32 %13, 0
br i1 %14, label %15, label %33
15: ; preds = %10
%16 = getelementptr inbounds [2 x i8], [2 x i8]* %3, i64 0, i64 1
br label %17
17: ; preds = %15, %30
%18 = load i8, i8* %11
%19 = icmp eq i8 %18, -1
%20 = load i8, i8* %16
%21 = icmp eq i8 %20, -1
%22 = select i1 %19, i1 %21, i1 false
br i1 %22, label %23, label %30
23: ; preds = %17
%24 = call i32 @fread(i8* %12, i32 25, i32 1, i32* %5)
%25 = icmp eq i32 %24, 0
br i1 %25, label %26, label %28
26: ; preds = %23
%27 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0))
br label %33
28: ; preds = %23
%29 = call i32 @readRecordData(i32* %5, i8* %12, i32 10)
br label %30
30: ; preds = %28, %17
%31 = call i32 @fread(i8* %11, i32 2, i32 1, i32* %5)
%32 = icmp sgt i32 %31, 0
br i1 %32, label %17, label %33
33: ; preds = %30, %10, %26
%34 = call i32 @fclose(i32* %5)
ret i32 0
}