#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 factorial(int);
double fn(int, int /*<<< orphan*/);
double pow(double, int);
double P(int grado, double x) {
  double P = 0;
  int i;
  for (i = 0; i <= grado; i++) {
    P += ((fn(i, 0)) * pow(x, i)) / factorial(i);
  }
  return P;
}


x86 assembly (clang, -O0):
<P>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
movsd  %xmm0,-0x10(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x4(%rbp),%eax
jg     11b4 <P+0x84>
mov    -0x1c(%rbp),%edi
xor    %esi,%esi
call   1030 <fn@plt>
movsd  %xmm0,-0x30(%rbp)
movsd  -0x10(%rbp),%xmm0
mov    -0x1c(%rbp),%edi
call   1050 <pow@plt>
movaps %xmm0,%xmm1
movsd  -0x30(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x1c(%rbp),%edi
call   1040 <factorial@plt>
movaps %xmm0,%xmm1
movsd  -0x28(%rbp),%xmm0
divsd  %xmm1,%xmm0
addsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    114f <P+0x1f>
movsd  -0x18(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<P>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
test   %edi,%edi
js     119e <P+0x6e>
mov    %edi,%ebx
add    $0x1,%ebx
xorpd  %xmm1,%xmm1
xor    %ebp,%ebp
movsd  %xmm0,0x8(%rsp)
nopl   0x0(%rax,%rax,1)
movsd  %xmm1,0x10(%rsp)
mov    %ebp,%edi
xor    %esi,%esi
call   1030 <fn@plt>
movsd  %xmm0,(%rsp)
movsd  0x8(%rsp),%xmm0
mov    %ebp,%edi
call   1050 <pow@plt>
mulsd  (%rsp),%xmm0
movsd  %xmm0,(%rsp)
mov    %ebp,%edi
call   1040 <factorial@plt>
movsd  0x10(%rsp),%xmm1
movsd  (%rsp),%xmm2
divsd  %xmm0,%xmm2
addsd  %xmm2,%xmm1
add    $0x1,%ebp
cmp    %ebp,%ebx
jne    1150 <P+0x20>
jmp    11a2 <P+0x72>
xorpd  %xmm1,%xmm1
movapd %xmm1,%xmm0
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define double @P(i32 %0, double %1) {
%3 = alloca i32
%4 = alloca double
%5 = alloca double
%6 = alloca i32
store i32 %0, i32* %3
store double %1, double* %4
store double 0.000000e+00, double* %5
store i32 0, i32* %6
br label %7
7: ; preds = %23, %2
%8 = load i32, i32* %6
%9 = load i32, i32* %3
%10 = icmp sle i32 %8, %9
br i1 %10, label %11, label %26
11: ; preds = %7
%12 = load i32, i32* %6
%13 = call double @fn(i32 %12, i32 0)
%14 = load double, double* %4
%15 = load i32, i32* %6
%16 = call double @pow(double %14, i32 %15)
%17 = fmul double %13, %16
%18 = load i32, i32* %6
%19 = call double @factorial(i32 %18)
%20 = fdiv double %17, %19
%21 = load double, double* %5
%22 = fadd double %21, %20
store double %22, double* %5
br label %23
23: ; preds = %11
%24 = load i32, i32* %6
%25 = add nsw i32 %24, 1
store i32 %25, i32* %6
br label %7
26: ; preds = %7
%27 = load double, double* %5
ret double %27
}

LLVM IR (-O2):
define double @P(i32 %0, double %1) {
%3 = icmp slt i32 %0, 0
br i1 %3, label %15, label %4
4: ; preds = %2, %4
%5 = phi i32 [ %13, %4 ], [ 0, %2 ]
%6 = phi double [ %12, %4 ], [ 0.000000e+00, %2 ]
%7 = tail call double @fn(i32 %5, i32 0)
%8 = tail call double @pow(double %1, i32 %5)
%9 = fmul double %7, %8
%10 = tail call double @factorial(i32 %5)
%11 = fdiv double %9, %10
%12 = fadd double %6, %11
%13 = add nuw i32 %5, 1
%14 = icmp eq i32 %5, %0
br i1 %14, label %15, label %4
15: ; preds = %4, %2
%16 = phi double [ 0.000000e+00, %2 ], [ %12, %4 ]
ret double %16
}