#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 fabs(float);
int /*<<< orphan*/ printf(char *, float, ...);
main() {
  int n = 0;
  float P, a, k = 1.0;
  P = 1.0;
  do {
    a = 1 / k + (k + 1) / (k + 2);
    P *= a;
    n++;
    k = k + 1.0;
    printf("%f %f\n", a, a / P);
  } while (fabs(a / P) < 10);
  printf("%d\n", n);
  printf("%f\n", P);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movss  0xec2(%rip),%xmm0
movss  %xmm0,-0x14(%rbp)
movss  0xeb5(%rip),%xmm0
movss  %xmm0,-0xc(%rbp)
movss  0xea8(%rip),%xmm0
divss  -0x14(%rbp),%xmm0
movss  0xe9b(%rip),%xmm1
addss  -0x14(%rbp),%xmm1
movss  0xe92(%rip),%xmm2
addss  -0x14(%rbp),%xmm2
divss  %xmm2,%xmm1
addss  %xmm1,%xmm0
movss  %xmm0,-0x10(%rbp)
movss  -0x10(%rbp),%xmm0
mulss  -0xc(%rbp),%xmm0
movss  %xmm0,-0xc(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
movss  -0x14(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xe5b(%rip),%xmm1
addsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x14(%rbp)
movss  -0x10(%rbp),%xmm0
movss  -0x10(%rbp),%xmm1
divss  -0xc(%rbp),%xmm1
cvtss2sd %xmm1,%xmm1
lea    0xe3c(%rip),%rdi
mov    $0x2,%al
call   1030 <printf@plt>
movss  -0x10(%rbp),%xmm0
divss  -0xc(%rbp),%xmm0
call   1040 <fabs@plt>
cmp    $0xa,%eax
jl     1150 <main+0x30>
cvtsi2ssl -0x8(%rbp),%xmm0
lea    0xe18(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
movss  -0xc(%rbp),%xmm0
lea    0xe01(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x38,%rsp
xor    %ebp,%ebp
movss  0xed0(%rip),%xmm0
lea    0xee9(%rip),%rbx
movss  %xmm0,0xc(%rsp)
movaps %xmm0,%xmm1
addss  0xeb8(%rip),%xmm1
movaps %xmm1,0x10(%rsp)
movaps %xmm0,%xmm1
addss  0xeac(%rip),%xmm1
movaps 0xeb1(%rip),%xmm2
unpcklps 0x10(%rsp),%xmm2
unpcklps %xmm1,%xmm0
divps  %xmm0,%xmm2
movaps %xmm2,%xmm0
shufps $0x55,%xmm2,%xmm0
addss  %xmm2,%xmm0
movss  0xc(%rsp),%xmm1
mulss  %xmm0,%xmm1
add    $0x1,%ebp
movaps %xmm0,%xmm2
movss  %xmm1,0xc(%rsp)
divss  %xmm1,%xmm2
movaps %xmm2,0x20(%rsp)
xorps  %xmm1,%xmm1
cvtss2sd %xmm2,%xmm1
mov    %rbx,%rdi
mov    $0x2,%al
call   1030 <printf@plt>
movaps 0x20(%rsp),%xmm0
call   1040 <fabs@plt>
movaps 0x10(%rsp),%xmm1
movaps %xmm1,%xmm0
cmp    $0xa,%eax
jl     1140 <main+0x20>
xorps  %xmm0,%xmm0
cvtsi2ss %ebp,%xmm0
lea    0xe5d(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
lea    0xe4b(%rip),%rdi
movss  0xc(%rsp),%xmm0
mov    $0x1,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x38,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [7 x i8] c"%f %f\0A\00"
@.str.1 = [4 x i8] c"%d\0A\00"
@.str.2 = [4 x i8] c"%f\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca float
%4 = alloca float
%5 = alloca float
store i32 0, i32* %1
store i32 0, i32* %2
store float 1.000000e+00, float* %5
store float 1.000000e+00, float* %3
br label %6
6: ; preds = %30, %0
%7 = load float, float* %5
%8 = fdiv float 1.000000e+00, %7
%9 = load float, float* %5
%10 = fadd float %9, 1.000000e+00
%11 = load float, float* %5
%12 = fadd float %11, 2.000000e+00
%13 = fdiv float %10, %12
%14 = fadd float %8, %13
store float %14, float* %4
%15 = load float, float* %4
%16 = load float, float* %3
%17 = fmul float %16, %15
store float %17, float* %3
%18 = load i32, i32* %2
%19 = add nsw i32 %18, 1
store i32 %19, i32* %2
%20 = load float, float* %5
%21 = fpext float %20 to double
%22 = fadd double %21, 1.000000e+00
%23 = fptrunc double %22 to float
store float %23, float* %5
%24 = load float, float* %4
%25 = load float, float* %4
%26 = load float, float* %3
%27 = fdiv float %25, %26
%28 = fpext float %27 to double
%29 = call i32 (i8*, float, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), float %24, double %28)
br label %30
30: ; preds = %6
%31 = load float, float* %4
%32 = load float, float* %3
%33 = fdiv float %31, %32
%34 = call i32 @fabs(float %33)
%35 = icmp slt i32 %34, 10
br i1 %35, label %6, label %36
36: ; preds = %30
%37 = load i32, i32* %2
%38 = sitofp i32 %37 to float
%39 = call i32 (i8*, float, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), float %38)
%40 = load float, float* %3
%41 = call i32 (i8*, float, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), float %40)
ret i32 0
}

LLVM IR (-O2):
@.str = [7 x i8] c"%f %f\0A\00"
@.str.1 = [4 x i8] c"%d\0A\00"
@.str.2 = [4 x i8] c"%f\0A\00"
define i32 @main() {
br label %1
1: ; preds = %1, %0
%2 = phi float [ 1.000000e+00, %0 ], [ %14, %1 ]
%3 = phi i32 [ 0, %0 ], [ %15, %1 ]
%4 = phi float [ 1.000000e+00, %0 ], [ %5, %1 ]
%5 = fadd float %4, 1.000000e+00
%6 = fadd float %4, 2.000000e+00
%7 = insertelement <2 x float> <float 1.000000e+00, float poison>, float %5, i64 1
%8 = insertelement <2 x float> poison, float %4, i64 0
%9 = insertelement <2 x float> %8, float %6, i64 1
%10 = fdiv <2 x float> %7, %9
%11 = shufflevector <2 x float> %10, <2 x float> poison, <2 x i32> <i32 1, i32 undef>
%12 = fadd <2 x float> %10, %11
%13 = extractelement <2 x float> %12, i64 0
%14 = fmul float %2, %13
%15 = add nuw nsw i32 %3, 1
%16 = fdiv float %13, %14
%17 = fpext float %16 to double
%18 = tail call i32 (i8*, float, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), float %13, double %17)
%19 = tail call i32 @fabs(float %16)
%20 = icmp slt i32 %19, 10
br i1 %20, label %1, label %21
21: ; preds = %1
%22 = sitofp i32 %15 to float
%23 = tail call i32 (i8*, float, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), float %22)
%24 = tail call i32 (i8*, float, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), float %14)
ret i32 0
}