#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 */
struct ccd_frame {
  int dummy;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ err_printf(char *, ...);
scalar_t__ fits_filename(char *, int);
int /*<<< orphan*/ *fopen(char *, char *);
struct ccd_frame *read_fits_file_from_fd(int /*<<< orphan*/ *, char *, int);
int /*<<< orphan*/ strncpy(char *, char *, int);
struct ccd_frame *read_fits_file(char *filename, int force_unsigned) {
  char fn[1024 + 1];
  FILE *fp;
  int zipped;
  strncpy(fn, filename, 1024);
  zipped = (fits_filename(fn, 1024) < 0);
  if (zipped) {
    err_printf("cannot open non-fits file\n");
    return NULL;
  }
  fp = fopen(fn, "r");
  if (fp == NULL) {
    err_printf("\nCannot open file: %s\n", fn);
    return NULL;
  }
  return read_fits_file_from_fd(fp, fn, force_unsigned);
}


x86 assembly (clang, -O0):
<read_fits_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
lea    -0x420(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0x400,%edx
call   1030 <strncpy@plt>
lea    -0x420(%rbp),%rdi
mov    $0x400,%esi
call   1040 <fits_filename@plt>
cmp    $0x0,%rax
setl   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x42c(%rbp)
cmpl   $0x0,-0x42c(%rbp)
je     11c2 <read_fits_file+0x72>
lea    0xe52(%rip),%rdi
mov    $0x0,%al
call   1070 <err_printf@plt>
movq   $0x0,-0x8(%rbp)
jmp    1226 <read_fits_file+0xd6>
lea    -0x420(%rbp),%rdi
lea    0xe4b(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x428(%rbp)
cmpq   $0x0,-0x428(%rbp)
jne    120c <read_fits_file+0xbc>
lea    -0x420(%rbp),%rsi
lea    0xe25(%rip),%rdi
mov    $0x0,%al
call   1070 <err_printf@plt>
movq   $0x0,-0x8(%rbp)
jmp    1226 <read_fits_file+0xd6>
mov    -0x428(%rbp),%rdi
lea    -0x420(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1050 <read_fits_file_from_fd@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_fits_file>:
push   %rbp
push   %rbx
sub    $0x408,%rsp
mov    %esi,%ebp
mov    %rdi,%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x400,%edx
call   1030 <strncpy@plt>
mov    %rbx,%rdi
mov    $0x400,%esi
call   1040 <fits_filename@plt>
test   %rax,%rax
js     11a6 <read_fits_file+0x56>
lea    0xe94(%rip),%rsi
mov    %rsp,%rdi
call   1060 <fopen@plt>
test   %rax,%rax
je     11b8 <read_fits_file+0x68>
mov    %rsp,%rsi
mov    %rax,%rdi
mov    %ebp,%edx
call   1050 <read_fits_file_from_fd@plt>
mov    %rax,%rbx
jmp    11cb <read_fits_file+0x7b>
lea    0xe53(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1070 <err_printf@plt>
jmp    11cb <read_fits_file+0x7b>
lea    0xe5e(%rip),%rdi
xor    %ebx,%ebx
mov    %rsp,%rsi
xor    %eax,%eax
call   1070 <err_printf@plt>
mov    %rbx,%rax
add    $0x408,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.ccd_frame = type { i32 }
@.str = [27 x i8] c"cannot open non-fits file\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [23 x i8] c"\0ACannot open file: %s\0A\00"
define %struct.ccd_frame* @read_fits_file(i8* %0, i32 %1) {
%3 = alloca %struct.ccd_frame*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca [1025 x i8]
%7 = alloca i32*
%8 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
%9 = getelementptr inbounds [1025 x i8], [1025 x i8]* %6, i64 0, i64 0
%10 = load i8*, i8** %4
%11 = call i32 @strncpy(i8* %9, i8* %10, i32 1024)
%12 = getelementptr inbounds [1025 x i8], [1025 x i8]* %6, i64 0, i64 0
%13 = call i64 @fits_filename(i8* %12, i32 1024)
%14 = icmp slt i64 %13, 0
%15 = zext i1 %14 to i32
store i32 %15, i32* %8
%16 = load i32, i32* %8
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %2
%19 = call i32 (i8*, ...) @err_printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
store %struct.ccd_frame* null, %struct.ccd_frame** %3
br label %33
20: ; preds = %2
%21 = getelementptr inbounds [1025 x i8], [1025 x i8]* %6, i64 0, i64 0
%22 = call i32* @fopen(i8* %21, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %22, i32** %7
%23 = load i32*, i32** %7
%24 = icmp eq i32* %23, null
br i1 %24, label %25, label %28
25: ; preds = %20
%26 = getelementptr inbounds [1025 x i8], [1025 x i8]* %6, i64 0, i64 0
%27 = call i32 (i8*, ...) @err_printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i8* %26)
store %struct.ccd_frame* null, %struct.ccd_frame** %3
br label %33
28: ; preds = %20
%29 = load i32*, i32** %7
%30 = getelementptr inbounds [1025 x i8], [1025 x i8]* %6, i64 0, i64 0
%31 = load i32, i32* %5
%32 = call %struct.ccd_frame* @read_fits_file_from_fd(i32* %29, i8* %30, i32 %31)
store %struct.ccd_frame* %32, %struct.ccd_frame** %3
br label %33
33: ; preds = %28, %25, %18
%34 = load %struct.ccd_frame*, %struct.ccd_frame** %3
ret %struct.ccd_frame* %34
}

LLVM IR (-O2):
%struct.ccd_frame = type { i32 }
@.str = [27 x i8] c"cannot open non-fits file\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [23 x i8] c"\0ACannot open file: %s\0A\00"
define %struct.ccd_frame* @read_fits_file(i8* %0, i32 %1) {
%3 = alloca [1025 x i8]
%4 = getelementptr inbounds [1025 x i8], [1025 x i8]* %3, i64 0, i64 0
%5 = call i32 @strncpy(i8* %4, i8* %0, i32 1024)
%6 = call i64 @fits_filename(i8* %4, i32 1024)
%7 = icmp slt i64 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %2
%9 = call i32 (i8*, ...) @err_printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
br label %17
10: ; preds = %2
%11 = call i32* @fopen(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %15
13: ; preds = %10
%14 = call i32 (i8*, ...) @err_printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i8* %4)
br label %17
15: ; preds = %10
%16 = call %struct.ccd_frame* @read_fits_file_from_fd(i32* %11, i8* %4, i32 %1)
br label %17
17: ; preds = %15, %13, %8
%18 = phi %struct.ccd_frame* [ null, %8 ], [ null, %13 ], [ %16, %15 ]
ret %struct.ccd_frame* %18
}