#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 */
int /*<<< orphan*/ printf(char *, int, double, char *);
int main() {
  double pid, s1, s2, s3, s4;
  double series(int m, int n);
  void ihex(double x, int m, char c[]);
  int id = 1000000;
  char chx[16];
  s1 = series(1, id);
  s2 = series(4, id);
  s3 = series(5, id);
  s4 = series(6, id);
  pid = 4. * s1 - 2. * s2 - s3 - s4;
  pid = pid - (int)pid + 1.;
  ihex(pid, 16, chx);
  printf(" position = %i\n fraction = %.15f \n hex digits =  %10.10s\n", id,
         pid, chx);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0xf4240,-0x34(%rbp)
mov    -0x34(%rbp),%esi
mov    $0x1,%edi
call   1030 <series@plt>
movsd  %xmm0,-0x18(%rbp)
mov    -0x34(%rbp),%esi
mov    $0x4,%edi
call   1030 <series@plt>
movsd  %xmm0,-0x20(%rbp)
mov    -0x34(%rbp),%esi
mov    $0x5,%edi
call   1030 <series@plt>
movsd  %xmm0,-0x28(%rbp)
mov    -0x34(%rbp),%esi
mov    $0x6,%edi
call   1030 <series@plt>
movsd  %xmm0,-0x30(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  0xe75(%rip),%xmm1
mulsd  -0x20(%rbp),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
movsd  0xe49(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
subsd  -0x28(%rbp),%xmm0
subsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
cvttsd2si -0x10(%rbp),%eax
cvtsi2sd %eax,%xmm1
subsd  %xmm1,%xmm0
movsd  0xe10(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
lea    -0x50(%rbp),%rsi
mov    $0x10,%edi
call   1050 <ihex@plt>
mov    -0x34(%rbp),%esi
movsd  -0x10(%rbp),%xmm0
lea    -0x50(%rbp),%rdx
lea    0xdf9(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x30,%rsp
mov    $0x1,%edi
mov    $0xf4240,%esi
call   1030 <series@plt>
movapd %xmm0,(%rsp)
mov    $0x4,%edi
mov    $0xf4240,%esi
call   1030 <series@plt>
movsd  %xmm0,0x18(%rsp)
mov    $0x5,%edi
mov    $0xf4240,%esi
call   1030 <series@plt>
movsd  %xmm0,0x10(%rsp)
mov    $0x6,%edi
mov    $0xf4240,%esi
call   1030 <series@plt>
movapd (%rsp),%xmm1
mulsd  0xe71(%rip),%xmm1
movsd  0x18(%rsp),%xmm2
addsd  %xmm2,%xmm2
subsd  %xmm2,%xmm1
subsd  0x10(%rsp),%xmm1
subsd  %xmm0,%xmm1
cvttpd2dq %xmm1,%xmm0
cvtdq2pd %xmm0,%xmm0
subsd  %xmm0,%xmm1
addsd  0xe4d(%rip),%xmm1
movapd %xmm1,(%rsp)
lea    0x20(%rsp),%rbx
movapd %xmm1,%xmm0
mov    $0x10,%edi
mov    %rbx,%rsi
call   1050 <ihex@plt>
lea    0xe33(%rip),%rdi
mov    $0xf4240,%esi
movaps (%rsp),%xmm0
mov    %rbx,%rdx
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [58 x i8] c" position = %i\0A fraction = %.15f \0A hex digits = %10.10s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca double
%3 = alloca double
%4 = alloca double
%5 = alloca double
%6 = alloca double
%7 = alloca i32
%8 = alloca [16 x i8]
store i32 0, i32* %1
store i32 1000000, i32* %7
%9 = load i32, i32* %7
%10 = call double @series(i32 1, i32 %9)
store double %10, double* %3
%11 = load i32, i32* %7
%12 = call double @series(i32 4, i32 %11)
store double %12, double* %4
%13 = load i32, i32* %7
%14 = call double @series(i32 5, i32 %13)
store double %14, double* %5
%15 = load i32, i32* %7
%16 = call double @series(i32 6, i32 %15)
store double %16, double* %6
%17 = load double, double* %3
%18 = load double, double* %4
%19 = fmul double 2.000000e+00, %18
%20 = fneg double %19
%21 = call double @llvm.fmuladd.f64(double 4.000000e+00, double %17, double %20)
%22 = load double, double* %5
%23 = fsub double %21, %22
%24 = load double, double* %6
%25 = fsub double %23, %24
store double %25, double* %2
%26 = load double, double* %2
%27 = load double, double* %2
%28 = fptosi double %27 to i32
%29 = sitofp i32 %28 to double
%30 = fsub double %26, %29
%31 = fadd double %30, 1.000000e+00
store double %31, double* %2
%32 = load double, double* %2
%33 = getelementptr inbounds [16 x i8], [16 x i8]* %8, i64 0, i64 0
%34 = load i32, i32* %7
%35 = load double, double* %2
%36 = getelementptr inbounds [16 x i8], [16 x i8]* %8, i64 0, i64 0
%37 = call i32 @printf(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str, i64 0, i64 0), i32 %34, double %35, i8* %36)
ret i32 0
}

LLVM IR (-O2):
@.str = [58 x i8] c" position = %i\0A fraction = %.15f \0A hex digits = %10.10s\0A\00"
define i32 @main() {
%1 = alloca [16 x i8]
%2 = getelementptr inbounds [16 x i8], [16 x i8]* %1, i64 0, i64 0
%3 = tail call double @series(i32 1, i32 1000000)
%4 = tail call double @series(i32 4, i32 1000000)
%5 = tail call double @series(i32 5, i32 1000000)
%6 = tail call double @series(i32 6, i32 1000000)
%7 = fmul double %4, -2.000000e+00
%8 = tail call double @llvm.fmuladd.f64(double %3, double 4.000000e+00, double %7)
%9 = fsub double %8, %5
%10 = fsub double %9, %6
%11 = fptosi double %10 to i32
%12 = sitofp i32 %11 to double
%13 = fsub double %10, %12
%14 = fadd double %13, 1.000000e+00
%15 = call i32 @printf(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str, i64 0, i64 0), i32 1000000, double %14, i8* %2)
ret i32 0
}