#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 */
typedef scalar_t__ clock_t;

/* Variables and functions */
float CLOCKS_PER_SEC;
double **LU_product(double **, int);
scalar_t__ clock();
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ free_matrix(double **, int);
double **generate_random_matrix(int);
int /*<<< orphan*/ printf(char *, ...);
int read_dimension();
double **read_matrix(char *, int);
int /*<<< orphan*/ stdin;
int strlen(char *);
int /*<<< orphan*/ write_matrix(char *, double **, int);
int main() {
  int n = 0;
  char filename[256];
  double **matrixA;
  double **matrixB;
  clock_t time;
  n = read_dimension();
  printf("Dimensio n=%d\n", n);
  printf("Arxiu? (buit per matriu random) ");
  fgets(filename, 255, stdin);
  if (filename[0] != '\n') {
    if (filename[strlen(filename) - 1] == '\n') {
      filename[strlen(filename) - 1] = '\0';
    }
    printf("\nMatriu de l'arxiu %s\n", filename);
    matrixA = read_matrix(filename, n);
  } else {
    printf("\nMatriu random\n");
    matrixA = generate_random_matrix(n);
  }
  printf("Començant calcul B = LU...\n");
  time = clock();
  matrixB = LU_product(matrixA, n);
  time = clock() - time;
  printf("Calcul finalitzat.\n");
  printf("S'escriura la matriu B a l'arxiu output1.txt\n");
  write_matrix("output1.txt", matrixB, n);
  printf("n = %d, t = %.6f, t/n = %.6f\n", n, ((float)time) / CLOCKS_PER_SEC,
         (((float)time) / CLOCKS_PER_SEC) / n);
  free_matrix(matrixA, n);
  free_matrix(matrixB, n);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
mov    $0x0,%al
call   10b0 <read_dimension@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%esi
lea    0xe33(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    0xe34(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    -0x110(%rbp),%rdi
mov    0x2df8(%rip),%rax
mov    (%rax),%edx
mov    $0xff,%esi
call   1090 <fgets@plt>
movsbl -0x110(%rbp),%eax
cmp    $0xa,%eax
je     1277 <main+0xd7>
lea    -0x110(%rbp),%rdi
call   1060 <strlen@plt>
sub    $0x1,%eax
cltq
movsbl -0x110(%rbp,%rax,1),%eax
ff
cmp    $0xa,%eax
jne    1247 <main+0xa7>
lea    -0x110(%rbp),%rdi
call   1060 <strlen@plt>
sub    $0x1,%eax
cltq
movb   $0x0,-0x110(%rbp,%rax,1)
lea    -0x110(%rbp),%rsi
lea    0xddb(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    -0x110(%rbp),%rdi
mov    -0x8(%rbp),%esi
call   10a0 <read_matrix@plt>
mov    %rax,-0x118(%rbp)
jmp    1294 <main+0xf4>
lea    0xdc9(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x8(%rbp),%edi
call   1080 <generate_random_matrix@plt>
mov    %rax,-0x118(%rbp)
lea    0xdbc(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    $0x0,%al
call   1050 <clock@plt>
mov    %rax,-0x128(%rbp)
mov    -0x118(%rbp),%rdi
mov    -0x8(%rbp),%esi
call   10c0 <LU_product@plt>
mov    %rax,-0x120(%rbp)
mov    $0x0,%al
call   1050 <clock@plt>
sub    -0x128(%rbp),%rax
mov    %rax,-0x128(%rbp)
lea    0xd92(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    0xd98(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x120(%rbp),%rsi
mov    -0x8(%rbp),%edx
lea    0xdae(%rip),%rdi
call   1030 <write_matrix@plt>
mov    -0x8(%rbp),%esi
cvtsi2ssq -0x128(%rbp),%xmm0
ff ff
mov    0x2cc0(%rip),%rax
divss  (%rax),%xmm0
cvtss2sd %xmm0,%xmm0
cvtsi2ssq -0x128(%rbp),%xmm1
ff ff
mov    0x2ca8(%rip),%rax
divss  (%rax),%xmm1
cvtsi2ssl -0x8(%rbp),%xmm2
divss  %xmm2,%xmm1
cvtss2sd %xmm1,%xmm1
lea    0xd72(%rip),%rdi
mov    $0x2,%al
call   1070 <printf@plt>
mov    -0x118(%rbp),%rdi
mov    -0x8(%rbp),%esi
call   1040 <free_matrix@plt>
mov    -0x120(%rbp),%rdi
mov    -0x8(%rbp),%esi
call   1040 <free_matrix@plt>
xor    %eax,%eax
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x100,%rsp
xor    %eax,%eax
call   10c0 <read_dimension@plt>
mov    %eax,%r12d
lea    0xe30(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1080 <printf@plt>
lea    0xe2f(%rip),%rdi
xor    %eax,%eax
call   1080 <printf@plt>
mov    0x2dfa(%rip),%rax
mov    (%rax),%edx
mov    %rsp,%r14
mov    %r14,%rdi
mov    $0xff,%esi
call   10a0 <fgets@plt>
cmpb   $0xa,(%rsp)
jne    121c <main+0x6c>
lea    0xe58(%rip),%rdi
call   1040 <puts@plt>
mov    %r12d,%edi
call   1090 <generate_random_matrix@plt>
jmp    125d <main+0xad>
mov    %r14,%rdi
call   1070 <strlen@plt>
cltq
cmpb   $0xa,-0x1(%rax,%r14,1)
jne    123e <main+0x8e>
mov    %r14,%rdi
call   1070 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%r14,1)
lea    0xdeb(%rip),%rdi
mov    %rsp,%r14
mov    %r14,%rsi
xor    %eax,%eax
call   1080 <printf@plt>
mov    %r14,%rdi
mov    %r12d,%esi
call   10b0 <read_matrix@plt>
mov    %rax,%r14
lea    0xe0d(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
call   1060 <clock@plt>
mov    %rax,%rbx
mov    %r14,%rdi
mov    %r12d,%esi
call   10d0 <LU_product@plt>
mov    %rax,%r15
xor    %eax,%eax
call   1060 <clock@plt>
mov    %rax,%rbp
sub    %rbx,%rbp
lea    0xdf8(%rip),%rdi
call   1040 <puts@plt>
lea    0xdff(%rip),%rdi
call   1040 <puts@plt>
lea    0xe14(%rip),%rdi
mov    %r15,%rsi
mov    %r12d,%edx
call   1030 <write_matrix@plt>
cvtsi2ss %rbp,%xmm1
mov    0x2d19(%rip),%rax
divss  (%rax),%xmm1
cvtsi2ss %r12d,%xmm2
cvtss2sd %xmm1,%xmm0
divss  %xmm2,%xmm1
cvtss2sd %xmm1,%xmm1
lea    0xd64(%rip),%rdi
mov    %r12d,%esi
mov    $0x2,%al
call   1080 <printf@plt>
mov    %r14,%rdi
mov    %r12d,%esi
call   1050 <free_matrix@plt>
mov    %r15,%rdi
mov    %r12d,%esi
call   1050 <free_matrix@plt>
xor    %eax,%eax
add    $0x100,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [15 x i8] c"Dimensio n=%d\0A\00"
@.str.1 = [33 x i8] c"Arxiu? (buit per matriu random) \00"
@stdin = global i32 0
@.str.2 = [23 x i8] c"\0AMatriu de l'arxiu %s\0A\00"
@.str.3 = [16 x i8] c"\0AMatriu random\0A\00"
@.str.4 = [29 x i8] c"Comen\C3\A7ant calcul B = LU...\0A\00"
@.str.5 = [20 x i8] c"Calcul finalitzat.\0A\00"
@.str.6 = [46 x i8] c"S'escriura la matriu B a l'arxiu output1.txt\0A\00"
@.str.7 = [12 x i8] c"output1.txt\00"
@.str.8 = [30 x i8] c"n = %d, t = %.6f, t/n = %.6f\0A\00"
@CLOCKS_PER_SEC = global float 0.000000e+00
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [256 x i8]
%4 = alloca double**
%5 = alloca double**
%6 = alloca i64
store i32 0, i32* %1
store i32 0, i32* %2
%7 = call i32 (...) @read_dimension()
store i32 %7, i32* %2
%8 = load i32, i32* %2
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %8)
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
%11 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%12 = load i32, i32* @stdin
%13 = call i32 @fgets(i8* %11, i32 255, i32 %12)
%14 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
%17 = icmp ne i32 %16, 10
br i1 %17, label %18, label %39
18: ; preds = %0
%19 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%20 = call i32 @strlen(i8* %19)
%21 = sub nsw i32 %20, 1
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 %22
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
%26 = icmp eq i32 %25, 10
br i1 %26, label %27, label %33
27: ; preds = %18
%28 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%29 = call i32 @strlen(i8* %28)
%30 = sub nsw i32 %29, 1
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 %31
store i8 0, i8* %32
br label %33
33: ; preds = %27, %18
%34 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i8* %34)
%36 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%37 = load i32, i32* %2
%38 = call double** @read_matrix(i8* %36, i32 %37)
store double** %38, double*** %4
br label %43
39: ; preds = %0
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
%41 = load i32, i32* %2
%42 = call double** @generate_random_matrix(i32 %41)
store double** %42, double*** %4
br label %43
43: ; preds = %39, %33
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0))
%45 = call i64 (...) @clock()
store i64 %45, i64* %6
%46 = load double**, double*** %4
%47 = load i32, i32* %2
%48 = call double** @LU_product(double** %46, i32 %47)
store double** %48, double*** %5
%49 = call i64 (...) @clock()
%50 = load i64, i64* %6
%51 = sub nsw i64 %49, %50
store i64 %51, i64* %6
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0))
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.6, i64 0, i64 0))
%54 = load double**, double*** %5
%55 = load i32, i32* %2
%56 = call i32 @write_matrix(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.7, i64 0, i64 0), double** %54, i32 %55)
%57 = load i32, i32* %2
%58 = load i64, i64* %6
%59 = sitofp i64 %58 to float
%60 = load float, float* @CLOCKS_PER_SEC
%61 = fdiv float %59, %60
%62 = fpext float %61 to double
%63 = load i64, i64* %6
%64 = sitofp i64 %63 to float
%65 = load float, float* @CLOCKS_PER_SEC
%66 = fdiv float %64, %65
%67 = load i32, i32* %2
%68 = sitofp i32 %67 to float
%69 = fdiv float %66, %68
%70 = fpext float %69 to double
%71 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.8, i64 0, i64 0), i32 %57, double %62, double %70)
%72 = load double**, double*** %4
%73 = load i32, i32* %2
%74 = call i32 @free_matrix(double** %72, i32 %73)
%75 = load double**, double*** %5
%76 = load i32, i32* %2
%77 = call i32 @free_matrix(double** %75, i32 %76)
ret i32 0
}

