#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 double 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*/ fread(double *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ readFileHeader(int /*<<< orphan*/ *);
int /*<<< orphan*/ readStarList(int /*<<< orphan*/ *, int /*<<< orphan*/,
                                int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
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], "r");
  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);
  fread(&maglim, 2, 1, f);
  fprintf(stdout, "Limiting Magnitude of Catalog File: %f\n", maglim / 1000.0);
  if (argc > 2) {
    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)
movsd  0xe52(%rip),%xmm0
movsd  %xmm0,-0x28(%rbp)
movq   $0x0,-0x20(%rbp)
cmpl   $0x1,-0x8(%rbp)
jg     1206 <main+0x76>
mov    0x2e14(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe34(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2df6(%rip),%rax
mov    (%rax),%edi
lea    0xe3a(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1300 <main+0x170>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe4b(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1254 <main+0xc4>
mov    0x2db0(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xe21(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1300 <main+0x170>
mov    -0x18(%rbp),%rdi
call   10b0 <readFileHeader@plt>
mov    -0x18(%rbp),%rdi
call   1070 <verifyIndexValidity@plt>
mov    -0x18(%rbp),%rdi
call   1080 <verifyStarData@plt>
mov    -0x18(%rbp),%rcx
lea    -0x28(%rbp),%rdi
mov    $0x2,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
mov    0x2d4b(%rip),%rax
mov    (%rax),%edi
movsd  -0x28(%rbp),%xmm0
movsd  0xd6c(%rip),%xmm1
divsd  %xmm1,%xmm0
lea    0xdeb(%rip),%rsi
mov    $0x1,%al
call   1060 <fprintf@plt>
cmpl   $0x2,-0x8(%rbp)
jle    12dc <main+0x14c>
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   1040 <readStarList@plt>
mov    -0x18(%rbp),%rdi
call   1050 <fclose@plt>
cmpq   $0x0,-0x20(%rbp)
je     12f9 <main+0x169>
mov    -0x20(%rbp),%rdi
call   1050 <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
sub    $0x10,%rsp
mov    %rsi,%r14
movabs $0xc07f400000000000,%rax
40 7f c0
mov    %rax,0x8(%rsp)
cmp    $0x1,%edi
jg     11de <main+0x4e>
mov    0x2e2a(%rip),%rbx
mov    (%rbx),%edi
mov    (%r14),%rdx
lea    0xe46(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    (%rbx),%edi
lea    0xe53(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
jmp    128d <main+0xfd>
mov    %edi,%ebp
mov    0x8(%r14),%rdi
lea    0xe6d(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     1272 <main+0xe2>
mov    %rax,%rbx
mov    %rax,%rdi
call   10b0 <readFileHeader@plt>
mov    %rbx,%rdi
call   1070 <verifyIndexValidity@plt>
mov    %rbx,%rdi
call   1080 <verifyStarData@plt>
lea    0x8(%rsp),%rdi
mov    $0x2,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1030 <fread@plt>
mov    0x2daa(%rip),%rax
mov    (%rax),%edi
movsd  0x8(%rsp),%xmm0
divsd  0xdc2(%rip),%xmm0
lea    0xe45(%rip),%rsi
mov    $0x1,%al
call   1060 <fprintf@plt>
cmp    $0x3,%ebp
jb     1266 <main+0xd6>
mov    0x10(%r14),%rdi
call   10a0 <atoi@plt>
mov    %rbx,%rdi
mov    %eax,%esi
xor    %edx,%edx
call   1040 <readStarList@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
xor    %eax,%eax
jmp    1292 <main+0x102>
mov    0x2d67(%rip),%rax
mov    (%rax),%edi
mov    0x8(%r14),%rdx
lea    0xdd4(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x1,%eax
add    $0x10,%rsp
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 = [2 x i8] c"r\00"
@.str.3 = [48 x i8] c"ERROR: Could not open file %s for binary read.\0A\00"
@stdout = global i32 0
@.str.4 = [40 x i8] c"Limiting Magnitude of Catalog File: %f\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 double
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store double -5.000000e+02, double* %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 %64
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 ([2 x i8], [2 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 %64
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** %6
%40 = call i32 @fread(double* %8, i32 2, i32 1, i32* %39)
%41 = load i32, i32* @stdout
%42 = load double, double* %8
%43 = fdiv double %42, 1.000000e+03
%44 = call i32 (i32, i8*, ...) @fprintf(i32 %41, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.4, i64 0, i64 0), double %43)
%45 = load i32, i32* %4
%46 = icmp sgt i32 %45, 2
br i1 %46, label %47, label %55
47: ; preds = %32
%48 = load i32*, i32** %6
%49 = load i8**, i8*** %5
%50 = getelementptr inbounds i8*, i8** %49, i64 2
%51 = load i8*, i8** %50
%52 = call i32 @atoi(i8* %51)
%53 = load i32*, i32** %7
%54 = call i32 @readStarList(i32* %48, i32 %52, i32* %53)
br label %55
55: ; preds = %47, %32
%56 = load i32*, i32** %6
%57 = call i32 @fclose(i32* %56)
%58 = load i32*, i32** %7
%59 = icmp ne i32* %58, null
br i1 %59, label %60, label %63
60: ; preds = %55
%61 = load i32*, i32** %7
%62 = call i32 @fclose(i32* %61)
br label %63
63: ; preds = %60, %55
store i32 0, i32* %3
br label %64
64: ; preds = %63, %26, %11
%65 = load i32, i32* %3
ret i32 %65
}

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 = [2 x i8] c"r\00"
@.str.3 = [48 x i8] c"ERROR: Could not open file %s for binary read.\0A\00"
@stdout = global i32 0
@.str.4 = [40 x i8] c"Limiting Magnitude of Catalog File: %f\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca double
%4 = bitcast double* %3 to i8*
store double -5.000000e+02, double* %3
%5 = icmp slt i32 %0, 2
br i1 %5, label %6, label %12
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = load i8*, i8** %1
%9 = tail call i32 (i32, i8*, ...) @fprintf(i32 %7, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* %8)
%10 = load i32, i32* @stderr
%11 = tail call i32 (i32, i8*, ...) @fprintf(i32 %10, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.1, i64 0, i64 0))
br label %38
12: ; preds = %2
%13 = getelementptr inbounds i8*, i8** %1, i64 1
%14 = load i8*, i8** %13
%15 = tail call i32* @fopen(i8* %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%16 = icmp eq i32* %15, null
br i1 %16, label %17, label %21
17: ; preds = %12
%18 = load i32, i32* @stderr
%19 = load i8*, i8** %13
%20 = tail call i32 (i32, i8*, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.3, i64 0, i64 0), i8* %19)
br label %38
21: ; preds = %12
%22 = tail call i32 @readFileHeader(i32* %15)
%23 = tail call i32 @verifyIndexValidity(i32* %15)
%24 = tail call i32 @verifyStarData(i32* %15)
%25 = call i32 @fread(double* %3, i32 2, i32 1, i32* %15)
%26 = load i32, i32* @stdout
%27 = load double, double* %3
%28 = fdiv double %27, 1.000000e+03
%29 = tail call i32 (i32, i8*, ...) @fprintf(i32 %26, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.4, i64 0, i64 0), double %28)
%30 = icmp ugt i32 %0, 2
br i1 %30, label %31, label %36
31: ; preds = %21
%32 = getelementptr inbounds i8*, i8** %1, i64 2
%33 = load i8*, i8** %32
%34 = tail call i32 @atoi(i8* %33)
%35 = tail call i32 @readStarList(i32* %15, i32 %34, i32* null)
br label %36
36: ; preds = %31, %21
%37 = tail call i32 @fclose(i32* %15)
br label %38
38: ; preds = %36, %17, %6
%39 = phi i32 [ 1, %6 ], [ 1, %17 ], [ 0, %36 ]
ret i32 %39
}