#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*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ free(int *);
int getlong(int /*<<< orphan*/ *);
int /*<<< orphan*/ handlefont(char *, int, int /*<<< orphan*/ *, int);
int *malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stderr;
void handlefile(char *filename) {
  FILE *ttc = fopen(filename, "r");
  int version, cnt, i;
  int *offsets;
  if (ttc == NULL) {
    fprintf(stderr, "Could not open %s\n", filename);
    return;
  }
  version = getlong(ttc);
  if (version != ((('t') << 24) | (('t') << 16) | (('c') << 8) | ('f'))) {
    fprintf(stderr, "%s does not look like a ttc file, bad version.\n",
            filename);
    fclose(ttc);
    return;
  }
  version = getlong(ttc);
  if (version != 0x10000 && version != 0x20000)
    fprintf(stderr, "Unexpected ttc version number: %08x\n", version);
  cnt = getlong(ttc);
  offsets = malloc(cnt * sizeof(int));
  for (i = 0; i < cnt; ++i)
    offsets[i] = getlong(ttc);
  printf("%s => ", filename);
  for (i = 0; i < cnt; ++i)
    handlefont(filename, i, ttc, offsets[i]);
  printf("\n");
  fclose(ttc);
  free(offsets);
}


x86 assembly (clang, -O0):
<handlefile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe69(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11cb <handlefile+0x4b>
mov    0x2e2e(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe43(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
jmp    1311 <handlefile+0x191>
mov    -0x10(%rbp),%rdi
call   1080 <getlong@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x74746366,-0x14(%rbp)
je     120d <handlefile+0x8d>
mov    0x2df5(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe1d(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
jmp    1311 <handlefile+0x191>
mov    -0x10(%rbp),%rdi
call   1080 <getlong@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x10000,-0x14(%rbp)
je     124d <handlefile+0xcd>
cmpl   $0x20000,-0x14(%rbp)
je     124d <handlefile+0xcd>
mov    0x2da6(%rip),%rax
mov    (%rax),%edi
mov    -0x14(%rbp),%edx
lea    0xdff(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x10(%rbp),%rdi
call   1080 <getlong@plt>
mov    %eax,-0x18(%rbp)
movslq -0x18(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    12a3 <handlefile+0x123>
mov    -0x10(%rbp),%rdi
call   1080 <getlong@plt>
mov    %eax,%edx
mov    -0x28(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1273 <handlefile+0xf3>
mov    -0x8(%rbp),%rsi
lea    0xdbc(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    12f1 <handlefile+0x171>
mov    -0x8(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    -0x10(%rbp),%rdx
mov    -0x28(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,4),%ecx
call   10a0 <handlefont@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    12bc <handlefile+0x13c>
lea    0xd4b(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<handlefile>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
lea    0xe5b(%rip),%rsi
call   10a0 <fopen@plt>
test   %rax,%rax
je     128d <handlefile+0xfd>
mov    %rax,%r15
mov    %rax,%rdi
call   1090 <getlong@plt>
cmp    $0x74746366,%eax
jne    12b5 <handlefile+0x125>
mov    %r15,%rdi
call   1090 <getlong@plt>
cmp    $0x10000,%eax
je     11f8 <handlefile+0x68>
cmp    $0x20000,%eax
je     11f8 <handlefile+0x68>
mov    0x2dfa(%rip),%rcx
mov    (%rcx),%edi
lea    0xe56(%rip),%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    %r15,%rdi
call   1090 <getlong@plt>
mov    %eax,%r12d
lea    0x0(,%r12,4),%edi
call   1080 <malloc@plt>
mov    %rax,%r13
test   %r12d,%r12d
jle    12e5 <handlefile+0x155>
mov    %r12d,%ebp
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r15,%rdi
call   1090 <getlong@plt>
mov    %eax,0x0(%r13,%rbx,4)
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1230 <handlefile+0xa0>
lea    0xe1d(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
test   %r12d,%r12d
jle    12f6 <handlefile+0x166>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    0x0(%r13,%rbx,4),%ecx
mov    %r14,%rdi
mov    %ebx,%esi
mov    %r15,%rdx
call   10b0 <handlefont@plt>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1270 <handlefile+0xe0>
jmp    12f6 <handlefile+0x166>
mov    0x2d4c(%rip),%rax
mov    (%rax),%edi
lea    0xd65(%rip),%rsi
mov    %r14,%rdx
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1070 <fprintf@plt>
mov    0x2d24(%rip),%rax
mov    (%rax),%edi
lea    0xd50(%rip),%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    %r15,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <fclose@plt>
lea    0xd7e(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0xa,%edi
call   1040 <putchar@plt>
mov    %r15,%rdi
call   1050 <fclose@plt>
mov    %r13,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [19 x i8] c"Could not open %s\0A\00"
@.str.2 = [48 x i8] c"%s does not look like a ttc file, bad version.\0A\00"
@.str.3 = [37 x i8] c"Unexpected ttc version number: %08x\0A\00"
@.str.4 = [7 x i8] c"%s => \00"
@.str.5 = [2 x i8] c"\0A\00"
define void @handlefile(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32*
store i8* %0, i8** %2
%8 = load i8*, i8** %2
%9 = call i32* @fopen(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %9, i32** %3
%10 = load i32*, i32** %3
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %16
12: ; preds = %1
%13 = load i32, i32* @stderr
%14 = load i8*, i8** %2
%15 = call i32 (i32, i8*, ...) @fprintf(i32 %13, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* %14)
br label %87
16: ; preds = %1
%17 = load i32*, i32** %3
%18 = call i32 @getlong(i32* %17)
store i32 %18, i32* %4
%19 = load i32, i32* %4
%20 = icmp ne i32 %19, 1953784678
br i1 %20, label %21, label %27
21: ; preds = %16
%22 = load i32, i32* @stderr
%23 = load i8*, i8** %2
%24 = call i32 (i32, i8*, ...) @fprintf(i32 %22, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.2, i64 0, i64 0), i8* %23)
%25 = load i32*, i32** %3
%26 = call i32 @fclose(i32* %25)
br label %87
27: ; preds = %16
%28 = load i32*, i32** %3
%29 = call i32 @getlong(i32* %28)
store i32 %29, i32* %4
%30 = load i32, i32* %4
%31 = icmp ne i32 %30, 65536
br i1 %31, label %32, label %39
32: ; preds = %27
%33 = load i32, i32* %4
%34 = icmp ne i32 %33, 131072
br i1 %34, label %35, label %39
35: ; preds = %32
%36 = load i32, i32* @stderr
%37 = load i32, i32* %4
%38 = call i32 (i32, i8*, ...) @fprintf(i32 %36, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.3, i64 0, i64 0), i32 %37)
br label %39
39: ; preds = %35, %32, %27
%40 = load i32*, i32** %3
%41 = call i32 @getlong(i32* %40)
store i32 %41, i32* %5
%42 = load i32, i32* %5
%43 = sext i32 %42 to i64
%44 = mul i64 %43, 4
%45 = trunc i64 %44 to i32
%46 = call i32* @malloc(i32 %45)
store i32* %46, i32** %7
store i32 0, i32* %6
br label %47
47: ; preds = %58, %39
%48 = load i32, i32* %6
%49 = load i32, i32* %5
%50 = icmp slt i32 %48, %49
br i1 %50, label %51, label %61
51: ; preds = %47
%52 = load i32*, i32** %3
%53 = call i32 @getlong(i32* %52)
%54 = load i32*, i32** %7
%55 = load i32, i32* %6
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds i32, i32* %54, i64 %56
store i32 %53, i32* %57
br label %58
58: ; preds = %51
%59 = load i32, i32* %6
%60 = add nsw i32 %59, 1
store i32 %60, i32* %6
br label %47
61: ; preds = %47
%62 = load i8*, i8** %2
%63 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i8* %62)
store i32 0, i32* %6
br label %64
64: ; preds = %78, %61
%65 = load i32, i32* %6
%66 = load i32, i32* %5
%67 = icmp slt i32 %65, %66
br i1 %67, label %68, label %81
68: ; preds = %64
%69 = load i8*, i8** %2
%70 = load i32, i32* %6
%71 = load i32*, i32** %3
%72 = load i32*, i32** %7
%73 = load i32, i32* %6
%74 = sext i32 %73 to i64
%75 = getelementptr inbounds i32, i32* %72, i64 %74
%76 = load i32, i32* %75
%77 = call i32 @handlefont(i8* %69, i32 %70, i32* %71, i32 %76)
br label %78
78: ; preds = %68
%79 = load i32, i32* %6
%80 = add nsw i32 %79, 1
store i32 %80, i32* %6
br label %64
81: ; preds = %64
%82 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%83 = load i32*, i32** %3
%84 = call i32 @fclose(i32* %83)
%85 = load i32*, i32** %7
%86 = call i32 @free(i32* %85)
br label %87
87: ; preds = %81, %21, %12
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [19 x i8] c"Could not open %s\0A\00"
@.str.2 = [48 x i8] c"%s does not look like a ttc file, bad version.\0A\00"
@.str.3 = [37 x i8] c"Unexpected ttc version number: %08x\0A\00"
@.str.4 = [7 x i8] c"%s => \00"
define void @handlefile(i8* %0) {
%2 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i32* %2, null
br i1 %3, label %4, label %7
4: ; preds = %1
%5 = load i32, i32* @stderr
%6 = tail call i32 (i32, i8*, ...) @fprintf(i32 %5, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %50
7: ; preds = %1
%8 = tail call i32 @getlong(i32* %2)
%9 = icmp eq i32 %8, 1953784678
br i1 %9, label %14, label %10
10: ; preds = %7
%11 = load i32, i32* @stderr
%12 = tail call i32 (i32, i8*, ...) @fprintf(i32 %11, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.2, i64 0, i64 0), i8* %0)
%13 = tail call i32 @fclose(i32* %2)
br label %50
14: ; preds = %7
%15 = tail call i32 @getlong(i32* %2)
switch i32 %15, label %16 [
i32 131072, label %19
i32 65536, label %19
]
16: ; preds = %14
%17 = load i32, i32* @stderr
%18 = tail call i32 (i32, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.3, i64 0, i64 0), i32 %15)
br label %19
19: ; preds = %14, %14, %16
%20 = tail call i32 @getlong(i32* %2)
%21 = shl i32 %20, 2
%22 = tail call i32* @malloc(i32 %21)
%23 = icmp sgt i32 %20, 0
br i1 %23, label %26, label %24
24: ; preds = %19
%25 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i8* %0)
br label %46
26: ; preds = %19
%27 = zext i32 %20 to i64
br label %28
28: ; preds = %26, %28
%29 = phi i64 [ 0, %26 ], [ %32, %28 ]
%30 = tail call i32 @getlong(i32* %2)
%31 = getelementptr inbounds i32, i32* %22, i64 %29
store i32 %30, i32* %31
%32 = add nuw nsw i64 %29, 1
%33 = icmp eq i64 %32, %27
br i1 %33, label %34, label %28
34: ; preds = %28
%35 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i8* %0)
br i1 %23, label %36, label %46
36: ; preds = %34
%37 = zext i32 %20 to i64
br label %38
38: ; preds = %36, %38
%39 = phi i64 [ 0, %36 ], [ %44, %38 ]
%40 = getelementptr inbounds i32, i32* %22, i64 %39
%41 = load i32, i32* %40
%42 = trunc i64 %39 to i32
%43 = tail call i32 @handlefont(i8* %0, i32 %42, i32* %2, i32 %41)
%44 = add nuw nsw i64 %39, 1
%45 = icmp eq i64 %44, %37
br i1 %45, label %46, label %38
46: ; preds = %38, %24, %34
%47 = tail call i32 @putchar(i32 10)
%48 = tail call i32 @fclose(i32* %2)
%49 = tail call i32 @free(i32* %22)
br label %50
50: ; preds = %46, %10, %4
ret void
}