#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*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *, ...);
int main(void) {
  int iDeg, i, iaArr[10];
  float fX, fSum = 0;
  printf("\n*******************************************************************"
         "**");
  printf("\n*\tPROGRAM TO EVALUATE A POLYNOMIAL USING HORNERS METHOD\t    *\n");
  printf(
      "*********************************************************************");
  printf("\nEnter the degree of the polynomial and value of x\n");
  scanf("%d%f", &iDeg, &fX);
  printf("\nEnter the coefficients in descending order of degree\n");
  for (i = 0; i <= iDeg; i++) {
    scanf("%d", &iaArr[i]);
  }
  for (i = 0; i < iDeg; i++) {
    fSum = (fSum + iaArr[i]) * fX;
  }
  fSum = fSum + iaArr[iDeg];
  printf("\nValue of polynomial after evaluation=%g\n", fSum);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x48(%rbp)
lea    0xec2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xefb(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xea7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xf1f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xf45(%rip),%rdi
lea    -0x8(%rbp),%rsi
lea    -0x44(%rbp),%rdx
mov    $0x0,%al
call   1040 <scanf@plt>
lea    0xf34(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jg     11d1 <main+0xb1>
movslq -0xc(%rbp),%rax
lea    -0x40(%rbp),%rsi
shl    $0x2,%rax
add    %rax,%rsi
lea    0xf3b(%rip),%rdi
mov    $0x0,%al
call   1040 <scanf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    119a <main+0x7a>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    120f <main+0xef>
movss  -0x48(%rbp),%xmm0
movslq -0xc(%rbp),%rax
cvtsi2ssl -0x40(%rbp,%rax,4),%xmm1
addss  %xmm1,%xmm0
mulss  -0x44(%rbp),%xmm0
movss  %xmm0,-0x48(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11d8 <main+0xb8>
movss  -0x48(%rbp),%xmm0
movslq -0x8(%rbp),%rax
cvtsi2ssl -0x40(%rbp,%rax,4),%xmm1
addss  %xmm1,%xmm0
movss  %xmm0,-0x48(%rbp)
movss  -0x48(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xec3(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x40,%rsp
lea    0xec0(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xf2b(%rip),%rdi
call   1030 <puts@plt>
lea    0xea7(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xf50(%rip),%rdi
call   1030 <puts@plt>
lea    0xed3(%rip),%rdi
lea    0x8(%rsp),%rsi
lea    0xc(%rsp),%rdx
xor    %eax,%eax
call   1050 <scanf@plt>
lea    0xf5f(%rip),%rdi
call   1030 <puts@plt>
mov    0x8(%rsp),%eax
xorps  %xmm3,%xmm3
test   %eax,%eax
js     1299 <main+0x169>
mov    $0xffffffffffffffff,%r15
lea    0x10(%rsp),%rbx
lea    0xe99(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <scanf@plt>
movslq 0x8(%rsp),%rax
add    $0x1,%r15
add    $0x4,%rbx
cmp    %rax,%r15
jl     11c0 <main+0x90>
test   %eax,%eax
jle    1201 <main+0xd1>
mov    %eax,%edx
movss  0xc(%rsp),%xmm0
lea    -0x1(%rdx),%rsi
mov    %edx,%ecx
and    $0x3,%ecx
cmp    $0x3,%rsi
jae    1209 <main+0xd9>
xorps  %xmm3,%xmm3
xor    %esi,%esi
jmp    126d <main+0x13d>
xorps  %xmm3,%xmm3
jmp    1299 <main+0x169>
and    $0xfffffffc,%edx
xorps  %xmm3,%xmm3
xor    %esi,%esi
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
xorps  %xmm1,%xmm1
cvtsi2ssl 0x10(%rsp,%rsi,4),%xmm1
xorps  %xmm2,%xmm2
cvtsi2ssl 0x14(%rsp,%rsi,4),%xmm2
addss  %xmm3,%xmm1
mulss  %xmm0,%xmm1
addss  %xmm1,%xmm2
mulss  %xmm0,%xmm2
xorps  %xmm1,%xmm1
cvtsi2ssl 0x18(%rsp,%rsi,4),%xmm1
addss  %xmm2,%xmm1
mulss  %xmm0,%xmm1
xorps  %xmm3,%xmm3
cvtsi2ssl 0x1c(%rsp,%rsi,4),%xmm3
addss  %xmm1,%xmm3
mulss  %xmm0,%xmm3
add    $0x4,%rsi
cmp    %rsi,%rdx
jne    1220 <main+0xf0>
test   %rcx,%rcx
je     1299 <main+0x169>
lea    (%rsp,%rsi,4),%rdx
add    $0x10,%rdx
xor    %esi,%esi
nopl   0x0(%rax)
xorps  %xmm1,%xmm1
cvtsi2ssl (%rdx,%rsi,4),%xmm1
addss  %xmm1,%xmm3
mulss  %xmm0,%xmm3
add    $0x1,%rsi
cmp    %rsi,%rcx
jne    1280 <main+0x150>
cltq
xorps  %xmm0,%xmm0
cvtsi2ssl 0x10(%rsp,%rax,4),%xmm0
addss  %xmm3,%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xd9c(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [71 x i8] c"\0A*********************************************************************\00"
@.str.1 = [64 x i8] c"\0A*\09PROGRAM TO EVALUATE A POLYNOMIAL USING HORNERS METHOD\09 *\0A\00"
@.str.2 = [70 x i8] c"*********************************************************************\00"
@.str.3 = [52 x i8] c"\0AEnter the degree of the polynomial and value of x\0A\00"
@.str.4 = [5 x i8] c"%d%f\00"
@.str.5 = [55 x i8] c"\0AEnter the coefficients in descending order of degree\0A\00"
@.str.6 = [3 x i8] c"%d\00"
@.str.7 = [42 x i8] c"\0AValue of polynomial after evaluation=%g\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca [10 x i32]
%5 = alloca float
%6 = alloca float
store i32 0, i32* %1
store float 0.000000e+00, float* %6
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([71 x i8], [71 x i8]* @.str, i64 0, i64 0))
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str.1, i64 0, i64 0))
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([70 x i8], [70 x i8]* @.str.2, i64 0, i64 0))
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.3, i64 0, i64 0))
%11 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32* %2, float* %5)
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.5, i64 0, i64 0))
store i32 0, i32* %3
br label %13
13: ; preds = %22, %0
%14 = load i32, i32* %3
%15 = load i32, i32* %2
%16 = icmp sle i32 %14, %15
br i1 %16, label %17, label %25
17: ; preds = %13
%18 = load i32, i32* %3
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds [10 x i32], [10 x i32]* %4, i64 0, i64 %19
%21 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i32* %20)
br label %22
22: ; preds = %17
%23 = load i32, i32* %3
%24 = add nsw i32 %23, 1
store i32 %24, i32* %3
br label %13
25: ; preds = %13
store i32 0, i32* %3
br label %26
26: ; preds = %40, %25
%27 = load i32, i32* %3
%28 = load i32, i32* %2
%29 = icmp slt i32 %27, %28
br i1 %29, label %30, label %43
30: ; preds = %26
%31 = load float, float* %6
%32 = load i32, i32* %3
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds [10 x i32], [10 x i32]* %4, i64 0, i64 %33
%35 = load i32, i32* %34
%36 = sitofp i32 %35 to float
%37 = fadd float %31, %36
%38 = load float, float* %5
%39 = fmul float %37, %38
store float %39, float* %6
br label %40
40: ; preds = %30
%41 = load i32, i32* %3
%42 = add nsw i32 %41, 1
store i32 %42, i32* %3
br label %26
43: ; preds = %26
%44 = load float, float* %6
%45 = load i32, i32* %2
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds [10 x i32], [10 x i32]* %4, i64 0, i64 %46
%48 = load i32, i32* %47
%49 = sitofp i32 %48 to float
%50 = fadd float %44, %49
store float %50, float* %6
%51 = load float, float* %6
%52 = fpext float %51 to double
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.7, i64 0, i64 0), double %52)
ret i32 0
}

