#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 abs(int);
scalar_t__ calloc(int, int);
int fread(void *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(int *);
int get_FITS_key(int const, char **, char *, char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ memset(char *, char, int);
scalar_t__ needswap();
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int snprintf(char *, int, char *, int);
int sscanf(char *, char *, int *);
int /*<<< orphan*/ swap_bytes(void *, int, int);
int read_FITS_image(FILE *inf, char **header, const int ncards, void **buf) {
  void *ptr;
  char keyword[8 + 1], value[70];
  int i, naxes, *naxis, bitpix, bytepix, pixnum;
  memset(value, ' ', 70);
  if (get_FITS_key(ncards, header, "NAXIS", value) == -1)
    return (0);
  if (sscanf(value, "%d", &naxes) < 1) {
    printf("\n\tERROR! read_FITS_image(): reading NAXIS\n");
    return (0);
  }
  if ((naxis = (int *)calloc(naxes, sizeof(int))) == NULL) {
    perror("\n\tERROR! read_FITS_image(): calloc(naxis)");
    return (0);
  }
  for (i = 0; i < naxes; i++) {
    if (snprintf(keyword, 8, "NAXIS%d", i + 1) < 6) {
      printf("\n\tERROR! read_FITS_image(): setting NAXIS_ keyword\n");
      free(naxis);
      return (0);
    }
    if (get_FITS_key(ncards, header, keyword, value) == -1) {
      free(naxis);
      return (0);
    }
    if (sscanf(value, "%d", &naxis[i]) < 1) {
      printf("\n\tERROR! read_FITS_image(): reading %s\n", keyword);
      free(naxis);
      return (0);
    }
  }
  pixnum = 1;
  for (i = 0; i < naxes; i++)
    pixnum *= naxis[i];
  free(naxis);
  if (get_FITS_key(ncards, header, "BITPIX", value) == -1)
    return (0);
  if (sscanf(value, "%d", &bitpix) < 1) {
    printf("\n\tERROR! read_FITS_image(): reading BITPIX from header\n");
    return (0);
  }
  bytepix = abs(bitpix) / 8;
  if ((ptr = (void *)malloc(pixnum * bytepix)) == NULL) {
    perror("\n\tERROR! read_FITS_image(): malloc(ptr)");
    return (0);
  }
  if (fread(ptr, bytepix, pixnum, inf) != pixnum) {
    printf("\n\tERROR! read_FITS_image(): reading the image\n");
    return (0);
  }
  if (needswap() != 0)
    swap_bytes(ptr, pixnum, bytepix);
  *buf = ptr;
  return (pixnum);
}


x86 assembly (clang, -O0):
<read_FITS_image>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %rcx,-0x28(%rbp)
lea    -0x80(%rbp),%rdi
mov    $0x20,%esi
mov    $0x46,%edx
call   1080 <memset@plt>
mov    -0x1c(%rbp),%edi
mov    -0x18(%rbp),%rsi
lea    -0x80(%rbp),%rcx
lea    0xdf1(%rip),%rdx
call   10c0 <get_FITS_key@plt>
cmp    $0xffffffff,%eax
jne    1229 <read_FITS_image+0x59>
movl   $0x0,-0x4(%rbp)
jmp    153f <read_FITS_image+0x36f>
lea    -0x80(%rbp),%rdi
lea    0xe2c(%rip),%rsi
lea    -0x88(%rbp),%rdx
call   10e0 <sscanf@plt>
cmp    $0x1,%eax
jge    1263 <read_FITS_image+0x93>
lea    0xdb6(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    153f <read_FITS_image+0x36f>
mov    -0x88(%rbp),%edi
mov    $0x4,%esi
call   1090 <calloc@plt>
mov    %rax,-0x90(%rbp)
cmp    $0x0,%rax
jne    129c <read_FITS_image+0xcc>
lea    0xda6(%rip),%rdi
call   10f0 <perror@plt>
movl   $0x0,-0x4(%rbp)
jmp    153f <read_FITS_image+0x36f>
movl   $0x0,-0x84(%rbp)
mov    -0x84(%rbp),%eax
cmp    -0x88(%rbp),%eax
jge    13ab <read_FITS_image+0x1db>
lea    -0x39(%rbp),%rdi
mov    -0x84(%rbp),%ecx
add    $0x1,%ecx
mov    $0x8,%esi
lea    0xd8a(%rip),%rdx
call   1070 <snprintf@plt>
cmp    $0x6,%eax
jge    1305 <read_FITS_image+0x135>
lea    0xd7d(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x90(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
jmp    153f <read_FITS_image+0x36f>
mov    -0x1c(%rbp),%edi
mov    -0x18(%rbp),%rsi
lea    -0x39(%rbp),%rdx
lea    -0x80(%rbp),%rcx
call   10c0 <get_FITS_key@plt>
cmp    $0xffffffff,%eax
jne    133a <read_FITS_image+0x16a>
mov    -0x90(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
jmp    153f <read_FITS_image+0x36f>
lea    -0x80(%rbp),%rdi
mov    -0x90(%rbp),%rdx
movslq -0x84(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdx
lea    0xd06(%rip),%rsi
call   10e0 <sscanf@plt>
cmp    $0x1,%eax
jge    1392 <read_FITS_image+0x1c2>
lea    -0x39(%rbp),%rsi
lea    0xd24(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x90(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
jmp    153f <read_FITS_image+0x36f>
jmp    1397 <read_FITS_image+0x1c7>
mov    -0x84(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x84(%rbp)
jmp    12a6 <read_FITS_image+0xd6>
movl   $0x1,-0x9c(%rbp)
movl   $0x0,-0x84(%rbp)
mov    -0x84(%rbp),%eax
cmp    -0x88(%rbp),%eax
jge    1403 <read_FITS_image+0x233>
mov    -0x90(%rbp),%rax
movslq -0x84(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
imul   -0x9c(%rbp),%eax
mov    %eax,-0x9c(%rbp)
mov    -0x84(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x84(%rbp)
jmp    13bf <read_FITS_image+0x1ef>
mov    -0x90(%rbp),%rdi
call   1030 <free@plt>
mov    -0x1c(%rbp),%edi
mov    -0x18(%rbp),%rsi
lea    -0x80(%rbp),%rcx
lea    0xc9e(%rip),%rdx
call   10c0 <get_FITS_key@plt>
cmp    $0xffffffff,%eax
jne    143b <read_FITS_image+0x26b>
movl   $0x0,-0x4(%rbp)
jmp    153f <read_FITS_image+0x36f>
lea    -0x80(%rbp),%rdi
lea    0xc1a(%rip),%rsi
lea    -0x94(%rbp),%rdx
call   10e0 <sscanf@plt>
cmp    $0x1,%eax
jge    1475 <read_FITS_image+0x2a5>
lea    0xc64(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    153f <read_FITS_image+0x36f>
mov    -0x94(%rbp),%edi
call   1050 <abs@plt>
mov    $0x8,%ecx
cltd
idiv   %ecx
mov    %eax,-0x98(%rbp)
mov    -0x9c(%rbp),%edi
imul   -0x98(%rbp),%edi
call   10d0 <malloc@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
jne    14c6 <read_FITS_image+0x2f6>
lea    0xc49(%rip),%rdi
call   10f0 <perror@plt>
movl   $0x0,-0x4(%rbp)
jmp    153f <read_FITS_image+0x36f>
mov    -0x30(%rbp),%rdi
mov    -0x98(%rbp),%esi
mov    -0x9c(%rbp),%edx
mov    -0x10(%rbp),%rcx
call   1040 <fread@plt>
cmp    -0x9c(%rbp),%eax
je     1505 <read_FITS_image+0x335>
lea    0xc34(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    153f <read_FITS_image+0x36f>
mov    $0x0,%al
call   10b0 <needswap@plt>
cmp    $0x0,%rax
je     152b <read_FITS_image+0x35b>
mov    -0x30(%rbp),%rdi
mov    -0x9c(%rbp),%esi
mov    -0x98(%rbp),%edx
call   10a0 <swap_bytes@plt>
mov    -0x30(%rbp),%rcx
mov    -0x28(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x9c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_FITS_image>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x88,%rsp
mov    %rcx,%r14
mov    %edx,%ebx
mov    %rsi,%rbp
mov    %rdi,%r15
lea    0x40(%rsp),%r12
mov    %r12,%rdi
mov    $0x20,%esi
mov    $0x46,%edx
call   1080 <memset@plt>
lea    0xf4b(%rip),%rdx
mov    %ebx,0x8(%rsp)
mov    %ebx,%edi
mov    %rbp,0x20(%rsp)
mov    %rbp,%rsi
mov    %r12,%rcx
call   10c0 <get_FITS_key@plt>
xor    %ebp,%ebp
cmp    $0xffffffff,%eax
je     134f <read_FITS_image+0x17f>
lea    0xe0d(%rip),%rsi
lea    0x40(%rsp),%rdi
lea    0xc(%rsp),%rdx
call   10e0 <sscanf@plt>
test   %eax,%eax
jle    130a <read_FITS_image+0x13a>
mov    0xc(%rsp),%edi
mov    $0x4,%esi
call   1090 <calloc@plt>
test   %rax,%rax
je     13b1 <read_FITS_image+0x1e1>
mov    %r15,0x10(%rsp)
mov    %r14,0x28(%rsp)
xor    %r13d,%r13d
lea    0xdc6(%rip),%rbp
lea    0x37(%rsp),%r14
lea    0x40(%rsp),%r15
lea    0xdba(%rip),%r12
mov    %rax,(%rsp)
mov    %rax,%rbx
nopl   0x0(%rax)
movslq 0xc(%rsp),%rax
cmp    %rax,%r13
jge    1318 <read_FITS_image+0x148>
lea    0x1(%r13),%ecx
mov    %r14,%rdi
mov    $0x8,%esi
mov    %rbp,%rdx
call   1070 <snprintf@plt>
cmp    $0x5,%eax
jle    1338 <read_FITS_image+0x168>
mov    0x8(%rsp),%edi
mov    0x20(%rsp),%rsi
mov    %r14,%rdx
mov    %r15,%rcx
call   10c0 <get_FITS_key@plt>
cmp    $0xffffffff,%eax
je     1344 <read_FITS_image+0x174>
mov    %r15,%rdi
mov    %r12,%rsi
mov    %rbx,%rdx
call   10e0 <sscanf@plt>
add    $0x4,%rbx
add    $0x1,%r13
test   %eax,%eax
jg     1290 <read_FITS_image+0xc0>
lea    0xd51(%rip),%rdi
xor    %ebp,%ebp
lea    0x37(%rsp),%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    (%rsp),%rdi
call   1030 <free@plt>
jmp    134f <read_FITS_image+0x17f>
lea    0xe20(%rip),%rdi
call   1040 <puts@plt>
jmp    134f <read_FITS_image+0x17f>
mov    %eax,%eax
test   %eax,%eax
jle    1363 <read_FITS_image+0x193>
cmp    $0x8,%eax
jae    1376 <read_FITS_image+0x1a6>
mov    $0x1,%ebp
xor    %ecx,%ecx
mov    0x10(%rsp),%r15
mov    (%rsp),%rdi
jmp    1560 <read_FITS_image+0x390>
lea    0xdbf(%rip),%rdi
call   1040 <puts@plt>
mov    (%rsp),%rdi
call   1030 <free@plt>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x88,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0x1,%ebp
mov    0x10(%rsp),%r15
mov    (%rsp),%rdi
jmp    156d <read_FITS_image+0x39d>
mov    %eax,%ecx
and    $0xfffffff8,%ecx
lea    -0x8(%rcx),%rsi
mov    %rsi,%rdx
shr    $0x3,%rdx
add    $0x1,%rdx
mov    %edx,%ebp
and    $0x3,%ebp
cmp    $0x18,%rsi
jae    13bf <read_FITS_image+0x1ef>
movdqa 0xc63(%rip),%xmm0
xor    %esi,%esi
movdqa %xmm0,%xmm1
mov    0x10(%rsp),%r15
mov    (%rsp),%rdi
jmp    14ab <read_FITS_image+0x2db>
lea    0xc58(%rip),%rdi
call   10f0 <perror@plt>
jmp    134f <read_FITS_image+0x17f>
and    $0xfffffffffffffffc,%rdx
movdqa 0xc35(%rip),%xmm0
xor    %esi,%esi
movdqa %xmm0,%xmm1
mov    0x10(%rsp),%r15
mov    (%rsp),%rdi
nopw   0x0(%rax,%rax,1)
movdqu (%rdi,%rsi,4),%xmm3
movdqu 0x10(%rdi,%rsi,4),%xmm2
movdqu 0x20(%rdi,%rsi,4),%xmm4
movdqu 0x30(%rdi,%rsi,4),%xmm5
pshufd $0xf5,%xmm3,%xmm6
pshufd $0xf5,%xmm0,%xmm7
pmuludq %xmm6,%xmm7
pmuludq %xmm0,%xmm3
pshufd $0xf5,%xmm2,%xmm0
pshufd $0xf5,%xmm1,%xmm6
pmuludq %xmm0,%xmm6
pmuludq %xmm1,%xmm2
pmuludq %xmm4,%xmm3
pshufd $0xf5,%xmm4,%xmm0
pmuludq %xmm7,%xmm0
pmuludq %xmm5,%xmm2
pshufd $0xf5,%xmm5,%xmm1
pmuludq %xmm6,%xmm1
movdqu 0x40(%rdi,%rsi,4),%xmm4
movdqu 0x50(%rdi,%rsi,4),%xmm5
pshufd $0xf5,%xmm4,%xmm6
pmuludq %xmm0,%xmm6
pmuludq %xmm4,%xmm3
pshufd $0xf5,%xmm5,%xmm4
pmuludq %xmm1,%xmm4
pmuludq %xmm5,%xmm2
movdqu 0x60(%rdi,%rsi,4),%xmm1
movdqu 0x70(%rdi,%rsi,4),%xmm5
pmuludq %xmm1,%xmm3
pshufd $0xe8,%xmm3,%xmm0
pshufd $0xf5,%xmm1,%xmm1
pmuludq %xmm6,%xmm1
pshufd $0xe8,%xmm1,%xmm1
punpckldq %xmm1,%xmm0
pmuludq %xmm5,%xmm2
pshufd $0xe8,%xmm2,%xmm1
pshufd $0xf5,%xmm5,%xmm2
pmuludq %xmm4,%xmm2
pshufd $0xe8,%xmm2,%xmm2
punpckldq %xmm2,%xmm1
add    $0x20,%rsi
add    $0xfffffffffffffffc,%rdx
jne    13e0 <read_FITS_image+0x210>
movdqa %xmm0,%xmm2
movdqa %xmm1,%xmm3
test   %rbp,%rbp
je     152c <read_FITS_image+0x35c>
lea    (%rdi,%rsi,4),%rsi
add    $0x10,%rsi
shl    $0x5,%rbp
xor    %edx,%edx
cs nopw 0x0(%rax,%rax,1)
movdqu -0x10(%rsi,%rdx,1),%xmm2
movdqu (%rsi,%rdx,1),%xmm3
pshufd $0xf5,%xmm2,%xmm4
pmuludq %xmm0,%xmm2
pshufd $0xe8,%xmm2,%xmm2
pshufd $0xf5,%xmm0,%xmm0
pmuludq %xmm4,%xmm0
pshufd $0xe8,%xmm0,%xmm0
punpckldq %xmm0,%xmm2
pshufd $0xf5,%xmm3,%xmm0
pmuludq %xmm1,%xmm3
pshufd $0xe8,%xmm3,%xmm3
pshufd $0xf5,%xmm1,%xmm1
pmuludq %xmm0,%xmm1
pshufd $0xe8,%xmm1,%xmm0
punpckldq %xmm0,%xmm3
add    $0x20,%rdx
movdqa %xmm2,%xmm0
movdqa %xmm3,%xmm1
cmp    %rdx,%rbp
jne    14d0 <read_FITS_image+0x300>
pshufd $0xf5,%xmm2,%xmm0
pshufd $0xf5,%xmm3,%xmm1
pmuludq %xmm0,%xmm1
pmuludq %xmm2,%xmm3
pshufd $0xee,%xmm3,%xmm0
pmuludq %xmm3,%xmm0
pshufd $0xaa,%xmm1,%xmm2
pmuludq %xmm1,%xmm2
pmuludq %xmm0,%xmm2
movd   %xmm2,%ebp
cmp    %rax,%rcx
je     156d <read_FITS_image+0x39d>
nopl   (%rax)
imul   (%rdi,%rcx,4),%ebp
add    $0x1,%rcx
cmp    %rcx,%rax
jne    1560 <read_FITS_image+0x390>
call   1030 <free@plt>
lea    0xaf1(%rip),%rdx
lea    0x40(%rsp),%rcx
mov    0x8(%rsp),%edi
mov    0x20(%rsp),%rsi
call   10c0 <get_FITS_key@plt>
cmp    $0xffffffff,%eax
je     134d <read_FITS_image+0x17d>
lea    0xaa3(%rip),%rsi
lea    0x40(%rsp),%rdi
lea    0x1c(%rsp),%rdx
call   10e0 <sscanf@plt>
test   %eax,%eax
jle    1607 <read_FITS_image+0x437>
mov    0x1c(%rsp),%eax
mov    %eax,%ebx
neg    %ebx
cmovs  %eax,%ebx
shr    $0x3,%ebx
mov    %ebx,%edi
imul   %ebp,%edi
call   10d0 <malloc@plt>
test   %rax,%rax
je     1621 <read_FITS_image+0x451>
mov    %rax,%r14
mov    %rax,%rdi
mov    %ebx,%esi
mov    %ebp,%edx
mov    %r15,%rcx
call   1050 <fread@plt>
cmp    %ebp,%eax
jne    1610 <read_FITS_image+0x440>
xor    %eax,%eax
call   10b0 <needswap@plt>
test   %rax,%rax
je     15fa <read_FITS_image+0x42a>
mov    %r14,%rdi
mov    %ebp,%esi
mov    %ebx,%edx
call   10a0 <swap_bytes@plt>
mov    0x28(%rsp),%rax
mov    %r14,(%rax)
jmp    134f <read_FITS_image+0x17f>
lea    0xab9(%rip),%rdi
jmp    1617 <read_FITS_image+0x447>
lea    0xa82(%rip),%rdi
call   1040 <puts@plt>
jmp    134d <read_FITS_image+0x17d>
lea    0xa49(%rip),%rdi
call   10f0 <perror@plt>
jmp    134d <read_FITS_image+0x17d>

LLVM IR (-O0):
@.str = [6 x i8] c"NAXIS\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [43 x i8] c"\0A\09ERROR! read_FITS_image(): reading NAXIS\0A\00"
@.str.3 = [42 x i8] c"\0A\09ERROR! read_FITS_image(): calloc(naxis)\00"
@.str.4 = [8 x i8] c"NAXIS%d\00"
@.str.5 = [52 x i8] c"\0A\09ERROR! read_FITS_image(): setting NAXIS_ keyword\0A\00"
@.str.6 = [40 x i8] c"\0A\09ERROR! read_FITS_image(): reading %s\0A\00"
@.str.7 = [7 x i8] c"BITPIX\00"
@.str.8 = [56 x i8] c"\0A\09ERROR! read_FITS_image(): reading BITPIX from header\0A\00"
@.str.9 = [40 x i8] c"\0A\09ERROR! read_FITS_image(): malloc(ptr)\00"
@.str.10 = [47 x i8] c"\0A\09ERROR! read_FITS_image(): reading the image\0A\00"
define i32 @read_FITS_image(i32* %0, i8** %1, i32 %2, i8** %3) {
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i8**
%8 = alloca i32
%9 = alloca i8**
%10 = alloca i8*
%11 = alloca [9 x i8]
%12 = alloca [70 x i8]
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32*
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32
store i32* %0, i32** %6
store i8** %1, i8*** %7
store i32 %2, i32* %8
store i8** %3, i8*** %9
%19 = getelementptr inbounds [70 x i8], [70 x i8]* %12, i64 0, i64 0
%20 = call i32 @memset(i8* %19, i8 signext 32, i32 70)
%21 = load i32, i32* %8
%22 = load i8**, i8*** %7
%23 = getelementptr inbounds [70 x i8], [70 x i8]* %12, i64 0, i64 0
%24 = call i32 @get_FITS_key(i32 %21, i8** %22, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %23)
%25 = icmp eq i32 %24, -1
br i1 %25, label %26, label %27
26: ; preds = %4
store i32 0, i32* %5
br label %147
27: ; preds = %4
%28 = getelementptr inbounds [70 x i8], [70 x i8]* %12, i64 0, i64 0
%29 = call i32 @sscanf(i8* %28, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %14)
%30 = icmp slt i32 %29, 1
br i1 %30, label %31, label %33
31: ; preds = %27
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %5
br label %147
33: ; preds = %27
%34 = load i32, i32* %14
%35 = call i64 @calloc(i32 %34, i32 4)
%36 = inttoptr i64 %35 to i32*
store i32* %36, i32** %15
%37 = icmp eq i32* %36, null
br i1 %37, label %38, label %40
38: ; preds = %33
%39 = call i32 @perror(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %5
br label %147
40: ; preds = %33
store i32 0, i32* %13
br label %41
41: ; preds = %79, %40
%42 = load i32, i32* %13
%43 = load i32, i32* %14
%44 = icmp slt i32 %42, %43
br i1 %44, label %45, label %82
45: ; preds = %41
%46 = getelementptr inbounds [9 x i8], [9 x i8]* %11, i64 0, i64 0
%47 = load i32, i32* %13
%48 = add nsw i32 %47, 1
%49 = call i32 @snprintf(i8* %46, i32 8, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i32 %48)
%50 = icmp slt i32 %49, 6
br i1 %50, label %51, label %55
51: ; preds = %45
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.5, i64 0, i64 0))
%53 = load i32*, i32** %15
%54 = call i32 @free(i32* %53)
store i32 0, i32* %5
br label %147
55: ; preds = %45
%56 = load i32, i32* %8
%57 = load i8**, i8*** %7
%58 = getelementptr inbounds [9 x i8], [9 x i8]* %11, i64 0, i64 0
%59 = getelementptr inbounds [70 x i8], [70 x i8]* %12, i64 0, i64 0
%60 = call i32 @get_FITS_key(i32 %56, i8** %57, i8* %58, i8* %59)
%61 = icmp eq i32 %60, -1
br i1 %61, label %62, label %65
62: ; preds = %55
%63 = load i32*, i32** %15
%64 = call i32 @free(i32* %63)
store i32 0, i32* %5
br label %147
65: ; preds = %55
%66 = getelementptr inbounds [70 x i8], [70 x i8]* %12, i64 0, i64 0
%67 = load i32*, i32** %15
%68 = load i32, i32* %13
%69 = sext i32 %68 to i64
%70 = getelementptr inbounds i32, i32* %67, i64 %69
%71 = call i32 @sscanf(i8* %66, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %70)
%72 = icmp slt i32 %71, 1
br i1 %72, label %73, label %78
73: ; preds = %65
%74 = getelementptr inbounds [9 x i8], [9 x i8]* %11, i64 0, i64 0
%75 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.6, i64 0, i64 0), i8* %74)
%76 = load i32*, i32** %15
%77 = call i32 @free(i32* %76)
store i32 0, i32* %5
br label %147
78: ; preds = %65
br label %79
79: ; preds = %78
%80 = load i32, i32* %13
%81 = add nsw i32 %80, 1
store i32 %81, i32* %13
br label %41
82: ; preds = %41
store i32 1, i32* %18
store i32 0, i32* %13
br label %83
83: ; preds = %95, %82
%84 = load i32, i32* %13
%85 = load i32, i32* %14
%86 = icmp slt i32 %84, %85
br i1 %86, label %87, label %98
87: ; preds = %83
%88 = load i32*, i32** %15
%89 = load i32, i32* %13
%90 = sext i32 %89 to i64
%91 = getelementptr inbounds i32, i32* %88, i64 %90
%92 = load i32, i32* %91
%93 = load i32, i32* %18
%94 = mul nsw i32 %93, %92
store i32 %94, i32* %18
br label %95
95: ; preds = %87
%96 = load i32, i32* %13
%97 = add nsw i32 %96, 1
store i32 %97, i32* %13
br label %83
98: ; preds = %83
%99 = load i32*, i32** %15
%100 = call i32 @free(i32* %99)
%101 = load i32, i32* %8
%102 = load i8**, i8*** %7
%103 = getelementptr inbounds [70 x i8], [70 x i8]* %12, i64 0, i64 0
%104 = call i32 @get_FITS_key(i32 %101, i8** %102, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0), i8* %103)
%105 = icmp eq i32 %104, -1
br i1 %105, label %106, label %107
106: ; preds = %98
store i32 0, i32* %5
br label %147
107: ; preds = %98
%108 = getelementptr inbounds [70 x i8], [70 x i8]* %12, i64 0, i64 0
%109 = call i32 @sscanf(i8* %108, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %16)
%110 = icmp slt i32 %109, 1
br i1 %110, label %111, label %113
111: ; preds = %107
%112 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.8, i64 0, i64 0))
store i32 0, i32* %5
br label %147
113: ; preds = %107
%114 = load i32, i32* %16
%115 = call i32 @abs(i32 %114)
%116 = sdiv i32 %115, 8
store i32 %116, i32* %17
%117 = load i32, i32* %18
%118 = load i32, i32* %17
%119 = mul nsw i32 %117, %118
%120 = call i64 @malloc(i32 %119)
%121 = inttoptr i64 %120 to i8*
store i8* %121, i8** %10
%122 = icmp eq i8* %121, null
br i1 %122, label %123, label %125
123: ; preds = %113
%124 = call i32 @perror(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.9, i64 0, i64 0))
store i32 0, i32* %5
br label %147
125: ; preds = %113
%126 = load i8*, i8** %10
%127 = load i32, i32* %17
%128 = load i32, i32* %18
%129 = load i32*, i32** %6
%130 = call i32 @fread(i8* %126, i32 %127, i32 %128, i32* %129)
%131 = load i32, i32* %18
%132 = icmp ne i32 %130, %131
br i1 %132, label %133, label %135
133: ; preds = %125
%134 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.10, i64 0, i64 0))
store i32 0, i32* %5
br label %147
135: ; preds = %125
%136 = call i64 (...) @needswap()
%137 = icmp ne i64 %136, 0
br i1 %137, label %138, label %143
138: ; preds = %135
%139 = load i8*, i8** %10
%140 = load i32, i32* %18
%141 = load i32, i32* %17
%142 = call i32 @swap_bytes(i8* %139, i32 %140, i32 %141)
br label %143
143: ; preds = %138, %135
%144 = load i8*, i8** %10
%145 = load i8**, i8*** %9
store i8* %144, i8** %145
%146 = load i32, i32* %18
store i32 %146, i32* %5
br label %147
147: ; preds = %143, %133, %123, %111, %106, %73, %62, %51, %38, %31, %26
%148 = load i32, i32* %5
ret i32 %148
}

LLVM IR (-O2):
@.str = [6 x i8] c"NAXIS\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.3 = [42 x i8] c"\0A\09ERROR! read_FITS_image(): calloc(naxis)\00"
@.str.4 = [8 x i8] c"NAXIS%d\00"
@.str.6 = [40 x i8] c"\0A\09ERROR! read_FITS_image(): reading %s\0A\00"
@.str.7 = [7 x i8] c"BITPIX\00"
@.str.9 = [40 x i8] c"\0A\09ERROR! read_FITS_image(): malloc(ptr)\00"
@str = [46 x i8] c"\0A\09ERROR! read_FITS_image(): reading the image\00"
@str.11 = [55 x i8] c"\0A\09ERROR! read_FITS_image(): reading BITPIX from header\00"
@str.12 = [51 x i8] c"\0A\09ERROR! read_FITS_image(): setting NAXIS_ keyword\00"
@str.13 = [42 x i8] c"\0A\09ERROR! read_FITS_image(): reading NAXIS\00"
define i32 @read_FITS_image(i32* nocapture %0, i8** %1, i32 %2, i8** nocapture writeonly %3) {
%5 = alloca [9 x i8]
%6 = alloca [70 x i8]
%7 = alloca i32
%8 = alloca i32
%9 = getelementptr inbounds [9 x i8], [9 x i8]* %5, i64 0, i64 0
%10 = getelementptr inbounds [70 x i8], [70 x i8]* %6, i64 0, i64 0
%11 = bitcast i32* %7 to i8*
%12 = bitcast i32* %8 to i8*
%13 = call i32 @memset(i8* %10, i8 signext 32, i32 70)
%14 = call i32 @get_FITS_key(i32 %2, i8** %1, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %10)
%15 = icmp eq i32 %14, -1
br i1 %15, label %181, label %16
16: ; preds = %4
%17 = call i32 @sscanf(i8* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %7)
%18 = icmp slt i32 %17, 1
br i1 %18, label %19, label %21
19: ; preds = %16
%20 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @str.13, i64 0, i64 0))
br label %181
21: ; preds = %16
%22 = load i32, i32* %7
%23 = call i64 @calloc(i32 %22, i32 4)
%24 = inttoptr i64 %23 to i32*
%25 = icmp eq i64 %23, 0
br i1 %25, label %26, label %28
26: ; preds = %21
%27 = call i32 @perror(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.3, i64 0, i64 0))
br label %181
28: ; preds = %21, %135
%29 = phi i64 [ %123, %135 ], [ 0, %21 ]
%30 = load i32, i32* %7
%31 = sext i32 %30 to i64
%32 = icmp slt i64 %29, %31
br i1 %32, label %122, label %33
33: ; preds = %28
%34 = icmp sgt i32 %30, 0
br i1 %34, label %35, label %150
35: ; preds = %33
%36 = zext i32 %30 to i64
%37 = icmp ult i32 %30, 8
br i1 %37, label %119, label %38
38: ; preds = %35
%39 = and i64 %36, 4294967288
%40 = add nsw i64 %39, -8
%41 = lshr exact i64 %40, 3
%42 = add nuw nsw i64 %41, 1
%43 = and i64 %42, 3
%44 = icmp ult i64 %40, 24
br i1 %44, label %90, label %45
45: ; preds = %38
%46 = and i64 %42, 4611686018427387900
br label %47
47: ; preds = %47, %45
%48 = phi i64 [ 0, %45 ], [ %87, %47 ]
%49 = phi <4 x i32> [ <i32 1, i32 1, i32 1, i32 1>, %45 ], [ %85, %47 ]
%50 = phi <4 x i32> [ <i32 1, i32 1, i32 1, i32 1>, %45 ], [ %86, %47 ]
%51 = phi i64 [ 0, %45 ], [ %88, %47 ]
%52 = getelementptr inbounds i32, i32* %24, i64 %48
%53 = bitcast i32* %52 to <4 x i32>*
%54 = load <4 x i32>, <4 x i32>* %53
%55 = getelementptr inbounds i32, i32* %52, i64 4
%56 = bitcast i32* %55 to <4 x i32>*
%57 = load <4 x i32>, <4 x i32>* %56
%58 = mul <4 x i32> %54, %49
%59 = mul <4 x i32> %57, %50
%60 = or i64 %48, 8
%61 = getelementptr inbounds i32, i32* %24, i64 %60
%62 = bitcast i32* %61 to <4 x i32>*
%63 = load <4 x i32>, <4 x i32>* %62
%64 = getelementptr inbounds i32, i32* %61, i64 4
%65 = bitcast i32* %64 to <4 x i32>*
%66 = load <4 x i32>, <4 x i32>* %65
%67 = mul <4 x i32> %63, %58
%68 = mul <4 x i32> %66, %59
%69 = or i64 %48, 16
%70 = getelementptr inbounds i32, i32* %24, i64 %69
%71 = bitcast i32* %70 to <4 x i32>*
%72 = load <4 x i32>, <4 x i32>* %71
%73 = getelementptr inbounds i32, i32* %70, i64 4
%74 = bitcast i32* %73 to <4 x i32>*
%75 = load <4 x i32>, <4 x i32>* %74
%76 = mul <4 x i32> %72, %67
%77 = mul <4 x i32> %75, %68
%78 = or i64 %48, 24
%79 = getelementptr inbounds i32, i32* %24, i64 %78
%80 = bitcast i32* %79 to <4 x i32>*
%81 = load <4 x i32>, <4 x i32>* %80
%82 = getelementptr inbounds i32, i32* %79, i64 4
%83 = bitcast i32* %82 to <4 x i32>*
%84 = load <4 x i32>, <4 x i32>* %83
%85 = mul <4 x i32> %81, %76
%86 = mul <4 x i32> %84, %77
%87 = add nuw i64 %48, 32
%88 = add i64 %51, 4
%89 = icmp eq i64 %88, %46
br i1 %89, label %90, label %47
90: ; preds = %47, %38
%91 = phi <4 x i32> [ undef, %38 ], [ %85, %47 ]
%92 = phi <4 x i32> [ undef, %38 ], [ %86, %47 ]
%93 = phi i64 [ 0, %38 ], [ %87, %47 ]
%94 = phi <4 x i32> [ <i32 1, i32 1, i32 1, i32 1>, %38 ], [ %85, %47 ]
%95 = phi <4 x i32> [ <i32 1, i32 1, i32 1, i32 1>, %38 ], [ %86, %47 ]
%96 = icmp eq i64 %43, 0
br i1 %96, label %113, label %97
97: ; preds = %90, %97
%98 = phi i64 [ %110, %97 ], [ %93, %90 ]
%99 = phi <4 x i32> [ %108, %97 ], [ %94, %90 ]
%100 = phi <4 x i32> [ %109, %97 ], [ %95, %90 ]
%101 = phi i64 [ %111, %97 ], [ 0, %90 ]
%102 = getelementptr inbounds i32, i32* %24, i64 %98
%103 = bitcast i32* %102 to <4 x i32>*
%104 = load <4 x i32>, <4 x i32>* %103
%105 = getelementptr inbounds i32, i32* %102, i64 4
%106 = bitcast i32* %105 to <4 x i32>*
%107 = load <4 x i32>, <4 x i32>* %106
%108 = mul <4 x i32> %104, %99
%109 = mul <4 x i32> %107, %100
%110 = add nuw i64 %98, 8
%111 = add i64 %101, 1
%112 = icmp eq i64 %111, %43
br i1 %112, label %113, label %97
113: ; preds = %97, %90
%114 = phi <4 x i32> [ %91, %90 ], [ %108, %97 ]
%115 = phi <4 x i32> [ %92, %90 ], [ %109, %97 ]
%116 = mul <4 x i32> %115, %114
%117 = call i32 @llvm.vector.reduce.mul.v4i32(<4 x i32> %116)
%118 = icmp eq i64 %39, %36
br i1 %118, label %150, label %119
119: ; preds = %35, %113
%120 = phi i64 [ 0, %35 ], [ %39, %113 ]
%121 = phi i32 [ 1, %35 ], [ %117, %113 ]
br label %142
122: ; preds = %28
%123 = add nuw nsw i64 %29, 1
%124 = trunc i64 %123 to i32
%125 = call i32 @snprintf(i8* %9, i32 8, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i32 %124)
%126 = icmp slt i32 %125, 6
br i1 %126, label %127, label %130
127: ; preds = %122
%128 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([51 x i8], [51 x i8]* @str.12, i64 0, i64 0))
%129 = call i32 @free(i32* %24)
br label %181
130: ; preds = %122
%131 = call i32 @get_FITS_key(i32 %2, i8** %1, i8* %9, i8* %10)
%132 = icmp eq i32 %131, -1
br i1 %132, label %133, label %135
133: ; preds = %130
%134 = call i32 @free(i32* %24)
br label %181
135: ; preds = %130
%136 = getelementptr inbounds i32, i32* %24, i64 %29
%137 = call i32 @sscanf(i8* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %136)
%138 = icmp slt i32 %137, 1
br i1 %138, label %139, label %28
139: ; preds = %135
%140 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str.6, i64 0, i64 0), i8* %9)
%141 = call i32 @free(i32* %24)
br label %181
142: ; preds = %119, %142
%143 = phi i64 [ %148, %142 ], [ %120, %119 ]
%144 = phi i32 [ %147, %142 ], [ %121, %119 ]
%145 = getelementptr inbounds i32, i32* %24, i64 %143
%146 = load i32, i32* %145
%147 = mul nsw i32 %146, %144
%148 = add nuw nsw i64 %143, 1
%149 = icmp eq i64 %148, %36
br i1 %149, label %150, label %142
150: ; preds = %142, %113, %33
%151 = phi i32 [ 1, %33 ], [ %117, %113 ], [ %147, %142 ]
%152 = call i32 @free(i32* %24)
%153 = call i32 @get_FITS_key(i32 %2, i8** %1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0), i8* %10)
%154 = icmp eq i32 %153, -1
br i1 %154, label %181, label %155
155: ; preds = %150
%156 = call i32 @sscanf(i8* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %8)
%157 = icmp slt i32 %156, 1
br i1 %157, label %158, label %160
158: ; preds = %155
%159 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([55 x i8], [55 x i8]* @str.11, i64 0, i64 0))
br label %181
160: ; preds = %155
%161 = load i32, i32* %8
%162 = call i32 @llvm.abs.i32(i32 %161, i1 true)
%163 = lshr i32 %162, 3
%164 = mul nsw i32 %163, %151
%165 = call i64 @malloc(i32 %164)
%166 = inttoptr i64 %165 to i8*
%167 = icmp eq i64 %165, 0
br i1 %167, label %168, label %170
168: ; preds = %160
%169 = call i32 @perror(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.9, i64 0, i64 0))
br label %181
170: ; preds = %160
%171 = call i32 @fread(i8* %166, i32 %163, i32 %151, i32* %0)
%172 = icmp eq i32 %171, %151
br i1 %172, label %175, label %173
173: ; preds = %170
%174 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @str, i64 0, i64 0))
br label %181
175: ; preds = %170
%176 = call i64 (...) @needswap()
%177 = icmp eq i64 %176, 0
br i1 %177, label %180, label %178
178: ; preds = %175
%179 = call i32 @swap_bytes(i8* %166, i32 %151, i32 %163)
br label %180
180: ; preds = %178, %175
store i8* %166, i8** %3
br label %181
181: ; preds = %150, %4, %180, %173, %168, %158, %139, %133, %127, %26, %19
%182 = phi i32 [ 0, %19 ], [ 0, %26 ], [ 0, %127 ], [ 0, %133 ], [ 0, %139 ], [ 0, %158 ], [ 0, %168 ], [ 0, %173 ], [ %151, %180 ], [ 0, %4 ], [ 0, %150 ]
ret i32 %182
}