#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 main() {
  int k, i = 1;
  double x, func_x;
  while (i == 1) {
    func_x = 0;
    printf("Please input x:");
    scanf("%lf", &x);
    for (k = 1; k <= 1000000; k++) {
      func_x = func_x + 1 / ((x + k) * k);
    }
    printf("x=%4.2lf,func_x=%16.12lf\n", x, func_x);
    printf("1:next  0:exit\n");
    scanf("%d", &i);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0xc(%rbp)
cmpl   $0x1,-0xc(%rbp)
jne    11f8 <main+0xd8>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
lea    0xeb9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xebb(%rip),%rdi
lea    -0x18(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
movl   $0x1,-0x8(%rbp)
cmpl   $0xf4240,-0x8(%rbp)
jg     11bb <main+0x9b>
movsd  -0x20(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm2
cvtsi2sdl -0x8(%rbp),%xmm1
addsd  %xmm1,%xmm2
cvtsi2sdl -0x8(%rbp),%xmm1
mulsd  %xmm1,%xmm2
movsd  0xe60(%rip),%xmm1
divsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    116f <main+0x4f>
movsd  -0x18(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm1
lea    0xe50(%rip),%rdi
mov    $0x2,%al
call   1030 <printf@plt>
lea    0xe5c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe5e(%rip),%rdi
lea    -0xc(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
jmp    1136 <main+0x16>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
movl   $0x1,0xc(%rsp)
lea    0xed3(%rip),%r15
lea    0x10(%rsp),%r12
lea    0xecb(%rip),%r13
lea    0xee1(%rip),%rbx
lea    0xed7(%rip),%rbp
lea    0xc(%rsp),%r14
nopl   0x0(%rax)
lea    0xe99(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r15,%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1050 <scanf@plt>
xorpd  %xmm1,%xmm1
mov    $0x2,%eax
movsd  0x10(%rsp),%xmm0
movsd  0xe5e(%rip),%xmm6
movapd %xmm6,%xmm2
movsd  0xe5a(%rip),%xmm7
xchg   %ax,%ax
movapd %xmm0,%xmm3
addsd  %xmm2,%xmm3
mulsd  %xmm2,%xmm3
movapd %xmm6,%xmm4
divsd  %xmm3,%xmm4
xorps  %xmm3,%xmm3
cvtsi2sd %eax,%xmm3
addsd  %xmm1,%xmm4
movapd %xmm0,%xmm5
addsd  %xmm3,%xmm5
mulsd  %xmm3,%xmm5
movapd %xmm6,%xmm1
divsd  %xmm5,%xmm1
addsd  %xmm4,%xmm1
addsd  %xmm7,%xmm2
add    $0x2,%eax
cmp    $0xf4242,%eax
jne    11b0 <main+0x80>
mov    %r13,%rdi
mov    $0x2,%al
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1030 <puts@plt>
mov    %rbp,%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1050 <scanf@plt>
cmpl   $0x1,0xc(%rsp)
je     1170 <main+0x40>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [16 x i8] c"Please input x:\00"
@.str.1 = [4 x i8] c"%lf\00"
@.str.2 = [26 x i8] c"x=%4.2lf,func_x=%16.12lf\0A\00"
@.str.3 = [16 x i8] c"1:next 0:exit\0A\00"
@.str.4 = [3 x i8] c"%d\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca double
%5 = alloca double
store i32 0, i32* %1
store i32 1, i32* %3
br label %6
6: ; preds = %29, %0
%7 = load i32, i32* %3
%8 = icmp eq i32 %7, 1
br i1 %8, label %9, label %35
9: ; preds = %6
store double 0.000000e+00, double* %5
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%11 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), double* %4)
store i32 1, i32* %2
br label %12
12: ; preds = %26, %9
%13 = load i32, i32* %2
%14 = icmp sle i32 %13, 1000000
br i1 %14, label %15, label %29
15: ; preds = %12
%16 = load double, double* %5
%17 = load double, double* %4
%18 = load i32, i32* %2
%19 = sitofp i32 %18 to double
%20 = fadd double %17, %19
%21 = load i32, i32* %2
%22 = sitofp i32 %21 to double
%23 = fmul double %20, %22
%24 = fdiv double 1.000000e+00, %23
%25 = fadd double %16, %24
store double %25, double* %5
br label %26
26: ; preds = %15
%27 = load i32, i32* %2
%28 = add nsw i32 %27, 1
store i32 %28, i32* %2
br label %12
29: ; preds = %12
%30 = load double, double* %4
%31 = load double, double* %5
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), double %30, double %31)
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
%34 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32* %3)
br label %6
35: ; preds = %6
ret i32 0
}

LLVM IR (-O2):
@.str = [16 x i8] c"Please input x:\00"
@.str.1 = [4 x i8] c"%lf\00"
@.str.2 = [26 x i8] c"x=%4.2lf,func_x=%16.12lf\0A\00"
@.str.4 = [3 x i8] c"%d\00"
@str = [15 x i8] c"1:next 0:exit\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca double
%3 = bitcast i32* %1 to i8*
store i32 1, i32* %1
%4 = bitcast double* %2 to i8*
br label %5
5: ; preds = %0, %25
%6 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%7 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), double* %2)
%8 = load double, double* %2
br label %9
9: ; preds = %9, %5
%10 = phi double [ 0.000000e+00, %5 ], [ %22, %9 ]
%11 = phi i32 [ 1, %5 ], [ %23, %9 ]
%12 = sitofp i32 %11 to double
%13 = fadd double %8, %12
%14 = fmul double %13, %12
%15 = fdiv double 1.000000e+00, %14
%16 = fadd double %10, %15
%17 = add nuw nsw i32 %11, 1
%18 = sitofp i32 %17 to double
%19 = fadd double %8, %18
%20 = fmul double %19, %18
%21 = fdiv double 1.000000e+00, %20
%22 = fadd double %16, %21
%23 = add nuw nsw i32 %11, 2
%24 = icmp eq i32 %23, 1000001
br i1 %24, label %25, label %9
25: ; preds = %9
%26 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), double %8, double %22)
%27 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str, i64 0, i64 0))
%28 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32* %1)
%29 = load i32, i32* %1
%30 = icmp eq i32 %29, 1
br i1 %30, label %5, label %31
31: ; preds = %25
ret i32 0
}