#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 *, double, int);
float sum_primes(float x) {
  double sum = 0, result = 0;
  for (int i = 1;; ++i) {
    result = 1 / i + 1 / (i + 2);
    printf("%f %d\n", result, i);
    if (result < x)
      break;
    sum += result;
  }
  return sum;
}


x86 assembly (clang, -O0):
<sum_primes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movss  %xmm0,-0x4(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x10(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x18(%rbp)
movl   $0x1,-0x1c(%rbp)
mov    $0x1,%eax
cltd
idivl  -0x1c(%rbp)
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%ecx
add    $0x2,%ecx
mov    $0x1,%eax
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x20(%rbp),%eax
add    %ecx,%eax
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
mov    -0x1c(%rbp),%esi
lea    0xe93(%rip),%rdi
call   1030 <printf@plt>
movsd  -0x18(%rbp),%xmm1
movss  -0x4(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
ucomisd %xmm1,%xmm0
jbe    118f <sum_primes+0x7f>
jmp    11ac <sum_primes+0x9c>
movsd  -0x18(%rbp),%xmm0
addsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1134 <sum_primes+0x24>
movsd  -0x10(%rbp),%xmm0
cvtsd2ss %xmm0,%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sum_primes>:
push   %r14
push   %rbx
push   %rax
movss  %xmm0,0x4(%rsp)
lea    0xeeb(%rip),%rdi
movsd  0xed7(%rip),%xmm0
mov    $0x1,%esi
call   1030 <printf@plt>
xorps  %xmm0,%xmm0
movss  0x4(%rsp),%xmm1
ucomiss 0xec5(%rip),%xmm1
ja     116f <sum_primes+0x5f>
lea    0xec0(%rip),%rdi
xorps  %xmm0,%xmm0
mov    $0x2,%esi
call   1030 <printf@plt>
xorps  %xmm0,%xmm0
movss  0x4(%rsp),%xmm1
ucomiss %xmm0,%xmm1
jbe    1177 <sum_primes+0x67>
movss  0xe99(%rip),%xmm0
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    $0x3,%ebx
lea    0xe89(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
xorps  %xmm0,%xmm0
mov    %r14,%rdi
mov    %ebx,%esi
call   1030 <printf@plt>
add    $0x1,%ebx
jmp    1190 <sum_primes+0x80>

LLVM IR (-O0):
@.str = [7 x i8] c"%f %d\0A\00"
define float @sum_primes(float %0) {
%2 = alloca float
%3 = alloca double
%4 = alloca double
%5 = alloca i32
store float %0, float* %2
store double 0.000000e+00, double* %3
store double 0.000000e+00, double* %4
store i32 1, i32* %5
br label %6
6: ; preds = %26, %1
%7 = load i32, i32* %5
%8 = sdiv i32 1, %7
%9 = load i32, i32* %5
%10 = add nsw i32 %9, 2
%11 = sdiv i32 1, %10
%12 = add nsw i32 %8, %11
%13 = sitofp i32 %12 to double
store double %13, double* %4
%14 = load double, double* %4
%15 = load i32, i32* %5
%16 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), double %14, i32 %15)
%17 = load double, double* %4
%18 = load float, float* %2
%19 = fpext float %18 to double
%20 = fcmp olt double %17, %19
br i1 %20, label %21, label %22
21: ; preds = %6
br label %29
22: ; preds = %6
%23 = load double, double* %4
%24 = load double, double* %3
%25 = fadd double %24, %23
store double %25, double* %3
br label %26
26: ; preds = %22
%27 = load i32, i32* %5
%28 = add nsw i32 %27, 1
store i32 %28, i32* %5
br label %6
29: ; preds = %21
%30 = load double, double* %3
%31 = fptrunc double %30 to float
ret float %31
}

LLVM IR (-O2):
@.str = [7 x i8] c"%f %d\0A\00"
define float @sum_primes(float %0) {
%2 = tail call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), double 1.000000e+00, i32 1)
%3 = fcmp ogt float %0, 1.000000e+00
br i1 %3, label %7, label %4
4: ; preds = %1
%5 = tail call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), double 0.000000e+00, i32 2)
%6 = fcmp ogt float %0, 0.000000e+00
br i1 %6, label %7, label %9
7: ; preds = %4, %1
%8 = phi float [ 0.000000e+00, %1 ], [ 1.000000e+00, %4 ]
ret float %8
9: ; preds = %4, %9
%10 = phi i32 [ %11, %9 ], [ 2, %4 ]
%11 = add nuw nsw i32 %10, 1
%12 = tail call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), double 0.000000e+00, i32 %11)
br label %9
}