#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 *, char *);
int fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strncmp(char *, char *, int);
int get_FITS_header_size(char *name) {
  FILE *in;
  char line[81];
  int found = 0;
  int count;
  int hs;
  if ((in = fopen(name, "r")) == NULL) {
    fprintf(stderr, "cannot open %s: aborting\n", name);
    return 0;
  }
  count = 0;
  while (!found) {
    if (fread(line, 1, 80, in) != 80) {
      break;
    }
    count++;
    if (!strncmp(line, "END ", 4)) {
      found = 1;
    }
  }
  fclose(in);
  if (!found)
    return 0;
  hs = count * 80;
  if ((hs % 2880) != 0) {
    hs = (1 + (hs / 2880)) * 2880;
  }
  return hs;
}


x86 assembly (clang, -O0):
<get_FITS_header_size>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x74(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe8f(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11a9 <get_FITS_header_size+0x59>
mov    0x2e55(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe6a(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1275 <get_FITS_header_size+0x125>
movl   $0x0,-0x78(%rbp)
cmpl   $0x0,-0x74(%rbp)
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11c6 <get_FITS_header_size+0x76>
jmp    121e <get_FITS_header_size+0xce>
lea    -0x70(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
mov    $0x50,%edx
call   1040 <fread@plt>
cmp    $0x50,%eax
je     11eb <get_FITS_header_size+0x9b>
jmp    121e <get_FITS_header_size+0xce>
mov    -0x78(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x78(%rbp)
lea    -0x70(%rbp),%rdi
lea    0xe1d(%rip),%rsi
mov    $0x4,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    1219 <get_FITS_header_size+0xc9>
movl   $0x1,-0x74(%rbp)
jmp    11b0 <get_FITS_header_size+0x60>
mov    -0x18(%rbp),%rdi
call   1050 <fclose@plt>
cmpl   $0x0,-0x74(%rbp)
jne    123d <get_FITS_header_size+0xed>
movl   $0x0,-0x4(%rbp)
jmp    1275 <get_FITS_header_size+0x125>
imul   $0x50,-0x78(%rbp),%eax
mov    %eax,-0x7c(%rbp)
mov    -0x7c(%rbp),%eax
mov    $0xb40,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
je     126f <get_FITS_header_size+0x11f>
mov    -0x7c(%rbp),%eax
mov    $0xb40,%ecx
cltd
idiv   %ecx
add    $0x1,%eax
imul   $0xb40,%eax,%eax
mov    %eax,-0x7c(%rbp)
mov    -0x7c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_FITS_header_size>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x60,%rsp
mov    %rdi,%rbx
lea    0xe9a(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     1201 <get_FITS_header_size+0xb1>
mov    %rax,%r14
xor    %ebx,%ebx
mov    %rsp,%r15
lea    0xe99(%rip),%r12
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r15,%rdi
mov    $0x1,%esi
mov    $0x50,%edx
mov    %r14,%rcx
call   1040 <fread@plt>
cmp    $0x50,%eax
jne    121b <get_FITS_header_size+0xcb>
add    $0x1,%ebp
mov    %r15,%rdi
mov    %r12,%rsi
mov    $0x4,%edx
call   1030 <strncmp@plt>
add    $0x50,%ebx
test   %eax,%eax
jne    1190 <get_FITS_header_size+0x40>
mov    %r14,%rdi
call   1050 <fclose@plt>
mov    %ebx,%eax
shr    $0x6,%eax
imul   $0x5b05b06,%rax,%rax
shr    $0x20,%rax
imul   $0xb40,%eax,%eax
cmp    %ebx,%eax
je     1225 <get_FITS_header_size+0xd5>
mov    %ebp,%eax
imul   $0x38e38e39,%rax,%rax
shr    $0x23,%rax
imul   $0xb40,%eax,%ebx
add    $0xb40,%ebx
jmp    1225 <get_FITS_header_size+0xd5>
mov    0x2dd8(%rip),%rax
mov    (%rax),%edi
lea    0xdf1(%rip),%rsi
mov    %rbx,%rdx
call   1060 <fprintf@plt>
jmp    1223 <get_FITS_header_size+0xd3>
mov    %r14,%rdi
call   1050 <fclose@plt>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x60,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [26 x i8] c"cannot open %s: aborting\0A\00"
@.str.2 = [5 x i8] c"END \00"
define i32 @get_FITS_header_size(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca [81 x i8]
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %3
store i32 0, i32* %6
%9 = load i8*, i8** %3
%10 = call i32* @fopen(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %10, i32** %4
%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** %3
%15 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* %14)
store i32 0, i32* %2
br label %54
16: ; preds = %1
store i32 0, i32* %7
br label %17
17: ; preds = %34, %16
%18 = load i32, i32* %6
%19 = icmp ne i32 %18, 0
%20 = xor i1 %19, true
br i1 %20, label %21, label %35
21: ; preds = %17
%22 = getelementptr inbounds [81 x i8], [81 x i8]* %5, i64 0, i64 0
%23 = load i32*, i32** %4
%24 = call i32 @fread(i8* %22, i32 1, i32 80, i32* %23)
%25 = icmp ne i32 %24, 80
br i1 %25, label %26, label %27
26: ; preds = %21
br label %35
27: ; preds = %21
%28 = load i32, i32* %7
%29 = add nsw i32 %28, 1
store i32 %29, i32* %7
%30 = getelementptr inbounds [81 x i8], [81 x i8]* %5, i64 0, i64 0
%31 = call i32 @strncmp(i8* %30, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 4)
%32 = icmp ne i32 %31, 0
br i1 %32, label %34, label %33
33: ; preds = %27
store i32 1, i32* %6
br label %34
34: ; preds = %33, %27
br label %17
35: ; preds = %26, %17
%36 = load i32*, i32** %4
%37 = call i32 @fclose(i32* %36)
%38 = load i32, i32* %6
%39 = icmp ne i32 %38, 0
br i1 %39, label %41, label %40
40: ; preds = %35
store i32 0, i32* %2
br label %54
41: ; preds = %35
%42 = load i32, i32* %7
%43 = mul nsw i32 %42, 80
store i32 %43, i32* %8
%44 = load i32, i32* %8
%45 = srem i32 %44, 2880
%46 = icmp ne i32 %45, 0
br i1 %46, label %47, label %52
47: ; preds = %41
%48 = load i32, i32* %8
%49 = sdiv i32 %48, 2880
%50 = add nsw i32 1, %49
%51 = mul nsw i32 %50, 2880
store i32 %51, i32* %8
br label %52
52: ; preds = %47, %41
%53 = load i32, i32* %8
store i32 %53, i32* %2
br label %54
54: ; preds = %52, %40, %12
%55 = load i32, i32* %2
ret i32 %55
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [26 x i8] c"cannot open %s: aborting\0A\00"
@.str.2 = [5 x i8] c"END \00"
define i32 @get_FITS_header_size(i8* %0) {
%2 = alloca [81 x i8]
%3 = getelementptr inbounds [81 x i8], [81 x i8]* %2, i64 0, i64 0
%4 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %9
6: ; preds = %1
%7 = load i32, i32* @stderr
%8 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %28
9: ; preds = %1, %13
%10 = phi i32 [ %14, %13 ], [ 0, %1 ]
%11 = call i32 @fread(i8* %3, i32 1, i32 80, i32* %4)
%12 = icmp eq i32 %11, 80
br i1 %12, label %13, label %17
13: ; preds = %9
%14 = add nuw nsw i32 %10, 1
%15 = call i32 @strncmp(i8* %3, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 4)
%16 = icmp eq i32 %15, 0
br i1 %16, label %19, label %9
17: ; preds = %9
%18 = call i32 @fclose(i32* %4)
br label %28
19: ; preds = %13
%20 = call i32 @fclose(i32* %4)
%21 = mul nsw i32 %14, 80
%22 = urem i32 %21, 2880
%23 = icmp eq i32 %22, 0
br i1 %23, label %28, label %24
24: ; preds = %19
%25 = udiv i32 %14, 36
%26 = mul i32 %25, 2880
%27 = add i32 %26, 2880
br label %28
28: ; preds = %17, %19, %24, %6
%29 = phi i32 [ 0, %6 ], [ 0, %17 ], [ %27, %24 ], [ %21, %19 ]
ret i32 %29
}