#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*/ fclose(int /*<<< orphan*/ *);
scalar_t__ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
unsigned char fsd_processheader(int /*<<< orphan*/ *);
int /*<<< orphan*/ fsd_processtrack(int /*<<< orphan*/ *, unsigned char);
int /*<<< orphan*/ printf(char *);
int main(int argc, char **argv) {
  unsigned char numtracks;
  unsigned char track;
  FILE *fp;
  if (argc != 2) {
    printf("Specify .fsd on command line\n");
    return 1;
  }
  fp = fopen(argv[1], "rb");
  if (fp == NULL) {
    printf("Unable to open file\n");
    return 2;
  }
  numtracks = fsd_processheader(fp);
  for (track = 0; track < numtracks; track++) {
    if (feof(fp))
      break;
    fsd_processtrack(fp, track);
  }
  fclose(fp);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     1198 <main+0x38>
lea    0xe79(%rip),%rdi
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1235 <main+0xd5>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe77(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11d3 <main+0x73>
lea    0xe5f(%rip),%rdi
call   1040 <printf@plt>
movl   $0x2,-0x4(%rbp)
jmp    1235 <main+0xd5>
mov    -0x20(%rbp),%rdi
call   1080 <fsd_processheader@plt>
mov    %al,-0x11(%rbp)
movb   $0x0,-0x12(%rbp)
movzbl -0x12(%rbp),%eax
movzbl -0x11(%rbp),%ecx
cmp    %ecx,%eax
jge    1225 <main+0xc5>
mov    -0x20(%rbp),%rdi
call   1050 <feof@plt>
cmp    $0x0,%rax
je     120b <main+0xab>
jmp    1225 <main+0xc5>
mov    -0x20(%rbp),%rdi
movzbl -0x12(%rbp),%esi
call   1060 <fsd_processtrack@plt>
mov    -0x12(%rbp),%al
add    $0x1,%al
mov    %al,-0x12(%rbp)
jmp    11e3 <main+0x83>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
cmp    $0x2,%edi
jne    11d0 <main+0x70>
mov    0x8(%rsi),%rdi
lea    0xe8c(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     11e3 <main+0x83>
mov    %rax,%rbx
mov    %rax,%rdi
call   1080 <fsd_processheader@plt>
test   %al,%al
je     11c4 <main+0x64>
mov    %eax,%r14d
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rbx,%rdi
call   1050 <feof@plt>
test   %rax,%rax
jne    11c4 <main+0x64>
movzbl %bpl,%ebp
mov    %rbx,%rdi
mov    %ebp,%esi
call   1060 <fsd_processtrack@plt>
add    $0x1,%bpl
cmp    %bpl,%r14b
jne    11a0 <main+0x40>
mov    %rbx,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
jmp    11f4 <main+0x94>
lea    0xe40(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%eax
jmp    11f4 <main+0x94>
lea    0xe19(%rip),%rdi
call   1030 <puts@plt>
mov    $0x2,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [30 x i8] c"Specify .fsd on command line\0A\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [21 x i8] c"Unable to open file\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8
%7 = alloca i8
%8 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp ne i32 %9, 2
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %46
13: ; preds = %2
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 1
%16 = load i8*, i8** %15
%17 = call i32* @fopen(i8* %16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %17, i32** %8
%18 = load i32*, i32** %8
%19 = icmp eq i32* %18, null
br i1 %19, label %20, label %22
20: ; preds = %13
%21 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
store i32 2, i32* %3
br label %46
22: ; preds = %13
%23 = load i32*, i32** %8
%24 = call zeroext i8 @fsd_processheader(i32* %23)
store i8 %24, i8* %6
store i8 0, i8* %7
br label %25
25: ; preds = %40, %22
%26 = load i8, i8* %7
%27 = zext i8 %26 to i32
%28 = load i8, i8* %6
%29 = zext i8 %28 to i32
%30 = icmp slt i32 %27, %29
br i1 %30, label %31, label %43
31: ; preds = %25
%32 = load i32*, i32** %8
%33 = call i64 @feof(i32* %32)
%34 = icmp ne i64 %33, 0
br i1 %34, label %35, label %36
35: ; preds = %31
br label %43
36: ; preds = %31
%37 = load i32*, i32** %8
%38 = load i8, i8* %7
%39 = call i32 @fsd_processtrack(i32* %37, i8 zeroext %38)
br label %40
40: ; preds = %36
%41 = load i8, i8* %7
%42 = add i8 %41, 1
store i8 %42, i8* %7
br label %25
43: ; preds = %35, %25
%44 = load i32*, i32** %8
%45 = call i32 @fclose(i32* %44)
store i32 0, i32* %3
br label %46
46: ; preds = %43, %20, %11
%47 = load i32, i32* %3
ret i32 %47
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"rb\00"
@str = [20 x i8] c"Unable to open file\00"
@str.3 = [29 x i8] c"Specify .fsd on command line\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %6, label %4
4: ; preds = %2
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str.3, i64 0, i64 0))
br label %26
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = tail call i32* @fopen(i8* %8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %13
11: ; preds = %6
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str, i64 0, i64 0))
br label %26
13: ; preds = %6
%14 = tail call zeroext i8 @fsd_processheader(i32* %9)
%15 = icmp eq i8 %14, 0
br i1 %15, label %24, label %16
16: ; preds = %13, %20
%17 = phi i8 [ %22, %20 ], [ 0, %13 ]
%18 = tail call i64 @feof(i32* %9)
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %24
20: ; preds = %16
%21 = tail call i32 @fsd_processtrack(i32* %9, i8 zeroext %17)
%22 = add nuw i8 %17, 1
%23 = icmp eq i8 %22, %14
br i1 %23, label %24, label %16
24: ; preds = %20, %16, %13
%25 = tail call i32 @fclose(i32* %9)
br label %26
26: ; preds = %24, %11, %4
%27 = phi i32 [ 1, %4 ], [ 2, %11 ], [ 0, %24 ]
ret i32 %27
}