#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 */
scalar_t__ floor(double);
double s_high(double a) {
  double t = 0;
  double b = 0;
  double p = 1;
  int k;
  a -= floor(a);
  for (k = 0; k < 48; ++k) {
    b += a;
    p /= 2;
    if (b >= 1)
      b -= 1;
    if (b + a >= 1)
      t += p;
  }
  return t;
}


x86 assembly (clang, -O0):
<s_high>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x8(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x10(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  0xecb(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x8(%rbp),%xmm0
call   1030 <floor@plt>
cvtsi2sd %rax,%xmm1
movsd  -0x8(%rbp),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
movl   $0x0,-0x24(%rbp)
cmpl   $0x30,-0x24(%rbp)
jge    11f8 <s_high+0xe8>
movsd  -0x8(%rbp),%xmm0
addsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  0xe84(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  0xe66(%rip),%xmm1
ucomisd %xmm1,%xmm0
jb     11ba <s_high+0xaa>
movsd  -0x18(%rbp),%xmm0
movsd  0xe4f(%rip),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
addsd  -0x8(%rbp),%xmm0
movsd  0xe34(%rip),%xmm1
ucomisd %xmm1,%xmm0
jb     11e5 <s_high+0xd5>
movsd  -0x20(%rbp),%xmm0
addsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
jmp    11ea <s_high+0xda>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    115e <s_high+0x4e>
movsd  -0x10(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<s_high>:
push   %rax
movsd  %xmm0,(%rsp)
call   1030 <floor@plt>
movsd  (%rsp),%xmm2
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
subsd  %xmm0,%xmm2
xorpd  %xmm3,%xmm3
movsd  0xec8(%rip),%xmm1
mov    $0x30,%eax
movsd  0xec2(%rip),%xmm9
movsd  0xec1(%rip),%xmm8
movsd  0xec1(%rip),%xmm4
movapd %xmm1,%xmm6
xorpd  %xmm0,%xmm0
jmp    11c5 <s_high+0xb5>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mulsd  %xmm9,%xmm6
movapd %xmm1,%xmm5
cmpnlesd %xmm7,%xmm5
movapd %xmm5,%xmm7
andpd  %xmm4,%xmm7
andnpd %xmm6,%xmm5
orpd   %xmm7,%xmm5
movapd %xmm0,%xmm7
addsd  %xmm5,%xmm7
mulsd  %xmm9,%xmm6
movapd %xmm2,%xmm5
addsd  %xmm3,%xmm5
movapd %xmm1,%xmm0
cmpnlesd %xmm5,%xmm0
movapd %xmm0,%xmm5
andpd  %xmm4,%xmm5
andnpd %xmm6,%xmm0
orpd   %xmm5,%xmm0
addsd  %xmm7,%xmm0
add    $0xfffffffe,%eax
je     1207 <s_high+0xf7>
addsd  %xmm2,%xmm3
movapd %xmm3,%xmm5
addsd  %xmm8,%xmm5
movapd %xmm1,%xmm7
cmpnlesd %xmm3,%xmm7
andpd  %xmm7,%xmm3
andnpd %xmm5,%xmm7
orpd   %xmm3,%xmm7
addsd  %xmm2,%xmm7
ucomisd %xmm1,%xmm7
movapd %xmm7,%xmm3
jb     1170 <s_high+0x60>
movapd %xmm7,%xmm3
addsd  %xmm8,%xmm3
jmp    1170 <s_high+0x60>
pop    %rax
ret

LLVM IR (-O0):
define double @s_high(double %0) {
%2 = alloca double
%3 = alloca double
%4 = alloca double
%5 = alloca double
%6 = alloca i32
store double %0, double* %2
store double 0.000000e+00, double* %3
store double 0.000000e+00, double* %4
store double 1.000000e+00, double* %5
%7 = load double, double* %2
%8 = call i64 @floor(double %7)
%9 = sitofp i64 %8 to double
%10 = load double, double* %2
%11 = fsub double %10, %9
store double %11, double* %2
store i32 0, i32* %6
br label %12
12: ; preds = %36, %1
%13 = load i32, i32* %6
%14 = icmp slt i32 %13, 48
br i1 %14, label %15, label %39
15: ; preds = %12
%16 = load double, double* %2
%17 = load double, double* %4
%18 = fadd double %17, %16
store double %18, double* %4
%19 = load double, double* %5
%20 = fdiv double %19, 2.000000e+00
store double %20, double* %5
%21 = load double, double* %4
%22 = fcmp oge double %21, 1.000000e+00
br i1 %22, label %23, label %26
23: ; preds = %15
%24 = load double, double* %4
%25 = fsub double %24, 1.000000e+00
store double %25, double* %4
br label %26
26: ; preds = %23, %15
%27 = load double, double* %4
%28 = load double, double* %2
%29 = fadd double %27, %28
%30 = fcmp oge double %29, 1.000000e+00
br i1 %30, label %31, label %35
31: ; preds = %26
%32 = load double, double* %5
%33 = load double, double* %3
%34 = fadd double %33, %32
store double %34, double* %3
br label %35
35: ; preds = %31, %26
br label %36
36: ; preds = %35
%37 = load i32, i32* %6
%38 = add nsw i32 %37, 1
store i32 %38, i32* %6
br label %12
39: ; preds = %12
%40 = load double, double* %3
ret double %40
}

LLVM IR (-O2):
define double @s_high(double %0) {
%2 = tail call i64 @floor(double %0)
%3 = sitofp i64 %2 to double
%4 = fsub double %0, %3
br label %5
5: ; preds = %5, %1
%6 = phi i32 [ 0, %1 ], [ %28, %5 ]
%7 = phi double [ 1.000000e+00, %1 ], [ %20, %5 ]
%8 = phi double [ 0.000000e+00, %1 ], [ %23, %5 ]
%9 = phi double [ 0.000000e+00, %1 ], [ %27, %5 ]
%10 = fadd double %4, %8
%11 = fmul double %7, 5.000000e-01
%12 = fcmp ult double %10, 1.000000e+00
%13 = fadd double %10, -1.000000e+00
%14 = select i1 %12, double %10, double %13
%15 = fadd double %4, %14
%16 = fcmp ult double %15, 1.000000e+00
%17 = select i1 %16, double -0.000000e+00, double %11
%18 = fadd double %9, %17
%19 = fadd double %4, %14
%20 = fmul double %11, 5.000000e-01
%21 = fcmp ult double %19, 1.000000e+00
%22 = fadd double %19, -1.000000e+00
%23 = select i1 %21, double %19, double %22
%24 = fadd double %4, %23
%25 = fcmp ult double %24, 1.000000e+00
%26 = select i1 %25, double -0.000000e+00, double %20
%27 = fadd double %18, %26
%28 = add nuw nsw i32 %6, 2
%29 = icmp eq i32 %28, 48
br i1 %29, label %30, label %5
30: ; preds = %5
ret double %27
}