#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 t_ct;
  double time, power_of_2;
  int limit;
  printf("Enter the number of terms you want: ");
  scanf("%d", &limit);
  for (time = 0, power_of_2 = 1, t_ct = 1; t_ct <= limit;
       t_ct++, power_of_2 *= 2.0) {
    time += 1.0 / power_of_2;
    printf("time = %f when terms = %d.\n", time, t_ct);
  }
  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    -0x1c(%rbp),%rsi
call   1040 <scanf@plt>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  0xea3(%rip),%xmm0
movsd  %xmm0,-0x18(%rbp)
movl   $0x1,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jg     11c2 <main+0xa2>
movsd  0xe83(%rip),%xmm0
divsd  -0x18(%rbp),%xmm0
addsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%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  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x18(%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    %ebx,%ebx
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xeef(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1040 <scanf@plt>
cmpl   $0x0,0x4(%rsp)
jle    11b1 <main+0x91>
xorpd  %xmm0,%xmm0
movsd  0xea5(%rip),%xmm2
lea    0xece(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movsd  %xmm2,0x8(%rsp)
add    $0x1,%ebx
movsd  0xe7f(%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
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 = [28 x i8] c"time = %f when terms = %d.\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca double
%4 = alloca double
%5 = alloca i32
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* %5)
store double 0.000000e+00, double* %3
store double 1.000000e+00, double* %4
store i32 1, i32* %2
br label %8
8: ; preds = %20, %0
%9 = load i32, i32* %2
%10 = load i32, i32* %5
%11 = icmp sle i32 %9, %10
br i1 %11, label %12, label %25
12: ; preds = %8
%13 = load double, double* %4
%14 = fdiv double 1.000000e+00, %13
%15 = load double, double* %3
%16 = fadd double %15, %14
store double %16, double* %3
%17 = load double, double* %3
%18 = load i32, i32* %2
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 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* %4
%24 = fmul double %23, 2.000000e+00
store double %24, double* %4
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 = [28 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 slt i32 %5, 1
br i1 %6, label %18, label %7
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 ([28 x i8], [28 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 %10, %16
br i1 %17, label %7, label %18
18: ; preds = %7, %0
ret i32 0
}