#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*/ free_ivector(int *, int, int);
int /*<<< orphan*/ free_matrix(float **, int, int, int, int);
int /*<<< orphan*/ free_vector(float *, int, int);
int *ivector(int, int);
float **matrix(int, int, int, int);
int /*<<< orphan*/ printf(char *, int, float, float);
float sin(int);
float *vector(int, int);
int main(void) {
  void lubksb(float **a, int n, int *indx, float b[]);
  void ludcmp(float **a, int n, int *indx, float *d);
  void quadmx(float **a, int n);
  float **a, d, *g, x;
  int *indx, j;
  indx = ivector(1, 40);
  a = matrix(1, 40, 1, 40);
  g = vector(1, 40);
  quadmx(a, 40);
  ludcmp(a, 40, indx, &d);
  for (j = 1; j <= 40; j++)
    g[j] = sin((j - 1) * 3.14159265 / (40 - 1));
  lubksb(a, 40, indx, g);
  for (j = 1; j <= 40; j++) {
    x = (j - 1) * 3.14159265 / (40 - 1);
    printf("%6.2d %12.6f %12.6f\n", j, x, g[j]);
  }
  free_vector(g, 1, 40);
  free_matrix(a, 1, 40, 1, 40);
  free_ivector(indx, 1, 40);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x1,%edi
mov    $0x28,%esi
call   10d0 <ivector@plt>
mov    %rax,-0x30(%rbp)
mov    $0x1,%edx
mov    $0x28,%ecx
mov    %edx,%edi
mov    %ecx,%esi
call   10a0 <matrix@plt>
mov    %rax,-0x10(%rbp)
mov    $0x1,%edi
mov    $0x28,%esi
call   10b0 <vector@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x28,%esi
call   1060 <quadmx@plt>
mov    -0x10(%rbp),%rdi
mov    -0x30(%rbp),%rdx
mov    $0x28,%esi
lea    -0x14(%rbp),%rcx
call   1030 <ludcmp@plt>
movl   $0x1,-0x34(%rbp)
cmpl   $0x28,-0x34(%rbp)
jg     1277 <main+0xc7>
mov    -0x34(%rbp),%eax
sub    $0x1,%eax
cvtsi2sd %eax,%xmm0
movsd  0xdc5(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xdb1(%rip),%xmm1
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
call   1080 <sin@plt>
mov    -0x20(%rbp),%rax
movslq -0x34(%rbp),%rcx
movss  %xmm0,(%rax,%rcx,4)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1227 <main+0x77>
mov    -0x10(%rbp),%rdi
mov    -0x30(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    $0x28,%esi
call   1090 <lubksb@plt>
movl   $0x1,-0x34(%rbp)
cmpl   $0x28,-0x34(%rbp)
jg     12f8 <main+0x148>
mov    -0x34(%rbp),%eax
sub    $0x1,%eax
cvtsi2sd %eax,%xmm0
movsd  0xd58(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xd44(%rip),%xmm1
divsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x24(%rbp)
mov    -0x34(%rbp),%esi
movss  -0x24(%rbp),%xmm0
mov    -0x20(%rbp),%rax
movslq -0x34(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm1
lea    0xd2b(%rip),%rdi
call   1050 <printf@plt>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1294 <main+0xe4>
mov    -0x20(%rbp),%rdi
mov    $0x1,%esi
mov    $0x28,%edx
call   1070 <free_vector@plt>
mov    -0x10(%rbp),%rdi
mov    $0x1,%ecx
mov    $0x28,%r8d
mov    %ecx,%esi
mov    %r8d,%edx
call   1040 <free_matrix@plt>
mov    -0x30(%rbp),%rdi
mov    $0x1,%esi
mov    $0x28,%edx
call   10c0 <free_ivector@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    $0x1,%edi
mov    $0x28,%esi
call   10d0 <ivector@plt>
mov    %rax,%r14
mov    $0x1,%edi
mov    $0x28,%esi
mov    $0x1,%edx
mov    $0x28,%ecx
call   10a0 <matrix@plt>
mov    %rax,%r15
mov    $0x1,%edi
mov    $0x28,%esi
call   10b0 <vector@plt>
mov    %rax,%r12
mov    %r15,%rdi
mov    $0x28,%esi
call   1060 <quadmx@plt>
lea    0xc(%rsp),%rcx
mov    %r15,%rdi
mov    $0x28,%esi
mov    %r14,%rdx
call   1030 <ludcmp@plt>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
xorps  %xmm0,%xmm0
cvtsi2sd %ebx,%xmm0
movsd  0xdc1(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xdbd(%rip),%xmm1
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
call   1080 <sin@plt>
movss  %xmm0,0x4(%r12,%rbx,4)
lea    0x1(%rbx),%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
mulsd  0xd8f(%rip),%xmm0
divsd  0xd8f(%rip),%xmm0
cvttsd2si %xmm0,%edi
call   1080 <sin@plt>
movss  %xmm0,0x8(%r12,%rbx,4)
add    $0x2,%rbx
cmp    $0x28,%rbx
jne    1230 <main+0x80>
mov    %r15,%rdi
mov    $0x28,%esi
mov    %r14,%rdx
mov    %r12,%rcx
call   1090 <lubksb@plt>
xor    %ebx,%ebx
lea    0xd61(%rip),%r13
nop
xorps  %xmm0,%xmm0
cvtsi2sd %ebx,%xmm0
mulsd  0xd41(%rip),%xmm0
divsd  0xd41(%rip),%xmm0
cvtsd2ss %xmm0,%xmm0
movss  0x4(%r12,%rbx,4),%xmm1
add    $0x1,%rbx
mov    %r13,%rdi
mov    %ebx,%esi
call   1050 <printf@plt>
cmp    $0x28,%rbx
jne    12b0 <main+0x100>
mov    %r12,%rdi
mov    $0x1,%esi
mov    $0x28,%edx
call   1070 <free_vector@plt>
mov    %r15,%rdi
mov    $0x1,%esi
mov    $0x28,%edx
mov    $0x1,%ecx
mov    $0x28,%r8d
call   1040 <free_matrix@plt>
mov    %r14,%rdi
mov    $0x1,%esi
mov    $0x28,%edx
call   10c0 <free_ivector@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [21 x i8] c"%6.2d %12.6f %12.6f\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca float**
%3 = alloca float
%4 = alloca float*
%5 = alloca float
%6 = alloca i32*
%7 = alloca i32
store i32 0, i32* %1
%8 = call i32* @ivector(i32 1, i32 40)
store i32* %8, i32** %6
%9 = call float** @matrix(i32 1, i32 40, i32 1, i32 40)
store float** %9, float*** %2
%10 = call float* @vector(i32 1, i32 40)
store float* %10, float** %4
%11 = load float**, float*** %2
%12 = load float**, float*** %2
%13 = load i32*, i32** %6
store i32 1, i32* %7
br label %14
14: ; preds = %29, %0
%15 = load i32, i32* %7
%16 = icmp sle i32 %15, 40
br i1 %16, label %17, label %32
17: ; preds = %14
%18 = load i32, i32* %7
%19 = sub nsw i32 %18, 1
%20 = sitofp i32 %19 to double
%21 = fmul double %20, 0x400921FB53C8D4F1
%22 = fdiv double %21, 3.900000e+01
%23 = fptosi double %22 to i32
%24 = call float @sin(i32 %23)
%25 = load float*, float** %4
%26 = load i32, i32* %7
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds float, float* %25, i64 %27
store float %24, float* %28
br label %29
29: ; preds = %17
%30 = load i32, i32* %7
%31 = add nsw i32 %30, 1
store i32 %31, i32* %7
br label %14
32: ; preds = %14
%33 = load float**, float*** %2
%34 = load i32*, i32** %6
%35 = load float*, float** %4
store i32 1, i32* %7
br label %36
36: ; preds = %54, %32
%37 = load i32, i32* %7
%38 = icmp sle i32 %37, 40
br i1 %38, label %39, label %57
39: ; preds = %36
%40 = load i32, i32* %7
%41 = sub nsw i32 %40, 1
%42 = sitofp i32 %41 to double
%43 = fmul double %42, 0x400921FB53C8D4F1
%44 = fdiv double %43, 3.900000e+01
%45 = fptrunc double %44 to float
store float %45, float* %5
%46 = load i32, i32* %7
%47 = load float, float* %5
%48 = load float*, float** %4
%49 = load i32, i32* %7
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds float, float* %48, i64 %50
%52 = load float, float* %51
%53 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i32 %46, float %47, float %52)
br label %54
54: ; preds = %39
%55 = load i32, i32* %7
%56 = add nsw i32 %55, 1
store i32 %56, i32* %7
br label %36
57: ; preds = %36
%58 = load float*, float** %4
%59 = call i32 @free_vector(float* %58, i32 1, i32 40)
%60 = load float**, float*** %2
%61 = call i32 @free_matrix(float** %60, i32 1, i32 40, i32 1, i32 40)
%62 = load i32*, i32** %6
%63 = call i32 @free_ivector(i32* %62, i32 1, i32 40)
ret i32 0
}

LLVM IR (-O2):
@.str = [21 x i8] c"%6.2d %12.6f %12.6f\0A\00"
define i32 @main() {
%1 = alloca float
%2 = bitcast float* %1 to i8*
%3 = tail call i32* @ivector(i32 1, i32 40)
%4 = tail call float** @matrix(i32 1, i32 40, i32 1, i32 40)
%5 = tail call float* @vector(i32 1, i32 40)
tail call void @quadmx(float** %4, i32 40)
br label %6
6: ; preds = %6, %0
%7 = phi i64 [ 1, %0 ], [ %25, %6 ]
%8 = trunc i64 %7 to i32
%9 = add nsw i32 %8, -1
%10 = sitofp i32 %9 to double
%11 = fmul double %10, 0x400921FB53C8D4F1
%12 = fdiv double %11, 3.900000e+01
%13 = fptosi double %12 to i32
%14 = call float @sin(i32 %13)
%15 = getelementptr inbounds float, float* %5, i64 %7
store float %14, float* %15
%16 = add nuw nsw i64 %7, 1
%17 = trunc i64 %16 to i32
%18 = add nsw i32 %17, -1
%19 = sitofp i32 %18 to double
%20 = fmul double %19, 0x400921FB53C8D4F1
%21 = fdiv double %20, 3.900000e+01
%22 = fptosi double %21 to i32
%23 = call float @sin(i32 %22)
%24 = getelementptr inbounds float, float* %5, i64 %16
store float %23, float* %24
%25 = add nuw nsw i64 %7, 2
%26 = icmp eq i64 %25, 41
br i1 %26, label %27, label %6
27: ; preds = %6
br label %28
28: ; preds = %27, %28
%29 = phi i64 [ 1, %27 ], [ %40, %28 ]
%30 = trunc i64 %29 to i32
%31 = add i32 %30, -1
%32 = sitofp i32 %31 to double
%33 = fmul double %32, 0x400921FB53C8D4F1
%34 = fdiv double %33, 3.900000e+01
%35 = fptrunc double %34 to float
%36 = getelementptr inbounds float, float* %5, i64 %29
%37 = load float, float* %36
%38 = trunc i64 %29 to i32
%39 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i32 %38, float %35, float %37)
%40 = add nuw nsw i64 %29, 1
%41 = icmp eq i64 %40, 41
br i1 %41, label %42, label %28
42: ; preds = %28
%43 = call i32 @free_vector(float* %5, i32 1, i32 40)
%44 = call i32 @free_matrix(float** %4, i32 1, i32 40, i32 1, i32 40)
%45 = call i32 @free_ivector(i32* %3, i32 1, i32 40)
ret i32 0
}