#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*/ fleg(float, float *, int);
int /*<<< orphan*/ free_vector(float *, int, int);
double plgndr(int, int /*<<< orphan*/, float);
int /*<<< orphan*/ printf(char *, ...);
float *vector(int, int);
int main(void) {
  int i, j;
  float x, *afunc;
  afunc = vector(1, 5);
  printf("\n%3s\n", "Legendre polynomials");
  printf("%9s %9s %9s %9s %9s\n", "n=1", "n=2", "n=3", "n=4", "n=5");
  for (i = 1; i <= 5; i++) {
    x = i * 0.2;
    fleg(x, afunc, 5);
    printf("x =%5.2f\n", x);
    for (j = 1; j <= 5; j++)
      printf("%10.4f", afunc[j]);
    printf("  routine FLEG\n");
    for (j = 1; j <= 5; j++)
      printf("%10.4f", plgndr(j - 1, 0, x));
    printf("  routine PLGNDR\n\n");
  }
  free_vector(afunc, 1, 5);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x1,%edi
mov    $0x5,%esi
call   1060 <vector@plt>
mov    %rax,-0x18(%rbp)
lea    0xe8f(%rip),%rdi
lea    0xe8e(%rip),%rsi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe95(%rip),%rdi
lea    0xea3(%rip),%rsi
lea    0xea0(%rip),%rdx
lea    0xe9d(%rip),%rcx
lea    0xe9a(%rip),%r8
lea    0xe97(%rip),%r9
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x8(%rbp)
cmpl   $0x5,-0x8(%rbp)
jg     12b4 <main+0x164>
cvtsi2sdl -0x8(%rbp),%xmm0
movsd  0xe2a(%rip),%xmm1
mulsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x10(%rbp)
movss  -0x10(%rbp),%xmm0
mov    -0x18(%rbp),%rdi
mov    $0x5,%esi
call   1050 <fleg@plt>
movss  -0x10(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xe46(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
movl   $0x1,-0xc(%rbp)
cmpl   $0x5,-0xc(%rbp)
jg     124b <main+0xfb>
mov    -0x18(%rbp),%rax
movslq -0xc(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xe20(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1214 <main+0xc4>
lea    0xe0b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0xc(%rbp)
cmpl   $0x5,-0xc(%rbp)
jg     1298 <main+0x148>
mov    -0xc(%rbp),%edi
sub    $0x1,%edi
movss  -0x10(%rbp),%xmm0
xor    %esi,%esi
call   1070 <plgndr@plt>
lea    0xdd3(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1260 <main+0x110>
lea    0xdce(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    11bf <main+0x6f>
mov    -0x18(%rbp),%rdi
mov    $0x1,%esi
mov    $0x5,%edx
call   1040 <free_vector@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    $0x5,%ebp
mov    $0x1,%edi
mov    $0x5,%esi
call   1070 <vector@plt>
mov    %rax,%r15
lea    0xe84(%rip),%rdi
lea    0xe83(%rip),%rsi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe8a(%rip),%rdi
lea    0xe98(%rip),%rsi
lea    0xe95(%rip),%rdx
lea    0xe92(%rip),%rcx
lea    0xe8f(%rip),%r8
lea    0xe8c(%rip),%r9
xor    %eax,%eax
call   1040 <printf@plt>
movsd  0xe2d(%rip),%xmm0
lea    0xe7a(%rip),%r14
lea    0xe7d(%rip),%rbx
lea    0xe7d(%rip),%r12
lea    0xe85(%rip),%r13
nop
movsd  %xmm0,0x10(%rsp)
movsd  0x10(%rsp),%xmm0
mulsd  0xe04(%rip),%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,0xc(%rsp)
mov    %r15,%rdi
mov    $0x5,%esi
call   1060 <fleg@plt>
movss  0xc(%rsp),%xmm0
cvtss2sd %xmm0,%xmm0
mov    %r14,%rdi
mov    $0x1,%al
call   1040 <printf@plt>
movss  0x4(%r15),%xmm0
cvtss2sd %xmm0,%xmm0
mov    %rbx,%rdi
mov    $0x1,%al
call   1040 <printf@plt>
movss  0x8(%r15),%xmm0
cvtss2sd %xmm0,%xmm0
mov    %rbx,%rdi
mov    $0x1,%al
call   1040 <printf@plt>
movss  0xc(%r15),%xmm0
cvtss2sd %xmm0,%xmm0
mov    %rbx,%rdi
mov    $0x1,%al
call   1040 <printf@plt>
movss  0x10(%r15),%xmm0
cvtss2sd %xmm0,%xmm0
mov    %rbx,%rdi
mov    $0x1,%al
call   1040 <printf@plt>
movss  0x14(%r15),%xmm0
cvtss2sd %xmm0,%xmm0
mov    %rbx,%rdi
mov    $0x1,%al
call   1040 <printf@plt>
mov    %r12,%rdi
call   1030 <puts@plt>
xor    %edi,%edi
xor    %esi,%esi
movss  0xc(%rsp),%xmm0
call   1080 <plgndr@plt>
mov    %rbx,%rdi
mov    $0x1,%al
call   1040 <printf@plt>
mov    $0x1,%edi
xor    %esi,%esi
movss  0xc(%rsp),%xmm0
call   1080 <plgndr@plt>
mov    %rbx,%rdi
mov    $0x1,%al
call   1040 <printf@plt>
mov    $0x2,%edi
xor    %esi,%esi
movss  0xc(%rsp),%xmm0
call   1080 <plgndr@plt>
mov    %rbx,%rdi
mov    $0x1,%al
call   1040 <printf@plt>
mov    $0x3,%edi
xor    %esi,%esi
movss  0xc(%rsp),%xmm0
call   1080 <plgndr@plt>
mov    %rbx,%rdi
mov    $0x1,%al
call   1040 <printf@plt>
mov    $0x4,%edi
xor    %esi,%esi
movss  0xc(%rsp),%xmm0
call   1080 <plgndr@plt>
mov    %rbx,%rdi
mov    $0x1,%al
call   1040 <printf@plt>
mov    %r13,%rdi
call   1030 <puts@plt>
movsd  0x10(%rsp),%xmm0
addsd  0xcc6(%rip),%xmm0
add    $0xffffffff,%ebp
jne    11f0 <main+0x90>
mov    %r15,%rdi
mov    $0x1,%esi
mov    $0x5,%edx
call   1050 <free_vector@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [6 x i8] c"\0A%3s\0A\00"
@.str.1 = [21 x i8] c"Legendre polynomials\00"
@.str.2 = [21 x i8] c"%9s %9s %9s %9s %9s\0A\00"
@.str.3 = [4 x i8] c"n=1\00"
@.str.4 = [4 x i8] c"n=2\00"
@.str.5 = [4 x i8] c"n=3\00"
@.str.6 = [4 x i8] c"n=4\00"
@.str.7 = [4 x i8] c"n=5\00"
@.str.8 = [10 x i8] c"x =%5.2f\0A\00"
@.str.9 = [7 x i8] c"%10.4f\00"
@.str.10 = [16 x i8] c" routine FLEG\0A\00"
@.str.11 = [19 x i8] c" routine PLGNDR\0A\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca float
%5 = alloca float*
store i32 0, i32* %1
%6 = call float* @vector(i32 1, i32 5)
store float* %6, float** %5
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0))
store i32 1, i32* %2
br label %9
9: ; preds = %53, %0
%10 = load i32, i32* %2
%11 = icmp sle i32 %10, 5
br i1 %11, label %12, label %56
12: ; preds = %9
%13 = load i32, i32* %2
%14 = sitofp i32 %13 to double
%15 = fmul double %14, 2.000000e-01
%16 = fptrunc double %15 to float
store float %16, float* %4
%17 = load float, float* %4
%18 = load float*, float** %5
%19 = call i32 @fleg(float %17, float* %18, i32 5)
%20 = load float, float* %4
%21 = fpext float %20 to double
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.8, i64 0, i64 0), double %21)
store i32 1, i32* %3
br label %23
23: ; preds = %34, %12
%24 = load i32, i32* %3
%25 = icmp sle i32 %24, 5
br i1 %25, label %26, label %37
26: ; preds = %23
%27 = load float*, float** %5
%28 = load i32, i32* %3
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds float, float* %27, i64 %29
%31 = load float, float* %30
%32 = fpext float %31 to double
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.9, i64 0, i64 0), double %32)
br label %34
34: ; preds = %26
%35 = load i32, i32* %3
%36 = add nsw i32 %35, 1
store i32 %36, i32* %3
br label %23
37: ; preds = %23
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.10, i64 0, i64 0))
store i32 1, i32* %3
br label %39
39: ; preds = %48, %37
%40 = load i32, i32* %3
%41 = icmp sle i32 %40, 5
br i1 %41, label %42, label %51
42: ; preds = %39
%43 = load i32, i32* %3
%44 = sub nsw i32 %43, 1
%45 = load float, float* %4
%46 = call double @plgndr(i32 %44, i32 0, float %45)
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.9, i64 0, i64 0), double %46)
br label %48
48: ; preds = %42
%49 = load i32, i32* %3
%50 = add nsw i32 %49, 1
store i32 %50, i32* %3
br label %39
51: ; preds = %39
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.11, i64 0, i64 0))
br label %53
53: ; preds = %51
%54 = load i32, i32* %2
%55 = add nsw i32 %54, 1
store i32 %55, i32* %2
br label %9
56: ; preds = %9
%57 = load float*, float** %5
%58 = call i32 @free_vector(float* %57, i32 1, i32 5)
ret i32 0
}

