#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*/ S_IWUSR;
int /*<<< orphan*/ chdir(char *);
int /*<<< orphan*/ dump_book(int /*<<< orphan*/ *, int /*<<< orphan*/ *, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ flxx_getitem(int /*<<< orphan*/ *, int);
int flxx_numitems(int /*<<< orphan*/ *);
int /*<<< orphan*/ *flxx_open(char *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
scalar_t__ mkdir(char *, int /*<<< orphan*/);
int /*<<< orphan*/ *stderr;
int main(int argc, char *argv[]) {
  FILE *fout, *fin;
  int i, max;
  if (argc != 2) {
    fprintf(stderr, "usage: %s <books filename>\n", argv[0]);
    exit(-1);
  }
  fin = flxx_open(argv[1]);
  if (fin == NULL) {
    fprintf(stderr, "couldn't open %s\n", argv[1]);
    exit(-1);
  }
  if (mkdir("u9-books", S_IWUSR) != 0) {
    fprintf(stderr, "unable to create u9-books directory\n");
    exit(-1);
  }
  chdir("u9-books");
  fout = fopen("index.html", "wt");
  if (fout == NULL) {
    fprintf(stderr, "couldn't create index.html\n");
    exit(-1);
  }
  fprintf(fout, "<HTML><HEAD><TITLE>U9 Books</TITLE></HEAD>\n");
  fprintf(fout, "<BODY>\n<H1>U9 Books</H1>\n");
  max = flxx_numitems(fin);
  for (i = 0; i < max; i++)
    if (flxx_getitem(fin, i) > 0)
      dump_book(fin, fout, i);
  fprintf(fout, "</BODY></HTML>\n");
  fclose(fout);
  fclose(fin);
  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)
cmpl   $0x2,-0x8(%rbp)
je     11e9 <main+0x49>
mov    0x2e11(%rip),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe28(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    $0xffffffff,%edi
call   10c0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10b0 <flxx_open@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    122f <main+0x8f>
mov    0x2dcc(%rip),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xdfe(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    $0xffffffff,%edi
call   10c0 <exit@plt>
mov    0x2db2(%rip),%rax
mov    (%rax),%esi
lea    0xdef(%rip),%rdi
call   1030 <mkdir@plt>
cmp    $0x0,%rax
je     1270 <main+0xd0>
mov    0x2d83(%rip),%rax
mov    (%rax),%rdi
lea    0xdd8(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    $0xffffffff,%edi
call   10c0 <exit@plt>
lea    0xdb7(%rip),%rdi
call   1050 <chdir@plt>
lea    0xdd9(%rip),%rdi
lea    0xddd(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    12c0 <main+0x120>
mov    0x2d33(%rip),%rax
mov    (%rax),%rdi
lea    0xdbb(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    $0xffffffff,%edi
call   10c0 <exit@plt>
mov    -0x18(%rbp),%rdi
lea    0xdbb(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x18(%rbp),%rdi
lea    0xdd5(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x20(%rbp),%rdi
call   1080 <flxx_numitems@plt>
mov    %eax,-0x28(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x28(%rbp),%eax
jge    133c <main+0x19c>
mov    -0x20(%rbp),%rdi
mov    -0x24(%rbp),%esi
call   1090 <flxx_getitem@plt>
cmp    $0x0,%rax
jle    1329 <main+0x189>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x24(%rbp),%edx
call   1060 <dump_book@plt>
jmp    132e <main+0x18e>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    12f7 <main+0x157>
mov    -0x18(%rbp),%rdi
lea    0xd85(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
cmp    $0x2,%edi
jne    12cb <main+0x11b>
mov    0x8(%rbx),%rdi
call   10b0 <flxx_open@plt>
test   %rax,%rax
je     12e1 <main+0x131>
mov    %rax,%r15
mov    0x2e09(%rip),%rax
mov    (%rax),%esi
lea    0xe46(%rip),%rdi
call   1030 <mkdir@plt>
test   %rax,%rax
jne    1307 <main+0x157>
lea    0xe31(%rip),%rdi
call   1050 <chdir@plt>
lea    0xe53(%rip),%rdi
lea    0xe57(%rip),%rsi
call   10a0 <fopen@plt>
test   %rax,%rax
je     131f <main+0x16f>
mov    %rax,%r14
lea    0xe5e(%rip),%rdi
mov    $0x2b,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   10d0 <fwrite@plt>
lea    0xe71(%rip),%rdi
mov    $0x19,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   10d0 <fwrite@plt>
mov    %r15,%rdi
call   1080 <flxx_numitems@plt>
test   %eax,%eax
jle    1295 <main+0xe5>
mov    %eax,%ebp
xor    %ebx,%ebx
jmp    1277 <main+0xc7>
cs nopw 0x0(%rax,%rax,1)
nop
add    $0x1,%ebx
cmp    %ebx,%ebp
je     1295 <main+0xe5>
mov    %r15,%rdi
mov    %ebx,%esi
call   1090 <flxx_getitem@plt>
test   %rax,%rax
jle    1270 <main+0xc0>
mov    %r15,%rdi
mov    %r14,%rsi
mov    %ebx,%edx
call   1060 <dump_book@plt>
jmp    1270 <main+0xc0>
lea    0xe30(%rip),%rdi
mov    $0xf,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   10d0 <fwrite@plt>
mov    %r14,%rdi
call   1040 <fclose@plt>
mov    %r15,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d06(%rip),%rax
mov    (%rax),%rdi
mov    (%rbx),%rdx
lea    0xd21(%rip),%rsi
jmp    12f6 <main+0x146>
mov    0x2cf0(%rip),%rax
mov    (%rax),%rdi
mov    0x8(%rbx),%rdx
lea    0xd26(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    $0xffffffff,%edi
call   10c0 <exit@plt>
mov    0x2cca(%rip),%rax
mov    (%rax),%rcx
lea    0xd1f(%rip),%rdi
mov    $0x24,%esi
jmp    1335 <main+0x185>
mov    0x2cb2(%rip),%rax
mov    (%rax),%rcx
lea    0xd3a(%rip),%rdi
mov    $0x1b,%esi
mov    $0x1,%edx
call   10d0 <fwrite@plt>
mov    $0xffffffff,%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
@stderr = global i32* null
@.str = [28 x i8] c"usage: %s <books filename>\0A\00"
@.str.1 = [18 x i8] c"couldn't open %s\0A\00"
@.str.2 = [9 x i8] c"u9-books\00"
@S_IWUSR = global i32 0
@.str.3 = [37 x i8] c"unable to create u9-books directory\0A\00"
@.str.4 = [11 x i8] c"index.html\00"
@.str.5 = [3 x i8] c"wt\00"
@.str.6 = [28 x i8] c"couldn't create index.html\0A\00"
@.str.7 = [44 x i8] c"<HTML><HEAD><TITLE>U9 Books</TITLE></HEAD>\0A\00"
@.str.8 = [26 x i8] c"<BODY>\0A<H1>U9 Books</H1>\0A\00"
@.str.9 = [16 x i8] c"</BODY></HTML>\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
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp ne i32 %10, 2
br i1 %11, label %12, label %19
12: ; preds = %2
%13 = load i32*, i32** @stderr
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 0
%16 = load i8*, i8** %15
%17 = call i32 (i32*, i8*, ...) @fprintf(i32* %13, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* %16)
%18 = call i32 @exit(i32 -1)
unreachable
19: ; preds = %2
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
%23 = call i32* @flxx_open(i8* %22)
store i32* %23, i32** %7
%24 = load i32*, i32** %7
%25 = icmp eq i32* %24, null
br i1 %25, label %26, label %33
26: ; preds = %19
%27 = load i32*, i32** @stderr
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 1
%30 = load i8*, i8** %29
%31 = call i32 (i32*, i8*, ...) @fprintf(i32* %27, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %30)
%32 = call i32 @exit(i32 -1)
unreachable
33: ; preds = %19
%34 = load i32, i32* @S_IWUSR
%35 = call i64 @mkdir(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 %34)
%36 = icmp ne i64 %35, 0
br i1 %36, label %37, label %41
37: ; preds = %33
%38 = load i32*, i32** @stderr
%39 = call i32 (i32*, i8*, ...) @fprintf(i32* %38, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.3, i64 0, i64 0))
%40 = call i32 @exit(i32 -1)
unreachable
41: ; preds = %33
%42 = call i32 @chdir(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
%43 = call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
store i32* %43, i32** %6
%44 = load i32*, i32** %6
%45 = icmp eq i32* %44, null
br i1 %45, label %46, label %50
46: ; preds = %41
%47 = load i32*, i32** @stderr
%48 = call i32 (i32*, i8*, ...) @fprintf(i32* %47, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.6, i64 0, i64 0))
%49 = call i32 @exit(i32 -1)
unreachable
50: ; preds = %41
%51 = load i32*, i32** %6
%52 = call i32 (i32*, i8*, ...) @fprintf(i32* %51, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.7, i64 0, i64 0))
%53 = load i32*, i32** %6
%54 = call i32 (i32*, i8*, ...) @fprintf(i32* %53, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.8, i64 0, i64 0))
%55 = load i32*, i32** %7
%56 = call i32 @flxx_numitems(i32* %55)
store i32 %56, i32* %9
store i32 0, i32* %8
br label %57
57: ; preds = %72, %50
%58 = load i32, i32* %8
%59 = load i32, i32* %9
%60 = icmp slt i32 %58, %59
br i1 %60, label %61, label %75
61: ; preds = %57
%62 = load i32*, i32** %7
%63 = load i32, i32* %8
%64 = call i64 @flxx_getitem(i32* %62, i32 %63)
%65 = icmp sgt i64 %64, 0
br i1 %65, label %66, label %71
66: ; preds = %61
%67 = load i32*, i32** %7
%68 = load i32*, i32** %6
%69 = load i32, i32* %8
%70 = call i32 @dump_book(i32* %67, i32* %68, i32 %69)
br label %71
71: ; preds = %66, %61
br label %72
72: ; preds = %71
%73 = load i32, i32* %8
%74 = add nsw i32 %73, 1
store i32 %74, i32* %8
br label %57
75: ; preds = %57
%76 = load i32*, i32** %6
%77 = call i32 (i32*, i8*, ...) @fprintf(i32* %76, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.9, i64 0, i64 0))
%78 = load i32*, i32** %6
%79 = call i32 @fclose(i32* %78)
%80 = load i32*, i32** %7
%81 = call i32 @fclose(i32* %80)
ret i32 0
}

LLVM IR (-O2):
@stderr = global i32* null
@.str = [28 x i8] c"usage: %s <books filename>\0A\00"
@.str.1 = [18 x i8] c"couldn't open %s\0A\00"
@.str.2 = [9 x i8] c"u9-books\00"
@S_IWUSR = global i32 0
@.str.3 = [37 x i8] c"unable to create u9-books directory\0A\00"
@.str.4 = [11 x i8] c"index.html\00"
@.str.5 = [3 x i8] c"wt\00"
@.str.6 = [28 x i8] c"couldn't create index.html\0A\00"
@.str.7 = [44 x i8] c"<HTML><HEAD><TITLE>U9 Books</TITLE></HEAD>\0A\00"
@.str.8 = [26 x i8] c"<BODY>\0A<H1>U9 Books</H1>\0A\00"
@.str.9 = [16 x i8] c"</BODY></HTML>\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %9, label %4
4: ; preds = %2
%5 = load i32*, i32** @stderr
%6 = load i8*, i8** %1
%7 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %5, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* %6)
%8 = tail call i32 @exit(i32 -1)
unreachable
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = tail call i32* @flxx_open(i8* %11)
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %19
14: ; preds = %9
%15 = load i32*, i32** @stderr
%16 = load i8*, i8** %10
%17 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %15, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %16)
%18 = tail call i32 @exit(i32 -1)
unreachable
19: ; preds = %9
%20 = load i32, i32* @S_IWUSR
%21 = tail call i64 @mkdir(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 %20)
%22 = icmp eq i64 %21, 0
br i1 %22, label %27, label %23
23: ; preds = %19
%24 = load i32*, i32** @stderr
%25 = tail call i64 @fwrite(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.3, i64 0, i64 0), i64 36, i64 1, i32* %24)
%26 = tail call i32 @exit(i32 -1)
unreachable
27: ; preds = %19
%28 = tail call i32 @chdir(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
%29 = tail call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
%30 = icmp eq i32* %29, null
br i1 %30, label %31, label %35
31: ; preds = %27
%32 = load i32*, i32** @stderr
%33 = tail call i64 @fwrite(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.6, i64 0, i64 0), i64 27, i64 1, i32* %32)
%34 = tail call i32 @exit(i32 -1)
unreachable
35: ; preds = %27
%36 = tail call i64 @fwrite(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.7, i64 0, i64 0), i64 43, i64 1, i32* %29)
%37 = tail call i64 @fwrite(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.8, i64 0, i64 0), i64 25, i64 1, i32* %29)
%38 = tail call i32 @flxx_numitems(i32* %12)
%39 = icmp sgt i32 %38, 0
br i1 %39, label %40, label %49
40: ; preds = %35, %46
%41 = phi i32 [ %47, %46 ], [ 0, %35 ]
%42 = tail call i64 @flxx_getitem(i32* %12, i32 %41)
%43 = icmp sgt i64 %42, 0
br i1 %43, label %44, label %46
44: ; preds = %40
%45 = tail call i32 @dump_book(i32* %12, i32* %29, i32 %41)
br label %46
46: ; preds = %40, %44
%47 = add nuw nsw i32 %41, 1
%48 = icmp eq i32 %47, %38
br i1 %48, label %49, label %40
49: ; preds = %46, %35
%50 = tail call i64 @fwrite(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.9, i64 0, i64 0), i64 15, i64 1, i32* %29)
%51 = tail call i32 @fclose(i32* %29)
%52 = tail call i32 @fclose(i32* %12)
ret i32 0
}