#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*/ getchar();
int log10(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
void eight() {
  int limit, i, j;
  float sum, term;
  printf("enter limit (int): ");
  scanf("%d", &limit);
  printf("\ngenerated limits of accuracy:\n\n");
  for (i = 1; i <= limit; ++i) {
    term = 1 / (float)i;
    sum = 0;
    for (j = 0; j < i; ++j)
      sum += term;
    printf("sum of %*d 1/%*d's is %f\n",
           log10(limit) > 0 ? (int)(1 + log10(limit)) : (int)(1 - log10(limit)),
           i,
           log10(limit) > 0 ? (int)(1 + log10(limit)) : (int)(1 - log10(limit)),
           i, sum);
  }
  getchar();
  printf("\nreturning to menu. press Enter...");
  getchar();
}


x86 assembly (clang, -O0):
<eight>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
lea    0xeb5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xebb(%rip),%rdi
lea    -0x4(%rbp),%rsi
call   1050 <scanf@plt>
lea    0xeae(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x4(%rbp),%eax
jg     1283 <eight+0x143>
cvtsi2ssl -0x8(%rbp),%xmm1
movss  0xe6c(%rip),%xmm0
divss  %xmm1,%xmm0
movss  %xmm0,-0x14(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x10(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11d5 <eight+0x95>
movss  -0x14(%rbp),%xmm0
addss  -0x10(%rbp),%xmm0
movss  %xmm0,-0x10(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11ac <eight+0x6c>
mov    -0x4(%rbp),%edi
call   1060 <log10@plt>
cmp    $0x0,%eax
jle    11f9 <eight+0xb9>
mov    -0x4(%rbp),%edi
call   1060 <log10@plt>
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    120d <eight+0xcd>
mov    -0x4(%rbp),%edi
call   1060 <log10@plt>
mov    %eax,%ecx
mov    $0x1,%eax
sub    %ecx,%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x4(%rbp),%edi
call   1060 <log10@plt>
cmp    $0x0,%eax
jle    123d <eight+0xfd>
mov    -0x4(%rbp),%edi
call   1060 <log10@plt>
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1251 <eight+0x111>
mov    -0x4(%rbp),%edi
call   1060 <log10@plt>
mov    %eax,%ecx
mov    $0x1,%eax
sub    %ecx,%eax
mov    %eax,-0x24(%rbp)
mov    -0x1c(%rbp),%edx
mov    -0x20(%rbp),%esi
mov    -0x24(%rbp),%ecx
mov    -0x8(%rbp),%r8d
movss  -0x10(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xdce(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    117b <eight+0x3b>
mov    $0x0,%al
call   1040 <getchar@plt>
lea    0xdc5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x0,%al
call   1040 <getchar@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<eight>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
lea    0xea1(%rip),%rdi
xor    %r12d,%r12d
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xea4(%rip),%rdi
lea    0x8(%rsp),%rsi
call   1060 <scanf@plt>
lea    0xed3(%rip),%rdi
call   1030 <puts@plt>
mov    0x8(%rsp),%edi
test   %edi,%edi
jle    129e <eight+0x14e>
mov    $0x1,%ebx
lea    0xe79(%rip),%r14
jmp    1222 <eight+0xd2>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movss  %xmm1,0xc(%rsp)
call   1070 <log10@plt>
mov    %eax,%r15d
mov    0x8(%rsp),%edi
call   1070 <log10@plt>
mov    %eax,%ebp
neg    %ebp
test   %r15d,%r15d
cmovg  %eax,%ebp
add    $0x1,%ebp
mov    0x8(%rsp),%edi
call   1070 <log10@plt>
mov    %eax,%r15d
mov    0x8(%rsp),%edi
call   1070 <log10@plt>
mov    %eax,%ecx
neg    %ecx
test   %r15d,%r15d
cmovg  %eax,%ecx
add    $0x1,%ecx
movss  0xc(%rsp),%xmm0
cvtss2sd %xmm0,%xmm0
mov    %r14,%rdi
mov    %ebp,%esi
mov    %ebx,%edx
mov    %ebx,%r8d
mov    $0x1,%al
call   1040 <printf@plt>
lea    0x1(%rbx),%eax
mov    0x8(%rsp),%edi
add    $0x1,%r12d
cmp    %edi,%ebx
mov    %eax,%ebx
jge    129e <eight+0x14e>
xorps  %xmm1,%xmm1
cvtsi2ss %ebx,%xmm1
movss  0xdcf(%rip),%xmm0
divss  %xmm1,%xmm0
xorps  %xmm1,%xmm1
cmp    $0x7,%r12d
jb     1275 <eight+0x125>
mov    %ebx,%eax
and    $0xfffffff8,%eax
xorps  %xmm1,%xmm1
cs nopw 0x0(%rax,%rax,1)
addss  %xmm0,%xmm1
addss  %xmm0,%xmm1
addss  %xmm0,%xmm1
addss  %xmm0,%xmm1
addss  %xmm0,%xmm1
addss  %xmm0,%xmm1
addss  %xmm0,%xmm1
addss  %xmm0,%xmm1
add    $0xfffffff8,%eax
jne    1250 <eight+0x100>
test   $0x7,%bl
je     11b0 <eight+0x60>
mov    %ebx,%eax
and    $0x7,%eax
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
addss  %xmm0,%xmm1
add    $0xffffffff,%eax
jne    1290 <eight+0x140>
jmp    11b0 <eight+0x60>
xor    %eax,%eax
call   1050 <getchar@plt>
lea    0xd89(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
call   1050 <getchar@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [20 x i8] c"enter limit (int): \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [33 x i8] c"\0Agenerated limits of accuracy:\0A\0A\00"
@.str.3 = [26 x i8] c"sum of %*d 1/%*d's is %f\0A\00"
@.str.4 = [35 x i8] c"\0Areturning to menu. press Enter...\00"
define void @eight() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca float
%5 = alloca float
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 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* %1)
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %2
br label %9
9: ; preds = %60, %0
%10 = load i32, i32* %2
%11 = load i32, i32* %1
%12 = icmp sle i32 %10, %11
br i1 %12, label %13, label %63
13: ; preds = %9
%14 = load i32, i32* %2
%15 = sitofp i32 %14 to float
%16 = fdiv float 1.000000e+00, %15
store float %16, float* %5
store float 0.000000e+00, float* %4
store i32 0, i32* %3
br label %17
17: ; preds = %25, %13
%18 = load i32, i32* %3
%19 = load i32, i32* %2
%20 = icmp slt i32 %18, %19
br i1 %20, label %21, label %28
21: ; preds = %17
%22 = load float, float* %5
%23 = load float, float* %4
%24 = fadd float %23, %22
store float %24, float* %4
br label %25
25: ; preds = %21
%26 = load i32, i32* %3
%27 = add nsw i32 %26, 1
store i32 %27, i32* %3
br label %17
28: ; preds = %17
%29 = load i32, i32* %1
%30 = call i32 @log10(i32 %29)
%31 = icmp sgt i32 %30, 0
br i1 %31, label %32, label %36
32: ; preds = %28
%33 = load i32, i32* %1
%34 = call i32 @log10(i32 %33)
%35 = add nsw i32 1, %34
br label %40
36: ; preds = %28
%37 = load i32, i32* %1
%38 = call i32 @log10(i32 %37)
%39 = sub nsw i32 1, %38
br label %40
40: ; preds = %36, %32
%41 = phi i32 [ %35, %32 ], [ %39, %36 ]
%42 = load i32, i32* %2
%43 = load i32, i32* %1
%44 = call i32 @log10(i32 %43)
%45 = icmp sgt i32 %44, 0
br i1 %45, label %46, label %50
46: ; preds = %40
%47 = load i32, i32* %1
%48 = call i32 @log10(i32 %47)
%49 = add nsw i32 1, %48
br label %54
50: ; preds = %40
%51 = load i32, i32* %1
%52 = call i32 @log10(i32 %51)
%53 = sub nsw i32 1, %52
br label %54
54: ; preds = %50, %46
%55 = phi i32 [ %49, %46 ], [ %53, %50 ]
%56 = load i32, i32* %2
%57 = load float, float* %4
%58 = fpext float %57 to double
%59 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i32 %41, i32 %42, i32 %55, i32 %56, double %58)
br label %60
60: ; preds = %54
%61 = load i32, i32* %2
%62 = add nsw i32 %61, 1
store i32 %62, i32* %2
br label %9
63: ; preds = %9
%64 = call i32 (...) @getchar()
%65 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.4, i64 0, i64 0))
%66 = call i32 (...) @getchar()
ret void
}

LLVM IR (-O2):
@.str = [20 x i8] c"enter limit (int): \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.3 = [26 x i8] c"sum of %*d 1/%*d's is %f\0A\00"
@.str.4 = [35 x i8] c"\0Areturning to menu. press Enter...\00"
@str = [32 x i8] c"\0Agenerated limits of accuracy:\0A\00"
define void @eight() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 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 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str, i64 0, i64 0))
%6 = load i32, i32* %1
%7 = icmp slt i32 %6, 1
br i1 %7, label %64, label %8
8: ; preds = %0, %41
%9 = phi i32 [ %63, %41 ], [ 0, %0 ]
%10 = phi i32 [ %61, %41 ], [ %6, %0 ]
%11 = phi i32 [ %60, %41 ], [ 1, %0 ]
%12 = sitofp i32 %11 to float
%13 = fdiv float 1.000000e+00, %12
%14 = and i32 %11, 7
%15 = icmp ult i32 %9, 7
br i1 %15, label %31, label %16
16: ; preds = %8
%17 = and i32 %11, 2147483640
br label %18
18: ; preds = %18, %16
%19 = phi float [ 0.000000e+00, %16 ], [ %28, %18 ]
%20 = phi i32 [ 0, %16 ], [ %29, %18 ]
%21 = fadd float %13, %19
%22 = fadd float %13, %21
%23 = fadd float %13, %22
%24 = fadd float %13, %23
%25 = fadd float %13, %24
%26 = fadd float %13, %25
%27 = fadd float %13, %26
%28 = fadd float %13, %27
%29 = add i32 %20, 8
%30 = icmp eq i32 %29, %17
br i1 %30, label %31, label %18
31: ; preds = %18, %8
%32 = phi float [ undef, %8 ], [ %28, %18 ]
%33 = phi float [ 0.000000e+00, %8 ], [ %28, %18 ]
%34 = icmp eq i32 %14, 0
br i1 %34, label %41, label %35
35: ; preds = %31, %35
%36 = phi float [ %38, %35 ], [ %33, %31 ]
%37 = phi i32 [ %39, %35 ], [ 0, %31 ]
%38 = fadd float %13, %36
%39 = add i32 %37, 1
%40 = icmp eq i32 %39, %14
br i1 %40, label %41, label %35
41: ; preds = %35, %31
%42 = phi float [ %32, %31 ], [ %38, %35 ]
%43 = call i32 @log10(i32 %10)
%44 = icmp sgt i32 %43, 0
%45 = load i32, i32* %1
%46 = call i32 @log10(i32 %45)
%47 = sub i32 0, %46
%48 = select i1 %44, i32 %46, i32 %47
%49 = add i32 %48, 1
%50 = load i32, i32* %1
%51 = call i32 @log10(i32 %50)
%52 = icmp sgt i32 %51, 0
%53 = load i32, i32* %1
%54 = call i32 @log10(i32 %53)
%55 = sub i32 0, %54
%56 = select i1 %52, i32 %54, i32 %55
%57 = add i32 %56, 1
%58 = fpext float %42 to double
%59 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i32 %49, i32 %11, i32 %57, i32 %11, double %58)
%60 = add nuw nsw i32 %11, 1
%61 = load i32, i32* %1
%62 = icmp slt i32 %11, %61
%63 = add i32 %9, 1
br i1 %62, label %8, label %64
64: ; preds = %41, %0
%65 = call i32 (...) @getchar()
%66 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.4, i64 0, i64 0))
%67 = call i32 (...) @getchar()
ret void
}