#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 calc_factorial(int);
double pow(float, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int main(void) {
  int terms = 20;
  float eular = 0;
  int counter = 0;
  int power = 0;
  printf("Please Enter  the power  to calculate Eular:");
  scanf("%d", &power);
  for (counter = 0; counter < terms; counter++) {
    eular = eular + 1. / calc_factorial(counter);
  }
  printf("\nEular constant is equal to:%f\n", pow(eular, power));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x14,-0x8(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
lea    0xe95(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xeb4(%rip),%rdi
lea    -0x14(%rbp),%rsi
call   1050 <scanf@plt>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11e3 <main+0xa3>
movss  -0xc(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x10(%rbp),%edi
call   1040 <calc_factorial@plt>
movsd  -0x20(%rbp),%xmm0
cvtsi2sd %eax,%xmm2
movsd  0xe3c(%rip),%xmm1
divsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0xc(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1191 <main+0x51>
movss  -0xc(%rbp),%xmm0
mov    -0x14(%rbp),%edi
call   1060 <pow@plt>
lea    0xe41(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
movl   $0x0,0x4(%rsp)
lea    0xeb4(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xed1(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1050 <scanf@plt>
xorps  %xmm0,%xmm0
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
cvtss2sd %xmm0,%xmm0
movsd  %xmm0,0x8(%rsp)
mov    %ebx,%edi
call   1040 <calc_factorial@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movsd  0xe60(%rip),%xmm1
divsd  %xmm0,%xmm1
addsd  0x8(%rsp),%xmm1
xorps  %xmm0,%xmm0
cvtsd2ss %xmm1,%xmm0
add    $0x1,%ebx
cmp    $0x14,%ebx
jne    1180 <main+0x40>
mov    0x4(%rsp),%edi
call   1060 <pow@plt>
lea    0xe6f(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [45 x i8] c"Please Enter the power to calculate Eular:\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [32 x i8] c"\0AEular constant is equal to:%f\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca float
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
store i32 20, i32* %2
store float 0.000000e+00, float* %3
store i32 0, i32* %4
store i32 0, i32* %5
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 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* %5)
store i32 0, i32* %4
br label %8
8: ; preds = %21, %0
%9 = load i32, i32* %4
%10 = load i32, i32* %2
%11 = icmp slt i32 %9, %10
br i1 %11, label %12, label %24
12: ; preds = %8
%13 = load float, float* %3
%14 = fpext float %13 to double
%15 = load i32, i32* %4
%16 = call i32 @calc_factorial(i32 %15)
%17 = sitofp i32 %16 to double
%18 = fdiv double 1.000000e+00, %17
%19 = fadd double %14, %18
%20 = fptrunc double %19 to float
store float %20, float* %3
br label %21
21: ; preds = %12
%22 = load i32, i32* %4
%23 = add nsw i32 %22, 1
store i32 %23, i32* %4
br label %8
24: ; preds = %8
%25 = load float, float* %3
%26 = load i32, i32* %5
%27 = call double @pow(float %25, i32 %26)
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), double %27)
ret i32 0
}

LLVM IR (-O2):
@.str = [45 x i8] c"Please Enter the power to calculate Eular:\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [32 x i8] c"\0AEular constant is equal to:%f\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
store i32 0, i32* %1
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 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)
br label %5
5: ; preds = %0, %5
%6 = phi i32 [ 0, %0 ], [ %14, %5 ]
%7 = phi float [ 0.000000e+00, %0 ], [ %13, %5 ]
%8 = fpext float %7 to double
%9 = call i32 @calc_factorial(i32 %6)
%10 = sitofp i32 %9 to double
%11 = fdiv double 1.000000e+00, %10
%12 = fadd double %11, %8
%13 = fptrunc double %12 to float
%14 = add nuw nsw i32 %6, 1
%15 = icmp eq i32 %14, 20
br i1 %15, label %16, label %5
16: ; preds = %5
%17 = load i32, i32* %1
%18 = call double @pow(float %13, i32 %17)
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), double %18)
ret i32 0
}