#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*/ fflush(int /*<<< orphan*/);
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 /*<<< orphan*/ printf(char *, unsigned int);
int read(int, unsigned char *, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
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 2352-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 (2352 != have_read) {
      int retval;
      retval = read(fin, inbuf + have_read, 2352 - have_read);
      if (retval < 0)
        exit(0);
      if (retval == 0)
        exit(0);
      have_read += retval;
    }
    memcpy(inbuf_copy, inbuf, 2352);
    memset(inbuf_copy, 0, 16);
    memset(inbuf_copy + 16 + 2048, 0, 4 + 8 + 276);
    do_encode_L2(inbuf_copy, 1, address++);
    if (memcmp(inbuf_copy, inbuf, 2352) != 0) {
      fprintf(stderr, "difference at sector %u\n", sector);
    } else
      verified++;
    printf("%d\r", sector);
    fflush(stdout);
  }
  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    121b <main+0x5b>
mov    0x2de0(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xdf8(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1438 <main+0x278>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
movsbl (%rax),%eax
cmp    $0x2d,%eax
jne    1240 <main+0x80>
mov    0x2d92(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
jmp    1259 <main+0x99>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2d99(%rip),%rax
mov    (%rax),%esi
call   10c0 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    1298 <main+0xd8>
lea    0xddb(%rip),%rdi
call   10d0 <perror@plt>
mov    0x2d62(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xd9a(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
movl   $0x96,-0x20(%rbp)
mov    $0x1,%al
test   $0x1,%al
jne    12ae <main+0xee>
jmp    140c <main+0x24c>
movl   $0x0,-0x1344(%rbp)
mov    $0x930,%eax
cmp    -0x1344(%rbp),%eax
je     1332 <main+0x172>
mov    -0x14(%rbp),%edi
lea    -0x9b0(%rbp),%rsi
movslq -0x1344(%rbp),%rax
add    %rax,%rsi
mov    $0x930,%edx
sub    -0x1344(%rbp),%edx
call   1060 <read@plt>
mov    %eax,-0x1348(%rbp)
cmpl   $0x0,-0x1348(%rbp)
jge    1307 <main+0x147>
xor    %edi,%edi
call   10e0 <exit@plt>
cmpl   $0x0,-0x1348(%rbp)
jne    131b <main+0x15b>
xor    %edi,%edi
call   10e0 <exit@plt>
mov    -0x1348(%rbp),%eax
add    -0x1344(%rbp),%eax
mov    %eax,-0x1344(%rbp)
jmp    12b8 <main+0xf8>
lea    -0x1340(%rbp),%rdi
lea    -0x9b0(%rbp),%rsi
mov    $0x930,%edx
call   1090 <memcpy@plt>
lea    -0x1340(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1040 <memset@plt>
lea    -0x1340(%rbp),%rdi
add    $0x10,%rdi
add    $0x800,%rdi
xor    %esi,%esi
mov    $0x120,%edx
call   1040 <memset@plt>
lea    -0x1340(%rbp),%rdi
mov    -0x20(%rbp),%edx
mov    %edx,%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
mov    $0x1,%esi
call   10a0 <do_encode_L2@plt>
lea    -0x1340(%rbp),%rdi
lea    -0x9b0(%rbp),%rsi
mov    $0x930,%edx
call   1070 <memcmp@plt>
cmp    $0x0,%rax
je     13d8 <main+0x218>
mov    0x2c18(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%edx
lea    0xc7a(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
jmp    13e1 <main+0x221>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%esi
lea    0xc74(%rip),%rdi
call   1030 <printf@plt>
mov    0x2bd9(%rip),%rax
mov    (%rax),%edi
call   10b0 <fflush@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    129f <main+0xdf>
mov    0x2bc5(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%edx
mov    -0x1c(%rbp),%ecx
lea    0xc41(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    -0x14(%rbp),%edi
call   1050 <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     11f8 <main+0x48>
mov    0x2e08(%rip),%rax
mov    (%rax),%edi
mov    0x0(%rbp),%rdx
lea    0xe23(%rip),%rsi
xor    %eax,%eax
call   1070 <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    120c <main+0x5c>
mov    0x2dc0(%rip),%rax
mov    (%rax),%ebx
jmp    121c <main+0x6c>
mov    0x2dd5(%rip),%rax
mov    (%rax),%esi
call   10b0 <open@plt>
mov    %eax,%ebx
cmp    $0xffffffff,%ebx
je     1327 <main+0x177>
mov    $0x96,%ebp
xor    %r13d,%r13d
mov    %rsp,%r15
lea    0x990(%rsp),%r12
xor    %r14d,%r14d
jmp    1270 <main+0xc0>
add    $0x1,%ebp
lea    0xe18(%rip),%rdi
mov    %r14d,%esi
call   1030 <printf@plt>
mov    0x2d7a(%rip),%rax
mov    (%rax),%edi
call   10a0 <fflush@plt>
add    $0x1,%r14d
xor    %r13d,%r13d
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movslq %r13d,%rax
lea    (%rsp,%rax,1),%rsi
add    $0x990,%rsi
mov    $0x930,%edx
sub    %eax,%edx
mov    %ebx,%edi
call   1050 <read@plt>
test   %eax,%eax
js     1320 <main+0x170>
je     1320 <main+0x170>
add    %eax,%r13d
cmp    $0x930,%r13d
jne    1270 <main+0xc0>
mov    %r15,%rdi
mov    %r12,%rsi
mov    $0x930,%edx
call   1080 <memcpy@plt>
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1040 <memset@plt>
lea    0x810(%rsp),%rdi
xor    %esi,%esi
mov    $0x120,%edx
call   1040 <memset@plt>
mov    %r15,%rdi
mov    $0x1,%esi
mov    %ebp,%edx
call   1090 <do_encode_L2@plt>
mov    %r15,%rdi
mov    %r12,%rsi
mov    $0x930,%edx
call   1060 <memcmp@plt>
test   %rax,%rax
je     123d <main+0x8d>
mov    0x2cd0(%rip),%rax
mov    (%rax),%edi
lea    0xd35(%rip),%rsi
mov    %r14d,%edx
xor    %eax,%eax
call   1070 <fprintf@plt>
jmp    123d <main+0x8d>
xor    %edi,%edi
call   10d0 <exit@plt>
lea    0xd17(%rip),%rdi
call   10c0 <perror@plt>
mov    0x2c9e(%rip),%rax
mov    (%rax),%edi
mov    0x8(%rbp),%rdx
lea    0xcda(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [33 x i8] c"Usage: %s 2352-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 = [4 x i8] c"%d\0D\00"
@stdout = global i32 0
@.str.5 = [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 %117
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 = %107, %49
br i1 true, label %51, label %110
51: ; preds = %50
store i32 0, i32* %12
br label %52
52: ; preds = %73, %51
%53 = load i32, i32* %12
%54 = icmp ne i32 2352, %53
br i1 %54, label %55, label %77
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 2352, %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 %68
66: ; preds = %55
%67 = call i32 @exit(i32 0)
unreachable
68: ; preds = %55
%69 = load i32, i32* %13
%70 = icmp eq i32 %69, 0
br i1 %70, label %71, label %73
71: ; preds = %68
%72 = call i32 @exit(i32 0)
unreachable
73: ; preds = %68
%74 = load i32, i32* %13
%75 = load i32, i32* %12
%76 = add nsw i32 %75, %74
store i32 %76, i32* %12
br label %52
77: ; preds = %52
%78 = getelementptr inbounds [2448 x i8], [2448 x i8]* %11, i64 0, i64 0
%79 = getelementptr inbounds [2448 x i8], [2448 x i8]* %10, i64 0, i64 0
%80 = call i32 @memcpy(i8* %78, i8* %79, i32 2352)
%81 = getelementptr inbounds [2448 x i8], [2448 x i8]* %11, i64 0, i64 0
%82 = call i32 @memset(i8* %81, i32 0, i32 16)
%83 = getelementptr inbounds [2448 x i8], [2448 x i8]* %11, i64 0, i64 0
%84 = getelementptr inbounds i8, i8* %83, i64 16
%85 = getelementptr inbounds i8, i8* %84, i64 2048
%86 = call i32 @memset(i8* %85, i32 0, i32 288)
%87 = getelementptr inbounds [2448 x i8], [2448 x i8]* %11, i64 0, i64 0
%88 = load i32, i32* %9
%89 = add nsw i32 %88, 1
store i32 %89, i32* %9
%90 = call i32 @do_encode_L2(i8* %87, i32 1, i32 %88)
%91 = getelementptr inbounds [2448 x i8], [2448 x i8]* %11, i64 0, i64 0
%92 = getelementptr inbounds [2448 x i8], [2448 x i8]* %10, i64 0, i64 0
%93 = call i64 @memcmp(i8* %91, i8* %92, i32 2352)
%94 = icmp ne i64 %93, 0
br i1 %94, label %95, label %99
95: ; preds = %77
%96 = load i32, i32* @stderr
%97 = load i32, i32* %7
%98 = call i32 (i32, i8*, ...) @fprintf(i32 %96, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i32 %97)
br label %102
99: ; preds = %77
%100 = load i32, i32* %8
%101 = add i32 %100, 1
store i32 %101, i32* %8
br label %102
102: ; preds = %99, %95
%103 = load i32, i32* %7
%104 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %103)
%105 = load i32, i32* @stdout
%106 = call i32 @fflush(i32 %105)
br label %107
107: ; preds = %102
%108 = load i32, i32* %7
%109 = add i32 %108, 1
store i32 %109, i32* %7
br label %50
110: ; preds = %50
%111 = load i32, i32* @stderr
%112 = load i32, i32* %7
%113 = load i32, i32* %8
%114 = call i32 (i32, i8*, ...) @fprintf(i32 %111, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0), i32 %112, i32 %113)
%115 = load i32, i32* %6
%116 = call i32 @close(i32 %115)
store i32 0, i32* %3
br label %117
117: ; preds = %110, %16
%118 = load i32, i32* %3
ret i32 %118
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [33 x i8] c"Usage: %s 2352-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 = [4 x i8] c"%d\0D\00"
@stdout = global i32 0
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 %27, 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
%26 = getelementptr inbounds [2448 x i8], [2448 x i8]* %4, i64 0, i64 2064
br label %33
27: ; preds = %20
%28 = tail call i32 @perror(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0))
%29 = load i32, i32* @stderr
%30 = load i8*, i8** %11
%31 = tail call i32 (i32, i8*, ...) @fprintf(i32 %29, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0), i8* %30)
%32 = tail call i32 @exit(i32 1)
unreachable
33: ; preds = %23, %63
%34 = phi i32 [ %67, %63 ], [ 0, %23 ]
%35 = phi i32 [ %56, %63 ], [ 150, %23 ]
br label %38
36: ; preds = %47
%37 = icmp eq i32 %49, 2352
br i1 %37, label %52, label %38
38: ; preds = %33, %36
%39 = phi i32 [ 0, %33 ], [ %49, %36 ]
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds [2448 x i8], [2448 x i8]* %3, i64 0, i64 %40
%42 = sub nsw i32 2352, %39
%43 = call i32 @read(i32 %21, i8* %41, i32 %42)
%44 = icmp slt i32 %43, 0
br i1 %44, label %45, label %47
45: ; preds = %38
%46 = call i32 @exit(i32 0)
unreachable
47: ; preds = %38
%48 = icmp eq i32 %43, 0
%49 = add nsw i32 %43, %39
br i1 %48, label %50, label %36
50: ; preds = %47
%51 = call i32 @exit(i32 0)
unreachable
52: ; preds = %36
%53 = call i32 @memcpy(i8* %25, i8* %24, i32 2352)
%54 = call i32 @memset(i8* %25, i32 0, i32 16)
%55 = call i32 @memset(i8* %26, i32 0, i32 288)
%56 = add nuw nsw i32 %35, 1
%57 = call i32 @do_encode_L2(i8* %25, i32 1, i32 %35)
%58 = call i64 @memcmp(i8* %25, i8* %24, i32 2352)
%59 = icmp eq i64 %58, 0
br i1 %59, label %63, label %60
60: ; preds = %52
%61 = load i32, i32* @stderr
%62 = call i32 (i32, i8*, ...) @fprintf(i32 %61, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i32 %34)
br label %63
63: ; preds = %52, %60
%64 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %34)
%65 = load i32, i32* @stdout
%66 = call i32 @fflush(i32 %65)
%67 = add i32 %34, 1
br label %33
}