#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 STDIN_FILENO;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ do_encode_L2(unsigned char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
scalar_t__ memcmp(unsigned char *, unsigned char *, int);
int /*<<< orphan*/ memcpy(unsigned char *, unsigned char *, int);
int /*<<< orphan*/ memset(unsigned char *, int /*<<< orphan*/, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int read(int, unsigned char *, int);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  int fin;
  unsigned int sector = 0;
  unsigned int verified = 0;
  int address;
  if (argc < 2) {
    fprintf(stderr, "Usage: %s 2448-byte-sector-file\n", argv[0]);
    return 0;
  }
  if (argv[1][0] == '-') {
    fin = STDIN_FILENO;
  } else {
    fin = open(argv[1], O_RDONLY);
  }
  if (fin == -1) {
    perror("");
    fprintf(stderr, "could not open file %s for reading.\n", argv[1]);
    exit(1);
  }
  address = 150;
  for (; 1; sector++) {
    unsigned char inbuf[2448];
    unsigned char inbuf_copy[2448];
    int have_read;
    have_read = 0;
    while (2448 != have_read) {
      int retval;
      retval = read(fin, inbuf + have_read, 2448 - have_read);
      if (retval < 0)
        break;
      if (retval == 0)
        break;
      have_read += retval;
    }
    memcpy(inbuf_copy, inbuf, 2448);
    memset(inbuf_copy, 0, 16);
    do_encode_L2(inbuf_copy, 2, address++);
    if (memcmp(inbuf_copy, inbuf, 2448) != 0) {
      fprintf(stderr, "difference at sector %u\n", sector);
    } else
      verified++;
  }
  fprintf(stderr, "%u sectors, %u verified ok\n", sector, verified);
  close(fin);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1350,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    11fb <main+0x5b>
mov    0x2e00(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe18(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    13de <main+0x23e>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
movsbl (%rax),%eax
cmp    $0x2d,%eax
jne    1220 <main+0x80>
mov    0x2dba(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
jmp    1239 <main+0x99>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2db9(%rip),%rax
mov    (%rax),%esi
call   10a0 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    1278 <main+0xd8>
lea    0xdfb(%rip),%rdi
call   10b0 <perror@plt>
mov    0x2d82(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xdba(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
movl   $0x96,-0x20(%rbp)
mov    $0x1,%al
test   $0x1,%al
jne    128e <main+0xee>
jmp    13b2 <main+0x212>
movl   $0x0,-0x1344(%rbp)
mov    $0x990,%eax
cmp    -0x1344(%rbp),%eax
je     130e <main+0x16e>
mov    -0x14(%rbp),%edi
lea    -0x9b0(%rbp),%rsi
movslq -0x1344(%rbp),%rax
add    %rax,%rsi
mov    $0x990,%edx
sub    -0x1344(%rbp),%edx
call   1050 <read@plt>
mov    %eax,-0x1348(%rbp)
cmpl   $0x0,-0x1348(%rbp)
jge    12e5 <main+0x145>
jmp    130e <main+0x16e>
cmpl   $0x0,-0x1348(%rbp)
jne    12f7 <main+0x157>
jmp    130e <main+0x16e>
mov    -0x1348(%rbp),%eax
add    -0x1344(%rbp),%eax
mov    %eax,-0x1344(%rbp)
jmp    1298 <main+0xf8>
lea    -0x1340(%rbp),%rdi
lea    -0x9b0(%rbp),%rsi
mov    $0x990,%edx
call   1080 <memcpy@plt>
lea    -0x1340(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1030 <memset@plt>
lea    -0x1340(%rbp),%rdi
mov    -0x20(%rbp),%edx
mov    %edx,%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
mov    $0x2,%esi
call   1090 <do_encode_L2@plt>
lea    -0x1340(%rbp),%rdi
lea    -0x9b0(%rbp),%rsi
mov    $0x990,%edx
call   1060 <memcmp@plt>
cmp    $0x0,%rax
je     1396 <main+0x1f6>
mov    0x2c5a(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%edx
lea    0xcbc(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
jmp    139f <main+0x1ff>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    13a4 <main+0x204>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    127f <main+0xdf>
mov    0x2c1f(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%edx
mov    -0x1c(%rbp),%ecx
lea    0xc97(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x14(%rbp),%edi
call   1040 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1350,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1328,%rsp
mov    %rsi,%rbp
cmp    $0x1,%edi
jg     11d8 <main+0x48>
mov    0x2e28(%rip),%rax
mov    (%rax),%edi
mov    0x0(%rbp),%rdx
lea    0xe43(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
xor    %eax,%eax
add    $0x1328,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x8(%rbp),%rdi
cmpb   $0x2d,(%rdi)
jne    11ec <main+0x5c>
mov    0x2de8(%rip),%rax
mov    (%rax),%ebx
jmp    11fc <main+0x6c>
mov    0x2df5(%rip),%rax
mov    (%rax),%esi
call   1090 <open@plt>
mov    %eax,%ebx
cmp    $0xffffffff,%ebx
je     12d0 <main+0x140>
mov    $0x96,%r14d
xor    %r12d,%r12d
xor    %r13d,%r13d
jmp    1228 <main+0x98>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    $0x1,%r14d
add    $0x1,%r13d
xor    %r15d,%r15d
nopl   0x0(%rax,%rax,1)
cmp    $0x990,%r15d
je     125e <main+0xce>
movslq %r15d,%rax
lea    (%rsp,%rax,1),%rsi
mov    $0x990,%edx
sub    %r15d,%edx
mov    %ebx,%edi
call   1040 <read@plt>
test   %eax,%eax
mov    %eax,%ecx
cmovle %r12d,%ecx
add    %ecx,%r15d
test   %eax,%eax
jg     1230 <main+0xa0>
lea    0x990(%rsp),%r15
mov    %r15,%rdi
mov    %rsp,%rbp
mov    %rbp,%rsi
mov    $0x990,%edx
call   1070 <memcpy@plt>
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1030 <memset@plt>
mov    %r15,%rdi
mov    $0x2,%esi
mov    %r14d,%edx
call   1080 <do_encode_L2@plt>
mov    %r15,%rdi
mov    %rbp,%rsi
mov    $0x990,%edx
call   1050 <memcmp@plt>
test   %rax,%rax
je     1220 <main+0x90>
mov    0x2d20(%rip),%rax
mov    (%rax),%edi
lea    0xd85(%rip),%rsi
mov    %r13d,%edx
xor    %eax,%eax
call   1060 <fprintf@plt>
jmp    1220 <main+0x90>
lea    0xd6e(%rip),%rdi
call   10a0 <perror@plt>
mov    0x2cf5(%rip),%rax
mov    (%rax),%edi
mov    0x8(%rbp),%rdx
lea    0xd31(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [33 x i8] c"Usage: %s 2448-byte-sector-file\0A\00"
@STDIN_FILENO = global i32 0
@O_RDONLY = global i32 0
@.str.1 = [1 x i8] zeroinitializer
@.str.2 = [37 x i8] c"could not open file %s for reading.\0A\00"
@.str.3 = [25 x i8] c"difference at sector %u\0A\00"
@.str.4 = [28 x i8] c"%u sectors, %u verified ok\0A\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 i32
%9 = alloca i32
%10 = alloca [2448 x i8]
%11 = alloca [2448 x i8]
%12 = alloca i32
%13 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %7
store i32 0, i32* %8
%14 = load i32, i32* %4
%15 = icmp slt i32 %14, 2
br i1 %15, label %16, label %22
16: ; preds = %2
%17 = load i32, i32* @stderr
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 0
%20 = load i8*, i8** %19
%21 = call i32 (i32, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i8* %20)
store i32 0, i32* %3
br label %107
22: ; preds = %2
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 1
%25 = load i8*, i8** %24
%26 = getelementptr inbounds i8, i8* %25, i64 0
%27 = load i8, i8* %26
%28 = sext i8 %27 to i32
%29 = icmp eq i32 %28, 45
br i1 %29, label %30, label %32
30: ; preds = %22
%31 = load i32, i32* @STDIN_FILENO
store i32 %31, i32* %6
br label %38
32: ; preds = %22
%33 = load i8**, i8*** %5
%34 = getelementptr inbounds i8*, i8** %33, i64 1
%35 = load i8*, i8** %34
%36 = load i32, i32* @O_RDONLY
%37 = call i32 @open(i8* %35, i32 %36)
store i32 %37, i32* %6
br label %38
38: ; preds = %32, %30
%39 = load i32, i32* %6
%40 = icmp eq i32 %39, -1
br i1 %40, label %41, label %49
41: ; preds = %38
%42 = call i32 @perror(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0))
%43 = load i32, i32* @stderr
%44 = load i8**, i8*** %5
%45 = getelementptr inbounds i8*, i8** %44, i64 1
%46 = load i8*, i8** %45
%47 = call i32 (i32, i8*, ...) @fprintf(i32 %43, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0), i8* %46)
%48 = call i32 @exit(i32 1)
unreachable
49: ; preds = %38
store i32 150, i32* %9
br label %50
50: ; preds = %97, %49
br i1 true, label %51, label %100
51: ; preds = %50
store i32 0, i32* %12
br label %52
52: ; preds = %71, %51
%53 = load i32, i32* %12
%54 = icmp ne i32 2448, %53
br i1 %54, label %55, label %75
55: ; preds = %52
%56 = load i32, i32* %6
%57 = getelementptr inbounds [2448 x i8], [2448 x i8]* %10, i64 0, i64 0
%58 = load i32, i32* %12
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds i8, i8* %57, i64 %59
%61 = load i32, i32* %12
%62 = sub nsw i32 2448, %61
%63 = call i32 @read(i32 %56, i8* %60, i32 %62)
store i32 %63, i32* %13
%64 = load i32, i32* %13
%65 = icmp slt i32 %64, 0
br i1 %65, label %66, label %67
66: ; preds = %55
br label %75
67: ; preds = %55
%68 = load i32, i32* %13
%69 = icmp eq i32 %68, 0
br i1 %69, label %70, label %71
70: ; preds = %67
br label %75
71: ; preds = %67
%72 = load i32, i32* %13
%73 = load i32, i32* %12
%74 = add nsw i32 %73, %72
store i32 %74, i32* %12
br label %52
75: ; preds = %70, %66, %52
%76 = getelementptr inbounds [2448 x i8], [2448 x i8]* %11, i64 0, i64 0
%77 = getelementptr inbounds [2448 x i8], [2448 x i8]* %10, i64 0, i64 0
%78 = call i32 @memcpy(i8* %76, i8* %77, i32 2448)
%79 = getelementptr inbounds [2448 x i8], [2448 x i8]* %11, i64 0, i64 0
%80 = call i32 @memset(i8* %79, i32 0, i32 16)
%81 = getelementptr inbounds [2448 x i8], [2448 x i8]* %11, i64 0, i64 0
%82 = load i32, i32* %9
%83 = add nsw i32 %82, 1
store i32 %83, i32* %9
%84 = call i32 @do_encode_L2(i8* %81, i32 2, i32 %82)
%85 = getelementptr inbounds [2448 x i8], [2448 x i8]* %11, i64 0, i64 0
%86 = getelementptr inbounds [2448 x i8], [2448 x i8]* %10, i64 0, i64 0
%87 = call i64 @memcmp(i8* %85, i8* %86, i32 2448)
%88 = icmp ne i64 %87, 0
br i1 %88, label %89, label %93
89: ; preds = %75
%90 = load i32, i32* @stderr
%91 = load i32, i32* %7
%92 = call i32 (i32, i8*, ...) @fprintf(i32 %90, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i32 %91)
br label %96
93: ; preds = %75
%94 = load i32, i32* %8
%95 = add i32 %94, 1
store i32 %95, i32* %8
br label %96
96: ; preds = %93, %89
br label %97
97: ; preds = %96
%98 = load i32, i32* %7
%99 = add i32 %98, 1
store i32 %99, i32* %7
br label %50
100: ; preds = %50
%101 = load i32, i32* @stderr
%102 = load i32, i32* %7
%103 = load i32, i32* %8
%104 = call i32 (i32, i8*, ...) @fprintf(i32 %101, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0), i32 %102, i32 %103)
%105 = load i32, i32* %6
%106 = call i32 @close(i32 %105)
store i32 0, i32* %3
br label %107
107: ; preds = %100, %16
%108 = load i32, i32* %3
ret i32 %108
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [33 x i8] c"Usage: %s 2448-byte-sector-file\0A\00"
@STDIN_FILENO = global i32 0
@O_RDONLY = global i32 0
@.str.1 = [1 x i8] zeroinitializer
@.str.2 = [37 x i8] c"could not open file %s for reading.\0A\00"
@.str.3 = [25 x i8] c"difference at sector %u\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [2448 x i8]
%4 = alloca [2448 x i8]
%5 = icmp slt i32 %0, 2
br i1 %5, label %6, label %10
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = load i8*, i8** %1
%9 = tail call i32 (i32, i8*, ...) @fprintf(i32 %7, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i8* %8)
ret i32 0
10: ; preds = %2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = load i8, i8* %12
%14 = icmp eq i8 %13, 45
br i1 %14, label %15, label %17
15: ; preds = %10
%16 = load i32, i32* @STDIN_FILENO
br label %20
17: ; preds = %10
%18 = load i32, i32* @O_RDONLY
%19 = tail call i32 @open(i8* %12, i32 %18)
br label %20
20: ; preds = %17, %15
%21 = phi i32 [ %16, %15 ], [ %19, %17 ]
%22 = icmp eq i32 %21, -1
br i1 %22, label %26, label %23
23: ; preds = %20
%24 = getelementptr inbounds [2448 x i8], [2448 x i8]* %3, i64 0, i64 0
%25 = getelementptr inbounds [2448 x i8], [2448 x i8]* %4, i64 0, i64 0
br label %32
26: ; preds = %20
%27 = tail call i32 @perror(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0))
%28 = load i32, i32* @stderr
%29 = load i8*, i8** %11
%30 = tail call i32 (i32, i8*, ...) @fprintf(i32 %28, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0), i8* %29)
%31 = tail call i32 @exit(i32 1)
unreachable
32: ; preds = %23, %56
%33 = phi i32 [ %57, %56 ], [ 0, %23 ]
%34 = phi i32 [ %49, %56 ], [ 150, %23 ]
br label %35
35: ; preds = %38, %32
%36 = phi i32 [ 0, %32 ], [ %45, %38 ]
%37 = icmp eq i32 %36, 2448
br i1 %37, label %46, label %38
38: ; preds = %35
%39 = sext i32 %36 to i64
%40 = getelementptr inbounds [2448 x i8], [2448 x i8]* %3, i64 0, i64 %39
%41 = sub nsw i32 2448, %36
%42 = call i32 @read(i32 %21, i8* %40, i32 %41)
%43 = icmp slt i32 %42, 1
%44 = select i1 %43, i32 0, i32 %42
%45 = add nsw i32 %44, %36
br i1 %43, label %46, label %35
46: ; preds = %38, %35
%47 = call i32 @memcpy(i8* %25, i8* %24, i32 2448)
%48 = call i32 @memset(i8* %25, i32 0, i32 16)
%49 = add nuw nsw i32 %34, 1
%50 = call i32 @do_encode_L2(i8* %25, i32 2, i32 %34)
%51 = call i64 @memcmp(i8* %25, i8* %24, i32 2448)
%52 = icmp eq i64 %51, 0
br i1 %52, label %56, label %53
53: ; preds = %46
%54 = load i32, i32* @stderr
%55 = call i32 (i32, i8*, ...) @fprintf(i32 %54, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i32 %33)
br label %56
56: ; preds = %46, %53
%57 = add i32 %33, 1
br label %32
}