#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*/ logarithm(double, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, ...);
int main() {
  int n;
  double x;
  printf("Enter the value of x: ");
  scanf("%lf", &x);
  printf("Enter the numbers of terms n: ");
  scanf("%d", &n);
  if (x > 0 && n > 0)
    printf("The value of log(%lf) approximated to %d terms is : %lf\n", x, n,
           logarithm(x, n));
  else
    printf("Try again\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeba(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xec3(%rip),%rdi
lea    -0x10(%rbp),%rsi
mov    $0x0,%al
call   1050 <scanf@plt>
lea    0xeb5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xec6(%rip),%rdi
lea    -0x8(%rbp),%rsi
mov    $0x0,%al
call   1050 <scanf@plt>
movsd  -0x10(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    11d5 <main+0xa5>
cmpl   $0x0,-0x8(%rbp)
jle    11d5 <main+0xa5>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x14(%rbp)
movsd  -0x10(%rbp),%xmm0
mov    -0x8(%rbp),%edi
call   1040 <logarithm@plt>
movsd  -0x20(%rbp),%xmm0
mov    -0x14(%rbp),%esi
mov    %eax,%edx
lea    0xe74(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
jmp    11e3 <main+0xb3>
lea    0xe9a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x20,%rsp
lea    0xeb4(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xebd(%rip),%rdi
lea    0x18(%rsp),%rsi
xor    %eax,%eax
call   1060 <scanf@plt>
lea    0xeae(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xebf(%rip),%rdi
lea    0xc(%rsp),%rsi
xor    %eax,%eax
call   1060 <scanf@plt>
movsd  0x18(%rsp),%xmm0
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    11c6 <main+0x86>
mov    0xc(%rsp),%ebx
test   %ebx,%ebx
jle    11c6 <main+0x86>
mov    %ebx,%edi
movsd  %xmm0,0x10(%rsp)
call   1050 <logarithm@plt>
lea    0xe8a(%rip),%rdi
movsd  0x10(%rsp),%xmm0
mov    %ebx,%esi
mov    %eax,%edx
mov    $0x1,%al
call   1040 <printf@plt>
jmp    11d2 <main+0x92>
lea    0xea9(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [23 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 numbers of terms n: \00"
@.str.3 = [3 x i8] c"%d\00"
@.str.4 = [57 x i8] c"The value of log(%lf) approximated to %d terms is : %lf\0A\00"
@.str.5 = [11 x i8] c"Try again\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca double
store i32 0, i32* %1
%4 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%5 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), double* %3)
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0))
%7 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %2)
%8 = load double, double* %3
%9 = fcmp ogt double %8, 0.000000e+00
br i1 %9, label %10, label %20
10: ; preds = %0
%11 = load i32, i32* %2
%12 = icmp sgt i32 %11, 0
br i1 %12, label %13, label %20
13: ; preds = %10
%14 = load double, double* %3
%15 = load i32, i32* %2
%16 = load double, double* %3
%17 = load i32, i32* %2
%18 = call i32 @logarithm(double %16, i32 %17)
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.4, i64 0, i64 0), double %14, i32 %15, i32 %18)
br label %22
20: ; preds = %10, %0
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0))
br label %22
22: ; preds = %20, %13
ret i32 0
}

LLVM IR (-O2):
@.str = [23 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 numbers of terms n: \00"
@.str.3 = [3 x i8] c"%d\00"
@.str.4 = [57 x i8] c"The value of log(%lf) approximated to %d terms is : %lf\0A\00"
@str = [10 x i8] c"Try again\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca double
%3 = bitcast i32* %1 to i8*
%4 = bitcast double* %2 to i8*
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%6 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), double* %2)
%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 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %1)
%9 = load double, double* %2
%10 = fcmp ogt double %9, 0.000000e+00
%11 = load i32, i32* %1
%12 = icmp sgt i32 %11, 0
%13 = select i1 %10, i1 %12, i1 false
br i1 %13, label %14, label %17
14: ; preds = %0
%15 = call i32 @logarithm(double %9, i32 %11)
%16 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([57 x i8], [57 x i8]* @.str.4, i64 0, i64 0), double %9, i32 %11, i32 %15)
br label %19
17: ; preds = %0
%18 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str, i64 0, i64 0))
br label %19
19: ; preds = %17, %14
ret i32 0
}