#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 log(double);
double log10(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, ...);
void Logarithm() {
  int input, output;
  double i, x;
  printf("1-Compute log base 10 \n2- calculate natural logarithm \n3-Custom "
         "Log \n\n Enter Choice\n>>");
  scanf("%d", &input);
  if (input == 1) {
    printf("Enter Number\n\n>>");
    scanf("%d", &input);
    printf("Logarithm %d to the base 10 = %f", input, log10(input));
  } else if (input == 2) {
    printf("Enter Number\n\n>>");
    scanf("%d", &input);
    printf("Logarithm %d to the base e = %f", input, log(input));
  } else if (input == 3) {
    printf("Enter base\n\n>>");
    scanf("%d", &input);
    printf("Enter number\n\n>>");
    scanf("%d", &x);
    i = log(input) / log(x);
    printf("Logarithm %d to the base e = %f", input, log(i));
  }
}


x86 assembly (clang, -O0):
<Logarithm>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
lea    0xeb1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xefa(%rip),%rdi
lea    -0x4(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
cmpl   $0x1,-0x4(%rbp)
jne    11b6 <Logarithm+0x76>
lea    0xee1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xed0(%rip),%rdi
lea    -0x4(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
mov    -0x4(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x4(%rbp),%edi
call   1060 <log10@plt>
mov    -0x1c(%rbp),%esi
lea    0xec1(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
jmp    12a5 <Logarithm+0x165>
cmpl   $0x2,-0x4(%rbp)
jne    1206 <Logarithm+0xc6>
lea    0xe93(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe82(%rip),%rdi
lea    -0x4(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
mov    -0x4(%rbp),%eax
mov    %eax,-0x20(%rbp)
cvtsi2sdl -0x4(%rbp),%xmm0
call   1050 <log@plt>
mov    -0x20(%rbp),%esi
lea    0xe92(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
jmp    12a0 <Logarithm+0x160>
cmpl   $0x3,-0x4(%rbp)
jne    129b <Logarithm+0x15b>
lea    0xe95(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe32(%rip),%rdi
lea    -0x4(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
lea    0xe84(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe12(%rip),%rdi
lea    -0x18(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
cvtsi2sdl -0x4(%rbp),%xmm0
call   1050 <log@plt>
movsd  %xmm0,-0x30(%rbp)
movsd  -0x18(%rbp),%xmm0
call   1050 <log@plt>
movaps %xmm0,%xmm1
movsd  -0x30(%rbp),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x24(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1050 <log@plt>
mov    -0x24(%rbp),%esi
lea    0xdf8(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
jmp    12a0 <Logarithm+0x160>
jmp    12a5 <Logarithm+0x165>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Logarithm>:
push   %rbx
sub    $0x20,%rsp
lea    0xeb4(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xefd(%rip),%rdi
lea    0xc(%rsp),%rsi
xor    %eax,%eax
call   1040 <scanf@plt>
mov    0xc(%rsp),%eax
cmp    $0x3,%eax
je     11b9 <Logarithm+0x79>
cmp    $0x2,%eax
je     122a <Logarithm+0xea>
cmp    $0x1,%eax
jne    1268 <Logarithm+0x128>
lea    0xed2(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xec1(%rip),%rdi
lea    0xc(%rsp),%rsi
xor    %eax,%eax
call   1040 <scanf@plt>
mov    0xc(%rsp),%ebx
mov    %ebx,%edi
call   1060 <log10@plt>
lea    0xeb7(%rip),%rdi
jmp    125f <Logarithm+0x11f>
lea    0xeec(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xe89(%rip),%rbx
lea    0xc(%rsp),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <scanf@plt>
lea    0xed7(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0x18(%rsp),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <scanf@plt>
cvtsi2sdl 0xc(%rsp),%xmm0
call   1050 <log@plt>
movsd  %xmm0,0x10(%rsp)
movsd  0x18(%rsp),%xmm0
call   1050 <log@plt>
movsd  0x10(%rsp),%xmm1
divsd  %xmm0,%xmm1
mov    0xc(%rsp),%ebx
movapd %xmm1,%xmm0
jmp    1253 <Logarithm+0x113>
lea    0xe29(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xe18(%rip),%rdi
lea    0xc(%rsp),%rsi
xor    %eax,%eax
call   1040 <scanf@plt>
mov    0xc(%rsp),%ebx
cvtsi2sd %ebx,%xmm0
call   1050 <log@plt>
lea    0xe2d(%rip),%rdi
mov    %ebx,%esi
mov    $0x1,%al
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [87 x i8] c"1-Compute log base 10 \0A2- calculate natural logarithm \0A3-Custom Log \0A\0A Enter Choice\0A>>\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [17 x i8] c"Enter Number\0A\0A>>\00"
@.str.3 = [33 x i8] c"Logarithm %d to the base 10 = %f\00"
@.str.4 = [32 x i8] c"Logarithm %d to the base e = %f\00"
@.str.5 = [15 x i8] c"Enter base\0A\0A>>\00"
@.str.6 = [17 x i8] c"Enter number\0A\0A>>\00"
define void @Logarithm() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca double
%4 = alloca double
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([87 x i8], [87 x i8]* @.str, i64 0, i64 0))
%6 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%7 = load i32, i32* %1
%8 = icmp eq i32 %7, 1
br i1 %8, label %9, label %16
9: ; preds = %0
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
%11 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%12 = load i32, i32* %1
%13 = load i32, i32* %1
%14 = call double @log10(i32 %13)
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0), i32 %12, double %14)
br label %47
16: ; preds = %0
%17 = load i32, i32* %1
%18 = icmp eq i32 %17, 2
br i1 %18, label %19, label %27
19: ; preds = %16
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
%21 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%22 = load i32, i32* %1
%23 = load i32, i32* %1
%24 = sitofp i32 %23 to double
%25 = call double @log(double %24)
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0), i32 %22, double %25)
br label %46
27: ; preds = %16
%28 = load i32, i32* %1
%29 = icmp eq i32 %28, 3
br i1 %29, label %30, label %45
30: ; preds = %27
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0))
%32 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0))
%34 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), double* %4)
%35 = load i32, i32* %1
%36 = sitofp i32 %35 to double
%37 = call double @log(double %36)
%38 = load double, double* %4
%39 = call double @log(double %38)
%40 = fdiv double %37, %39
store double %40, double* %3
%41 = load i32, i32* %1
%42 = load double, double* %3
%43 = call double @log(double %42)
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0), i32 %41, double %43)
br label %45
45: ; preds = %30, %27
br label %46
46: ; preds = %45, %19
br label %47
47: ; preds = %46, %9
ret void
}

LLVM IR (-O2):
@.str = [87 x i8] c"1-Compute log base 10 \0A2- calculate natural logarithm \0A3-Custom Log \0A\0A Enter Choice\0A>>\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [17 x i8] c"Enter Number\0A\0A>>\00"
@.str.3 = [33 x i8] c"Logarithm %d to the base 10 = %f\00"
@.str.4 = [32 x i8] c"Logarithm %d to the base e = %f\00"
@.str.5 = [15 x i8] c"Enter base\0A\0A>>\00"
@.str.6 = [17 x i8] c"Enter number\0A\0A>>\00"
define void @Logarithm() {
%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 ([87 x i8], [87 x i8]* @.str, i64 0, i64 0))
%6 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%7 = load i32, i32* %1
switch i32 %7, label %35 [
i32 1, label %8
i32 2, label %14
i32 3, label %21
]
8: ; preds = %0
%9 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
%10 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%11 = load i32, i32* %1
%12 = call double @log10(i32 %11)
%13 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0), i32 %11, double %12)
br label %35
14: ; preds = %0
%15 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
%16 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%17 = load i32, i32* %1
%18 = sitofp i32 %17 to double
%19 = call double @log(double %18)
%20 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0), i32 %17, double %19)
br label %35
21: ; preds = %0
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0))
%23 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0))
%25 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), double* %2)
%26 = load i32, i32* %1
%27 = sitofp i32 %26 to double
%28 = call double @log(double %27)
%29 = load double, double* %2
%30 = call double @log(double %29)
%31 = fdiv double %28, %30
%32 = load i32, i32* %1
%33 = call double @log(double %31)
%34 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0), i32 %32, double %33)
br label %35
35: ; preds = %0, %14, %21, %8
ret void
}