#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 */
scalar_t__ pow(double, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, double *);
int main() {
  double x, n;
  printf("Enter the value of x : ");
  scanf("%lf", &x);
  printf("Enter the number of terms n : ");
  scanf("%lf", &n);
  double ln_x = 0;
  int i;
  for (i = 1; i <= n; i++) {
    ln_x += pow((x - 1) * 1.0 / x, i);
  }
  printf("The value of log(%d) approximated to %d terms is : %lf\n", (int)x,
         (int)n, ln_x);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xec2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xecc(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   1040 <scanf@plt>
lea    0xec0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xeae(%rip),%rdi
lea    -0x18(%rbp),%rsi
call   1040 <scanf@plt>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
movl   $0x1,-0x24(%rbp)
cvtsi2sdl -0x24(%rbp),%xmm1
movsd  -0x18(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jb     11e5 <main+0xb5>
movsd  -0x10(%rbp),%xmm0
movsd  0xe55(%rip),%xmm1
subsd  %xmm1,%xmm0
movsd  0xe49(%rip),%xmm1
mulsd  %xmm1,%xmm0
divsd  -0x10(%rbp),%xmm0
mov    -0x24(%rbp),%edi
call   1050 <pow@plt>
cvtsi2sd %rax,%xmm0
addsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    118a <main+0x5a>
cvttsd2si -0x10(%rbp),%esi
cvttsd2si -0x18(%rbp),%edx
movsd  -0x20(%rbp),%xmm0
lea    0xe48(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x20,%rsp
lea    0xed4(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xede(%rip),%rbx
lea    0x10(%rsp),%rsi
mov    %rbx,%rdi
call   1040 <scanf@plt>
lea    0xece(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
call   1040 <scanf@plt>
movsd  0x8(%rsp),%xmm2
xorpd  %xmm0,%xmm0
ucomisd 0xe7c(%rip),%xmm2
jb     11db <main+0xab>
xorpd  %xmm0,%xmm0
mov    $0x1,%ebx
nop
movsd  %xmm0,0x18(%rsp)
movsd  0x10(%rsp),%xmm1
movapd %xmm1,%xmm0
addsd  0xe60(%rip),%xmm0
divsd  %xmm1,%xmm0
mov    %ebx,%edi
call   1050 <pow@plt>
movsd  0x18(%rsp),%xmm0
xorps  %xmm2,%xmm2
cvtsi2sd %rax,%xmm2
add    $0x1,%ebx
xorps  %xmm1,%xmm1
cvtsi2sd %ebx,%xmm1
addsd  %xmm2,%xmm0
movsd  0x8(%rsp),%xmm2
ucomisd %xmm1,%xmm2
jae    1190 <main+0x60>
cvttsd2si 0x10(%rsp),%esi
cvttsd2si %xmm2,%edx
lea    0xe5f(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [24 x i8] c"Enter the value of x : \00"
@.str.1 = [4 x i8] c"%lf\00"
@.str.2 = [31 x i8] c"Enter the number of terms n : \00"
@.str.3 = [56 x i8] c"The value of log(%d) approximated to %d terms is : %lf\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca double
%3 = alloca double
%4 = alloca double
%5 = alloca i32
store i32 0, i32* %1
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
%7 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), double* %2)
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0))
%9 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), double* %3)
store double 0.000000e+00, double* %4
store i32 1, i32* %5
br label %10
10: ; preds = %26, %0
%11 = load i32, i32* %5
%12 = sitofp i32 %11 to double
%13 = load double, double* %3
%14 = fcmp ole double %12, %13
br i1 %14, label %15, label %29
15: ; preds = %10
%16 = load double, double* %2
%17 = fsub double %16, 1.000000e+00
%18 = fmul double %17, 1.000000e+00
%19 = load double, double* %2
%20 = fdiv double %18, %19
%21 = load i32, i32* %5
%22 = call i64 @pow(double %20, i32 %21)
%23 = sitofp i64 %22 to double
%24 = load double, double* %4
%25 = fadd double %24, %23
store double %25, double* %4
br label %26
26: ; preds = %15
%27 = load i32, i32* %5
%28 = add nsw i32 %27, 1
store i32 %28, i32* %5
br label %10
29: ; preds = %10
%30 = load double, double* %2
%31 = fptosi double %30 to i32
%32 = load double, double* %3
%33 = fptosi double %32 to i32
%34 = load double, double* %4
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.3, i64 0, i64 0), i32 %31, i32 %33, double %34)
%36 = load i32, i32* %1
ret i32 %36
}

LLVM IR (-O2):
@.str = [24 x i8] c"Enter the value of x : \00"
@.str.1 = [4 x i8] c"%lf\00"
@.str.2 = [31 x i8] c"Enter the number of terms n : \00"
@.str.3 = [56 x i8] c"The value of log(%d) approximated to %d terms is : %lf\0A\00"
define i32 @main() {
%1 = alloca double
%2 = alloca double
%3 = bitcast double* %1 to i8*
%4 = bitcast double* %2 to i8*
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), double* %1)
%7 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0))
%8 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), double* %2)
%9 = load double, double* %2
%10 = fcmp ult double %9, 1.000000e+00
br i1 %10, label %24, label %11
11: ; preds = %0, %11
%12 = phi i32 [ %20, %11 ], [ 1, %0 ]
%13 = phi double [ %19, %11 ], [ 0.000000e+00, %0 ]
%14 = load double, double* %1
%15 = fadd double %14, -1.000000e+00
%16 = fdiv double %15, %14
%17 = call i64 @pow(double %16, i32 %12)
%18 = sitofp i64 %17 to double
%19 = fadd double %13, %18
%20 = add nuw nsw i32 %12, 1
%21 = sitofp i32 %20 to double
%22 = load double, double* %2
%23 = fcmp ult double %22, %21
br i1 %23, label %24, label %11
24: ; preds = %11, %0
%25 = phi double [ 0.000000e+00, %0 ], [ %19, %11 ]
%26 = phi double [ %9, %0 ], [ %22, %11 ]
%27 = load double, double* %1
%28 = fptosi double %27 to i32
%29 = fptosi double %26 to i32
%30 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([56 x i8], [56 x i8]* @.str.3, i64 0, i64 0), i32 %28, i32 %29, double %25)
ret i32 0
}