#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 int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ calc_matrix_vector(int, int, double **, double *, double *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, double);
scalar_t__ malloc(int);
int /*<<< orphan*/ read_mat(int *, int *, double **, int);
int /*<<< orphan*/ read_vector(double *, int);
void main() {
  double **a;
  double *x, *b;
  int i, j, n, m;
  read_mat(&n, &m, a, 0);
  a = (double **)malloc(n * sizeof(double *));
  for (i = 0; i < n; i++) {
    *(a + i) = (double *)malloc(m * sizeof(double));
  }
  read_mat(&n, &m, a, 1);
  x = (double *)malloc(m * sizeof(double));
  b = (double *)malloc(n * sizeof(double));
  read_vector(x, m);
  calc_matrix_vector(n, m, a, x, b);
  FILE *fp;
  fp = fopen("output.dat", "w");
  for (i = 0; i < n; i++) {
    if (i == n - 1) {
      fprintf(fp, "%f\n", b[i]);
    } else {
      fprintf(fp, "%f ", b[i]);
    }
  }
  fclose(fp);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    -0x8(%rbp),%rdx
lea    -0x24(%rbp),%rdi
lea    -0x28(%rbp),%rsi
xor    %ecx,%ecx
call   1030 <read_mat@plt>
movslq -0x24(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x8(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    11dd <main+0x6d>
movslq -0x28(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,%rdx
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11a5 <main+0x35>
mov    -0x8(%rbp),%rdx
lea    -0x24(%rbp),%rdi
lea    -0x28(%rbp),%rsi
mov    $0x1,%ecx
call   1030 <read_mat@plt>
movslq -0x28(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x10(%rbp)
movslq -0x24(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%esi
call   1060 <read_vector@plt>
mov    -0x24(%rbp),%edi
mov    -0x28(%rbp),%esi
mov    -0x8(%rbp),%rdx
mov    -0x10(%rbp),%rcx
mov    -0x18(%rbp),%r8
call   1080 <calc_matrix_vector@plt>
lea    0xdbd(%rip),%rdi
lea    0xdc1(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    12c9 <main+0x159>
mov    -0x1c(%rbp),%eax
mov    -0x24(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jne    1299 <main+0x129>
mov    -0x30(%rbp),%rdi
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
lea    0xd7e(%rip),%rsi
call   1050 <fprintf@plt>
jmp    12b6 <main+0x146>
mov    -0x30(%rbp),%rdi
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
lea    0xd60(%rip),%rsi
call   1050 <fprintf@plt>
jmp    12bb <main+0x14b>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    125a <main+0xea>
mov    -0x30(%rbp),%rdi
call   1040 <fclose@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
lea    0x8(%rsp),%rdi
lea    0xc(%rsp),%rsi
xor    %ecx,%ecx
call   1030 <read_mat@plt>
mov    0x8(%rsp),%edi
shl    $0x3,%edi
call   1070 <malloc@plt>
mov    %rax,%r12
cmpl   $0x0,0x8(%rsp)
jle    11ce <main+0x5e>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
mov    0xc(%rsp),%edi
shl    $0x3,%edi
call   1070 <malloc@plt>
mov    %rax,(%r12,%rbx,8)
add    $0x1,%rbx
movslq 0x8(%rsp),%rax
cmp    %rax,%rbx
jl     11b0 <main+0x40>
lea    0x8(%rsp),%rdi
lea    0xc(%rsp),%rsi
mov    %r12,%rdx
mov    $0x1,%ecx
call   1030 <read_mat@plt>
mov    0xc(%rsp),%edi
shl    $0x3,%edi
call   1070 <malloc@plt>
mov    %rax,%r15
mov    0x8(%rsp),%edi
shl    $0x3,%edi
call   1070 <malloc@plt>
mov    %rax,%r14
mov    0xc(%rsp),%esi
mov    %r15,%rdi
call   1060 <read_vector@plt>
mov    0x8(%rsp),%edi
mov    0xc(%rsp),%esi
mov    %r12,%rdx
mov    %r15,%rcx
mov    %r14,%r8
call   1080 <calc_matrix_vector@plt>
lea    0xdd4(%rip),%rdi
lea    0xdd8(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,%r15
mov    0x8(%rsp),%eax
test   %eax,%eax
jle    1289 <main+0x119>
xor    %ebx,%ebx
lea    0xdc1(%rip),%r12
lea    0xdbe(%rip),%r13
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    $0xffffffff,%eax
cmp    %rax,%rbx
movsd  (%r14,%rbx,8),%xmm0
mov    %r13,%rsi
cmove  %r12,%rsi
mov    %r15,%rdi
call   1050 <fprintf@plt>
add    $0x1,%rbx
movslq 0x8(%rsp),%rax
cmp    %rax,%rbx
jl     1260 <main+0xf0>
mov    %r15,%rdi
call   1040 <fclose@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [11 x i8] c"output.dat\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [4 x i8] c"%f\0A\00"
@.str.3 = [4 x i8] c"%f \00"
define void @main() {
%1 = alloca double**
%2 = alloca double*
%3 = alloca double*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32*
%9 = load double**, double*** %1
%10 = call i32 @read_mat(i32* %6, i32* %7, double** %9, i32 0)
%11 = load i32, i32* %6
%12 = sext i32 %11 to i64
%13 = mul i64 %12, 8
%14 = trunc i64 %13 to i32
%15 = call i64 @malloc(i32 %14)
%16 = inttoptr i64 %15 to double**
store double** %16, double*** %1
store i32 0, i32* %4
br label %17
17: ; preds = %32, %0
%18 = load i32, i32* %4
%19 = load i32, i32* %6
%20 = icmp slt i32 %18, %19
br i1 %20, label %21, label %35
21: ; preds = %17
%22 = load i32, i32* %7
%23 = sext i32 %22 to i64
%24 = mul i64 %23, 8
%25 = trunc i64 %24 to i32
%26 = call i64 @malloc(i32 %25)
%27 = inttoptr i64 %26 to double*
%28 = load double**, double*** %1
%29 = load i32, i32* %4
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds double*, double** %28, i64 %30
store double* %27, double** %31
br label %32
32: ; preds = %21
%33 = load i32, i32* %4
%34 = add nsw i32 %33, 1
store i32 %34, i32* %4
br label %17
35: ; preds = %17
%36 = load double**, double*** %1
%37 = call i32 @read_mat(i32* %6, i32* %7, double** %36, i32 1)
%38 = load i32, i32* %7
%39 = sext i32 %38 to i64
%40 = mul i64 %39, 8
%41 = trunc i64 %40 to i32
%42 = call i64 @malloc(i32 %41)
%43 = inttoptr i64 %42 to double*
store double* %43, double** %2
%44 = load i32, i32* %6
%45 = sext i32 %44 to i64
%46 = mul i64 %45, 8
%47 = trunc i64 %46 to i32
%48 = call i64 @malloc(i32 %47)
%49 = inttoptr i64 %48 to double*
store double* %49, double** %3
%50 = load double*, double** %2
%51 = load i32, i32* %7
%52 = call i32 @read_vector(double* %50, i32 %51)
%53 = load i32, i32* %6
%54 = load i32, i32* %7
%55 = load double**, double*** %1
%56 = load double*, double** %2
%57 = load double*, double** %3
%58 = call i32 @calc_matrix_vector(i32 %53, i32 %54, double** %55, double* %56, double* %57)
%59 = call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %59, i32** %8
store i32 0, i32* %4
br label %60
60: ; preds = %86, %35
%61 = load i32, i32* %4
%62 = load i32, i32* %6
%63 = icmp slt i32 %61, %62
br i1 %63, label %64, label %89
64: ; preds = %60
%65 = load i32, i32* %4
%66 = load i32, i32* %6
%67 = sub nsw i32 %66, 1
%68 = icmp eq i32 %65, %67
br i1 %68, label %69, label %77
69: ; preds = %64
%70 = load i32*, i32** %8
%71 = load double*, double** %3
%72 = load i32, i32* %4
%73 = sext i32 %72 to i64
%74 = getelementptr inbounds double, double* %71, i64 %73
%75 = load double, double* %74
%76 = call i32 @fprintf(i32* %70, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), double %75)
br label %85
77: ; preds = %64
%78 = load i32*, i32** %8
%79 = load double*, double** %3
%80 = load i32, i32* %4
%81 = sext i32 %80 to i64
%82 = getelementptr inbounds double, double* %79, i64 %81
%83 = load double, double* %82
%84 = call i32 @fprintf(i32* %78, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), double %83)
br label %85
85: ; preds = %77, %69
br label %86
86: ; preds = %85
%87 = load i32, i32* %4
%88 = add nsw i32 %87, 1
store i32 %88, i32* %4
br label %60
89: ; preds = %60
%90 = load i32*, i32** %8
%91 = call i32 @fclose(i32* %90)
ret void
}

LLVM IR (-O2):
@.str = [11 x i8] c"output.dat\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [4 x i8] c"%f\0A\00"
@.str.3 = [4 x i8] c"%f \00"
define void @main() {
%1 = alloca i32
%2 = alloca i32
%3 = bitcast i32* %1 to i8*
%4 = bitcast i32* %2 to i8*
%5 = call i32 @read_mat(i32* %1, i32* %2, double** undef, i32 0)
%6 = load i32, i32* %1
%7 = shl i32 %6, 3
%8 = call i64 @malloc(i32 %7)
%9 = inttoptr i64 %8 to double**
%10 = load i32, i32* %1
%11 = icmp sgt i32 %10, 0
br i1 %11, label %12, label %23
12: ; preds = %0, %12
%13 = phi i64 [ %19, %12 ], [ 0, %0 ]
%14 = load i32, i32* %2
%15 = shl i32 %14, 3
%16 = call i64 @malloc(i32 %15)
%17 = inttoptr i64 %16 to double*
%18 = getelementptr inbounds double*, double** %9, i64 %13
store double* %17, double** %18
%19 = add nuw nsw i64 %13, 1
%20 = load i32, i32* %1
%21 = sext i32 %20 to i64
%22 = icmp slt i64 %19, %21
br i1 %22, label %12, label %23
23: ; preds = %12, %0
%24 = call i32 @read_mat(i32* %1, i32* %2, double** %9, i32 1)
%25 = load i32, i32* %2
%26 = shl i32 %25, 3
%27 = call i64 @malloc(i32 %26)
%28 = inttoptr i64 %27 to double*
%29 = load i32, i32* %1
%30 = shl i32 %29, 3
%31 = call i64 @malloc(i32 %30)
%32 = inttoptr i64 %31 to double*
%33 = load i32, i32* %2
%34 = call i32 @read_vector(double* %28, i32 %33)
%35 = load i32, i32* %1
%36 = load i32, i32* %2
%37 = call i32 @calc_matrix_vector(i32 %35, i32 %36, double** %9, double* %28, double* %32)
%38 = call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%39 = load i32, i32* %1
%40 = icmp sgt i32 %39, 0
br i1 %40, label %41, label %55
41: ; preds = %23, %41
%42 = phi i64 [ %51, %41 ], [ 0, %23 ]
%43 = phi i32 [ %52, %41 ], [ %39, %23 ]
%44 = add nsw i32 %43, -1
%45 = zext i32 %44 to i64
%46 = icmp eq i64 %42, %45
%47 = getelementptr inbounds double, double* %32, i64 %42
%48 = load double, double* %47
%49 = select i1 %46, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0)
%50 = call i32 @fprintf(i32* %38, i8* %49, double %48)
%51 = add nuw nsw i64 %42, 1
%52 = load i32, i32* %1
%53 = sext i32 %52 to i64
%54 = icmp slt i64 %51, %53
br i1 %54, label %41, label %55
55: ; preds = %41, %23
%56 = call i32 @fclose(i32* %38)
ret void
}