#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 */
long decode(int /*<<< orphan*/ *, long);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int main(int argc, char *argv[]) {
  FILE *fin;
  long offset;
  printf("Palm Font Extractor, Version 1.3\n"
         "Copyright (C) 2002-2003 Serge Vakulenko\n\n");
  if (argc != 2) {
    printf("Extracts Pilot font resources to ASCII files that can be\n"
           "compiled with PilRC, and binary files that can be edited\n"
           "with Pilot Font Editor.\n"
           "\nUsage:\n\tfextract infile\n\n"
           "For every font it creates text files named `a-WxH.pfn',\n"
           "and binary files named `a-WxH.pft'. Here W and H are\n"
           "the font width and height respectively. The first letter\n"
           "is `a' for first font, `b' for second font and so on.\n");
    exit(1);
  }
  fin = fopen(argv[1], "rb");
  if (!fin) {
    perror(argv[1]);
    exit(1);
  }
  offset = 0;
  while (offset >= 0)
    offset = decode(fin, offset);
  fclose(fin);
  exit(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)
lea    0xe83(%rip),%rdi
call   1040 <printf@plt>
cmpl   $0x2,-0x8(%rbp)
je     11a2 <main+0x42>
lea    0xeb8(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0x101b(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11dc <main+0x7c>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
movq   $0x0,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jl     1205 <main+0xa5>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1050 <decode@plt>
mov    %rax,-0x20(%rbp)
jmp    11e4 <main+0x84>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
xor    %edi,%edi
call   1080 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %edi,%ebx
lea    0xe93(%rip),%rdi
call   1030 <puts@plt>
cmp    $0x2,%ebx
jne    11a2 <main+0x42>
mov    0x8(%r14),%rdi
lea    0xe7b(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
jne    11b8 <main+0x58>
mov    0x8(%r14),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
lea    0xea4(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    %rax,%rbx
xor    %eax,%eax
nopl   (%rax)
mov    %rbx,%rdi
mov    %rax,%rsi
call   1050 <decode@plt>
test   %rax,%rax
jns    11c0 <main+0x60>
mov    %rbx,%rdi
call   1040 <fclose@plt>
xor    %edi,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [75 x i8] c"Palm Font Extractor, Version 1.3\0ACopyright (C) 2002-2003 Serge Vakulenko\0A\0A\00"
@.str.1 = [385 x i8] c"Extracts Pilot font resources to ASCII files that can be\0Acompiled with PilRC, and binary files that can be edited\0Awith Pilot Font Editor.\0A\0AUsage:\0A\09fextract infile\0A\0AFor every font it creates text files named `a-WxH.pfn',\0Aand binary files named `a-WxH.pft'. Here W and H are\0Athe font width and height respectively. The first letter\0Ais `a' for first font, `b' for second font and so on.\0A\00"
@.str.2 = [3 x i8] c"rb\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = call i32 @printf(i8* getelementptr inbounds ([75 x i8], [75 x i8]* @.str, i64 0, i64 0))
%9 = load i32, i32* %4
%10 = icmp ne i32 %9, 2
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = call i32 @printf(i8* getelementptr inbounds ([385 x i8], [385 x i8]* @.str.1, i64 0, i64 0))
%13 = call i32 @exit(i32 1)
unreachable
14: ; preds = %2
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
%18 = call i32* @fopen(i8* %17, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i32* %18, i32** %6
%19 = load i32*, i32** %6
%20 = icmp ne i32* %19, null
br i1 %20, label %27, label %21
21: ; preds = %14
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i8*, i8** %23
%25 = call i32 @perror(i8* %24)
%26 = call i32 @exit(i32 1)
unreachable
27: ; preds = %14
store i64 0, i64* %7
br label %28
28: ; preds = %31, %27
%29 = load i64, i64* %7
%30 = icmp sge i64 %29, 0
br i1 %30, label %31, label %35
31: ; preds = %28
%32 = load i32*, i32** %6
%33 = load i64, i64* %7
%34 = call i64 @decode(i32* %32, i64 %33)
store i64 %34, i64* %7
br label %28
35: ; preds = %28
%36 = load i32*, i32** %6
%37 = call i32 @fclose(i32* %36)
%38 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str.2 = [3 x i8] c"rb\00"
@str = [74 x i8] c"Palm Font Extractor, Version 1.3\0ACopyright (C) 2002-2003 Serge Vakulenko\0A\00"
@str.3 = [384 x i8] c"Extracts Pilot font resources to ASCII files that can be\0Acompiled with PilRC, and binary files that can be edited\0Awith Pilot Font Editor.\0A\0AUsage:\0A\09fextract infile\0A\0AFor every font it creates text files named `a-WxH.pfn',\0Aand binary files named `a-WxH.pft'. Here W and H are\0Athe font width and height respectively. The first letter\0Ais `a' for first font, `b' for second font and so on.\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([74 x i8], [74 x i8]* @str, i64 0, i64 0))
%4 = icmp eq i32 %0, 2
br i1 %4, label %8, label %5
5: ; preds = %2
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([384 x i8], [384 x i8]* @str.3, i64 0, i64 0))
%7 = tail call i32 @exit(i32 1)
unreachable
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = tail call i32* @fopen(i8* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %17
13: ; preds = %8
%14 = load i8*, i8** %9
%15 = tail call i32 @perror(i8* %14)
%16 = tail call i32 @exit(i32 1)
unreachable
17: ; preds = %8, %17
%18 = phi i64 [ %19, %17 ], [ 0, %8 ]
%19 = tail call i64 @decode(i32* %11, i64 %18)
%20 = icmp sgt i64 %19, -1
br i1 %20, label %17, label %21
21: ; preds = %17
%22 = tail call i32 @fclose(i32* %11)
%23 = tail call i32 @exit(i32 0)
unreachable
}