#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 */
scalar_t__ calloc(int, int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ ffpmsg(char const *);
int /*<<< orphan*/ *fopen(char const *, char *);
int fread(char *, int, long, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
scalar_t__ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/, int);
long ftell(int /*<<< orphan*/ *);
int /*<<< orphan*/ snprintf(char *, int, char *, int, ...);
char *irafrdhead(const char *filename, int *lihead) {
  FILE *fd;
  int nbr;
  char *irafheader;
  char errmsg[81];
  long nbhead;
  int nihead;
  *lihead = 0;
  fd = fopen(filename, "rb");
  if (fd == NULL) {
    ffpmsg("unable to open IRAF header file:");
    ffpmsg(filename);
    return (NULL);
  }
  if (fseek(fd, 0, 2) != 0) {
    ffpmsg("IRAFRHEAD: cannot seek in file:");
    ffpmsg(filename);
    return (NULL);
  }
  nbhead = ftell(fd);
  if (nbhead < 0) {
    ffpmsg("IRAFRHEAD: cannot get pos. in file:");
    ffpmsg(filename);
    return (NULL);
  }
  if (fseek(fd, 0, 0) != 0) {
    ffpmsg("IRAFRHEAD: cannot seek to beginning of file:");
    ffpmsg(filename);
    return (NULL);
  }
  nihead = nbhead + 5000;
  irafheader = (char *)calloc(1, nihead);
  if (irafheader == NULL) {
    snprintf(errmsg, 81, "IRAFRHEAD Cannot allocate %d-byte header", nihead);
    ffpmsg(errmsg);
    ffpmsg(filename);
    return (NULL);
  }
  *lihead = nihead;
  nbr = fread(irafheader, 1, nbhead, fd);
  fclose(fd);
  if (nbr < 1024) {
    snprintf(errmsg, 81, "IRAFRHEAD header file: %d / %d bytes read.", nbr,
             1024);
    ffpmsg(errmsg);
    ffpmsg(filename);
    free(irafheader);
    return (NULL);
  }
  return (irafheader);
}


x86 assembly (clang, -O0):
<irafrdhead>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
lea    0xe48(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11ee <irafrdhead+0x5e>
lea    0xe30(%rip),%rdi
call   1060 <ffpmsg@plt>
mov    -0x10(%rbp),%rdi
call   1060 <ffpmsg@plt>
movq   $0x0,-0x8(%rbp)
jmp    13ab <irafrdhead+0x21b>
mov    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x2,%edx
call   10a0 <fseek@plt>
cmp    $0x0,%rax
je     122a <irafrdhead+0x9a>
lea    0xe15(%rip),%rdi
call   1060 <ffpmsg@plt>
mov    -0x10(%rbp),%rdi
call   1060 <ffpmsg@plt>
movq   $0x0,-0x8(%rbp)
jmp    13ab <irafrdhead+0x21b>
mov    -0x20(%rbp),%rdi
call   1090 <ftell@plt>
mov    %rax,-0x98(%rbp)
cmpq   $0x0,-0x98(%rbp)
jge    126a <irafrdhead+0xda>
lea    0xdf5(%rip),%rdi
call   1060 <ffpmsg@plt>
mov    -0x10(%rbp),%rdi
call   1060 <ffpmsg@plt>
movq   $0x0,-0x8(%rbp)
jmp    13ab <irafrdhead+0x21b>
mov    -0x20(%rbp),%rdi
xor    %edx,%edx
mov    %edx,%esi
call   10a0 <fseek@plt>
cmp    $0x0,%rax
je     12a3 <irafrdhead+0x113>
lea    0xde0(%rip),%rdi
call   1060 <ffpmsg@plt>
mov    -0x10(%rbp),%rdi
call   1060 <ffpmsg@plt>
movq   $0x0,-0x8(%rbp)
jmp    13ab <irafrdhead+0x21b>
mov    -0x98(%rbp),%rax
add    $0x1388,%rax
mov    %eax,-0x9c(%rbp)
mov    -0x9c(%rbp),%esi
mov    $0x1,%edi
call   1080 <calloc@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1317 <irafrdhead+0x187>
lea    -0x90(%rbp),%rdi
mov    -0x9c(%rbp),%ecx
mov    $0x51,%esi
lea    0xda7(%rip),%rdx
mov    $0x0,%al
call   1070 <snprintf@plt>
lea    -0x90(%rbp),%rdi
call   1060 <ffpmsg@plt>
mov    -0x10(%rbp),%rdi
call   1060 <ffpmsg@plt>
movq   $0x0,-0x8(%rbp)
jmp    13ab <irafrdhead+0x21b>
mov    -0x9c(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x30(%rbp),%rdi
mov    -0x98(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    $0x1,%esi
call   1040 <fread@plt>
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%rdi
call   1050 <fclose@plt>
cmpl   $0x400,-0x24(%rbp)
jge    13a3 <irafrdhead+0x213>
lea    -0x90(%rbp),%rdi
mov    -0x24(%rbp),%ecx
mov    $0x51,%esi
lea    0xd53(%rip),%rdx
mov    $0x400,%r8d
mov    $0x0,%al
call   1070 <snprintf@plt>
lea    -0x90(%rbp),%rdi
call   1060 <ffpmsg@plt>
mov    -0x10(%rbp),%rdi
call   1060 <ffpmsg@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
jmp    13ab <irafrdhead+0x21b>
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<irafrdhead>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x58,%rsp
mov    %rsi,%r12
mov    %rdi,%r14
movl   $0x0,(%rsi)
lea    0xe4f(%rip),%rsi
call   10b0 <fopen@plt>
test   %rax,%rax
je     11db <irafrdhead+0x4b>
mov    %rax,%rbx
mov    %rax,%rdi
xor    %esi,%esi
mov    $0x2,%edx
call   10a0 <fseek@plt>
test   %rax,%rax
je     1204 <irafrdhead+0x74>
lea    0xe4b(%rip),%rdi
jmp    11e2 <irafrdhead+0x52>
lea    0xe21(%rip),%rdi
call   1060 <ffpmsg@plt>
mov    %r14,%rdi
call   1060 <ffpmsg@plt>
xor    %r15d,%r15d
mov    %r15,%rax
add    $0x58,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %rbx,%rdi
call   1090 <ftell@plt>
test   %rax,%rax
js     122e <irafrdhead+0x9e>
mov    %rax,%r13
mov    %rbx,%rdi
xor    %esi,%esi
xor    %edx,%edx
call   10a0 <fseek@plt>
test   %rax,%rax
je     1237 <irafrdhead+0xa7>
lea    0xe3c(%rip),%rdi
jmp    11e2 <irafrdhead+0x52>
lea    0xe0f(%rip),%rdi
jmp    11e2 <irafrdhead+0x52>
lea    0x1388(%r13),%ebp
mov    $0x1,%edi
mov    %ebp,%esi
call   1080 <calloc@plt>
test   %rax,%rax
je     12bd <irafrdhead+0x12d>
mov    %rax,%r15
mov    %ebp,(%r12)
mov    %rax,%rdi
mov    $0x1,%esi
mov    %r13,%rdx
mov    %rbx,%rcx
call   1040 <fread@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1050 <fclose@plt>
cmp    $0x3ff,%ebp
jg     11f2 <irafrdhead+0x62>
lea    0xe38(%rip),%rdx
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x51,%esi
mov    %ebp,%ecx
mov    $0x400,%r8d
xor    %eax,%eax
call   1070 <snprintf@plt>
mov    %rbx,%rdi
call   1060 <ffpmsg@plt>
mov    %r14,%rdi
call   1060 <ffpmsg@plt>
mov    %r15,%rdi
call   1030 <free@plt>
jmp    11ef <irafrdhead+0x5f>
lea    0xdd1(%rip),%rdx
xor    %r15d,%r15d
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x51,%esi
mov    %ebp,%ecx
xor    %eax,%eax
call   1070 <snprintf@plt>
mov    %rbx,%rdi
call   1060 <ffpmsg@plt>
mov    %r14,%rdi
call   1060 <ffpmsg@plt>
jmp    11f2 <irafrdhead+0x62>

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
@.str.1 = [33 x i8] c"unable to open IRAF header file:\00"
@.str.2 = [32 x i8] c"IRAFRHEAD: cannot seek in file:\00"
@.str.3 = [36 x i8] c"IRAFRHEAD: cannot get pos. in file:\00"
@.str.4 = [45 x i8] c"IRAFRHEAD: cannot seek to beginning of file:\00"
@.str.5 = [41 x i8] c"IRAFRHEAD Cannot allocate %d-byte header\00"
@.str.6 = [43 x i8] c"IRAFRHEAD header file: %d / %d bytes read.\00"
define i8* @irafrdhead(i8* %0, i32* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca [81 x i8]
%10 = alloca i64
%11 = alloca i32
store i8* %0, i8** %4
store i32* %1, i32** %5
%12 = load i32*, i32** %5
store i32 0, i32* %12
%13 = load i8*, i8** %4
%14 = call i32* @fopen(i8* %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %14, i32** %6
%15 = load i32*, i32** %6
%16 = icmp eq i32* %15, null
br i1 %16, label %17, label %21
17: ; preds = %2
%18 = call i32 @ffpmsg(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
%19 = load i8*, i8** %4
%20 = call i32 @ffpmsg(i8* %19)
store i8* null, i8** %3
br label %86
21: ; preds = %2
%22 = load i32*, i32** %6
%23 = call i64 @fseek(i32* %22, i32 0, i32 2)
%24 = icmp ne i64 %23, 0
br i1 %24, label %25, label %29
25: ; preds = %21
%26 = call i32 @ffpmsg(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0))
%27 = load i8*, i8** %4
%28 = call i32 @ffpmsg(i8* %27)
store i8* null, i8** %3
br label %86
29: ; preds = %21
%30 = load i32*, i32** %6
%31 = call i64 @ftell(i32* %30)
store i64 %31, i64* %10
%32 = load i64, i64* %10
%33 = icmp slt i64 %32, 0
br i1 %33, label %34, label %38
34: ; preds = %29
%35 = call i32 @ffpmsg(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0))
%36 = load i8*, i8** %4
%37 = call i32 @ffpmsg(i8* %36)
store i8* null, i8** %3
br label %86
38: ; preds = %29
%39 = load i32*, i32** %6
%40 = call i64 @fseek(i32* %39, i32 0, i32 0)
%41 = icmp ne i64 %40, 0
br i1 %41, label %42, label %46
42: ; preds = %38
%43 = call i32 @ffpmsg(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.4, i64 0, i64 0))
%44 = load i8*, i8** %4
%45 = call i32 @ffpmsg(i8* %44)
store i8* null, i8** %3
br label %86
46: ; preds = %38
%47 = load i64, i64* %10
%48 = add nsw i64 %47, 5000
%49 = trunc i64 %48 to i32
store i32 %49, i32* %11
%50 = load i32, i32* %11
%51 = call i64 @calloc(i32 1, i32 %50)
%52 = inttoptr i64 %51 to i8*
store i8* %52, i8** %8
%53 = load i8*, i8** %8
%54 = icmp eq i8* %53, null
br i1 %54, label %55, label %63
55: ; preds = %46
%56 = getelementptr inbounds [81 x i8], [81 x i8]* %9, i64 0, i64 0
%57 = load i32, i32* %11
%58 = call i32 (i8*, i32, i8*, i32, ...) @snprintf(i8* %56, i32 81, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.5, i64 0, i64 0), i32 %57)
%59 = getelementptr inbounds [81 x i8], [81 x i8]* %9, i64 0, i64 0
%60 = call i32 @ffpmsg(i8* %59)
%61 = load i8*, i8** %4
%62 = call i32 @ffpmsg(i8* %61)
store i8* null, i8** %3
br label %86
63: ; preds = %46
%64 = load i32, i32* %11
%65 = load i32*, i32** %5
store i32 %64, i32* %65
%66 = load i8*, i8** %8
%67 = load i64, i64* %10
%68 = load i32*, i32** %6
%69 = call i32 @fread(i8* %66, i32 1, i64 %67, i32* %68)
store i32 %69, i32* %7
%70 = load i32*, i32** %6
%71 = call i32 @fclose(i32* %70)
%72 = load i32, i32* %7
%73 = icmp slt i32 %72, 1024
br i1 %73, label %74, label %84
74: ; preds = %63
%75 = getelementptr inbounds [81 x i8], [81 x i8]* %9, i64 0, i64 0
%76 = load i32, i32* %7
%77 = call i32 (i8*, i32, i8*, i32, ...) @snprintf(i8* %75, i32 81, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.6, i64 0, i64 0), i32 %76, i32 1024)
%78 = getelementptr inbounds [81 x i8], [81 x i8]* %9, i64 0, i64 0
%79 = call i32 @ffpmsg(i8* %78)
%80 = load i8*, i8** %4
%81 = call i32 @ffpmsg(i8* %80)
%82 = load i8*, i8** %8
%83 = call i32 @free(i8* %82)
store i8* null, i8** %3
br label %86
84: ; preds = %63
%85 = load i8*, i8** %8
store i8* %85, i8** %3
br label %86
86: ; preds = %84, %74, %55, %42, %34, %25, %17
%87 = load i8*, i8** %3
ret i8* %87
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@.str.1 = [33 x i8] c"unable to open IRAF header file:\00"
@.str.2 = [32 x i8] c"IRAFRHEAD: cannot seek in file:\00"
@.str.3 = [36 x i8] c"IRAFRHEAD: cannot get pos. in file:\00"
@.str.4 = [45 x i8] c"IRAFRHEAD: cannot seek to beginning of file:\00"
@.str.5 = [41 x i8] c"IRAFRHEAD Cannot allocate %d-byte header\00"
@.str.6 = [43 x i8] c"IRAFRHEAD header file: %d / %d bytes read.\00"
define i8* @irafrdhead(i8* %0, i32* nocapture writeonly %1) {
%3 = alloca [81 x i8]
%4 = getelementptr inbounds [81 x i8], [81 x i8]* %3, i64 0, i64 0
store i32 0, i32* %1
%5 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %10
7: ; preds = %2
%8 = tail call i32 @ffpmsg(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
%9 = tail call i32 @ffpmsg(i8* %0)
br label %47
10: ; preds = %2
%11 = tail call i64 @fseek(i32* %5, i32 0, i32 2)
%12 = icmp eq i64 %11, 0
br i1 %12, label %16, label %13
13: ; preds = %10
%14 = tail call i32 @ffpmsg(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0))
%15 = tail call i32 @ffpmsg(i8* %0)
br label %47
16: ; preds = %10
%17 = tail call i64 @ftell(i32* %5)
%18 = icmp slt i64 %17, 0
br i1 %18, label %19, label %22
19: ; preds = %16
%20 = tail call i32 @ffpmsg(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0))
%21 = tail call i32 @ffpmsg(i8* %0)
br label %47
22: ; preds = %16
%23 = tail call i64 @fseek(i32* %5, i32 0, i32 0)
%24 = icmp eq i64 %23, 0
br i1 %24, label %28, label %25
25: ; preds = %22
%26 = tail call i32 @ffpmsg(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.4, i64 0, i64 0))
%27 = tail call i32 @ffpmsg(i8* %0)
br label %47
28: ; preds = %22
%29 = trunc i64 %17 to i32
%30 = add i32 %29, 5000
%31 = tail call i64 @calloc(i32 1, i32 %30)
%32 = inttoptr i64 %31 to i8*
%33 = icmp eq i64 %31, 0
br i1 %33, label %34, label %38
34: ; preds = %28
%35 = call i32 (i8*, i32, i8*, i32, ...) @snprintf(i8* %4, i32 81, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.5, i64 0, i64 0), i32 %30)
%36 = call i32 @ffpmsg(i8* %4)
%37 = call i32 @ffpmsg(i8* %0)
br label %47
38: ; preds = %28
store i32 %30, i32* %1
%39 = tail call i32 @fread(i8* %32, i32 1, i64 %17, i32* %5)
%40 = tail call i32 @fclose(i32* %5)
%41 = icmp slt i32 %39, 1024
br i1 %41, label %42, label %47
42: ; preds = %38
%43 = call i32 (i8*, i32, i8*, i32, ...) @snprintf(i8* %4, i32 81, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.6, i64 0, i64 0), i32 %39, i32 1024)
%44 = call i32 @ffpmsg(i8* %4)
%45 = call i32 @ffpmsg(i8* %0)
%46 = call i32 @free(i8* %32)
br label %47
47: ; preds = %38, %42, %34, %25, %19, %13, %7
%48 = phi i8* [ null, %7 ], [ null, %13 ], [ null, %19 ], [ null, %25 ], [ null, %34 ], [ null, %42 ], [ %32, %38 ]
ret i8* %48
}