#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 */
float factorial(int);
scalar_t__ power(int, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *, int *);
int main(void) {
  int x, i, n;
  float E_x = 1;
  printf("Enter the values of x and n: ");
  scanf("%d%d", &x, &n);
  for (i = 1; i <= n; i++)
    E_x += (float)power(x, i) / factorial(i);
  printf("The results of this calculation is: \n");
  printf("\t\tE^x = %f\n", E_x);
  printf("\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movss  0xea9(%rip),%xmm0
movss  %xmm0,-0x14(%rbp)
lea    0xea1(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xeb1(%rip),%rdi
lea    -0x8(%rbp),%rsi
lea    -0x10(%rbp),%rdx
call   1060 <scanf@plt>
movl   $0x1,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
jg     11d2 <main+0x92>
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1030 <power@plt>
cvtsi2ss %rax,%xmm0
movss  %xmm0,-0x18(%rbp)
mov    -0xc(%rbp),%edi
call   1040 <factorial@plt>
movaps %xmm0,%xmm1
movss  -0x18(%rbp),%xmm0
divss  %xmm1,%xmm0
addss  -0x14(%rbp),%xmm0
movss  %xmm0,-0x14(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1185 <main+0x45>
lea    0xe4e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movss  -0x14(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xe5d(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
lea    0xe4d(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x20,%rsp
lea    0xea0(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xeae(%rip),%rdi
lea    0x1c(%rsp),%rsi
lea    0xc(%rsp),%rdx
call   1080 <scanf@plt>
cmpl   $0x0,0xc(%rsp)
jle    11e9 <main+0x89>
movss  0xe6e(%rip),%xmm0
nopw   0x0(%rax,%rax,1)
movss  %xmm0,0x10(%rsp)
add    $0x1,%ebx
mov    0x1c(%rsp),%edi
mov    %ebx,%esi
call   1040 <power@plt>
xorps  %xmm0,%xmm0
cvtsi2ss %rax,%xmm0
movss  %xmm0,0x18(%rsp)
mov    %ebx,%edi
call   1060 <factorial@plt>
movss  0x18(%rsp),%xmm1
divss  %xmm0,%xmm1
movss  0x10(%rsp),%xmm0
addss  %xmm1,%xmm0
cmp    0xc(%rsp),%ebx
jl     11a0 <main+0x40>
cvtss2sd %xmm0,%xmm0
jmp    11f1 <main+0x91>
movsd  0xe0f(%rip),%xmm0
movsd  %xmm0,0x10(%rsp)
lea    0xe3d(%rip),%rdi
call   1050 <puts@plt>
lea    0xe25(%rip),%rdi
movsd  0x10(%rsp),%xmm0
mov    $0x1,%al
call   1070 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [30 x i8] c"Enter the values of x and n: \00"
@.str.1 = [5 x i8] c"%d%d\00"
@.str.2 = [38 x i8] c"The results of this calculation is: \0A\00"
@.str.3 = [12 x i8] c"\09\09E^x = %f\0A\00"
@.str.4 = [2 x i8] c"\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca float
store i32 0, i32* %1
store float 1.000000e+00, float* %5
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
%7 = call i32 @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32* %2, i32* %4)
store i32 1, i32* %3
br label %8
8: ; preds = %22, %0
%9 = load i32, i32* %3
%10 = load i32, i32* %4
%11 = icmp sle i32 %9, %10
br i1 %11, label %12, label %25
12: ; preds = %8
%13 = load i32, i32* %2
%14 = load i32, i32* %3
%15 = call i64 @power(i32 %13, i32 %14)
%16 = sitofp i64 %15 to float
%17 = load i32, i32* %3
%18 = call float @factorial(i32 %17)
%19 = fdiv float %16, %18
%20 = load float, float* %5
%21 = fadd float %20, %19
store float %21, float* %5
br label %22
22: ; preds = %12
%23 = load i32, i32* %3
%24 = add nsw i32 %23, 1
store i32 %24, i32* %3
br label %8
25: ; preds = %8
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0))
%27 = load float, float* %5
%28 = fpext float %27 to double
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), double %28)
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str = [30 x i8] c"Enter the values of x and n: \00"
@.str.1 = [5 x i8] c"%d%d\00"
@.str.3 = [12 x i8] c"\09\09E^x = %f\0A\00"
@str = [37 x i8] c"The results of this calculation is: \00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = bitcast i32* %1 to i8*
%4 = bitcast i32* %2 to i8*
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32* %1, i32* %2)
%7 = load i32, i32* %2
%8 = icmp slt i32 %7, 1
br i1 %8, label %23, label %9
9: ; preds = %0, %9
%10 = phi float [ %17, %9 ], [ 1.000000e+00, %0 ]
%11 = phi i32 [ %18, %9 ], [ 1, %0 ]
%12 = load i32, i32* %1
%13 = call i64 @power(i32 %12, i32 %11)
%14 = sitofp i64 %13 to float
%15 = call float @factorial(i32 %11)
%16 = fdiv float %14, %15
%17 = fadd float %10, %16
%18 = add nuw nsw i32 %11, 1
%19 = load i32, i32* %2
%20 = icmp slt i32 %11, %19
br i1 %20, label %9, label %21
21: ; preds = %9
%22 = fpext float %17 to double
br label %23
23: ; preds = %21, %0
%24 = phi double [ 1.000000e+00, %0 ], [ %22, %21 ]
%25 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @str, i64 0, i64 0))
%26 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), double %24)
%27 = call i32 @putchar(i32 10)
ret i32 0
}