LLVM IR (-O2):
@.str = [71 x i8] c"\0A*********************************************************************\00"
@.str.2 = [70 x i8] c"*********************************************************************\00"
@.str.4 = [5 x i8] c"%d%f\00"
@.str.6 = [3 x i8] c"%d\00"
@.str.7 = [42 x i8] c"\0AValue of polynomial after evaluation=%g\0A\00"
@str = [63 x i8] c"\0A*\09PROGRAM TO EVALUATE A POLYNOMIAL USING HORNERS METHOD\09 *\00"
@str.8 = [51 x i8] c"\0AEnter the degree of the polynomial and value of x\00"
@str.9 = [54 x i8] c"\0AEnter the coefficients in descending order of degree\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [10 x i32]
%3 = alloca float
%4 = bitcast i32* %1 to i8*
%5 = bitcast [10 x i32]* %2 to i8*
%6 = bitcast float* %3 to i8*
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([71 x i8], [71 x i8]* @.str, i64 0, i64 0))
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([63 x i8], [63 x i8]* @str, i64 0, i64 0))
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([70 x i8], [70 x i8]* @.str.2, i64 0, i64 0))
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([51 x i8], [51 x i8]* @str.8, i64 0, i64 0))
%11 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32* %1, float* %3)
%12 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([54 x i8], [54 x i8]* @str.9, i64 0, i64 0))
%13 = load i32, i32* %1
%14 = icmp slt i32 %13, 0
br i1 %14, label %80, label %25
15: ; preds = %25
%16 = icmp sgt i32 %30, 0
br i1 %16, label %17, label %80
17: ; preds = %15
%18 = load float, float* %3
%19 = zext i32 %30 to i64
%20 = add nsw i64 %19, -1
%21 = and i64 %19, 3
%22 = icmp ult i64 %20, 3
br i1 %22, label %63, label %23
23: ; preds = %17
%24 = and i64 %19, 4294967292
br label %33
25: ; preds = %0, %25
%26 = phi i64 [ %29, %25 ], [ 0, %0 ]
%27 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 %26
%28 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i32* %27)
%29 = add nuw nsw i64 %26, 1
%30 = load i32, i32* %1
%31 = sext i32 %30 to i64
%32 = icmp slt i64 %26, %31
br i1 %32, label %25, label %15
33: ; preds = %33, %23
%34 = phi i64 [ 0, %23 ], [ %60, %33 ]
%35 = phi float [ 0.000000e+00, %23 ], [ %59, %33 ]
%36 = phi i64 [ 0, %23 ], [ %61, %33 ]
%37 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 %34
%38 = load i32, i32* %37
%39 = sitofp i32 %38 to float
%40 = fadd float %35, %39
%41 = fmul float %18, %40
%42 = or i64 %34, 1
%43 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 %42
%44 = load i32, i32* %43
%45 = sitofp i32 %44 to float
%46 = fadd float %41, %45
%47 = fmul float %18, %46
%48 = or i64 %34, 2
%49 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 %48
%50 = load i32, i32* %49
%51 = sitofp i32 %50 to float
%52 = fadd float %47, %51
%53 = fmul float %18, %52
%54 = or i64 %34, 3
%55 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 %54
%56 = load i32, i32* %55
%57 = sitofp i32 %56 to float
%58 = fadd float %53, %57
%59 = fmul float %18, %58
%60 = add nuw nsw i64 %34, 4
%61 = add i64 %36, 4
%62 = icmp eq i64 %61, %24
br i1 %62, label %63, label %33
63: ; preds = %33, %17
%64 = phi float [ undef, %17 ], [ %59, %33 ]
%65 = phi i64 [ 0, %17 ], [ %60, %33 ]
%66 = phi float [ 0.000000e+00, %17 ], [ %59, %33 ]
%67 = icmp eq i64 %21, 0
br i1 %67, label %80, label %68
68: ; preds = %63, %68
%69 = phi i64 [ %77, %68 ], [ %65, %63 ]
%70 = phi float [ %76, %68 ], [ %66, %63 ]
%71 = phi i64 [ %78, %68 ], [ 0, %63 ]
%72 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 %69
%73 = load i32, i32* %72
%74 = sitofp i32 %73 to float
%75 = fadd float %70, %74
%76 = fmul float %18, %75
%77 = add nuw nsw i64 %69, 1
%78 = add i64 %71, 1
%79 = icmp eq i64 %78, %21
br i1 %79, label %80, label %68
80: ; preds = %63, %68, %0, %15
%81 = phi i32 [ %30, %15 ], [ %13, %0 ], [ %30, %68 ], [ %30, %63 ]
%82 = phi float [ 0.000000e+00, %15 ], [ 0.000000e+00, %0 ], [ %64, %63 ], [ %76, %68 ]
%83 = sext i32 %81 to i64
%84 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 %83
%85 = load i32, i32* %84
%86 = sitofp i32 %85 to float
%87 = fadd float %82, %86
%88 = fpext float %87 to double
%89 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str.7, i64 0, i64 0), double %88)
ret i32 0
}