#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 scalar_t__ int16_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
double Angle(double, double, double, double);
double CompassAndClino(scalar_t__, scalar_t__, scalar_t__, scalar_t__,
                       scalar_t__, scalar_t__, double *, double *);
double M_PI;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ print_usage();
int /*<<< orphan*/ printf(char *, double);
int /*<<< orphan*/ sscanf(char *, char *, unsigned int *, unsigned int *,
                          unsigned int *, unsigned int *, unsigned int *,
                          unsigned int *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ *stdout;
scalar_t__ strlen(char *);
int main(int argc, char **argv) {
  FILE *fp;
  int print_compass_clino = 0;
  int ac = 1;
  int nr = 0;
  double angle = 0.0;
  FILE *fpout = stdout;
  while (ac < argc && argv[ac][0] == '-') {
    if (argv[ac][1] == 'v') {
      print_compass_clino = 1;
    } else if (argv[ac][1] == 'h') {
      print_usage();
    } else {
      print_usage();
      return 0;
    }
    ++ac;
  }
  if (argc < ac + 1) {
    print_usage();
    return 0;
  }
  if (argv[ac + 1] && strlen(argv[ac + 1]) > 0) {
    fp = fopen(argv[ac + 1], "w");
    if (fp != NULL)
      fpout = fp;
  }
  fp = fopen(argv[ac], "r");
  if (fp == NULL) {
    fprintf(stderr, "ERROR: cannot open input file \"%s\"\n", argv[ac]);
    return 0;
  }
  {
    unsigned int gx, gy, gz, mx, my, mz;
    int guess = 1;
    int cnt = 0;
    double compass1 = 0.0, clino1 = 0.0, compass2 = 0.0, clino2 = 0.0;
    char line[256];
    while (fgets(line, 256, fp)) {
      double a;
      int16_t gxs, gys, gzs, mxs, mys, mzs;
      sscanf(line, "%x %x %x %x %x %x", &gx, &gy, &gz, &mx, &my, &mz);
      gxs = (int16_t)(gx & 0xffff);
      gys = (int16_t)(gy & 0xffff);
      gzs = (int16_t)(gz & 0xffff);
      mxs = (int16_t)(mx & 0xffff);
      mys = (int16_t)(my & 0xffff);
      mzs = (int16_t)(mz & 0xffff);
      a = CompassAndClino(gxs, gys, gzs, mxs, mys, mzs, &compass1, &clino1);
      angle += a;
      ++nr;
      if (cnt == 0) {
        compass2 = compass1;
        clino2 = clino1;
      } else {
        if (Angle(compass1, clino1, compass2, clino2) > 20.0) {
          compass2 = compass1;
          clino2 = clino1;
          ++guess;
        }
      }
      ++cnt;
      fprintf(fpout, "0x%04x 0x%04x 0x%04x 0x%04x 0x%04x 0x%04x %2d 0", gx, gy,
              gz, mx, my, mz, guess);
      if (print_compass_clino) {
        fprintf(fpout, " %7.1f %7.1f %.2f\n", compass1 * 180.0 / M_PI,
                clino1 * 180.0 / M_PI, a * 180.0 / M_PI);
      } else {
        fprintf(fpout, "\n");
      }
    }
  }
  fclose(fp);
  if (fpout != stdout) {
    fclose(fpout);
  }
  if (print_compass_clino) {
    printf("Average G-M angle: %.2f \n", angle / nr * 180.0 / M_PI);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1e0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x1,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    0x2df3(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x38(%rbp)
mov    -0x20(%rbp),%ecx
xor    %eax,%eax
cmp    -0x8(%rbp),%ecx
mov    %al,-0x1b9(%rbp)
jge    1213 <main+0x73>
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movsbl (%rax),%eax
cmp    $0x2d,%eax
sete   %al
mov    %al,-0x1b9(%rbp)
mov    -0x1b9(%rbp),%al
test   $0x1,%al
jne    1226 <main+0x86>
jmp    1296 <main+0xf6>
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movsbl 0x1(%rax),%eax
cmp    $0x76,%eax
jne    124b <main+0xab>
movl   $0x1,-0x1c(%rbp)
jmp    1288 <main+0xe8>
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movsbl 0x1(%rax),%eax
cmp    $0x68,%eax
jne    1270 <main+0xd0>
mov    $0x0,%al
call   10b0 <print_usage@plt>
jmp    1283 <main+0xe3>
mov    $0x0,%al
call   10b0 <print_usage@plt>
movl   $0x0,-0x4(%rbp)
jmp    1668 <main+0x4c8>
jmp    1288 <main+0xe8>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    11e4 <main+0x44>
mov    -0x8(%rbp),%eax
mov    -0x20(%rbp),%ecx
add    $0x1,%ecx
cmp    %ecx,%eax
jge    12ba <main+0x11a>
mov    $0x0,%al
call   10b0 <print_usage@plt>
movl   $0x0,-0x4(%rbp)
jmp    1668 <main+0x4c8>
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
cmpq   $0x0,(%rax,%rcx,8)
je     132b <main+0x18b>
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdi
call   1040 <strlen@plt>
cmp    $0x0,%rax
jle    132b <main+0x18b>
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xd06(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1326 <main+0x186>
mov    -0x18(%rbp),%rax
mov    %rax,-0x38(%rbp)
jmp    132b <main+0x18b>
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xcd4(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1382 <main+0x1e2>
mov    0x2c7f(%rip),%rax
movslq (%rax),%rdi
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xca5(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1668 <main+0x4c8>
movl   $0x1,-0x54(%rbp)
movl   $0x0,-0x58(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x60(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x68(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x70(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x78(%rbp)
lea    -0x180(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x100,%esi
call   1060 <fgets@plt>
cmp    $0x0,%rax
je     1600 <main+0x460>
lea    -0x180(%rbp),%rdi
lea    0xc5b(%rip),%rsi
lea    -0x3c(%rbp),%rdx
lea    -0x40(%rbp),%rcx
lea    -0x44(%rbp),%r8
lea    -0x48(%rbp),%r9
lea    -0x4c(%rbp),%r10
lea    -0x50(%rbp),%rax
mov    %r10,(%rsp)
mov    %rax,0x8(%rsp)
call   1080 <sscanf@plt>
mov    -0x3c(%rbp),%eax
and    $0xffff,%eax
mov    %eax,%eax
mov    %rax,-0x190(%rbp)
mov    -0x40(%rbp),%eax
and    $0xffff,%eax
mov    %eax,%eax
mov    %rax,-0x198(%rbp)
mov    -0x44(%rbp),%eax
and    $0xffff,%eax
mov    %eax,%eax
mov    %rax,-0x1a0(%rbp)
mov    -0x48(%rbp),%eax
and    $0xffff,%eax
mov    %eax,%eax
mov    %rax,-0x1a8(%rbp)
mov    -0x4c(%rbp),%eax
and    $0xffff,%eax
mov    %eax,%eax
mov    %rax,-0x1b0(%rbp)
mov    -0x50(%rbp),%eax
and    $0xffff,%eax
mov    %eax,%eax
mov    %rax,-0x1b8(%rbp)
mov    -0x190(%rbp),%rdi
mov    -0x198(%rbp),%rsi
mov    -0x1a0(%rbp),%rdx
mov    -0x1a8(%rbp),%rcx
mov    -0x1b0(%rbp),%r8
mov    -0x1b8(%rbp),%r9
lea    -0x60(%rbp),%r10
lea    -0x68(%rbp),%rax
mov    %r10,(%rsp)
mov    %rax,0x8(%rsp)
call   1090 <CompassAndClino@plt>
movsd  %xmm0,-0x188(%rbp)
ff
movsd  -0x188(%rbp),%xmm0
ff
addsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x58(%rbp)
jne    14ef <main+0x34f>
movsd  -0x60(%rbp),%xmm0
movsd  %xmm0,-0x70(%rbp)
movsd  -0x68(%rbp),%xmm0
movsd  %xmm0,-0x78(%rbp)
jmp    153c <main+0x39c>
movsd  -0x60(%rbp),%xmm0
movsd  -0x68(%rbp),%xmm1
movsd  -0x70(%rbp),%xmm2
movsd  -0x78(%rbp),%xmm3
call   10c0 <Angle@plt>
movsd  0xaf8(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    1537 <main+0x397>
movsd  -0x60(%rbp),%xmm0
movsd  %xmm0,-0x70(%rbp)
movsd  -0x68(%rbp),%xmm0
movsd  %xmm0,-0x78(%rbp)
mov    -0x54(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x54(%rbp)
jmp    153c <main+0x39c>
mov    -0x58(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x58(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x3c(%rbp),%edx
mov    -0x40(%rbp),%ecx
mov    -0x44(%rbp),%r8d
mov    -0x48(%rbp),%r9d
mov    -0x4c(%rbp),%r11d
mov    -0x50(%rbp),%r10d
mov    -0x54(%rbp),%eax
lea    0xae1(%rip),%rsi
mov    %r11d,(%rsp)
mov    %r10d,0x8(%rsp)
mov    %eax,0x10(%rsp)
mov    $0x0,%al
call   1070 <fprintf@plt>
cmpl   $0x0,-0x1c(%rbp)
je     15e9 <main+0x449>
mov    -0x38(%rbp),%rdi
movsd  0xa6d(%rip),%xmm0
mulsd  -0x60(%rbp),%xmm0
mov    0x2a49(%rip),%rax
divsd  (%rax),%xmm0
movsd  0xa55(%rip),%xmm1
mulsd  -0x68(%rbp),%xmm1
mov    0x2a31(%rip),%rax
divsd  (%rax),%xmm1
movsd  0xa3d(%rip),%xmm2
mulsd  -0x188(%rbp),%xmm2
ff
mov    0x2a16(%rip),%rax
divsd  (%rax),%xmm2
lea    0xa9d(%rip),%rsi
mov    $0x3,%al
call   1070 <fprintf@plt>
jmp    15fb <main+0x45b>
mov    -0x38(%rbp),%rdi
lea    0xab1(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
jmp    13b0 <main+0x210>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x38(%rbp),%rax
mov    0x29bc(%rip),%rcx
cmp    (%rcx),%rax
je     1626 <main+0x486>
mov    -0x38(%rbp),%rdi
call   1030 <fclose@plt>
cmpl   $0x0,-0x1c(%rbp)
je     1661 <main+0x4c1>
movsd  -0x30(%rbp),%xmm0
cvtsi2sdl -0x24(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  0x9ba(%rip),%xmm1
mulsd  %xmm1,%xmm0
mov    0x2997(%rip),%rax
divsd  (%rax),%xmm0
lea    0xa31(%rip),%rdi
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1e0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x158,%rsp
cmp    $0x2,%edi
jl     1215 <main+0x65>
mov    %rsi,%r13
mov    0x2e00(%rip),%rax
mov    (%rax),%r12
mov    %edi,%ebp
mov    $0x1,%ebx
xor    %r15d,%r15d
jmp    11ec <main+0x3c>
nop
add    $0x1,%rbx
mov    %eax,%r15d
cmp    %rbx,%rbp
je     1215 <main+0x65>
mov    0x0(%r13,%rbx,8),%rax
cmpb   $0x2d,(%rax)
jne    1230 <main+0x80>
movzbl 0x1(%rax),%ecx
mov    $0x1,%eax
cmp    $0x76,%cl
je     11e0 <main+0x30>
cmp    $0x68,%cl
jne    1215 <main+0x65>
xor    %eax,%eax
call   10c0 <print_usage@plt>
mov    %r15d,%eax
jmp    11e0 <main+0x30>
xor    %eax,%eax
call   10c0 <print_usage@plt>
xor    %eax,%eax
add    $0x158,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x8(%r13,%rbx,8),%r14
test   %r14,%r14
je     125d <main+0xad>
mov    %r14,%rdi
call   1040 <strlen@plt>
test   %rax,%rax
jle    125d <main+0xad>
lea    0xdc2(%rip),%rsi
mov    %r14,%rdi
call   10b0 <fopen@plt>
test   %rax,%rax
cmovne %rax,%r12
mov    0x2d6c(%rip),%r14
mov    0x0(%r13,%rbx,8),%rdi
lea    0xda2(%rip),%rsi
call   10b0 <fopen@plt>
test   %rax,%rax
je     14a1 <main+0x2f1>
mov    %rax,%rbp
movq   $0x0,0x30(%rsp)
movq   $0x0,0x28(%rsp)
lea    0x50(%rsp),%rdi
mov    $0x100,%esi
mov    %rax,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
je     14c3 <main+0x313>
mov    %rbp,0x48(%rsp)
mov    $0x1,%r13d
xorps  %xmm0,%xmm0
movsd  %xmm0,0x20(%rsp)
lea    0x50(%rsp),%rbx
xor    %r14d,%r14d
xorps  %xmm0,%xmm0
movsd  %xmm0,0x38(%rsp)
xorps  %xmm0,%xmm0
movsd  %xmm0,0x40(%rsp)
jmp    1322 <main+0x172>
xchg   %ax,%ax
mov    $0xa,%edi
mov    %r12,%rsi
call   1060 <fputc@plt>
lea    0x50(%rsp),%rbx
movsd  (%rsp),%xmm1
movsd  0x20(%rsp),%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,0x20(%rsp)
mov    %rbx,%rdi
mov    $0x100,%esi
mov    0x48(%rsp),%rdx
call   1070 <fgets@plt>
test   %rax,%rax
je     1483 <main+0x2d3>
mov    %rbx,%rdi
lea    0xd0c(%rip),%rsi
lea    0x1c(%rsp),%rdx
lea    0x18(%rsp),%rcx
lea    0x14(%rsp),%r8
lea    0x10(%rsp),%r9
lea    0x8(%rsp),%rax
push   %rax
lea    0x14(%rsp),%rax
push   %rax
call   1090 <sscanf@plt>
add    $0x10,%rsp
movzwl 0x1c(%rsp),%edi
movzwl 0x18(%rsp),%esi
movzwl 0x14(%rsp),%edx
movzwl 0x10(%rsp),%ecx
movzwl 0xc(%rsp),%r8d
movzwl 0x8(%rsp),%r9d
lea    0x28(%rsp),%rax
push   %rax
lea    0x38(%rsp),%rax
push   %rax
call   10a0 <CompassAndClino@plt>
add    $0x10,%rsp
movsd  %xmm0,(%rsp)
movsd  0x30(%rsp),%xmm0
movsd  0x28(%rsp),%xmm1
sub    $0x1,%r14d
jae    13b0 <main+0x200>
movsd  %xmm0,0x40(%rsp)
movsd  %xmm1,0x38(%rsp)
jmp    13e7 <main+0x237>
nop
movsd  0x40(%rsp),%xmm2
movsd  0x38(%rsp),%xmm3
call   10d0 <Angle@plt>
ucomisd 0xc37(%rip),%xmm0
jbe    13e7 <main+0x237>
movsd  0x30(%rsp),%xmm0
movsd  %xmm0,0x40(%rsp)
movsd  0x28(%rsp),%xmm0
movsd  %xmm0,0x38(%rsp)
add    $0x1,%r13d
mov    0x1c(%rsp),%edx
mov    0x18(%rsp),%ecx
mov    0x14(%rsp),%r8d
mov    0x10(%rsp),%r9d
mov    0xc(%rsp),%ebx
mov    0x8(%rsp),%ebp
sub    $0x8,%rsp
mov    %r12,%rdi
lea    0xc3b(%rip),%rsi
xor    %eax,%eax
push   %r13
push   %rbp
push   %rbx
call   1080 <fprintf@plt>
add    $0x20,%rsp
test   %r15d,%r15d
je     12e0 <main+0x130>
movsd  0x30(%rsp),%xmm0
movsd  0xbd3(%rip),%xmm4
mulsd  %xmm4,%xmm0
mov    0x2ba8(%rip),%rax
movsd  (%rax),%xmm3
divsd  %xmm3,%xmm0
movsd  0x28(%rsp),%xmm1
mulsd  %xmm4,%xmm1
divsd  %xmm3,%xmm1
movsd  (%rsp),%xmm2
mulsd  %xmm4,%xmm2
divsd  %xmm3,%xmm2
mov    %r12,%rdi
lea    0xc0d(%rip),%rsi
mov    $0x3,%al
call   1080 <fprintf@plt>
movsd  (%rsp),%xmm1
lea    0x50(%rsp),%rbx
jmp    12f7 <main+0x147>
neg    %r14d
xorps  %xmm0,%xmm0
cvtsi2sd %r14d,%xmm0
movsd  %xmm0,(%rsp)
mov    0x2b36(%rip),%r14
mov    0x48(%rsp),%rbp
jmp    14d6 <main+0x326>
mov    0x2b30(%rip),%rax
movslq (%rax),%rdi
mov    0x0(%r13,%rbx,8),%rdx
lea    0xb5d(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
jmp    121c <main+0x6c>
xorpd  %xmm0,%xmm0
movsd  %xmm0,0x20(%rsp)
xorpd  %xmm0,%xmm0
movsd  %xmm0,(%rsp)
mov    %rbp,%rdi
call   1030 <fclose@plt>
cmp    (%r14),%r12
je     14eb <main+0x33b>
mov    %r12,%rdi
call   1030 <fclose@plt>
test   %r15d,%r15d
je     121c <main+0x6c>
movsd  0x20(%rsp),%xmm0
divsd  (%rsp),%xmm0
mulsd  0xb01(%rip),%xmm0
mov    0x2ada(%rip),%rax
divsd  (%rax),%xmm0
lea    0xb74(%rip),%rdi
call   1050 <printf@plt>
jmp    121c <main+0x6c>

LLVM IR (-O0):
@stdout = global i32* null
@.str = [2 x i8] c"w\00"
@.str.1 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.2 = [36 x i8] c"ERROR: cannot open input file \22%s\22\0A\00"
@.str.3 = [18 x i8] c"%x %x %x %x %x %x\00"
@.str.4 = [48 x i8] c"0x%04x 0x%04x 0x%04x 0x%04x 0x%04x 0x%04x %2d 0\00"
@.str.5 = [19 x i8] c" %7.1f %7.1f %.2f\0A\00"
@M_PI = global double 0.000000e+00
@.str.6 = [2 x i8] c"\0A\00"
@.str.7 = [26 x i8] c"Average G-M angle: %.2f \0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca double
%11 = alloca i32*
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32
%19 = alloca i32
%20 = alloca double
%21 = alloca double
%22 = alloca double
%23 = alloca double
%24 = alloca [256 x i8]
%25 = alloca double
%26 = alloca i64
%27 = alloca i64
%28 = alloca i64
%29 = alloca i64
%30 = alloca i64
%31 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %7
store i32 1, i32* %8
store i32 0, i32* %9
store double 0.000000e+00, double* %10
%32 = load i32*, i32** @stdout
store i32* %32, i32** %11
br label %33
33: ; preds = %75, %2
%34 = load i32, i32* %8
%35 = load i32, i32* %4
%36 = icmp slt i32 %34, %35
br i1 %36, label %37, label %47
37: ; preds = %33
%38 = load i8**, i8*** %5
%39 = load i32, i32* %8
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i8*, i8** %38, i64 %40
%42 = load i8*, i8** %41
%43 = getelementptr inbounds i8, i8* %42, i64 0
%44 = load i8, i8* %43
%45 = sext i8 %44 to i32
%46 = icmp eq i32 %45, 45
br label %47
47: ; preds = %37, %33
%48 = phi i1 [ false, %33 ], [ %46, %37 ]
br i1 %48, label %49, label %78
49: ; preds = %47
%50 = load i8**, i8*** %5
%51 = load i32, i32* %8
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds i8*, i8** %50, i64 %52
%54 = load i8*, i8** %53
%55 = getelementptr inbounds i8, i8* %54, i64 1
%56 = load i8, i8* %55
%57 = sext i8 %56 to i32
%58 = icmp eq i32 %57, 118
br i1 %58, label %59, label %60
59: ; preds = %49
store i32 1, i32* %7
br label %75
60: ; preds = %49
%61 = load i8**, i8*** %5
%62 = load i32, i32* %8
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds i8*, i8** %61, i64 %63
%65 = load i8*, i8** %64
%66 = getelementptr inbounds i8, i8* %65, i64 1
%67 = load i8, i8* %66
%68 = sext i8 %67 to i32
%69 = icmp eq i32 %68, 104
br i1 %69, label %70, label %72
70: ; preds = %60
%71 = call i32 (...) @print_usage()
br label %74
72: ; preds = %60
%73 = call i32 (...) @print_usage()
store i32 0, i32* %3
br label %246
74: ; preds = %70
br label %75
75: ; preds = %74, %59
%76 = load i32, i32* %8
%77 = add nsw i32 %76, 1
store i32 %77, i32* %8
br label %33
78: ; preds = %47
%79 = load i32, i32* %4
%80 = load i32, i32* %8
%81 = add nsw i32 %80, 1
%82 = icmp slt i32 %79, %81
br i1 %82, label %83, label %85
83: ; preds = %78
%84 = call i32 (...) @print_usage()
store i32 0, i32* %3
br label %246
85: ; preds = %78
%86 = load i8**, i8*** %5
%87 = load i32, i32* %8
%88 = add nsw i32 %87, 1
%89 = sext i32 %88 to i64
%90 = getelementptr inbounds i8*, i8** %86, i64 %89
%91 = load i8*, i8** %90
%92 = icmp ne i8* %91, null
br i1 %92, label %93, label %115
93: ; preds = %85
%94 = load i8**, i8*** %5
%95 = load i32, i32* %8
%96 = add nsw i32 %95, 1
%97 = sext i32 %96 to i64
%98 = getelementptr inbounds i8*, i8** %94, i64 %97
%99 = load i8*, i8** %98
%100 = call i64 @strlen(i8* %99)
%101 = icmp sgt i64 %100, 0
br i1 %101, label %102, label %115
102: ; preds = %93
%103 = load i8**, i8*** %5
%104 = load i32, i32* %8
%105 = add nsw i32 %104, 1
%106 = sext i32 %105 to i64
%107 = getelementptr inbounds i8*, i8** %103, i64 %106
%108 = load i8*, i8** %107
%109 = call i32* @fopen(i8* %108, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %109, i32** %6
%110 = load i32*, i32** %6
%111 = icmp ne i32* %110, null
br i1 %111, label %112, label %114
112: ; preds = %102
%113 = load i32*, i32** %6
store i32* %113, i32** %11
br label %114
114: ; preds = %112, %102
br label %115
115: ; preds = %114, %93, %85
%116 = load i8**, i8*** %5
%117 = load i32, i32* %8
%118 = sext i32 %117 to i64
%119 = getelementptr inbounds i8*, i8** %116, i64 %118
%120 = load i8*, i8** %119
%121 = call i32* @fopen(i8* %120, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %121, i32** %6
%122 = load i32*, i32** %6
%123 = icmp eq i32* %122, null
br i1 %123, label %124, label %134
124: ; preds = %115
%125 = load i32, i32* @stderr
%126 = sext i32 %125 to i64
%127 = inttoptr i64 %126 to i32*
%128 = load i8**, i8*** %5
%129 = load i32, i32* %8
%130 = sext i32 %129 to i64
%131 = getelementptr inbounds i8*, i8** %128, i64 %130
%132 = load i8*, i8** %131
%133 = call i32 (i32*, i8*, ...) @fprintf(i32* %127, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0), i8* %132)
store i32 0, i32* %3
br label %246
134: ; preds = %115
store i32 1, i32* %18
store i32 0, i32* %19
store double 0.000000e+00, double* %20
store double 0.000000e+00, double* %21
store double 0.000000e+00, double* %22
store double 0.000000e+00, double* %23
br label %135
135: ; preds = %223, %134
%136 = getelementptr inbounds [256 x i8], [256 x i8]* %24, i64 0, i64 0
%137 = load i32*, i32** %6
%138 = call i64 @fgets(i8* %136, i32 256, i32* %137)
%139 = icmp ne i64 %138, 0
br i1 %139, label %140, label %224
140: ; preds = %135
%141 = getelementptr inbounds [256 x i8], [256 x i8]* %24, i64 0, i64 0
%142 = call i32 @sscanf(i8* %141, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i32* %12, i32* %13, i32* %14, i32* %15, i32* %16, i32* %17)
%143 = load i32, i32* %12
%144 = and i32 %143, 65535
%145 = zext i32 %144 to i64
store i64 %145, i64* %26
%146 = load i32, i32* %13
%147 = and i32 %146, 65535
%148 = zext i32 %147 to i64
store i64 %148, i64* %27
%149 = load i32, i32* %14
%150 = and i32 %149, 65535
%151 = zext i32 %150 to i64
store i64 %151, i64* %28
%152 = load i32, i32* %15
%153 = and i32 %152, 65535
%154 = zext i32 %153 to i64
store i64 %154, i64* %29
%155 = load i32, i32* %16
%156 = and i32 %155, 65535
%157 = zext i32 %156 to i64
store i64 %157, i64* %30
%158 = load i32, i32* %17
%159 = and i32 %158, 65535
%160 = zext i32 %159 to i64
store i64 %160, i64* %31
%161 = load i64, i64* %26
%162 = load i64, i64* %27
%163 = load i64, i64* %28
%164 = load i64, i64* %29
%165 = load i64, i64* %30
%166 = load i64, i64* %31
%167 = call double @CompassAndClino(i64 %161, i64 %162, i64 %163, i64 %164, i64 %165, i64 %166, double* %20, double* %21)
store double %167, double* %25
%168 = load double, double* %25
%169 = load double, double* %10
%170 = fadd double %169, %168
store double %170, double* %10
%171 = load i32, i32* %9
%172 = add nsw i32 %171, 1
store i32 %172, i32* %9
%173 = load i32, i32* %19
%174 = icmp eq i32 %173, 0
br i1 %174, label %175, label %178
175: ; preds = %140
%176 = load double, double* %20
store double %176, double* %22
%177 = load double, double* %21
store double %177, double* %23
br label %191
178: ; preds = %140
%179 = load double, double* %20
%180 = load double, double* %21
%181 = load double, double* %22
%182 = load double, double* %23
%183 = call double @Angle(double %179, double %180, double %181, double %182)
%184 = fcmp ogt double %183, 2.000000e+01
br i1 %184, label %185, label %190
185: ; preds = %178
%186 = load double, double* %20
store double %186, double* %22
%187 = load double, double* %21
store double %187, double* %23
%188 = load i32, i32* %18
%189 = add nsw i32 %188, 1
store i32 %189, i32* %18
br label %190
190: ; preds = %185, %178
br label %191
191: ; preds = %190, %175
%192 = load i32, i32* %19
%193 = add nsw i32 %192, 1
store i32 %193, i32* %19
%194 = load i32*, i32** %11
%195 = load i32, i32* %12
%196 = load i32, i32* %13
%197 = load i32, i32* %14
%198 = load i32, i32* %15
%199 = load i32, i32* %16
%200 = load i32, i32* %17
%201 = load i32, i32* %18
%202 = call i32 (i32*, i8*, ...) @fprintf(i32* %194, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.4, i64 0, i64 0), i32 %195, i32 %196, i32 %197, i32 %198, i32 %199, i32 %200, i32 %201)
%203 = load i32, i32* %7
%204 = icmp ne i32 %203, 0
br i1 %204, label %205, label %220
205: ; preds = %191
%206 = load i32*, i32** %11
%207 = load double, double* %20
%208 = fmul double %207, 1.800000e+02
%209 = load double, double* @M_PI
%210 = fdiv double %208, %209
%211 = load double, double* %21
%212 = fmul double %211, 1.800000e+02
%213 = load double, double* @M_PI
%214 = fdiv double %212, %213
%215 = load double, double* %25
%216 = fmul double %215, 1.800000e+02
%217 = load double, double* @M_PI
%218 = fdiv double %216, %217
%219 = call i32 (i32*, i8*, ...) @fprintf(i32* %206, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0), double %210, double %214, double %218)
br label %223
220: ; preds = %191
%221 = load i32*, i32** %11
%222 = call i32 (i32*, i8*, ...) @fprintf(i32* %221, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
br label %223
223: ; preds = %220, %205
br label %135
224: ; preds = %135
%225 = load i32*, i32** %6
%226 = call i32 @fclose(i32* %225)
%227 = load i32*, i32** %11
%228 = load i32*, i32** @stdout
%229 = icmp ne i32* %227, %228
br i1 %229, label %230, label %233
230: ; preds = %224
%231 = load i32*, i32** %11
%232 = call i32 @fclose(i32* %231)
br label %233
233: ; preds = %230, %224
%234 = load i32, i32* %7
%235 = icmp ne i32 %234, 0
br i1 %235, label %236, label %245
236: ; preds = %233
%237 = load double, double* %10
%238 = load i32, i32* %9
%239 = sitofp i32 %238 to double
%240 = fdiv double %237, %239
%241 = fmul double %240, 1.800000e+02
%242 = load double, double* @M_PI
%243 = fdiv double %241, %242
%244 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.7, i64 0, i64 0), double %243)
br label %245
245: ; preds = %236, %233
store i32 0, i32* %3
br label %246
246: ; preds = %245, %124, %83, %72
%247 = load i32, i32* %3
ret i32 %247
}

LLVM IR (-O2):
@stdout = global i32* null
@.str = [2 x i8] c"w\00"
@.str.1 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.2 = [36 x i8] c"ERROR: cannot open input file \22%s\22\0A\00"
@.str.3 = [18 x i8] c"%x %x %x %x %x %x\00"
@.str.4 = [48 x i8] c"0x%04x 0x%04x 0x%04x 0x%04x 0x%04x 0x%04x %2d 0\00"
@.str.5 = [19 x i8] c" %7.1f %7.1f %.2f\0A\00"
@M_PI = global double 0.000000e+00
@.str.7 = [26 x i8] c"Average G-M angle: %.2f \0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca double
%10 = alloca double
%11 = alloca [256 x i8]
%12 = load i32*, i32** @stdout
%13 = icmp sgt i32 %0, 1
br i1 %13, label %14, label %34
14: ; preds = %2
%15 = zext i32 %0 to i64
br label %16
16: ; preds = %14, %30
%17 = phi i64 [ 1, %14 ], [ %32, %30 ]
%18 = phi i32 [ 0, %14 ], [ %31, %30 ]
%19 = getelementptr inbounds i8*, i8** %1, i64 %17
%20 = load i8*, i8** %19
%21 = load i8, i8* %20
%22 = icmp eq i8 %21, 45
br i1 %22, label %23, label %36
23: ; preds = %16
%24 = getelementptr inbounds i8, i8* %20, i64 1
%25 = load i8, i8* %24
switch i8 %25, label %28 [
i8 118, label %30
i8 104, label %26
]
26: ; preds = %23
%27 = tail call i32 (...) @print_usage()
br label %30
28: ; preds = %23
%29 = tail call i32 (...) @print_usage()
br label %159
30: ; preds = %23, %26
%31 = phi i32 [ %18, %26 ], [ 1, %23 ]
%32 = add nuw nsw i64 %17, 1
%33 = icmp eq i64 %32, %15
br i1 %33, label %34, label %16
34: ; preds = %30, %2
%35 = tail call i32 (...) @print_usage()
br label %159
36: ; preds = %16
%37 = add nuw i64 %17, 1
%38 = and i64 %37, 4294967295
%39 = getelementptr inbounds i8*, i8** %1, i64 %38
%40 = load i8*, i8** %39
%41 = icmp eq i8* %40, null
br i1 %41, label %49, label %42
42: ; preds = %36
%43 = tail call i64 @strlen(i8* %40)
%44 = icmp sgt i64 %43, 0
br i1 %44, label %45, label %49
45: ; preds = %42
%46 = tail call i32* @fopen(i8* %40, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%47 = icmp eq i32* %46, null
%48 = select i1 %47, i32* %12, i32* %46
br label %49
49: ; preds = %45, %42, %36
%50 = phi i32* [ %12, %42 ], [ %12, %36 ], [ %48, %45 ]
%51 = and i64 %17, 4294967295
%52 = getelementptr inbounds i8*, i8** %1, i64 %51
%53 = load i8*, i8** %52
%54 = tail call i32* @fopen(i8* %53, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%55 = icmp eq i32* %54, null
br i1 %55, label %56, label %62
56: ; preds = %49
%57 = load i32, i32* @stderr
%58 = sext i32 %57 to i64
%59 = inttoptr i64 %58 to i32*
%60 = load i8*, i8** %52
%61 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %59, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0), i8* %60)
br label %159
62: ; preds = %49
%63 = bitcast i32* %3 to i8*
%64 = bitcast i32* %4 to i8*
%65 = bitcast i32* %5 to i8*
%66 = bitcast i32* %6 to i8*
%67 = bitcast i32* %7 to i8*
%68 = bitcast i32* %8 to i8*
%69 = bitcast double* %9 to i8*
store double 0.000000e+00, double* %9
%70 = bitcast double* %10 to i8*
store double 0.000000e+00, double* %10
%71 = getelementptr inbounds [256 x i8], [256 x i8]* %11, i64 0, i64 0
%72 = call i64 @fgets(i8* %71, i32 256, i32* %54)
%73 = icmp eq i64 %72, 0
br i1 %73, label %143, label %74
74: ; preds = %62
%75 = icmp eq i32 %18, 0
br label %76
76: ; preds = %74, %138
%77 = phi i32 [ 0, %74 ], [ %103, %138 ]
%78 = phi double [ 0.000000e+00, %74 ], [ %102, %138 ]
%79 = phi double [ 0.000000e+00, %74 ], [ %117, %138 ]
%80 = phi double [ 0.000000e+00, %74 ], [ %116, %138 ]
%81 = phi i32 [ 1, %74 ], [ %115, %138 ]
%82 = call i32 @sscanf(i8* %71, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i32* %3, i32* %4, i32* %5, i32* %6, i32* %7, i32* %8)
%83 = load i32, i32* %3
%84 = and i32 %83, 65535
%85 = zext i32 %84 to i64
%86 = load i32, i32* %4
%87 = and i32 %86, 65535
%88 = zext i32 %87 to i64
%89 = load i32, i32* %5
%90 = and i32 %89, 65535
%91 = zext i32 %90 to i64
%92 = load i32, i32* %6
%93 = and i32 %92, 65535
%94 = zext i32 %93 to i64
%95 = load i32, i32* %7
%96 = and i32 %95, 65535
%97 = zext i32 %96 to i64
%98 = load i32, i32* %8
%99 = and i32 %98, 65535
%100 = zext i32 %99 to i64
%101 = call double @CompassAndClino(i64 %85, i64 %88, i64 %91, i64 %94, i64 %97, i64 %100, double* %9, double* %10)
%102 = fadd double %78, %101
%103 = add nuw nsw i32 %77, 1
%104 = icmp eq i32 %77, 0
%105 = load double, double* %9
%106 = load double, double* %10
br i1 %104, label %114, label %107
107: ; preds = %76
%108 = call double @Angle(double %105, double %106, double %80, double %79)
%109 = fcmp ogt double %108, 2.000000e+01
br i1 %109, label %110, label %114
110: ; preds = %107
%111 = load double, double* %9
%112 = load double, double* %10
%113 = add nsw i32 %81, 1
br label %114
114: ; preds = %76, %107, %110
%115 = phi i32 [ %113, %110 ], [ %81, %107 ], [ %81, %76 ]
%116 = phi double [ %111, %110 ], [ %80, %107 ], [ %105, %76 ]
%117 = phi double [ %112, %110 ], [ %79, %107 ], [ %106, %76 ]
%118 = load i32, i32* %3
%119 = load i32, i32* %4
%120 = load i32, i32* %5
%121 = load i32, i32* %6
%122 = load i32, i32* %7
%123 = load i32, i32* %8
%124 = call i32 (i32*, i8*, ...) @fprintf(i32* %50, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.4, i64 0, i64 0), i32 %118, i32 %119, i32 %120, i32 %121, i32 %122, i32 %123, i32 %115)
br i1 %75, label %136, label %125
125: ; preds = %114
%126 = load double, double* %9
%127 = fmul double %126, 1.800000e+02
%128 = load double, double* @M_PI
%129 = fdiv double %127, %128
%130 = load double, double* %10
%131 = fmul double %130, 1.800000e+02
%132 = fdiv double %131, %128
%133 = fmul double %101, 1.800000e+02
%134 = fdiv double %133, %128
%135 = call i32 (i32*, i8*, ...) @fprintf(i32* %50, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0), double %129, double %132, double %134)
br label %138
136: ; preds = %114
%137 = call i32 @fputc(i32 10, i32* %50)
br label %138
138: ; preds = %136, %125
%139 = call i64 @fgets(i8* %71, i32 256, i32* %54)
%140 = icmp eq i64 %139, 0
br i1 %140, label %141, label %76
141: ; preds = %138
%142 = sitofp i32 %103 to double
br label %143
143: ; preds = %141, %62
%144 = phi double [ 0.000000e+00, %62 ], [ %102, %141 ]
%145 = phi double [ 0.000000e+00, %62 ], [ %142, %141 ]
%146 = call i32 @fclose(i32* %54)
%147 = load i32*, i32** @stdout
%148 = icmp eq i32* %50, %147
br i1 %148, label %151, label %149
149: ; preds = %143
%150 = call i32 @fclose(i32* %50)
br label %151
151: ; preds = %149, %143
%152 = icmp eq i32 %18, 0
br i1 %152, label %159, label %153
153: ; preds = %151
%154 = fdiv double %144, %145
%155 = fmul double %154, 1.800000e+02
%156 = load double, double* @M_PI
%157 = fdiv double %155, %156
%158 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.7, i64 0, i64 0), double %157)
br label %159
159: ; preds = %151, %153, %56, %34, %28
ret i32 0
}