#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 */

/* Variables and functions */
double M_PI;
int SHRT_MAX;
int /*<<< orphan*/ fwrite(short *, int, int, int /*<<< orphan*/);
double get_phase(double, double);
scalar_t__ getchar();
int /*<<< orphan*/ stdout;
int main() {
  double i1 = 0, i2, q1 = 0, q2;
  short s;
  for (;;) {
    i2 = ((unsigned char)getchar() - 127);
    q2 = ((unsigned char)getchar() - 127);
    double phi1 = get_phase(i1, q1);
    double phi2 = get_phase(i2, q2);
    double dphi = phi2 - phi1;
    if (dphi < -M_PI)
      dphi += 2 * M_PI;
    if (dphi > M_PI)
      dphi -= 2 * M_PI;
    s = ((SHRT_MAX - 1) / M_PI) * dphi;
    fwrite(&s, sizeof(short), 1, stdout);
    i1 = i2;
    q1 = q2;
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x10(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    $0x0,%al
call   1030 <getchar@plt>
movzbl %al,%eax
sub    $0x7f,%eax
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    $0x0,%al
call   1030 <getchar@plt>
movzbl %al,%eax
sub    $0x7f,%eax
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm1
call   1040 <get_phase@plt>
movsd  %xmm0,-0x38(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm1
call   1040 <get_phase@plt>
movsd  %xmm0,-0x40(%rbp)
movsd  -0x40(%rbp),%xmm0
subsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x48(%rbp),%xmm1
mov    0x2e2a(%rip),%rax
movsd  (%rax),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
ucomisd %xmm1,%xmm0
jbe    1200 <main+0xd0>
mov    0x2dfe(%rip),%rax
movsd  (%rax),%xmm0
movsd  -0x48(%rbp),%xmm1
addsd  %xmm0,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x48(%rbp),%xmm0
mov    0x2ddc(%rip),%rax
ucomisd (%rax),%xmm0
jbe    1233 <main+0x103>
mov    0x2dcb(%rip),%rax
movsd  (%rax),%xmm1
movsd  -0x48(%rbp),%xmm0
addsd  %xmm1,%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x48(%rbp)
mov    0x2d9e(%rip),%rax
mov    (%rax),%eax
add    $0xffffffff,%eax
cvtsi2sd %eax,%xmm0
mov    0x2d9e(%rip),%rax
movsd  (%rax),%xmm1
divsd  %xmm1,%xmm0
movsd  -0x48(%rbp),%xmm1
mulsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %ax,-0x2a(%rbp)
mov    0x2d66(%rip),%rax
mov    (%rax),%ecx
lea    -0x2a(%rbp),%rdi
mov    $0x2,%esi
mov    $0x1,%edx
call   1050 <fwrite@plt>
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
jmp    114f <main+0x1f>

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x28,%rsp
xorps  %xmm0,%xmm0
mov    0x2ea3(%rip),%r14
mov    0x2e8c(%rip),%r15
mov    0x2e7d(%rip),%r12
lea    0x6(%rsp),%rbx
xorps  %xmm1,%xmm1
nopl   0x0(%rax,%rax,1)
movsd  %xmm1,0x20(%rsp)
movsd  %xmm0,0x8(%rsp)
xor    %eax,%eax
call   1030 <getchar@plt>
movzbl %al,%eax
add    $0xffffff81,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movsd  %xmm0,0x18(%rsp)
xor    %eax,%eax
call   1030 <getchar@plt>
movzbl %al,%eax
add    $0xffffff81,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movsd  %xmm0,0x10(%rsp)
movsd  0x20(%rsp),%xmm0
movsd  0x8(%rsp),%xmm1
call   1040 <get_phase@plt>
movsd  %xmm0,0x8(%rsp)
movsd  0x18(%rsp),%xmm0
movsd  0x10(%rsp),%xmm1
call   1040 <get_phase@plt>
subsd  0x8(%rsp),%xmm0
movsd  (%r14),%xmm2
movapd %xmm2,%xmm1
movapd %xmm2,%xmm3
mov    (%r15),%eax
add    $0xffffffff,%eax
xorps  %xmm4,%xmm4
cvtsi2sd %eax,%xmm4
divsd  %xmm2,%xmm4
xorpd  0xe0c(%rip),%xmm2
addsd  %xmm1,%xmm1
movapd %xmm0,%xmm5
cmpltsd %xmm2,%xmm5
movapd %xmm1,%xmm2
addsd  %xmm0,%xmm2
andpd  %xmm5,%xmm2
andnpd %xmm0,%xmm5
orpd   %xmm2,%xmm5
cmpltsd %xmm5,%xmm3
movapd %xmm5,%xmm0
subsd  %xmm1,%xmm0
andpd  %xmm3,%xmm0
andnpd %xmm5,%xmm3
orpd   %xmm0,%xmm3
mulsd  %xmm3,%xmm4
cvttsd2si %xmm4,%eax
mov    %ax,0x6(%rsp)
mov    (%r12),%ecx
mov    %rbx,%rdi
mov    $0x2,%esi
mov    $0x1,%edx
call   1050 <fwrite@plt>
movsd  0x10(%rsp),%xmm0
movsd  0x18(%rsp),%xmm1
jmp    1160 <main+0x30>

LLVM IR (-O0):
@M_PI = global double 0.000000e+00
@SHRT_MAX = global i32 0
@stdout = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca double
%3 = alloca double
%4 = alloca double
%5 = alloca double
%6 = alloca i16
%7 = alloca double
%8 = alloca double
%9 = alloca double
store i32 0, i32* %1
store double 0.000000e+00, double* %2
store double 0.000000e+00, double* %4
br label %10
10: ; preds = %46, %0
%11 = call i64 (...) @getchar()
%12 = trunc i64 %11 to i8
%13 = zext i8 %12 to i32
%14 = sub nsw i32 %13, 127
%15 = sitofp i32 %14 to double
store double %15, double* %3
%16 = call i64 (...) @getchar()
%17 = trunc i64 %16 to i8
%18 = zext i8 %17 to i32
%19 = sub nsw i32 %18, 127
%20 = sitofp i32 %19 to double
store double %20, double* %5
%21 = load double, double* %2
%22 = load double, double* %4
%23 = call double @get_phase(double %21, double %22)
store double %23, double* %7
%24 = load double, double* %3
%25 = load double, double* %5
%26 = call double @get_phase(double %24, double %25)
store double %26, double* %8
%27 = load double, double* %8
%28 = load double, double* %7
%29 = fsub double %27, %28
store double %29, double* %9
%30 = load double, double* %9
%31 = load double, double* @M_PI
%32 = fneg double %31
%33 = fcmp olt double %30, %32
br i1 %33, label %34, label %38
34: ; preds = %10
%35 = load double, double* @M_PI
%36 = load double, double* %9
%37 = call double @llvm.fmuladd.f64(double 2.000000e+00, double %35, double %36)
store double %37, double* %9
br label %38
38: ; preds = %34, %10
%39 = load double, double* %9
%40 = load double, double* @M_PI
%41 = fcmp ogt double %39, %40
br i1 %41, label %42, label %46
42: ; preds = %38
%43 = load double, double* @M_PI
%44 = load double, double* %9
%45 = call double @llvm.fmuladd.f64(double -2.000000e+00, double %43, double %44)
store double %45, double* %9
br label %46
46: ; preds = %42, %38
%47 = load i32, i32* @SHRT_MAX
%48 = sub nsw i32 %47, 1
%49 = sitofp i32 %48 to double
%50 = load double, double* @M_PI
%51 = fdiv double %49, %50
%52 = load double, double* %9
%53 = fmul double %51, %52
%54 = fptosi double %53 to i16
store i16 %54, i16* %6
%55 = load i32, i32* @stdout
%56 = call i32 @fwrite(i16* %6, i32 2, i32 1, i32 %55)
%57 = load double, double* %3
store double %57, double* %2
%58 = load double, double* %5
store double %58, double* %4
br label %10
}

LLVM IR (-O2):
@M_PI = global double 0.000000e+00
@SHRT_MAX = global i32 0
@stdout = global i32 0
define i32 @main() {
%1 = alloca i16
%2 = bitcast i16* %1 to i8*
br label %3
3: ; preds = %3, %0
%4 = phi double [ 0.000000e+00, %0 ], [ %15, %3 ]
%5 = phi double [ 0.000000e+00, %0 ], [ %10, %3 ]
%6 = call i64 (...) @getchar()
%7 = trunc i64 %6 to i32
%8 = and i32 %7, 255
%9 = add nsw i32 %8, -127
%10 = sitofp i32 %9 to double
%11 = call i64 (...) @getchar()
%12 = trunc i64 %11 to i32
%13 = and i32 %12, 255
%14 = add nsw i32 %13, -127
%15 = sitofp i32 %14 to double
%16 = call double @get_phase(double %5, double %4)
%17 = call double @get_phase(double %10, double %15)
%18 = fsub double %17, %16
%19 = load double, double* @M_PI
%20 = fneg double %19
%21 = fcmp olt double %18, %20
%22 = call double @llvm.fmuladd.f64(double %19, double 2.000000e+00, double %18)
%23 = select i1 %21, double %22, double %18
%24 = fcmp ogt double %23, %19
%25 = call double @llvm.fmuladd.f64(double %19, double -2.000000e+00, double %23)
%26 = select i1 %24, double %25, double %23
%27 = load i32, i32* @SHRT_MAX
%28 = add nsw i32 %27, -1
%29 = sitofp i32 %28 to double
%30 = fdiv double %29, %19
%31 = fmul double %30, %26
%32 = fptosi double %31 to i16
store i16 %32, i16* %1
%33 = load i32, i32* @stdout
%34 = call i32 @fwrite(i16* %1, i32 2, i32 1, i32 %33)
br label %3
}