#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*/ eulsum(float *, float, int, float *);
int /*<<< orphan*/ free_vector(float *, int, int);
double log(double);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
float *vector(int, int);
int main(void) {
  int i, j, mval;
  float sum, term, x, xpower, *wksp;
  wksp = vector(1, 40);
  for (;;) {
    printf("\nHow many terms in polynomial?\n");
    printf("Enter n between 1 and %2d. (n=0 to end) ", 40);
    scanf("%d", &mval);
    printf("\n");
    if ((mval <= 0) || (mval > 40))
      break;
    printf("%9s %14s %14s\n", "x", "actual", "polynomial");
    for (i = -8; i <= 8; i++) {
      x = i / 10.0;
      sum = 0.0;
      xpower = -1;
      for (j = 1; j <= mval; j++) {
        xpower *= (-x);
        term = xpower / j;
        eulsum(&sum, term, j, wksp);
      }
      printf("%12.6f %12.6f %12.6f\n", x, log(1.0 + x), sum);
    }
  }
  free_vector(wksp, 1, 40);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x1,%edi
mov    $0x28,%esi
call   1060 <vector@plt>
mov    %rax,-0x28(%rbp)
lea    0xe8f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xea1(%rip),%rdi
mov    $0x28,%esi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xeb7(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   1070 <scanf@plt>
lea    0xe7c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0x0,-0x10(%rbp)
jle    11d5 <main+0x75>
cmpl   $0x28,-0x10(%rbp)
jle    11da <main+0x7a>
jmp    12fc <main+0x19c>
lea    0xe83(%rip),%rdi
lea    0xe8b(%rip),%rsi
lea    0xe86(%rip),%rdx
lea    0xe86(%rip),%rcx
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xfffffff8,-0x8(%rbp)
cmpl   $0x8,-0x8(%rbp)
jg     12f7 <main+0x197>
cvtsi2sdl -0x8(%rbp),%xmm0
movsd  0xded(%rip),%xmm1
divsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x1c(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x14(%rbp)
movss  0xdc8(%rip),%xmm0
movss  %xmm0,-0x20(%rbp)
movl   $0x1,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
jg     12a2 <main+0x142>
movss  -0x1c(%rbp),%xmm0
movd   %xmm0,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm0
mulss  -0x20(%rbp),%xmm0
movss  %xmm0,-0x20(%rbp)
movss  -0x20(%rbp),%xmm0
cvtsi2ssl -0xc(%rbp),%xmm1
divss  %xmm1,%xmm0
movss  %xmm0,-0x18(%rbp)
movss  -0x18(%rbp),%xmm0
mov    -0xc(%rbp),%esi
mov    -0x28(%rbp),%rdx
lea    -0x14(%rbp),%rdi
call   1050 <eulsum@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1244 <main+0xe4>
movss  -0x1c(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  %xmm0,-0x30(%rbp)
movss  -0x1c(%rbp),%xmm0
cvtss2sd %xmm0,%xmm1
movsd  0xd4f(%rip),%xmm0
addsd  %xmm1,%xmm0
call   1080 <log@plt>
movaps %xmm0,%xmm1
movsd  -0x30(%rbp),%xmm0
movss  -0x14(%rbp),%xmm2
cvtss2sd %xmm2,%xmm2
lea    0xda5(%rip),%rdi
mov    $0x3,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1204 <main+0xa4>
jmp    1182 <main+0x22>
mov    -0x28(%rbp),%rdi
mov    $0x1,%esi
mov    $0x28,%edx
call   1040 <free_vector@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    $0x1,%edi
mov    $0x28,%esi
call   1080 <vector@plt>
mov    %rax,%rbx
lea    0xef2(%rip),%rdi
call   1040 <puts@plt>
lea    0xe81(%rip),%rdi
mov    $0x28,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe97(%rip),%rdi
lea    0x8(%rsp),%rsi
call   1090 <scanf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    0x8(%rsp),%eax
add    $0xffffffd7,%eax
cmp    $0xffffffd8,%eax
jae    1209 <main+0x89>
mov    %rbx,%rdi
mov    $0x1,%esi
mov    $0x28,%edx
call   1060 <free_vector@plt>
xor    %eax,%eax
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe73(%rip),%rbp
lea    0x8(%rsp),%r13
lea    0xc(%rsp),%r14
jmp    1264 <main+0xe4>
nopl   0x0(%rax)
lea    0xe72(%rip),%rdi
call   1040 <puts@plt>
lea    0xe01(%rip),%rdi
mov    $0x28,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe17(%rip),%rdi
mov    %r13,%rsi
call   1090 <scanf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    0x8(%rsp),%eax
add    $0xffffffd7,%eax
cmp    $0xffffffd8,%eax
jb     11e6 <main+0x66>
lea    0xdf5(%rip),%rdi
lea    0xdfd(%rip),%rsi
lea    0xdf8(%rip),%rdx
lea    0xdf8(%rip),%rcx
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xfffffff8,%r12d
movsd  0xd6b(%rip),%xmm0
jmp    12fd <main+0x17d>
nopw   0x0(%rax,%rax,1)
movaps 0x20(%rsp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  %xmm0,0x10(%rsp)
movsd  0xd59(%rip),%xmm1
addsd  %xmm1,%xmm0
call   10a0 <log@plt>
movapd %xmm0,%xmm1
movss  0xc(%rsp),%xmm0
xorps  %xmm2,%xmm2
cvtss2sd %xmm0,%xmm2
mov    %rbp,%rdi
movsd  0x10(%rsp),%xmm0
mov    $0x3,%al
call   1050 <printf@plt>
movsd  0x18(%rsp),%xmm0
addsd  0xd21(%rip),%xmm0
add    $0x1,%r12d
cmp    $0x9,%r12d
je     1220 <main+0xa0>
movsd  %xmm0,0x18(%rsp)
divsd  0xcfd(%rip),%xmm0
cvtsd2ss %xmm0,%xmm0
movaps %xmm0,0x20(%rsp)
movl   $0x0,0xc(%rsp)
cmpl   $0x0,0x8(%rsp)
jle    12a0 <main+0x120>
movaps 0x20(%rsp),%xmm0
xorps  0xced(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
xor    %r15d,%r15d
movss  0xced(%rip),%xmm0
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    $0x1,%r15d
mulss  0x30(%rsp),%xmm0
movss  %xmm0,0x10(%rsp)
xorps  %xmm1,%xmm1
cvtsi2ss %r15d,%xmm1
movss  0x10(%rsp),%xmm0
divss  %xmm1,%xmm0
mov    %r14,%rdi
mov    %r15d,%esi
mov    %rbx,%rdx
call   1070 <eulsum@plt>
movss  0x10(%rsp),%xmm0
cmp    0x8(%rsp),%r15d
jl     1350 <main+0x1d0>
jmp    12a0 <main+0x120>

LLVM IR (-O0):
@.str = [32 x i8] c"\0AHow many terms in polynomial?\0A\00"
@.str.1 = [41 x i8] c"Enter n between 1 and %2d. (n=0 to end) \00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [2 x i8] c"\0A\00"
@.str.4 = [15 x i8] c"%9s %14s %14s\0A\00"
@.str.5 = [2 x i8] c"x\00"
@.str.6 = [7 x i8] c"actual\00"
@.str.7 = [11 x i8] c"polynomial\00"
@.str.8 = [22 x i8] c"%12.6f %12.6f %12.6f\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca float
%6 = alloca float
%7 = alloca float
%8 = alloca float
%9 = alloca float*
store i32 0, i32* %1
%10 = call float* @vector(i32 1, i32 40)
store float* %10, float** %9
br label %11
11: ; preds = %65, %0
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0), i32 40)
%14 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %4)
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%16 = load i32, i32* %4
%17 = icmp sle i32 %16, 0
br i1 %17, label %21, label %18
18: ; preds = %11
%19 = load i32, i32* %4
%20 = icmp sgt i32 %19, 40
br i1 %20, label %21, label %22
21: ; preds = %18, %11
br label %66
22: ; preds = %18
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.7, i64 0, i64 0))
store i32 -8, i32* %2
br label %24
24: ; preds = %62, %22
%25 = load i32, i32* %2
%26 = icmp sle i32 %25, 8
br i1 %26, label %27, label %65
27: ; preds = %24
%28 = load i32, i32* %2
%29 = sitofp i32 %28 to double
%30 = fdiv double %29, 1.000000e+01
%31 = fptrunc double %30 to float
store float %31, float* %7
store float 0.000000e+00, float* %5
store float -1.000000e+00, float* %8
store i32 1, i32* %3
br label %32
32: ; preds = %49, %27
%33 = load i32, i32* %3
%34 = load i32, i32* %4
%35 = icmp sle i32 %33, %34
br i1 %35, label %36, label %52
36: ; preds = %32
%37 = load float, float* %7
%38 = fneg float %37
%39 = load float, float* %8
%40 = fmul float %39, %38
store float %40, float* %8
%41 = load float, float* %8
%42 = load i32, i32* %3
%43 = sitofp i32 %42 to float
%44 = fdiv float %41, %43
store float %44, float* %6
%45 = load float, float* %6
%46 = load i32, i32* %3
%47 = load float*, float** %9
%48 = call i32 @eulsum(float* %5, float %45, i32 %46, float* %47)
br label %49
49: ; preds = %36
%50 = load i32, i32* %3
%51 = add nsw i32 %50, 1
store i32 %51, i32* %3
br label %32
52: ; preds = %32
%53 = load float, float* %7
%54 = fpext float %53 to double
%55 = load float, float* %7
%56 = fpext float %55 to double
%57 = fadd double 1.000000e+00, %56
%58 = call double @log(double %57)
%59 = load float, float* %5
%60 = fpext float %59 to double
%61 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.8, i64 0, i64 0), double %54, double %58, double %60)
br label %62
62: ; preds = %52
%63 = load i32, i32* %2
%64 = add nsw i32 %63, 1
store i32 %64, i32* %2
br label %24
65: ; preds = %24
br label %11
66: ; preds = %21
%67 = load float*, float** %9
%68 = call i32 @free_vector(float* %67, i32 1, i32 40)
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [41 x i8] c"Enter n between 1 and %2d. (n=0 to end) \00"
@.str.2 = [3 x i8] c"%d\00"
@.str.4 = [15 x i8] c"%9s %14s %14s\0A\00"
@.str.5 = [2 x i8] c"x\00"
@.str.6 = [7 x i8] c"actual\00"
@.str.7 = [11 x i8] c"polynomial\00"
@.str.8 = [22 x i8] c"%12.6f %12.6f %12.6f\0A\00"
@str = [31 x i8] c"\0AHow many terms in polynomial?\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca float
%3 = bitcast i32* %1 to i8*
%4 = bitcast float* %2 to i8*
%5 = tail call float* @vector(i32 1, i32 40)
%6 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str, i64 0, i64 0))
%7 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0), i32 40)
%8 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %1)
%9 = call i32 @putchar(i32 10)
%10 = load i32, i32* %1
%11 = add i32 %10, -41
%12 = icmp ult i32 %11, -40
br i1 %12, label %51, label %21
13: ; preds = %42
%14 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str, i64 0, i64 0))
%15 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0), i32 40)
%16 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %1)
%17 = call i32 @putchar(i32 10)
%18 = load i32, i32* %1
%19 = add i32 %18, -41
%20 = icmp ult i32 %19, -40
br i1 %20, label %51, label %21
21: ; preds = %0, %13
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.7, i64 0, i64 0))
br label %23
23: ; preds = %21, %42
%24 = phi i32 [ -8, %21 ], [ %49, %42 ]
%25 = sitofp i32 %24 to double
%26 = fdiv double %25, 1.000000e+01
%27 = fptrunc double %26 to float
store float 0.000000e+00, float* %2
%28 = load i32, i32* %1
%29 = icmp slt i32 %28, 1
br i1 %29, label %42, label %30
30: ; preds = %23
%31 = fneg float %27
br label %32
32: ; preds = %30, %32
%33 = phi float [ -1.000000e+00, %30 ], [ %35, %32 ]
%34 = phi i32 [ 1, %30 ], [ %39, %32 ]
%35 = fmul float %33, %31
%36 = sitofp i32 %34 to float
%37 = fdiv float %35, %36
%38 = call i32 @eulsum(float* %2, float %37, i32 %34, float* %5)
%39 = add nuw nsw i32 %34, 1
%40 = load i32, i32* %1
%41 = icmp slt i32 %34, %40
br i1 %41, label %32, label %42
42: ; preds = %32, %23
%43 = fpext float %27 to double
%44 = fadd double %43, 1.000000e+00
%45 = call double @log(double %44)
%46 = load float, float* %2
%47 = fpext float %46 to double
%48 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.8, i64 0, i64 0), double %43, double %45, double %47)
%49 = add nsw i32 %24, 1
%50 = icmp eq i32 %49, 9
br i1 %50, label %13, label %23
51: ; preds = %13, %0
%52 = call i32 @free_vector(float* %5, i32 1, i32 40)
ret i32 0
}