#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);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ list_file(int /*<<< orphan*/ *, char *);
int /*<<< orphan*/ printf(char *);
scalar_t__ strncmp(char const *, char *, int);
int main(int argc, char **argv) {
  int a;
  FILE *f;
  char buf[16];
  printf("FILENAME                                 KC-NAME       "
         "ADDR START LENGTH\n");
  for (a = 1; a < argc; a++) {
    f = fopen(argv[a], "rb");
    if (!f)
      continue;
    if (fread(buf, 1, 16, f) != 16) {
      fclose(f);
      exit(2);
    }
    if (strncmp((const char *)&buf[1], "KC-TAPE by AF", 13) != 0) {
      fclose(f);
      exit(3);
    }
    list_file(f, argv[a]);
    fclose(f);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe73(%rip),%rdi
call   1060 <printf@plt>
movl   $0x1,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1266 <main+0xf6>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xe92(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11d1 <main+0x61>
jmp    1258 <main+0xe8>
lea    -0x30(%rbp),%rdi
mov    -0x20(%rbp),%rcx
mov    $0x1,%esi
mov    $0x10,%edx
call   1040 <fread@plt>
cmp    $0x10,%eax
je     1204 <main+0x94>
mov    -0x20(%rbp),%rdi
call   1050 <fclose@plt>
mov    $0x2,%edi
call   1090 <exit@plt>
lea    -0x30(%rbp),%rdi
add    $0x1,%rdi
lea    0xe3a(%rip),%rsi
mov    $0xd,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
je     123a <main+0xca>
mov    -0x20(%rbp),%rdi
call   1050 <fclose@plt>
mov    $0x3,%edi
call   1090 <exit@plt>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
call   1070 <list_file@plt>
mov    -0x20(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1199 <main+0x29>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
lea    0xe87(%rip),%rdi
call   1040 <puts@plt>
cmp    $0x2,%ebp
jl     1234 <main+0xc4>
mov    %ebp,%r14d
mov    $0x1,%r12d
lea    0xe58(%rip),%r15
lea    0xe54(%rip),%r13
jmp    11dd <main+0x6d>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    (%rbx,%r12,8),%rsi
mov    %rbp,%rdi
call   1070 <list_file@plt>
mov    %rbp,%rdi
call   1060 <fclose@plt>
add    $0x1,%r12
cmp    %r12,%r14
je     1234 <main+0xc4>
mov    (%rbx,%r12,8),%rdi
mov    %r15,%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     11d4 <main+0x64>
mov    %rax,%rbp
mov    %rsp,%rdi
mov    $0x1,%esi
mov    $0x10,%edx
mov    %rax,%rcx
call   1050 <fread@plt>
cmp    $0x10,%eax
jne    1245 <main+0xd5>
lea    0x1(%rsp),%rdi
mov    %r13,%rsi
mov    $0xd,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     11c0 <main+0x50>
mov    %rbp,%rdi
call   1060 <fclose@plt>
mov    $0x3,%edi
call   1090 <exit@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %rbp,%rdi
call   1060 <fclose@plt>
mov    $0x2,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [74 x i8] c"FILENAME KC-NAME ADDR START LENGTH\0A\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [14 x i8] c"KC-TAPE by AF\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 [16 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = call i32 @printf(i8* getelementptr inbounds ([74 x i8], [74 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %6
br label %10
10: ; preds = %51, %2
%11 = load i32, i32* %6
%12 = load i32, i32* %4
%13 = icmp slt i32 %11, %12
br i1 %13, label %14, label %54
14: ; preds = %10
%15 = load i8**, i8*** %5
%16 = load i32, i32* %6
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8*, i8** %15, i64 %17
%19 = load i8*, i8** %18
%20 = call i32* @fopen(i8* %19, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %20, i32** %7
%21 = load i32*, i32** %7
%22 = icmp ne i32* %21, null
br i1 %22, label %24, label %23
23: ; preds = %14
br label %51
24: ; preds = %14
%25 = getelementptr inbounds [16 x i8], [16 x i8]* %8, i64 0, i64 0
%26 = load i32*, i32** %7
%27 = call i32 @fread(i8* %25, i32 1, i32 16, i32* %26)
%28 = icmp ne i32 %27, 16
br i1 %28, label %29, label %33
29: ; preds = %24
%30 = load i32*, i32** %7
%31 = call i32 @fclose(i32* %30)
%32 = call i32 @exit(i32 2)
unreachable
33: ; preds = %24
%34 = getelementptr inbounds [16 x i8], [16 x i8]* %8, i64 0, i64 1
%35 = call i64 @strncmp(i8* %34, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32 13)
%36 = icmp ne i64 %35, 0
br i1 %36, label %37, label %41
37: ; preds = %33
%38 = load i32*, i32** %7
%39 = call i32 @fclose(i32* %38)
%40 = call i32 @exit(i32 3)
unreachable
41: ; preds = %33
%42 = load i32*, i32** %7
%43 = load i8**, i8*** %5
%44 = load i32, i32* %6
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds i8*, i8** %43, i64 %45
%47 = load i8*, i8** %46
%48 = call i32 @list_file(i32* %42, i8* %47)
%49 = load i32*, i32** %7
%50 = call i32 @fclose(i32* %49)
br label %51
51: ; preds = %41, %23
%52 = load i32, i32* %6
%53 = add nsw i32 %52, 1
store i32 %53, i32* %6
br label %10
54: ; preds = %10
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [14 x i8] c"KC-TAPE by AF\00"
@str = [73 x i8] c"FILENAME KC-NAME ADDR START LENGTH\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [16 x i8]
%4 = getelementptr inbounds [16 x i8], [16 x i8]* %3, i64 0, i64 0
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([73 x i8], [73 x i8]* @str, i64 0, i64 0))
%6 = icmp sgt i32 %0, 1
br i1 %6, label %7, label %35
7: ; preds = %2
%8 = getelementptr inbounds [16 x i8], [16 x i8]* %3, i64 0, i64 1
%9 = zext i32 %0 to i64
br label %10
10: ; preds = %7, %32
%11 = phi i64 [ 1, %7 ], [ %33, %32 ]
%12 = getelementptr inbounds i8*, i8** %1, i64 %11
%13 = load i8*, i8** %12
%14 = call i32* @fopen(i8* %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%15 = icmp eq i32* %14, null
br i1 %15, label %32, label %16
16: ; preds = %10
%17 = call i32 @fread(i8* %4, i32 1, i32 16, i32* %14)
%18 = icmp eq i32 %17, 16
br i1 %18, label %22, label %19
19: ; preds = %16
%20 = call i32 @fclose(i32* %14)
%21 = call i32 @exit(i32 2)
unreachable
22: ; preds = %16
%23 = call i64 @strncmp(i8* %8, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32 13)
%24 = icmp eq i64 %23, 0
br i1 %24, label %28, label %25
25: ; preds = %22
%26 = call i32 @fclose(i32* %14)
%27 = call i32 @exit(i32 3)
unreachable
28: ; preds = %22
%29 = load i8*, i8** %12
%30 = call i32 @list_file(i32* %14, i8* %29)
%31 = call i32 @fclose(i32* %14)
br label %32
32: ; preds = %10, %28
%33 = add nuw nsw i64 %11, 1
%34 = icmp eq i64 %33, %9
br i1 %34, label %35, label %10
35: ; preds = %32, %2
ret i32 0
}