#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 */
double pow(int, int);
int /*<<< orphan*/ printf(char *, ...);
void series5(int n) {
  double sum = 0;
  int i;
  for (i = 0; i <= n; i++) {
    printf("1/%d", (int)pow(2, i));
    i != n ? printf("+") : printf(".");
    sum += 1.0 / pow(2, i);
  }
  printf("\nSum of the above series is %f", sum);
}


x86 assembly (clang, -O0):
<series5>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x4(%rbp),%eax
jg     11c6 <series5+0xa6>
mov    -0x14(%rbp),%esi
mov    $0x2,%edi
call   1040 <pow@plt>
cvttsd2si %xmm0,%esi
lea    0xeaa(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
cmp    -0x4(%rbp),%eax
je     1184 <series5+0x64>
lea    0xe95(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1192 <series5+0x72>
lea    0xe84(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%esi
mov    $0x2,%edi
call   1040 <pow@plt>
movaps %xmm0,%xmm1
movsd  0xe56(%rip),%xmm0
divsd  %xmm1,%xmm0
addsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    113a <series5+0x1a>
movsd  -0x10(%rbp),%xmm0
lea    0xe3f(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<series5>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
test   %edi,%edi
js     11ac <series5+0x7c>
mov    %edi,%ebx
lea    0x1(%rbx),%r15d
xorpd  %xmm0,%xmm0
lea    0xebc(%rip),%r14
xor    %ebp,%ebp
xchg   %ax,%ax
movsd  %xmm0,(%rsp)
mov    $0x2,%edi
mov    %ebp,%esi
call   1050 <pow@plt>
cvttsd2si %xmm0,%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
cmp    %ebp,%ebx
sete   %al
lea    (%rax,%rax,2),%edi
add    $0x2b,%edi
call   1030 <putchar@plt>
mov    $0x2,%edi
mov    %ebp,%esi
call   1050 <pow@plt>
movsd  0xe6b(%rip),%xmm1
divsd  %xmm0,%xmm1
movsd  (%rsp),%xmm0
addsd  %xmm1,%xmm0
add    $0x1,%ebp
cmp    %ebp,%r15d
jne    1150 <series5+0x20>
jmp    11b0 <series5+0x80>
xorpd  %xmm0,%xmm0
lea    0xe56(%rip),%rdi
mov    $0x1,%al
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <printf@plt>

LLVM IR (-O0):
@.str = [5 x i8] c"1/%d\00"
@.str.1 = [2 x i8] c"+\00"
@.str.2 = [2 x i8] c".\00"
@.str.3 = [31 x i8] c"\0ASum of the above series is %f\00"
define void @series5(i32 %0) {
%2 = alloca i32
%3 = alloca double
%4 = alloca i32
store i32 %0, i32* %2
store double 0.000000e+00, double* %3
store i32 0, i32* %4
br label %5
5: ; preds = %28, %1
%6 = load i32, i32* %4
%7 = load i32, i32* %2
%8 = icmp sle i32 %6, %7
br i1 %8, label %9, label %31
9: ; preds = %5
%10 = load i32, i32* %4
%11 = call double @pow(i32 2, i32 %10)
%12 = fptosi double %11 to i32
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %12)
%14 = load i32, i32* %4
%15 = load i32, i32* %2
%16 = icmp ne i32 %14, %15
br i1 %16, label %17, label %19
17: ; preds = %9
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %21
19: ; preds = %9
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %21
21: ; preds = %19, %17
%22 = phi i32 [ %18, %17 ], [ %20, %19 ]
%23 = load i32, i32* %4
%24 = call double @pow(i32 2, i32 %23)
%25 = fdiv double 1.000000e+00, %24
%26 = load double, double* %3
%27 = fadd double %26, %25
store double %27, double* %3
br label %28
28: ; preds = %21
%29 = load i32, i32* %4
%30 = add nsw i32 %29, 1
store i32 %30, i32* %4
br label %5
31: ; preds = %5
%32 = load double, double* %3
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0), double %32)
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c"1/%d\00"
@.str.3 = [31 x i8] c"\0ASum of the above series is %f\00"
define void @series5(i32 %0) {
%2 = icmp slt i32 %0, 0
br i1 %2, label %17, label %3
3: ; preds = %1, %3
%4 = phi i32 [ %15, %3 ], [ 0, %1 ]
%5 = phi double [ %14, %3 ], [ 0.000000e+00, %1 ]
%6 = tail call double @pow(i32 2, i32 %4)
%7 = fptosi double %6 to i32
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %7)
%9 = icmp eq i32 %4, %0
%10 = select i1 %9, i32 46, i32 43
%11 = tail call i32 @putchar(i32 %10)
%12 = tail call double @pow(i32 2, i32 %4)
%13 = fdiv double 1.000000e+00, %12
%14 = fadd double %5, %13
%15 = add nuw i32 %4, 1
%16 = icmp eq i32 %4, %0
br i1 %16, label %17, label %3
17: ; preds = %3, %1
%18 = phi double [ 0.000000e+00, %1 ], [ %14, %3 ]
%19 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0), double %18)
ret void
}