LLVM IR (-O2):
@.str = [15 x i8] c"Dimensio n=%d\0A\00"
@.str.1 = [33 x i8] c"Arxiu? (buit per matriu random) \00"
@stdin = global i32 0
@.str.2 = [23 x i8] c"\0AMatriu de l'arxiu %s\0A\00"
@.str.7 = [12 x i8] c"output1.txt\00"
@.str.8 = [30 x i8] c"n = %d, t = %.6f, t/n = %.6f\0A\00"
@CLOCKS_PER_SEC = global float 0.000000e+00
@str = [15 x i8] c"\0AMatriu random\00"
@str.9 = [28 x i8] c"Comen\C3\A7ant calcul B = LU...\00"
@str.10 = [19 x i8] c"Calcul finalitzat.\00"
@str.11 = [45 x i8] c"S'escriura la matriu B a l'arxiu output1.txt\00"
define i32 @main() {
%1 = alloca [256 x i8]
%2 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 0
%3 = tail call i32 (...) @read_dimension()
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
%6 = load i32, i32* @stdin
%7 = call i32 @fgets(i8* %2, i32 255, i32 %6)
%8 = load i8, i8* %2
%9 = icmp eq i8 %8, 10
br i1 %9, label %25, label %10
10: ; preds = %0
%11 = call i32 @strlen(i8* %2)
%12 = add nsw i32 %11, -1
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 %13
%15 = load i8, i8* %14
%16 = icmp eq i8 %15, 10
br i1 %16, label %17, label %22
17: ; preds = %10
%18 = call i32 @strlen(i8* %2)
%19 = add nsw i32 %18, -1
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 %20
store i8 0, i8* %21
br label %22
22: ; preds = %17, %10
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i8* %2)
%24 = call double** @read_matrix(i8* %2, i32 %3)
br label %28
25: ; preds = %0
%26 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str, i64 0, i64 0))
%27 = call double** @generate_random_matrix(i32 %3)
br label %28
28: ; preds = %25, %22
%29 = phi double** [ %24, %22 ], [ %27, %25 ]
%30 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str.9, i64 0, i64 0))
%31 = call i64 (...) @clock()
%32 = call double** @LU_product(double** %29, i32 %3)
%33 = call i64 (...) @clock()
%34 = sub nsw i64 %33, %31
%35 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str.10, i64 0, i64 0))
%36 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @str.11, i64 0, i64 0))
%37 = call i32 @write_matrix(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.7, i64 0, i64 0), double** %32, i32 %3)
%38 = sitofp i64 %34 to float
%39 = load float, float* @CLOCKS_PER_SEC
%40 = fdiv float %38, %39
%41 = fpext float %40 to double
%42 = sitofp i32 %3 to float
%43 = fdiv float %40, %42
%44 = fpext float %43 to double
%45 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.8, i64 0, i64 0), i32 %3, double %41, double %44)
%46 = call i32 @free_matrix(double** %29, i32 %3)
%47 = call i32 @free_matrix(double** %32, i32 %3)
ret i32 0
}