#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*/ conv2adts(int *, int);
int /*<<< orphan*/ exit(int);
int find_fillcount(int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int fread_bo(int *, int, int, int /*<<< orphan*/ *, int);
int /*<<< orphan*/ stderr;
int read_tbv(FILE *fp, short int *data, short int *aux, float *r2a, int pol,
             int ncsamples) {
  unsigned short aux_mask[16], header;
  short int odd, even;
  int rval, k, tmpbuf[20], buf[((2048 / 1) - 16)], count, flag = 0;
  aux_mask[0] = 32768;
  for (k = 1; k < 16; k++)
    aux_mask[k] = aux_mask[k - 1] >> 1;
  while (flag == 0) {
    if ((rval = find_fillcount(fp)) < 0) {
      if (rval == -1)
        fprintf(stderr, "Unable to find fillcount word.\n");
      if (rval == -2)
        fprintf(stderr, "Unable to read input file.\n");
      return (-1);
    }
    if (fread_bo(tmpbuf, 20 * sizeof(int), 1, fp, sizeof(int)) != 1) {
      fprintf(stderr, "Error reading input data.\n");
      exit(1);
    }
    if (fread_bo(buf, ncsamples * sizeof(int), 1, fp, sizeof(int)) != 1) {
      fprintf(stderr, "Error reading input data.\n");
      exit(1);
    }
    (void)conv2adts(buf, ncsamples);
    for (k = 0; k < 57; k++)
      aux[k] = 0x0000;
    for (k = 0, count = 0, header = 0; k < ncsamples; k++) {
      odd = (short int)((buf[k] >> 20) & 0x000003ff);
      if (((buf[k] >> 30) & 0x00000001) > 0)
        odd |= 0xfc00;
      even = (short int)((buf[k] >> 4) & 0x000003ff);
      if (((buf[k] >> 14) & 0x00000001) > 0)
        even |= 0xfc00;
      data[2 * k] = even;
      data[2 * k + 1] = odd;
      if ((k < (57 + 1) * 16) && ((buf[k] & 0x00000008) != 0)) {
        if (!count)
          header = header | aux_mask[k % 16];
        else
          aux[count - 1] = aux[count - 1] | aux_mask[k % 16];
      }
      if ((k < (57 + 1) * 16) && (k + 1) % 16 == 0) {
        if (count == 0) {
          if ((header | 0x00f0) == 0x03f0) {
            if (pol == 0)
              flag = 1;
          } else if ((header | 0x00f0) == 0x43f5) {
            if (pol == 1)
              flag = 1;
            else
              break;
          } else if ((header | 0x00f0) == 0x83fa) {
            if (pol == 2)
              flag = 1;
            else
              break;
          } else if ((header | 0x00f0) == 0xc3ff) {
            if (pol == 3)
              flag = 1;
            else
              break;
          } else {
            fprintf(stderr, "Invalid polarization ID.\n");
            exit(1);
          }
        }
        count++;
      }
      if ((k > (57 + 1) * 16) && pol != 0 && ((header | 0x00f0) == 0x03f0))
        break;
    }
    if (pol == 0)
      *r2a = 2.0 * aux[27] + (aux[28] & 0x7fff) / 16384.;
  }
  return (0);
}


x86 assembly (clang, -O0):
<read_tbv>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2080,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8d,-0x2c(%rbp)
mov    %r9d,-0x30(%rbp)
movl   $0x0,-0x2078(%rbp)
movw   $0x8000,-0x50(%rbp)
movl   $0x1,-0x60(%rbp)
cmpl   $0x10,-0x60(%rbp)
jge    11be <read_tbv+0x6e>
mov    -0x60(%rbp),%eax
sub    $0x1,%eax
cltq
movzwl -0x50(%rbp,%rax,2),%eax
sar    $0x1,%eax
mov    %ax,%cx
movslq -0x60(%rbp),%rax
mov    %cx,-0x50(%rbp,%rax,2)
mov    -0x60(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x60(%rbp)
jmp    118a <read_tbv+0x3a>
jmp    11c3 <read_tbv+0x73>
cmpl   $0x0,-0x2078(%rbp)
jne    1650 <read_tbv+0x500>
mov    -0x10(%rbp),%rdi
call   1070 <find_fillcount@plt>
mov    %eax,-0x5c(%rbp)
cmp    $0x0,%eax
jge    122f <read_tbv+0xdf>
cmpl   $0xffffffff,-0x5c(%rbp)
jne    1204 <read_tbv+0xb4>
mov    0x2dea(%rip),%rax
mov    (%rax),%edi
lea    0xe09(%rip),%rsi
call   1040 <fprintf@plt>
cmpl   $0xfffffffe,-0x5c(%rbp)
jne    1223 <read_tbv+0xd3>
mov    0x2dcb(%rip),%rax
mov    (%rax),%edi
lea    0xe0a(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1657 <read_tbv+0x507>
lea    -0xb0(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x50,%esi
mov    $0x1,%edx
mov    $0x4,%r8d
call   1050 <fread_bo@plt>
cmp    $0x1,%eax
je     1277 <read_tbv+0x127>
mov    0x2d81(%rip),%rax
mov    (%rax),%edi
lea    0xddc(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
lea    -0x2070(%rbp),%rdi
movslq -0x30(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%esi
mov    -0x10(%rbp),%rcx
mov    $0x1,%edx
mov    $0x4,%r8d
call   1050 <fread_bo@plt>
cmp    $0x1,%eax
je     12c4 <read_tbv+0x174>
mov    0x2d34(%rip),%rax
mov    (%rax),%edi
lea    0xd8f(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
lea    -0x2070(%rbp),%rdi
mov    -0x30(%rbp),%esi
call   1030 <conv2adts@plt>
movl   $0x0,-0x60(%rbp)
cmpl   $0x39,-0x60(%rbp)
jge    1300 <read_tbv+0x1b0>
mov    -0x20(%rbp),%rax
movslq -0x60(%rbp),%rcx
movw   $0x0,(%rax,%rcx,2)
mov    -0x60(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x60(%rbp)
jmp    12da <read_tbv+0x18a>
movl   $0x0,-0x60(%rbp)
movl   $0x0,-0x2074(%rbp)
movw   $0x0,-0x52(%rbp)
mov    -0x60(%rbp),%eax
cmp    -0x30(%rbp),%eax
jge    1604 <read_tbv+0x4b4>
movslq -0x60(%rbp),%rax
mov    -0x2070(%rbp,%rax,4),%eax
sar    $0x14,%eax
and    $0x3ff,%eax
mov    %ax,-0x54(%rbp)
movslq -0x60(%rbp),%rax
mov    -0x2070(%rbp,%rax,4),%eax
sar    $0x1e,%eax
and    $0x1,%eax
cmp    $0x0,%eax
jle    1361 <read_tbv+0x211>
movswl -0x54(%rbp),%eax
or     $0xfc00,%eax
mov    %ax,-0x54(%rbp)
movslq -0x60(%rbp),%rax
mov    -0x2070(%rbp,%rax,4),%eax
sar    $0x4,%eax
and    $0x3ff,%eax
mov    %ax,-0x56(%rbp)
movslq -0x60(%rbp),%rax
mov    -0x2070(%rbp,%rax,4),%eax
sar    $0xe,%eax
and    $0x1,%eax
cmp    $0x0,%eax
jle    139f <read_tbv+0x24f>
movswl -0x56(%rbp),%eax
or     $0xfc00,%eax
mov    %ax,-0x56(%rbp)
mov    -0x56(%rbp),%dx
mov    -0x18(%rbp),%rax
mov    -0x60(%rbp),%ecx
shl    $0x1,%ecx
movslq %ecx,%rcx
mov    %dx,(%rax,%rcx,2)
mov    -0x54(%rbp),%dx
mov    -0x18(%rbp),%rax
mov    -0x60(%rbp),%ecx
shl    $0x1,%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    %dx,(%rax,%rcx,2)
cmpl   $0x3a0,-0x60(%rbp)
jge    147c <read_tbv+0x32c>
movslq -0x60(%rbp),%rax
mov    -0x2070(%rbp,%rax,4),%eax
and    $0x8,%eax
cmp    $0x0,%eax
je     147c <read_tbv+0x32c>
cmpl   $0x0,-0x2074(%rbp)
jne    142b <read_tbv+0x2db>
movzwl -0x52(%rbp),%eax
mov    %eax,-0x207c(%rbp)
mov    -0x60(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
mov    -0x207c(%rbp),%eax
movslq %edx,%rcx
movzwl -0x50(%rbp,%rcx,2),%ecx
or     %ecx,%eax
mov    %ax,-0x52(%rbp)
jmp    1477 <read_tbv+0x327>
mov    -0x20(%rbp),%rax
mov    -0x2074(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movswl (%rax,%rcx,2),%eax
mov    %eax,-0x2080(%rbp)
mov    -0x60(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
mov    -0x2080(%rbp),%eax
movslq %edx,%rcx
movzwl -0x50(%rbp,%rcx,2),%ecx
or     %ecx,%eax
mov    %ax,%dx
mov    -0x20(%rbp),%rax
mov    -0x2074(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    %dx,(%rax,%rcx,2)
jmp    147c <read_tbv+0x32c>
cmpl   $0x3a0,-0x60(%rbp)
jge    15c1 <read_tbv+0x471>
mov    -0x60(%rbp),%eax
add    $0x1,%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    15c1 <read_tbv+0x471>
cmpl   $0x0,-0x2074(%rbp)
jne    15b2 <read_tbv+0x462>
movzwl -0x52(%rbp),%eax
or     $0xf0,%eax
cmp    $0x3f0,%eax
jne    14da <read_tbv+0x38a>
cmpl   $0x0,-0x2c(%rbp)
jne    14d5 <read_tbv+0x385>
movl   $0x1,-0x2078(%rbp)
jmp    15ad <read_tbv+0x45d>
movzwl -0x52(%rbp),%eax
or     $0xf0,%eax
cmp    $0x43f5,%eax
jne    1511 <read_tbv+0x3c1>
cmpl   $0x1,-0x2c(%rbp)
jne    1507 <read_tbv+0x3b7>
movl   $0x1,-0x2078(%rbp)
jmp    150c <read_tbv+0x3bc>
jmp    1604 <read_tbv+0x4b4>
jmp    15a8 <read_tbv+0x458>
movzwl -0x52(%rbp),%eax
or     $0xf0,%eax
cmp    $0x83fa,%eax
jne    1548 <read_tbv+0x3f8>
cmpl   $0x2,-0x2c(%rbp)
jne    153e <read_tbv+0x3ee>
movl   $0x1,-0x2078(%rbp)
jmp    1543 <read_tbv+0x3f3>
jmp    1604 <read_tbv+0x4b4>
jmp    15a3 <read_tbv+0x453>
movzwl -0x52(%rbp),%eax
or     $0xf0,%eax
cmp    $0xc3ff,%eax
jne    157f <read_tbv+0x42f>
cmpl   $0x3,-0x2c(%rbp)
jne    1575 <read_tbv+0x425>
movl   $0x1,-0x2078(%rbp)
jmp    157a <read_tbv+0x42a>
jmp    1604 <read_tbv+0x4b4>
jmp    159e <read_tbv+0x44e>
mov    0x2a5a(%rip),%rax
mov    (%rax),%edi
lea    0xad0(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
jmp    15a3 <read_tbv+0x453>
jmp    15a8 <read_tbv+0x458>
jmp    15ad <read_tbv+0x45d>
jmp    15b2 <read_tbv+0x462>
mov    -0x2074(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2074(%rbp)
cmpl   $0x3a0,-0x60(%rbp)
jle    15f1 <read_tbv+0x4a1>
cmpl   $0x0,-0x2c(%rbp)
je     15f1 <read_tbv+0x4a1>
movzwl -0x52(%rbp),%eax
or     $0xf0,%eax
cmp    $0x3f0,%eax
jne    15f1 <read_tbv+0x4a1>
jmp    1604 <read_tbv+0x4b4>
jmp    15f6 <read_tbv+0x4a6>
mov    -0x60(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x60(%rbp)
jmp    1317 <read_tbv+0x1c7>
cmpl   $0x0,-0x2c(%rbp)
jne    164b <read_tbv+0x4fb>
mov    -0x20(%rbp),%rax
movswl 0x36(%rax),%eax
cvtsi2sd %eax,%xmm0
mov    -0x20(%rbp),%rax
movswl 0x38(%rax),%eax
and    $0x7fff,%eax
cvtsi2sd %eax,%xmm1
movsd  0x9cd(%rip),%xmm2
divsd  %xmm2,%xmm1
addsd  %xmm0,%xmm0
addsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
mov    -0x28(%rbp),%rax
movss  %xmm0,(%rax)
jmp    11c3 <read_tbv+0x73>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x2080,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_tbv>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x2068,%rsp
mov    %rcx,0x10(%rsp)
mov    %rsi,%rbp
movaps 0xe90(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
movaps 0xe94(%rip),%xmm0
movaps %xmm0,0x40(%rsp)
lea    0x0(,%r9,4),%eax
mov    %eax,0xc(%rsp)
mov    %r9,0x28(%rsp)
mov    %r9d,%r15d
lea    0xa0(%rsp),%r13
mov    %rdi,0x20(%rsp)
mov    %r15,0x18(%rsp)
jmp    11be <read_tbv+0x6e>
nopl   0x0(%rax)
test   %r11d,%r11d
mov    0x20(%rsp),%rdi
jne    1454 <read_tbv+0x304>
mov    %rdx,%r14
mov    %r8d,%r15d
mov    %rdi,%r12
call   1070 <find_fillcount@plt>
test   %eax,%eax
js     143c <read_tbv+0x2ec>
lea    0x50(%rsp),%rdi
mov    $0x50,%esi
mov    $0x1,%edx
mov    %r12,%rcx
mov    $0x4,%r8d
call   1050 <fread_bo@plt>
cmp    $0x1,%eax
jne    1481 <read_tbv+0x331>
mov    %r13,%rbx
mov    %r13,%rdi
mov    0xc(%rsp),%esi
mov    $0x1,%edx
mov    %r12,%rcx
mov    $0x4,%r8d
call   1050 <fread_bo@plt>
cmp    $0x1,%eax
jne    1481 <read_tbv+0x331>
mov    %rbx,%rdi
mov    0x28(%rsp),%rbx
mov    %ebx,%esi
call   1030 <conv2adts@plt>
mov    %r14,%rdx
xorps  %xmm0,%xmm0
movups %xmm0,(%r14)
movups %xmm0,0x10(%r14)
movups %xmm0,0x20(%r14)
movups %xmm0,0x30(%r14)
movups %xmm0,0x40(%r14)
movups %xmm0,0x50(%r14)
movups %xmm0,0x60(%r14)
movw   $0x0,0x70(%r14)
test   %ebx,%ebx
jle    13f0 <read_tbv+0x2a0>
xor    %ecx,%ecx
xor    %r11d,%r11d
xor    %r14d,%r14d
xor    %r9d,%r9d
mov    %r15d,%r8d
mov    0x18(%rsp),%r15
jmp    12a5 <read_tbv+0x155>
movslq %r14d,%rax
mov    %ecx,%edi
and    $0xf,%edi
movzwl 0x30(%rsp,%rdi,2),%esi
or     %si,-0x2(%rdx,%rax,2)
lea    0x1(%rcx),%eax
test   $0xf,%al
je     1361 <read_tbv+0x211>
add    $0x1,%rcx
cmp    %rcx,%r15
je     13f6 <read_tbv+0x2a6>
mov    0xa0(%rsp,%rcx,4),%edi
mov    %edi,%eax
shr    $0x14,%eax
and    $0x3ff,%eax
xor    %ebx,%ebx
test   $0x40000000,%edi
sete   %bl
shl    $0xa,%ebx
add    %ebx,%eax
add    $0xfffffc00,%eax
mov    %edi,%ebx
shr    $0x4,%ebx
and    $0x3ff,%ebx
xor    %esi,%esi
test   $0x4000,%edi
sete   %sil
shl    $0xa,%esi
add    %ebx,%esi
add    $0xfffffc00,%esi
mov    %si,0x0(%rbp,%rcx,4)
mov    %ax,0x2(%rbp,%rcx,4)
cmp    $0x39f,%rcx
ja     1330 <read_tbv+0x1e0>
test   $0x8,%dil
je     128d <read_tbv+0x13d>
test   %r14d,%r14d
jne    127b <read_tbv+0x12b>
mov    %ecx,%eax
and    $0xf,%eax
or     0x30(%rsp,%rax,2),%r9w
lea    0x1(%rcx),%eax
test   $0xf,%al
je     1375 <read_tbv+0x225>
xor    %r14d,%r14d
jmp    1298 <read_tbv+0x148>
nopl   0x0(%rax)
test   %r8d,%r8d
je     1298 <read_tbv+0x148>
cmp    $0x3a0,%rcx
je     1298 <read_tbv+0x148>
mov    %r9d,%eax
and    $0xff0f,%eax
movzwl %ax,%eax
cmp    $0x300,%eax
jne    1298 <read_tbv+0x148>
jmp    11b0 <read_tbv+0x60>
test   %r14d,%r14d
je     1375 <read_tbv+0x225>
mov    %r11d,%edi
add    $0x1,%r14d
mov    %edi,%r11d
jmp    1298 <read_tbv+0x148>
mov    %r9d,%edi
or     $0xf0,%edi
movswl %di,%eax
movzwl %di,%edi
cmp    $0x3ef,%eax
jg     13ac <read_tbv+0x25c>
cmp    $0x83fa,%edi
je     13ce <read_tbv+0x27e>
cmp    $0xc3ff,%edi
jne    14a0 <read_tbv+0x350>
mov    $0x1,%edi
cmp    $0x3,%r8d
je     1369 <read_tbv+0x219>
jmp    13f6 <read_tbv+0x2a6>
cmp    $0x43f5,%edi
je     13db <read_tbv+0x28b>
cmp    $0x3f0,%edi
jne    14a0 <read_tbv+0x350>
test   %r8d,%r8d
mov    $0x1,%eax
cmove  %eax,%r11d
jmp    1366 <read_tbv+0x216>
mov    $0x1,%edi
cmp    $0x2,%r8d
je     1369 <read_tbv+0x219>
jmp    13f6 <read_tbv+0x2a6>
mov    %r8d,%edi
cmp    $0x1,%r8d
je     1369 <read_tbv+0x219>
jmp    13f6 <read_tbv+0x2a6>
cs nopw 0x0(%rax,%rax,1)
xor    %r11d,%r11d
mov    %r15d,%r8d
test   %r8d,%r8d
jne    11b0 <read_tbv+0x60>
movswl 0x36(%rdx),%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movzwl 0x38(%rdx),%eax
and    $0x7fff,%eax
xorps  %xmm1,%xmm1
cvtsi2sd %eax,%xmm1
mulsd  0xbfe(%rip),%xmm1
addsd  %xmm0,%xmm0
addsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
mov    0x10(%rsp),%rax
movss  %xmm0,(%rax)
jmp    11b0 <read_tbv+0x60>
mov    $0xffffffff,%ebx
cmp    $0xffffffff,%eax
je     1458 <read_tbv+0x308>
cmp    $0xfffffffe,%eax
jne    146d <read_tbv+0x31d>
lea    0xbf6(%rip),%rsi
jmp    145f <read_tbv+0x30f>
xor    %ebx,%ebx
jmp    146d <read_tbv+0x31d>
lea    0xbc9(%rip),%rsi
mov    0x2b7a(%rip),%rax
mov    (%rax),%edi
call   1040 <fprintf@plt>
mov    %ebx,%eax
add    $0x2068,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2b58(%rip),%rax
mov    (%rax),%edi
lea    0xbd3(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    0x2b39(%rip),%rax
mov    (%rax),%edi
lea    0xbcf(%rip),%rsi
jmp    1491 <read_tbv+0x341>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [32 x i8] c"Unable to find fillcount word.\0A\00"
@.str.1 = [28 x i8] c"Unable to read input file.\0A\00"
@.str.2 = [27 x i8] c"Error reading input data.\0A\00"
@.str.3 = [26 x i8] c"Invalid polarization ID.\0A\00"
define i32 @read_tbv(i32* %0, i16* %1, i16* %2, float* %3, i32 %4, i32 %5) {
%7 = alloca i32
%8 = alloca i32*
%9 = alloca i16*
%10 = alloca i16*
%11 = alloca float*
%12 = alloca i32
%13 = alloca i32
%14 = alloca [16 x i16]
%15 = alloca i16
%16 = alloca i16
%17 = alloca i16
%18 = alloca i32
%19 = alloca i32
%20 = alloca [20 x i32]
%21 = alloca [2032 x i32]
%22 = alloca i32
%23 = alloca i32
store i32* %0, i32** %8
store i16* %1, i16** %9
store i16* %2, i16** %10
store float* %3, float** %11
store i32 %4, i32* %12
store i32 %5, i32* %13
store i32 0, i32* %23
%24 = getelementptr inbounds [16 x i16], [16 x i16]* %14, i64 0, i64 0
store i16 -32768, i16* %24
store i32 1, i32* %19
br label %25
25: ; preds = %40, %6
%26 = load i32, i32* %19
%27 = icmp slt i32 %26, 16
br i1 %27, label %28, label %43
28: ; preds = %25
%29 = load i32, i32* %19
%30 = sub nsw i32 %29, 1
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds [16 x i16], [16 x i16]* %14, i64 0, i64 %31
%33 = load i16, i16* %32
%34 = zext i16 %33 to i32
%35 = ashr i32 %34, 1
%36 = trunc i32 %35 to i16
%37 = load i32, i32* %19
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds [16 x i16], [16 x i16]* %14, i64 0, i64 %38
store i16 %36, i16* %39
br label %40
40: ; preds = %28
%41 = load i32, i32* %19
%42 = add nsw i32 %41, 1
store i32 %42, i32* %19
br label %25
43: ; preds = %25
br label %44
44: ; preds = %305, %43
%45 = load i32, i32* %23
%46 = icmp eq i32 %45, 0
br i1 %46, label %47, label %306
47: ; preds = %44
%48 = load i32*, i32** %8
%49 = call i32 @find_fillcount(i32* %48)
store i32 %49, i32* %18
%50 = icmp slt i32 %49, 0
br i1 %50, label %51, label %64
51: ; preds = %47
%52 = load i32, i32* %18
%53 = icmp eq i32 %52, -1
br i1 %53, label %54, label %57
54: ; preds = %51
%55 = load i32, i32* @stderr
%56 = call i32 @fprintf(i32 %55, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
br label %57
57: ; preds = %54, %51
%58 = load i32, i32* %18
%59 = icmp eq i32 %58, -2
br i1 %59, label %60, label %63
60: ; preds = %57
%61 = load i32, i32* @stderr
%62 = call i32 @fprintf(i32 %61, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
br label %63
63: ; preds = %60, %57
store i32 -1, i32* %7
br label %307
64: ; preds = %47
%65 = getelementptr inbounds [20 x i32], [20 x i32]* %20, i64 0, i64 0
%66 = load i32*, i32** %8
%67 = call i32 @fread_bo(i32* %65, i32 80, i32 1, i32* %66, i32 4)
%68 = icmp ne i32 %67, 1
br i1 %68, label %69, label %73
69: ; preds = %64
%70 = load i32, i32* @stderr
%71 = call i32 @fprintf(i32 %70, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
%72 = call i32 @exit(i32 1)
unreachable
73: ; preds = %64
%74 = getelementptr inbounds [2032 x i32], [2032 x i32]* %21, i64 0, i64 0
%75 = load i32, i32* %13
%76 = sext i32 %75 to i64
%77 = mul i64 %76, 4
%78 = trunc i64 %77 to i32
%79 = load i32*, i32** %8
%80 = call i32 @fread_bo(i32* %74, i32 %78, i32 1, i32* %79, i32 4)
%81 = icmp ne i32 %80, 1
br i1 %81, label %82, label %86
82: ; preds = %73
%83 = load i32, i32* @stderr
%84 = call i32 @fprintf(i32 %83, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
%85 = call i32 @exit(i32 1)
unreachable
86: ; preds = %73
%87 = getelementptr inbounds [2032 x i32], [2032 x i32]* %21, i64 0, i64 0
%88 = load i32, i32* %13
%89 = call i32 @conv2adts(i32* %87, i32 %88)
store i32 0, i32* %19
br label %90
90: ; preds = %98, %86
%91 = load i32, i32* %19
%92 = icmp slt i32 %91, 57
br i1 %92, label %93, label %101
93: ; preds = %90
%94 = load i16*, i16** %10
%95 = load i32, i32* %19
%96 = sext i32 %95 to i64
%97 = getelementptr inbounds i16, i16* %94, i64 %96
store i16 0, i16* %97
br label %98
98: ; preds = %93
%99 = load i32, i32* %19
%100 = add nsw i32 %99, 1
store i32 %100, i32* %19
br label %90
101: ; preds = %90
store i32 0, i32* %19
store i32 0, i32* %22
store i16 0, i16* %15
br label %102
102: ; preds = %283, %101
%103 = load i32, i32* %19
%104 = load i32, i32* %13
%105 = icmp slt i32 %103, %104
br i1 %105, label %106, label %286
106: ; preds = %102
%107 = load i32, i32* %19
%108 = sext i32 %107 to i64
%109 = getelementptr inbounds [2032 x i32], [2032 x i32]* %21, i64 0, i64 %108
%110 = load i32, i32* %109
%111 = ashr i32 %110, 20
%112 = and i32 %111, 1023
%113 = trunc i32 %112 to i16
store i16 %113, i16* %16
%114 = load i32, i32* %19
%115 = sext i32 %114 to i64
%116 = getelementptr inbounds [2032 x i32], [2032 x i32]* %21, i64 0, i64 %115
%117 = load i32, i32* %116
%118 = ashr i32 %117, 30
%119 = and i32 %118, 1
%120 = icmp sgt i32 %119, 0
br i1 %120, label %121, label %126
121: ; preds = %106
%122 = load i16, i16* %16
%123 = sext i16 %122 to i32
%124 = or i32 %123, 64512
%125 = trunc i32 %124 to i16
store i16 %125, i16* %16
br label %126
126: ; preds = %121, %106
%127 = load i32, i32* %19
%128 = sext i32 %127 to i64
%129 = getelementptr inbounds [2032 x i32], [2032 x i32]* %21, i64 0, i64 %128
%130 = load i32, i32* %129
%131 = ashr i32 %130, 4
%132 = and i32 %131, 1023
%133 = trunc i32 %132 to i16
store i16 %133, i16* %17
%134 = load i32, i32* %19
%135 = sext i32 %134 to i64
%136 = getelementptr inbounds [2032 x i32], [2032 x i32]* %21, i64 0, i64 %135
%137 = load i32, i32* %136
%138 = ashr i32 %137, 14
%139 = and i32 %138, 1
%140 = icmp sgt i32 %139, 0
br i1 %140, label %141, label %146
141: ; preds = %126
%142 = load i16, i16* %17
%143 = sext i16 %142 to i32
%144 = or i32 %143, 64512
%145 = trunc i32 %144 to i16
store i16 %145, i16* %17
br label %146
146: ; preds = %141, %126
%147 = load i16, i16* %17
%148 = load i16*, i16** %9
%149 = load i32, i32* %19
%150 = mul nsw i32 2, %149
%151 = sext i32 %150 to i64
%152 = getelementptr inbounds i16, i16* %148, i64 %151
store i16 %147, i16* %152
%153 = load i16, i16* %16
%154 = load i16*, i16** %9
%155 = load i32, i32* %19
%156 = mul nsw i32 2, %155
%157 = add nsw i32 %156, 1
%158 = sext i32 %157 to i64
%159 = getelementptr inbounds i16, i16* %154, i64 %158
store i16 %153, i16* %159
%160 = load i32, i32* %19
%161 = icmp slt i32 %160, 928
br i1 %161, label %162, label %205
162: ; preds = %146
%163 = load i32, i32* %19
%164 = sext i32 %163 to i64
%165 = getelementptr inbounds [2032 x i32], [2032 x i32]* %21, i64 0, i64 %164
%166 = load i32, i32* %165
%167 = and i32 %166, 8
%168 = icmp ne i32 %167, 0
br i1 %168, label %169, label %205
169: ; preds = %162
%170 = load i32, i32* %22
%171 = icmp ne i32 %170, 0
br i1 %171, label %183, label %172
172: ; preds = %169
%173 = load i16, i16* %15
%174 = zext i16 %173 to i32
%175 = load i32, i32* %19
%176 = srem i32 %175, 16
%177 = sext i32 %176 to i64
%178 = getelementptr inbounds [16 x i16], [16 x i16]* %14, i64 0, i64 %177
%179 = load i16, i16* %178
%180 = zext i16 %179 to i32
%181 = or i32 %174, %180
%182 = trunc i32 %181 to i16
store i16 %182, i16* %15
br label %204
183: ; preds = %169
%184 = load i16*, i16** %10
%185 = load i32, i32* %22
%186 = sub nsw i32 %185, 1
%187 = sext i32 %186 to i64
%188 = getelementptr inbounds i16, i16* %184, i64 %187
%189 = load i16, i16* %188
%190 = sext i16 %189 to i32
%191 = load i32, i32* %19
%192 = srem i32 %191, 16
%193 = sext i32 %192 to i64
%194 = getelementptr inbounds [16 x i16], [16 x i16]* %14, i64 0, i64 %193
%195 = load i16, i16* %194
%196 = zext i16 %195 to i32
%197 = or i32 %190, %196
%198 = trunc i32 %197 to i16
%199 = load i16*, i16** %10
%200 = load i32, i32* %22
%201 = sub nsw i32 %200, 1
%202 = sext i32 %201 to i64
%203 = getelementptr inbounds i16, i16* %199, i64 %202
store i16 %198, i16* %203
br label %204
204: ; preds = %183, %172
br label %205
205: ; preds = %204, %162, %146
%206 = load i32, i32* %19
%207 = icmp slt i32 %206, 928
br i1 %207, label %208, label %270
208: ; preds = %205
%209 = load i32, i32* %19
%210 = add nsw i32 %209, 1
%211 = srem i32 %210, 16
%212 = icmp eq i32 %211, 0
br i1 %212, label %213, label %270
213: ; preds = %208
%214 = load i32, i32* %22
%215 = icmp eq i32 %214, 0
br i1 %215, label %216, label %267
216: ; preds = %213
%217 = load i16, i16* %15
%218 = zext i16 %217 to i32
%219 = or i32 %218, 240
%220 = icmp eq i32 %219, 1008
br i1 %220, label %221, label %226
221: ; preds = %216
%222 = load i32, i32* %12
%223 = icmp eq i32 %222, 0
br i1 %223, label %224, label %225
224: ; preds = %221
store i32 1, i32* %23
br label %225
225: ; preds = %224, %221
br label %266
226: ; preds = %216
%227 = load i16, i16* %15
%228 = zext i16 %227 to i32
%229 = or i32 %228, 240
%230 = icmp eq i32 %229, 17397
br i1 %230, label %231, label %237
231: ; preds = %226
%232 = load i32, i32* %12
%233 = icmp eq i32 %232, 1
br i1 %233, label %234, label %235
234: ; preds = %231
store i32 1, i32* %23
br label %236
235: ; preds = %231
br label %286
236: ; preds = %234
br label %265
237: ; preds = %226
%238 = load i16, i16* %15
%239 = zext i16 %238 to i32
%240 = or i32 %239, 240
%241 = icmp eq i32 %240, 33786
br i1 %241, label %242, label %248
242: ; preds = %237
%243 = load i32, i32* %12
%244 = icmp eq i32 %243, 2
br i1 %244, label %245, label %246
245: ; preds = %242
store i32 1, i32* %23
br label %247
246: ; preds = %242
br label %286
247: ; preds = %245
br label %264
248: ; preds = %237
%249 = load i16, i16* %15
%250 = zext i16 %249 to i32
%251 = or i32 %250, 240
%252 = icmp eq i32 %251, 50175
br i1 %252, label %253, label %259
253: ; preds = %248
%254 = load i32, i32* %12
%255 = icmp eq i32 %254, 3
br i1 %255, label %256, label %257
256: ; preds = %253
store i32 1, i32* %23
br label %258
257: ; preds = %253
br label %286
258: ; preds = %256
br label %263
259: ; preds = %248
%260 = load i32, i32* @stderr
%261 = call i32 @fprintf(i32 %260, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0))
%262 = call i32 @exit(i32 1)
unreachable
263: ; preds = %258
br label %264
264: ; preds = %263, %247
br label %265
265: ; preds = %264, %236
br label %266
266: ; preds = %265, %225
br label %267
267: ; preds = %266, %213
%268 = load i32, i32* %22
%269 = add nsw i32 %268, 1
store i32 %269, i32* %22
br label %270
270: ; preds = %267, %208, %205
%271 = load i32, i32* %19
%272 = icmp sgt i32 %271, 928
br i1 %272, label %273, label %282
273: ; preds = %270
%274 = load i32, i32* %12
%275 = icmp ne i32 %274, 0
br i1 %275, label %276, label %282
276: ; preds = %273
%277 = load i16, i16* %15
%278 = zext i16 %277 to i32
%279 = or i32 %278, 240
%280 = icmp eq i32 %279, 1008
br i1 %280, label %281, label %282
281: ; preds = %276
br label %286
282: ; preds = %276, %273, %270
br label %283
283: ; preds = %282
%284 = load i32, i32* %19
%285 = add nsw i32 %284, 1
store i32 %285, i32* %19
br label %102
286: ; preds = %281, %257, %246, %235, %102
%287 = load i32, i32* %12
%288 = icmp eq i32 %287, 0
br i1 %288, label %289, label %305
289: ; preds = %286
%290 = load i16*, i16** %10
%291 = getelementptr inbounds i16, i16* %290, i64 27
%292 = load i16, i16* %291
%293 = sext i16 %292 to i32
%294 = sitofp i32 %293 to double
%295 = load i16*, i16** %10
%296 = getelementptr inbounds i16, i16* %295, i64 28
%297 = load i16, i16* %296
%298 = sext i16 %297 to i32
%299 = and i32 %298, 32767
%300 = sitofp i32 %299 to double
%301 = fdiv double %300, 1.638400e+04
%302 = call double @llvm.fmuladd.f64(double 2.000000e+00, double %294, double %301)
%303 = fptrunc double %302 to float
%304 = load float*, float** %11
store float %303, float* %304
br label %305
305: ; preds = %289, %286
br label %44
306: ; preds = %44
store i32 0, i32* %7
br label %307
307: ; preds = %306, %63
%308 = load i32, i32* %7
ret i32 %308
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [32 x i8] c"Unable to find fillcount word.\0A\00"
@.str.1 = [28 x i8] c"Unable to read input file.\0A\00"
@.str.2 = [27 x i8] c"Error reading input data.\0A\00"
@.str.3 = [26 x i8] c"Invalid polarization ID.\0A\00"
define i32 @read_tbv(i32* %0, i16* nocapture writeonly %1, i16* nocapture %2, float* nocapture writeonly %3, i32 %4, i32 %5) {
%7 = bitcast i16* %2 to i8*
%8 = alloca [16 x i16]
%9 = alloca [20 x i32]
%10 = alloca [2032 x i32]
%11 = bitcast [16 x i16]* %8 to i8*
%12 = bitcast [20 x i32]* %9 to i8*
%13 = bitcast [2032 x i32]* %10 to i8*
%14 = bitcast [16 x i16]* %8 to <8 x i16>*
store <8 x i16> <i16 -32768, i16 16384, i16 8192, i16 4096, i16 2048, i16 1024, i16 512, i16 256>, <8 x i16>* %14
%15 = getelementptr inbounds [16 x i16], [16 x i16]* %8, i64 0, i64 8
%16 = bitcast i16* %15 to <8 x i16>*
store <8 x i16> <i16 128, i16 64, i16 32, i16 16, i16 8, i16 4, i16 2, i16 1>, <8 x i16>* %16
%17 = getelementptr inbounds [20 x i32], [20 x i32]* %9, i64 0, i64 0
%18 = getelementptr inbounds [2032 x i32], [2032 x i32]* %10, i64 0, i64 0
%19 = shl i32 %5, 2
%20 = icmp sgt i32 %5, 0
%21 = icmp ne i32 %4, 0
%22 = icmp eq i32 %4, 0
%23 = getelementptr inbounds i16, i16* %2, i64 27
%24 = getelementptr inbounds i16, i16* %2, i64 28
%25 = zext i32 %5 to i64
br label %26
26: ; preds = %6, %143
%27 = call i32 @find_fillcount(i32* %0)
%28 = icmp slt i32 %27, 0
br i1 %28, label %29, label %31
29: ; preds = %26
switch i32 %27, label %150 [
i32 -1, label %146
i32 -2, label %30
]
30: ; preds = %29
br label %146
31: ; preds = %26
%32 = call i32 @fread_bo(i32* %17, i32 80, i32 1, i32* %0, i32 4)
%33 = icmp eq i32 %32, 1
br i1 %33, label %38, label %34
34: ; preds = %31
%35 = load i32, i32* @stderr
%36 = call i32 @fprintf(i32 %35, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
%37 = call i32 @exit(i32 1)
unreachable
38: ; preds = %31
%39 = call i32 @fread_bo(i32* %18, i32 %19, i32 1, i32* %0, i32 4)
%40 = icmp eq i32 %39, 1
br i1 %40, label %45, label %41
41: ; preds = %38
%42 = load i32, i32* @stderr
%43 = call i32 @fprintf(i32 %42, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
%44 = call i32 @exit(i32 1)
unreachable
45: ; preds = %38
%46 = call i32 @conv2adts(i32* %18, i32 %5)
br i1 %20, label %47, label %131
47: ; preds = %45, %125
%48 = phi i64 [ %129, %125 ], [ 0, %45 ]
%49 = phi i32 [ %126, %125 ], [ 0, %45 ]
%50 = phi i32 [ %127, %125 ], [ 0, %45 ]
%51 = phi i16 [ %128, %125 ], [ 0, %45 ]
%52 = getelementptr inbounds [2032 x i32], [2032 x i32]* %10, i64 0, i64 %48
%53 = load i32, i32* %52
%54 = lshr i32 %53, 20
%55 = trunc i32 %54 to i16
%56 = and i16 %55, 1023
%57 = and i32 %53, 1073741824
%58 = icmp eq i32 %57, 0
%59 = select i1 %58, i16 0, i16 -1024
%60 = or i16 %56, %59
%61 = trunc i32 %53 to i16
%62 = lshr i16 %61, 4
%63 = and i16 %62, 1023
%64 = and i32 %53, 16384
%65 = icmp eq i32 %64, 0
%66 = select i1 %65, i16 0, i16 -1024
%67 = or i16 %63, %66
%68 = shl nuw nsw i64 %48, 1
%69 = getelementptr inbounds i16, i16* %1, i64 %68
store i16 %67, i16* %69
%70 = or i64 %68, 1
%71 = getelementptr inbounds i16, i16* %1, i64 %70
store i16 %60, i16* %71
%72 = icmp ult i64 %48, 928
br i1 %72, label %73, label %119
73: ; preds = %47
%74 = and i32 %53, 8
%75 = icmp eq i32 %74, 0
br i1 %75, label %87, label %76
76: ; preds = %73
%77 = icmp eq i32 %50, 0
br i1 %77, label %92, label %78
78: ; preds = %76
%79 = add nsw i32 %50, -1
%80 = sext i32 %79 to i64
%81 = getelementptr inbounds i16, i16* %2, i64 %80
%82 = load i16, i16* %81
%83 = and i64 %48, 15
%84 = getelementptr inbounds [16 x i16], [16 x i16]* %8, i64 0, i64 %83
%85 = load i16, i16* %84
%86 = or i16 %85, %82
store i16 %86, i16* %81
br label %87
87: ; preds = %78, %73
%88 = trunc i64 %48 to i32
%89 = add nuw nsw i32 %88, 1
%90 = and i32 %89, 15
%91 = icmp eq i32 %90, 0
br i1 %91, label %101, label %125
92: ; preds = %76
%93 = and i64 %48, 15
%94 = getelementptr inbounds [16 x i16], [16 x i16]* %8, i64 0, i64 %93
%95 = load i16, i16* %94
%96 = or i16 %95, %51
%97 = trunc i64 %48 to i32
%98 = add nuw nsw i32 %97, 1
%99 = and i32 %98, 15
%100 = icmp eq i32 %99, 0
br i1 %100, label %103, label %125
101: ; preds = %87
%102 = icmp eq i32 %50, 0
br i1 %102, label %103, label %115
103: ; preds = %92, %101
%104 = phi i16 [ %51, %101 ], [ %96, %92 ]
%105 = or i16 %104, 240
switch i16 %105, label %111 [
i16 1008, label %106
i16 17397, label %108
i16 -31750, label %109
i16 -15361, label %110
]
106: ; preds = %103
%107 = select i1 %22, i32 1, i32 %49
br label %115
108: ; preds = %103
switch i32 %4, label %143 [
i32 1, label %115
i32 0, label %133
]
109: ; preds = %103
switch i32 %4, label %143 [
i32 2, label %115
i32 0, label %133
]
110: ; preds = %103
switch i32 %4, label %143 [
i32 3, label %115
i32 0, label %133
]
111: ; preds = %103
%112 = load i32, i32* @stderr
%113 = call i32 @fprintf(i32 %112, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0))
%114 = call i32 @exit(i32 1)
unreachable
115: ; preds = %110, %109, %108, %106, %101
%116 = phi i16 [ %51, %101 ], [ %104, %106 ], [ %104, %108 ], [ %104, %109 ], [ %104, %110 ]
%117 = phi i32 [ %49, %101 ], [ %107, %106 ], [ %4, %108 ], [ 1, %109 ], [ 1, %110 ]
%118 = add nsw i32 %50, 1
br label %125
119: ; preds = %47
%120 = icmp ne i64 %48, 928
%121 = and i1 %21, %120
%122 = and i16 %51, -241
%123 = icmp eq i16 %122, 768
%124 = select i1 %121, i1 %123, i1 false
br i1 %124, label %143, label %125
125: ; preds = %87, %115, %92, %119
%126 = phi i32 [ %49, %119 ], [ %49, %92 ], [ %49, %87 ], [ %117, %115 ]
%127 = phi i32 [ %50, %119 ], [ 0, %92 ], [ %50, %87 ], [ %118, %115 ]
%128 = phi i16 [ %51, %119 ], [ %96, %92 ], [ %51, %87 ], [ %116, %115 ]
%129 = add nuw nsw i64 %48, 1
%130 = icmp eq i64 %129, %25
br i1 %130, label %131, label %47
131: ; preds = %125, %45
%132 = phi i32 [ 0, %45 ], [ %126, %125 ]
br i1 %22, label %133, label %143
133: ; preds = %110, %109, %108, %131
%134 = phi i32 [ %132, %131 ], [ %49, %108 ], [ %49, %109 ], [ %49, %110 ]
%135 = load i16, i16* %23
%136 = sitofp i16 %135 to double
%137 = load i16, i16* %24
%138 = and i16 %137, 32767
%139 = uitofp i16 %138 to double
%140 = fmul double %139, 0x3F10000000000000
%141 = call double @llvm.fmuladd.f64(double %136, double 2.000000e+00, double %140)
%142 = fptrunc double %141 to float
store float %142, float* %3
br label %143
143: ; preds = %110, %109, %108, %119, %133, %131
%144 = phi i32 [ %134, %133 ], [ %132, %131 ], [ %49, %119 ], [ %49, %108 ], [ %49, %109 ], [ %49, %110 ]
%145 = icmp eq i32 %144, 0
br i1 %145, label %26, label %150
146: ; preds = %29, %30
%147 = phi i8* [ getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), %30 ], [ getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), %29 ]
%148 = load i32, i32* @stderr
%149 = call i32 @fprintf(i32 %148, i8* %147)
br label %150
150: ; preds = %143, %146, %29
%151 = phi i32 [ -1, %29 ], [ -1, %146 ], [ 0, %143 ]
ret i32 %151
}