LLVM IR (-O2):
@.str = [6 x i8] c"\0A%3s\0A\00"
@.str.1 = [21 x i8] c"Legendre polynomials\00"
@.str.2 = [21 x i8] c"%9s %9s %9s %9s %9s\0A\00"
@.str.3 = [4 x i8] c"n=1\00"
@.str.4 = [4 x i8] c"n=2\00"
@.str.5 = [4 x i8] c"n=3\00"
@.str.6 = [4 x i8] c"n=4\00"
@.str.7 = [4 x i8] c"n=5\00"
@.str.8 = [10 x i8] c"x =%5.2f\0A\00"
@.str.9 = [7 x i8] c"%10.4f\00"
@str = [15 x i8] c" routine FLEG\00"
@str.12 = [18 x i8] c" routine PLGNDR\0A\00"
define i32 @main() {
%1 = tail call float* @vector(i32 1, i32 5)
%2 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0))
%4 = getelementptr inbounds float, float* %1, i64 1
%5 = getelementptr inbounds float, float* %1, i64 2
%6 = getelementptr inbounds float, float* %1, i64 3
%7 = getelementptr inbounds float, float* %1, i64 4
%8 = getelementptr inbounds float, float* %1, i64 5
br label %9
9: ; preds = %0, %9
%10 = phi i32 [ 1, %0 ], [ %44, %9 ]
%11 = sitofp i32 %10 to double
%12 = fmul double %11, 2.000000e-01
%13 = fptrunc double %12 to float
%14 = tail call i32 @fleg(float %13, float* %1, i32 5)
%15 = fpext float %13 to double
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.8, i64 0, i64 0), double %15)
%17 = load float, float* %4
%18 = fpext float %17 to double
%19 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.9, i64 0, i64 0), double %18)
%20 = load float, float* %5
%21 = fpext float %20 to double
%22 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.9, i64 0, i64 0), double %21)
%23 = load float, float* %6
%24 = fpext float %23 to double
%25 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.9, i64 0, i64 0), double %24)
%26 = load float, float* %7
%27 = fpext float %26 to double
%28 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.9, i64 0, i64 0), double %27)
%29 = load float, float* %8
%30 = fpext float %29 to double
%31 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.9, i64 0, i64 0), double %30)
%32 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str, i64 0, i64 0))
%33 = tail call double @plgndr(i32 0, i32 0, float %13)
%34 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.9, i64 0, i64 0), double %33)
%35 = tail call double @plgndr(i32 1, i32 0, float %13)
%36 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.9, i64 0, i64 0), double %35)
%37 = tail call double @plgndr(i32 2, i32 0, float %13)
%38 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.9, i64 0, i64 0), double %37)
%39 = tail call double @plgndr(i32 3, i32 0, float %13)
%40 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.9, i64 0, i64 0), double %39)
%41 = tail call double @plgndr(i32 4, i32 0, float %13)
%42 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.9, i64 0, i64 0), double %41)
%43 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.12, i64 0, i64 0))
%44 = add nuw nsw i32 %10, 1
%45 = icmp eq i32 %44, 6
br i1 %45, label %46, label %9
46: ; preds = %9
%47 = tail call i32 @free_vector(float* %1, i32 1, i32 5)
ret i32 0
}