#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 int16_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ atoi(char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ readFileHeader(int /*<<< orphan*/ *);
int /*<<< orphan*/ readStarList(int /*<<< orphan*/ *, int /*<<< orphan*/,
                                int /*<<< orphan*/ *);
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ verifyIndexValidity(int /*<<< orphan*/ *);
int /*<<< orphan*/ verifyStarData(int /*<<< orphan*/ *);
int main(int argc, char *argv[]) {
  FILE *f, *names;
  int16_t maglim = -500;
  names = NULL;
  if (argc <= 1) {
    fprintf(stderr, "USAGE: %s filename [trixel]\n", argv[0]);
    fprintf(stderr, "Designed for use only with KStars star data files\n");
    return 1;
  }
  f = fopen(argv[1], "rb");
  if (f == NULL) {
    fprintf(stderr, "ERROR: Could not open file %s for binary read.\n",
            argv[1]);
    return 1;
  }
  readFileHeader(f);
  verifyIndexValidity(f);
  verifyStarData(f);
  if (argc > 2) {
    rewind(f);
    readStarList(f, atoi(argv[2]), names);
  }
  fclose(f);
  if (names)
    fclose(names);
  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)
movl   $0xfffffe0c,-0x24(%rbp)
movq   $0x0,-0x20(%rbp)
cmpl   $0x1,-0x8(%rbp)
jg     1200 <main+0x70>
mov    0x2e1a(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe2a(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2dfc(%rip),%rax
mov    (%rax),%edi
lea    0xe30(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12c4 <main+0x134>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe41(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    124e <main+0xbe>
mov    0x2db6(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xe18(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12c4 <main+0x134>
mov    -0x18(%rbp),%rdi
call   10b0 <readFileHeader@plt>
mov    -0x18(%rbp),%rdi
call   1070 <verifyIndexValidity@plt>
mov    -0x18(%rbp),%rdi
call   1080 <verifyStarData@plt>
cmpl   $0x2,-0x8(%rbp)
jle    12a0 <main+0x110>
mov    -0x18(%rbp),%rdi
call   1050 <rewind@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   10a0 <atoi@plt>
mov    -0x30(%rbp),%rdi
mov    %eax,%esi
mov    -0x20(%rbp),%rdx
call   1030 <readStarList@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
cmpq   $0x0,-0x20(%rbp)
je     12bd <main+0x12d>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%r14
cmp    $0x1,%edi
jg     11c8 <main+0x38>
mov    0x2e3d(%rip),%rbx
mov    (%rbx),%edi
mov    (%r14),%rdx
lea    0xe51(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    (%rbx),%edi
lea    0xe5e(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
jmp    1243 <main+0xb3>
mov    %edi,%ebp
mov    0x8(%r14),%rdi
lea    0xe7b(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     1228 <main+0x98>
mov    %rax,%rbx
mov    %rax,%rdi
call   10b0 <readFileHeader@plt>
mov    %rbx,%rdi
call   1070 <verifyIndexValidity@plt>
mov    %rbx,%rdi
call   1080 <verifyStarData@plt>
cmp    $0x3,%ebp
jb     121c <main+0x8c>
mov    %rbx,%rdi
call   1050 <rewind@plt>
mov    0x10(%r14),%rdi
call   10a0 <atoi@plt>
mov    %rbx,%rdi
mov    %eax,%esi
xor    %edx,%edx
call   1030 <readStarList@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
jmp    1248 <main+0xb8>
mov    0x2db1(%rip),%rax
mov    (%rax),%edi
mov    0x8(%r14),%rdx
lea    0xe17(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x1,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [29 x i8] c"USAGE: %s filename [trixel]\0A\00"
@.str.1 = [51 x i8] c"Designed for use only with KStars star data files\0A\00"
@.str.2 = [3 x i8] c"rb\00"
@.str.3 = [48 x i8] c"ERROR: Could not open file %s for binary read.\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
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 -500, i32* %8
store i32* null, i32** %7
%9 = load i32, i32* %4
%10 = icmp sle i32 %9, 1
br i1 %10, label %11, label %19
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 0
%15 = load i8*, i8** %14
%16 = call i32 (i32, i8*, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* %15)
%17 = load i32, i32* @stderr
%18 = call i32 (i32, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %3
br label %60
19: ; preds = %2
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
%23 = call i32* @fopen(i8* %22, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i32* %23, i32** %6
%24 = load i32*, i32** %6
%25 = icmp eq i32* %24, null
br i1 %25, label %26, label %32
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 ([48 x i8], [48 x i8]* @.str.3, i64 0, i64 0), i8* %30)
store i32 1, i32* %3
br label %60
32: ; preds = %19
%33 = load i32*, i32** %6
%34 = call i32 @readFileHeader(i32* %33)
%35 = load i32*, i32** %6
%36 = call i32 @verifyIndexValidity(i32* %35)
%37 = load i32*, i32** %6
%38 = call i32 @verifyStarData(i32* %37)
%39 = load i32, i32* %4
%40 = icmp sgt i32 %39, 2
br i1 %40, label %41, label %51
41: ; preds = %32
%42 = load i32*, i32** %6
%43 = call i32 @rewind(i32* %42)
%44 = load i32*, i32** %6
%45 = load i8**, i8*** %5
%46 = getelementptr inbounds i8*, i8** %45, i64 2
%47 = load i8*, i8** %46
%48 = call i32 @atoi(i8* %47)
%49 = load i32*, i32** %7
%50 = call i32 @readStarList(i32* %44, i32 %48, i32* %49)
br label %51
51: ; preds = %41, %32
%52 = load i32*, i32** %6
%53 = call i32 @fclose(i32* %52)
%54 = load i32*, i32** %7
%55 = icmp ne i32* %54, null
br i1 %55, label %56, label %59
56: ; preds = %51
%57 = load i32*, i32** %7
%58 = call i32 @fclose(i32* %57)
br label %59
59: ; preds = %56, %51
store i32 0, i32* %3
br label %60
60: ; preds = %59, %26, %11
%61 = load i32, i32* %3
ret i32 %61
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [29 x i8] c"USAGE: %s filename [trixel]\0A\00"
@.str.1 = [51 x i8] c"Designed for use only with KStars star data files\0A\00"
@.str.2 = [3 x i8] c"rb\00"
@.str.3 = [48 x i8] c"ERROR: Could not open file %s for binary read.\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %4, label %10
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 ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* %6)
%8 = load i32, i32* @stderr
%9 = tail call i32 (i32, i8*, ...) @fprintf(i32 %8, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.1, i64 0, i64 0))
br label %32
10: ; preds = %2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = tail call i32* @fopen(i8* %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %19
15: ; preds = %10
%16 = load i32, i32* @stderr
%17 = load i8*, i8** %11
%18 = tail call i32 (i32, i8*, ...) @fprintf(i32 %16, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.3, i64 0, i64 0), i8* %17)
br label %32
19: ; preds = %10
%20 = tail call i32 @readFileHeader(i32* %13)
%21 = tail call i32 @verifyIndexValidity(i32* %13)
%22 = tail call i32 @verifyStarData(i32* %13)
%23 = icmp ugt i32 %0, 2
br i1 %23, label %24, label %30
24: ; preds = %19
%25 = tail call i32 @rewind(i32* %13)
%26 = getelementptr inbounds i8*, i8** %1, i64 2
%27 = load i8*, i8** %26
%28 = tail call i32 @atoi(i8* %27)
%29 = tail call i32 @readStarList(i32* %13, i32 %28, i32* null)
br label %30
30: ; preds = %24, %19
%31 = tail call i32 @fclose(i32* %13)
br label %32
32: ; preds = %30, %15, %4
%33 = phi i32 [ 1, %4 ], [ 1, %15 ], [ 0, %30 ]
ret i32 %33
}