#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 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];
    unsigned int result;
    int have_read;
    have_read = 0;
    while (2352 != have_read) {
      int retval;
      retval = read(fin, inbuf + have_read, 2352 - have_read);
      if (retval < 0)
        break;
      if (retval == 0)
        break;
      have_read += retval;
    }
    if (have_read != 2352)
      break;
    memcpy(inbuf_copy, inbuf, 2352);
    memset(inbuf_copy, 0, 16);
    memset(inbuf_copy + 16 + 8 + 2324, 0, 4);
    do_encode_L2(inbuf_copy, 4, address++);
    if (memcmp(inbuf_copy, inbuf, 2352) != 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    1415 <main+0x275>
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    13e9 <main+0x249>
movl   $0x0,-0x1348(%rbp)
mov    $0x930,%eax
cmp    -0x1348(%rbp),%eax
je     130e <main+0x16e>
mov    -0x14(%rbp),%edi
lea    -0x9b0(%rbp),%rsi
movslq -0x1348(%rbp),%rax
add    %rax,%rsi
mov    $0x930,%edx
sub    -0x1348(%rbp),%edx
call   1050 <read@plt>
mov    %eax,-0x134c(%rbp)
cmpl   $0x0,-0x134c(%rbp)
jge    12e5 <main+0x145>
jmp    130e <main+0x16e>
cmpl   $0x0,-0x134c(%rbp)
jne    12f7 <main+0x157>
jmp    130e <main+0x16e>
mov    -0x134c(%rbp),%eax
add    -0x1348(%rbp),%eax
mov    %eax,-0x1348(%rbp)
jmp    1298 <main+0xf8>
cmpl   $0x930,-0x1348(%rbp)
je     1323 <main+0x183>
jmp    13e9 <main+0x249>
lea    -0x1340(%rbp),%rdi
lea    -0x9b0(%rbp),%rsi
mov    $0x930,%edx
call   1080 <memcpy@plt>
lea    -0x1340(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1030 <memset@plt>
lea    -0x1340(%rbp),%rdi
add    $0x10,%rdi
add    $0x8,%rdi
add    $0x914,%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1030 <memset@plt>
lea    -0x1340(%rbp),%rdi
mov    -0x20(%rbp),%edx
mov    %edx,%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
mov    $0x4,%esi
call   1090 <do_encode_L2@plt>
lea    -0x1340(%rbp),%rdi
lea    -0x9b0(%rbp),%rsi
mov    $0x930,%edx
call   1060 <memcmp@plt>
cmp    $0x0,%rax
je     13cd <main+0x22d>
mov    0x2c23(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%edx
lea    0xc85(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
jmp    13d6 <main+0x236>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    13db <main+0x23b>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    127f <main+0xdf>
mov    0x2be8(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%edx
mov    -0x1c(%rbp),%ecx
lea    0xc60(%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    $0x1338,%rsp
mov    %rsi,%rbp
cmp    $0x1,%edi
jg     11d9 <main+0x39>
mov    0x2e18(%rip),%rax
mov    (%rax),%edi
mov    0x0(%rbp),%rdx
lea    0xe33(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
jmp    1339 <main+0x199>
mov    0x8(%rbp),%rdi
cmpb   $0x2d,(%rdi)
jne    11ed <main+0x4d>
mov    0x2de7(%rip),%rax
mov    (%rax),%ebx
jmp    11fd <main+0x5d>
mov    0x2df4(%rip),%rax
mov    (%rax),%esi
call   10a0 <open@plt>
mov    %eax,%ebx
cmp    $0xffffffff,%ebx
je     134d <main+0x1ad>
mov    $0x96,%r15d
xor    %r14d,%r14d
xor    %r12d,%r12d
movl   $0x0,0x8(%rsp)
jmp    1231 <main+0x91>
nopl   0x0(%rax)
addl   $0x1,0x8(%rsp)
mov    0xc(%rsp),%r12d
add    $0x1,%r12d
mov    %r13d,%r15d
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
cmp    $0x930,%ebp
je     127e <main+0xde>
movslq %ebp,%rax
lea    (%rsp,%rax,1),%rsi
add    $0x9a0,%rsi
mov    $0x930,%edx
sub    %ebp,%edx
mov    %ebx,%edi
call   1050 <read@plt>
test   %eax,%eax
mov    %eax,%ecx
cmovle %r14d,%ecx
add    %ecx,%ebp
test   %eax,%eax
jg     1240 <main+0xa0>
cmp    $0x930,%ebp
jne    1314 <main+0x174>
mov    %r12d,0xc(%rsp)
lea    0x10(%rsp),%rbp
mov    %rbp,%rdi
lea    0x9a0(%rsp),%r12
mov    %r12,%rsi
mov    $0x930,%edx
call   1080 <memcpy@plt>
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1030 <memset@plt>
lea    0x93c(%rsp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1030 <memset@plt>
lea    0x1(%r15),%r13d
mov    %rbp,%rdi
mov    $0x4,%esi
mov    %r15d,%edx
call   1090 <do_encode_L2@plt>
mov    %rbp,%rdi
mov    %r12,%rsi
mov    $0x930,%edx
call   1060 <memcmp@plt>
test   %rax,%rax
je     1220 <main+0x80>
mov    0x2ce1(%rip),%rax
mov    (%rax),%edi
lea    0xd46(%rip),%rsi
mov    0xc(%rsp),%r12d
mov    %r12d,%edx
xor    %eax,%eax
call   1070 <fprintf@plt>
jmp    122a <main+0x8a>
mov    0x2cbd(%rip),%rax
mov    (%rax),%edi
lea    0xd3b(%rip),%rsi
mov    %r12d,%edx
mov    0x8(%rsp),%ecx
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    %ebx,%edi
call   1040 <close@plt>
xor    %eax,%eax
add    $0x1338,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xcf1(%rip),%rdi
call   10b0 <perror@plt>
mov    0x2c78(%rip),%rax
mov    (%rax),%edi
mov    0x8(%rbp),%rdx
lea    0xcb4(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10c0 <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 = [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
%14 = 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
%15 = load i32, i32* %4
%16 = icmp slt i32 %15, 2
br i1 %16, label %17, label %23
17: ; preds = %2
%18 = load i32, i32* @stderr
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 0
%21 = load i8*, i8** %20
%22 = call i32 (i32, i8*, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i8* %21)
store i32 0, i32* %3
br label %117
23: ; preds = %2
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 1
%26 = load i8*, i8** %25
%27 = getelementptr inbounds i8, i8* %26, i64 0
%28 = load i8, i8* %27
%29 = sext i8 %28 to i32
%30 = icmp eq i32 %29, 45
br i1 %30, label %31, label %33
31: ; preds = %23
%32 = load i32, i32* @STDIN_FILENO
store i32 %32, i32* %6
br label %39
33: ; preds = %23
%34 = load i8**, i8*** %5
%35 = getelementptr inbounds i8*, i8** %34, i64 1
%36 = load i8*, i8** %35
%37 = load i32, i32* @O_RDONLY
%38 = call i32 @open(i8* %36, i32 %37)
store i32 %38, i32* %6
br label %39
39: ; preds = %33, %31
%40 = load i32, i32* %6
%41 = icmp eq i32 %40, -1
br i1 %41, label %42, label %50
42: ; preds = %39
%43 = call i32 @perror(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0))
%44 = load i32, i32* @stderr
%45 = load i8**, i8*** %5
%46 = getelementptr inbounds i8*, i8** %45, i64 1
%47 = load i8*, i8** %46
%48 = call i32 (i32, i8*, ...) @fprintf(i32 %44, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0), i8* %47)
%49 = call i32 @exit(i32 1)
unreachable
50: ; preds = %39
store i32 150, i32* %9
br label %51
51: ; preds = %107, %50
br i1 true, label %52, label %110
52: ; preds = %51
store i32 0, i32* %13
br label %53
53: ; preds = %72, %52
%54 = load i32, i32* %13
%55 = icmp ne i32 2352, %54
br i1 %55, label %56, label %76
56: ; preds = %53
%57 = load i32, i32* %6
%58 = getelementptr inbounds [2448 x i8], [2448 x i8]* %10, i64 0, i64 0
%59 = load i32, i32* %13
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds i8, i8* %58, i64 %60
%62 = load i32, i32* %13
%63 = sub nsw i32 2352, %62
%64 = call i32 @read(i32 %57, i8* %61, i32 %63)
store i32 %64, i32* %14
%65 = load i32, i32* %14
%66 = icmp slt i32 %65, 0
br i1 %66, label %67, label %68
67: ; preds = %56
br label %76
68: ; preds = %56
%69 = load i32, i32* %14
%70 = icmp eq i32 %69, 0
br i1 %70, label %71, label %72
71: ; preds = %68
br label %76
72: ; preds = %68
%73 = load i32, i32* %14
%74 = load i32, i32* %13
%75 = add nsw i32 %74, %73
store i32 %75, i32* %13
br label %53
76: ; preds = %71, %67, %53
%77 = load i32, i32* %13
%78 = icmp ne i32 %77, 2352
br i1 %78, label %79, label %80
79: ; preds = %76
br label %110
80: ; preds = %76
%81 = getelementptr inbounds [2448 x i8], [2448 x i8]* %11, i64 0, i64 0
%82 = getelementptr inbounds [2448 x i8], [2448 x i8]* %10, i64 0, i64 0
%83 = call i32 @memcpy(i8* %81, i8* %82, i32 2352)
%84 = getelementptr inbounds [2448 x i8], [2448 x i8]* %11, i64 0, i64 0
%85 = call i32 @memset(i8* %84, i32 0, i32 16)
%86 = getelementptr inbounds [2448 x i8], [2448 x i8]* %11, i64 0, i64 0
%87 = getelementptr inbounds i8, i8* %86, i64 16
%88 = getelementptr inbounds i8, i8* %87, i64 8
%89 = getelementptr inbounds i8, i8* %88, i64 2324
%90 = call i32 @memset(i8* %89, i32 0, i32 4)
%91 = getelementptr inbounds [2448 x i8], [2448 x i8]* %11, i64 0, i64 0
%92 = load i32, i32* %9
%93 = add nsw i32 %92, 1
store i32 %93, i32* %9
%94 = call i32 @do_encode_L2(i8* %91, i32 4, i32 %92)
%95 = getelementptr inbounds [2448 x i8], [2448 x i8]* %11, i64 0, i64 0
%96 = getelementptr inbounds [2448 x i8], [2448 x i8]* %10, i64 0, i64 0
%97 = call i64 @memcmp(i8* %95, i8* %96, i32 2352)
%98 = icmp ne i64 %97, 0
br i1 %98, label %99, label %103
99: ; preds = %80
%100 = load i32, i32* @stderr
%101 = load i32, i32* %7
%102 = call i32 (i32, i8*, ...) @fprintf(i32 %100, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i32 %101)
br label %106
103: ; preds = %80
%104 = load i32, i32* %8
%105 = add i32 %104, 1
store i32 %105, i32* %8
br label %106
106: ; preds = %103, %99
br label %107
107: ; preds = %106
%108 = load i32, i32* %7
%109 = add i32 %108, 1
store i32 %109, i32* %7
br label %51
110: ; preds = %79, %51
%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.4, 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, %17
%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 = [28 x i8] c"%u sectors, %u verified ok\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)
br label %70
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 2348
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 [ %65, %63 ], [ 0, %23 ]
%35 = phi i32 [ %64, %63 ], [ 0, %23 ]
%36 = phi i32 [ %54, %63 ], [ 150, %23 ]
br label %37
37: ; preds = %40, %33
%38 = phi i32 [ 0, %33 ], [ %47, %40 ]
%39 = icmp eq i32 %38, 2352
br i1 %39, label %50, label %40
40: ; preds = %37
%41 = sext i32 %38 to i64
%42 = getelementptr inbounds [2448 x i8], [2448 x i8]* %3, i64 0, i64 %41
%43 = sub nsw i32 2352, %38
%44 = call i32 @read(i32 %21, i8* %42, i32 %43)
%45 = icmp slt i32 %44, 1
%46 = select i1 %45, i32 0, i32 %44
%47 = add nsw i32 %46, %38
br i1 %45, label %48, label %37
48: ; preds = %40
%49 = icmp eq i32 %47, 2352
br i1 %49, label %50, label %66
50: ; preds = %37, %48
%51 = call i32 @memcpy(i8* %25, i8* %24, i32 2352)
%52 = call i32 @memset(i8* %25, i32 0, i32 16)
%53 = call i32 @memset(i8* %26, i32 0, i32 4)
%54 = add nuw nsw i32 %36, 1
%55 = call i32 @do_encode_L2(i8* %25, i32 4, i32 %36)
%56 = call i64 @memcmp(i8* %25, i8* %24, i32 2352)
%57 = icmp eq i64 %56, 0
br i1 %57, label %61, label %58
58: ; preds = %50
%59 = load i32, i32* @stderr
%60 = call i32 (i32, i8*, ...) @fprintf(i32 %59, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i32 %34)
br label %63
61: ; preds = %50
%62 = add i32 %35, 1
br label %63
63: ; preds = %61, %58
%64 = phi i32 [ %62, %61 ], [ %35, %58 ]
%65 = add i32 %34, 1
br label %33
66: ; preds = %48
%67 = load i32, i32* @stderr
%68 = call i32 (i32, i8*, ...) @fprintf(i32 %67, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0), i32 %34, i32 %35)
%69 = call i32 @close(i32 %21)
br label %70
70: ; preds = %66, %6
ret i32 0
}