#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 /*<<< orphan*/ scanf(char *, int *);
int main(void) {
  int term_cnt, limit;
  double time, power_of_2;
  printf("Enter the number of terms you want: ");
  scanf("%d", &limit);
  for (time = 0, power_of_2 = 1, term_cnt = 1; term_cnt < limit;
       term_cnt++, power_of_2 *= 2) {
    time += 1 / power_of_2;
    printf("time = %f when terms = %d\n", time, term_cnt);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeda(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xef1(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   1040 <scanf@plt>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  0xea3(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
movl   $0x1,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11c2 <main+0xa2>
movsd  0xe83(%rip),%xmm0
divsd  -0x20(%rbp),%xmm0
addsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
mov    -0x8(%rbp),%esi
lea    0xe9d(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
movsd  0xe55(%rip),%xmm0
mulsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
jmp    1169 <main+0x49>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x18,%rsp
lea    0xeda(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xef1(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1040 <scanf@plt>
cmpl   $0x2,0x4(%rsp)
jl     11b1 <main+0x91>
mov    $0x1,%ebx
xorpd  %xmm0,%xmm0
movsd  0xea2(%rip),%xmm2
lea    0xecb(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nop
movsd  %xmm2,0x8(%rsp)
movsd  0xe82(%rip),%xmm1
divsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,0x10(%rsp)
mov    %r14,%rdi
mov    %ebx,%esi
mov    $0x1,%al
call   1030 <printf@plt>
movsd  0x8(%rsp),%xmm2
movsd  0x10(%rsp),%xmm0
add    $0x1,%ebx
addsd  %xmm2,%xmm2
cmp    0x4(%rsp),%ebx
jl     1170 <main+0x50>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [37 x i8] c"Enter the number of terms you want: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [27 x i8] c"time = %f when terms = %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca double
%5 = alloca double
store i32 0, i32* %1
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0))
%7 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
store double 0.000000e+00, double* %4
store double 1.000000e+00, double* %5
store i32 1, i32* %2
br label %8
8: ; preds = %20, %0
%9 = load i32, i32* %2
%10 = load i32, i32* %3
%11 = icmp slt i32 %9, %10
br i1 %11, label %12, label %25
12: ; preds = %8
%13 = load double, double* %5
%14 = fdiv double 1.000000e+00, %13
%15 = load double, double* %4
%16 = fadd double %15, %14
store double %16, double* %4
%17 = load double, double* %4
%18 = load i32, i32* %2
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), double %17, i32 %18)
br label %20
20: ; preds = %12
%21 = load i32, i32* %2
%22 = add nsw i32 %21, 1
store i32 %22, i32* %2
%23 = load double, double* %5
%24 = fmul double %23, 2.000000e+00
store double %24, double* %5
br label %8
25: ; preds = %8
ret i32 0
}

LLVM IR (-O2):
@.str = [37 x i8] c"Enter the number of terms you want: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [27 x i8] c"time = %f when terms = %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0))
%4 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%5 = load i32, i32* %1
%6 = icmp sgt i32 %5, 1
br i1 %6, label %7, label %18
7: ; preds = %0, %7
%8 = phi double [ %15, %7 ], [ 1.000000e+00, %0 ]
%9 = phi double [ %12, %7 ], [ 0.000000e+00, %0 ]
%10 = phi i32 [ %14, %7 ], [ 1, %0 ]
%11 = fdiv double 1.000000e+00, %8
%12 = fadd double %9, %11
%13 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), double %12, i32 %10)
%14 = add nuw nsw i32 %10, 1
%15 = fmul double %8, 2.000000e+00
%16 = load i32, i32* %1
%17 = icmp slt i32 %14, %16
br i1 %17, label %7, label %18
18: ; preds = %7, %0
ret i32 0
}