#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*/ Get_dims(int *, int *);
int /*<<< orphan*/ Mat_vect_mult(double *, double *, double *, int, int);
int /*<<< orphan*/ Print_vector(char *, double *, int);
int /*<<< orphan*/ Read_matrix(char *, double *, int, int);
int /*<<< orphan*/ Read_vector(char *, double *, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ free(double *);
double *malloc(int);
int /*<<< orphan*/ stderr;
int main(void) {
  double *A = NULL;
  double *x = NULL;
  double *y = NULL;
  int m, n;
  Get_dims(&m, &n);
  A = malloc(m * n * sizeof(double));
  x = malloc(n * sizeof(double));
  y = malloc(m * sizeof(double));
  if (A == NULL || x == NULL || y == NULL) {
    fprintf(stderr, "Can't allocate storage\n");
    exit(-1);
  }
  Read_matrix("A", A, m, n);
  Read_vector("x", x, n);
  Mat_vect_mult(A, x, y, m, n);
  Print_vector("y", y, m);
  free(A);
  free(x);
  free(y);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x0,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
lea    -0x24(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   1050 <Get_dims@plt>
mov    -0x24(%rbp),%eax
imul   -0x28(%rbp),%eax
cltq
shl    $0x3,%rax
mov    %eax,%edi
call   1090 <malloc@plt>
mov    %rax,-0x10(%rbp)
movslq -0x28(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1090 <malloc@plt>
mov    %rax,-0x18(%rbp)
movslq -0x24(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1090 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1223 <main+0x93>
cmpq   $0x0,-0x18(%rbp)
je     1223 <main+0x93>
cmpq   $0x0,-0x20(%rbp)
jne    1242 <main+0xb2>
mov    0x2db6(%rip),%rax
mov    (%rax),%edi
lea    0xdcd(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>
mov    -0x10(%rbp),%rsi
mov    -0x24(%rbp),%edx
mov    -0x28(%rbp),%ecx
lea    0xdc5(%rip),%rdi
call   1080 <Read_matrix@plt>
mov    -0x18(%rbp),%rsi
mov    -0x28(%rbp),%edx
lea    0xdb4(%rip),%rdi
call   10b0 <Read_vector@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x24(%rbp),%ecx
mov    -0x28(%rbp),%r8d
call   1030 <Mat_vect_mult@plt>
mov    -0x20(%rbp),%rsi
mov    -0x24(%rbp),%edx
lea    0xd8b(%rip),%rdi
call   1070 <Print_vector@plt>
mov    -0x10(%rbp),%rdi
call   1040 <free@plt>
mov    -0x18(%rbp),%rdi
call   1040 <free@plt>
mov    -0x20(%rbp),%rdi
call   1040 <free@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
push   %rax
lea    0x4(%rsp),%rdi
mov    %rsp,%rsi
call   1050 <Get_dims@plt>
mov    0x4(%rsp),%r12d
mov    (%rsp),%ebx
lea    0x0(,%r12,8),%ebp
mov    %ebp,%edi
imul   %ebx,%edi
call   1090 <malloc@plt>
mov    %rax,%r14
lea    0x0(,%rbx,8),%edi
call   1090 <malloc@plt>
mov    %rax,%r15
mov    %ebp,%edi
call   1090 <malloc@plt>
test   %r14,%r14
je     126d <main+0xdd>
test   %r15,%r15
je     126d <main+0xdd>
mov    %rax,%r13
test   %rax,%rax
je     126d <main+0xdd>
lea    0xe1c(%rip),%rdi
mov    %r14,%rsi
mov    %r12d,%edx
mov    %ebx,%ecx
call   1080 <Read_matrix@plt>
mov    (%rsp),%edx
lea    0xe07(%rip),%rdi
mov    %r15,%rsi
call   10b0 <Read_vector@plt>
mov    0x4(%rsp),%ecx
mov    (%rsp),%r8d
mov    %r14,%rdi
mov    %r15,%rsi
mov    %r13,%rdx
call   1030 <Mat_vect_mult@plt>
mov    0x4(%rsp),%edx
lea    0xde0(%rip),%rdi
mov    %r13,%rsi
call   1070 <Print_vector@plt>
mov    %r14,%rdi
call   1040 <free@plt>
mov    %r15,%rdi
call   1040 <free@plt>
mov    %r13,%rdi
call   1040 <free@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d6c(%rip),%rax
mov    (%rax),%edi
lea    0xd83(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [24 x i8] c"Can't allocate storage\0A\00"
@.str.1 = [2 x i8] c"A\00"
@.str.2 = [2 x i8] c"x\00"
@.str.3 = [2 x i8] c"y\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca double*
%3 = alloca double*
%4 = alloca double*
%5 = alloca i32
%6 = alloca i32
store i32 0, i32* %1
store double* null, double** %2
store double* null, double** %3
store double* null, double** %4
%7 = call i32 @Get_dims(i32* %5, i32* %6)
%8 = load i32, i32* %5
%9 = load i32, i32* %6
%10 = mul nsw i32 %8, %9
%11 = sext i32 %10 to i64
%12 = mul i64 %11, 8
%13 = trunc i64 %12 to i32
%14 = call double* @malloc(i32 %13)
store double* %14, double** %2
%15 = load i32, i32* %6
%16 = sext i32 %15 to i64
%17 = mul i64 %16, 8
%18 = trunc i64 %17 to i32
%19 = call double* @malloc(i32 %18)
store double* %19, double** %3
%20 = load i32, i32* %5
%21 = sext i32 %20 to i64
%22 = mul i64 %21, 8
%23 = trunc i64 %22 to i32
%24 = call double* @malloc(i32 %23)
store double* %24, double** %4
%25 = load double*, double** %2
%26 = icmp eq double* %25, null
br i1 %26, label %33, label %27
27: ; preds = %0
%28 = load double*, double** %3
%29 = icmp eq double* %28, null
br i1 %29, label %33, label %30
30: ; preds = %27
%31 = load double*, double** %4
%32 = icmp eq double* %31, null
br i1 %32, label %33, label %37
33: ; preds = %30, %27, %0
%34 = load i32, i32* @stderr
%35 = call i32 @fprintf(i32 %34, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
%36 = call i32 @exit(i32 -1)
unreachable
37: ; preds = %30
%38 = load double*, double** %2
%39 = load i32, i32* %5
%40 = load i32, i32* %6
%41 = call i32 @Read_matrix(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), double* %38, i32 %39, i32 %40)
%42 = load double*, double** %3
%43 = load i32, i32* %6
%44 = call i32 @Read_vector(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), double* %42, i32 %43)
%45 = load double*, double** %2
%46 = load double*, double** %3
%47 = load double*, double** %4
%48 = load i32, i32* %5
%49 = load i32, i32* %6
%50 = call i32 @Mat_vect_mult(double* %45, double* %46, double* %47, i32 %48, i32 %49)
%51 = load double*, double** %4
%52 = load i32, i32* %5
%53 = call i32 @Print_vector(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), double* %51, i32 %52)
%54 = load double*, double** %2
%55 = call i32 @free(double* %54)
%56 = load double*, double** %3
%57 = call i32 @free(double* %56)
%58 = load double*, double** %4
%59 = call i32 @free(double* %58)
ret i32 0
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [24 x i8] c"Can't allocate storage\0A\00"
@.str.1 = [2 x i8] c"A\00"
@.str.2 = [2 x i8] c"x\00"
@.str.3 = [2 x i8] c"y\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = bitcast i32* %1 to i8*
%4 = bitcast i32* %2 to i8*
%5 = call i32 @Get_dims(i32* %1, i32* %2)
%6 = load i32, i32* %1
%7 = load i32, i32* %2
%8 = shl i32 %6, 3
%9 = mul i32 %8, %7
%10 = call double* @malloc(i32 %9)
%11 = shl i32 %7, 3
%12 = call double* @malloc(i32 %11)
%13 = call double* @malloc(i32 %8)
%14 = icmp eq double* %10, null
%15 = icmp eq double* %12, null
%16 = or i1 %14, %15
%17 = icmp eq double* %13, null
%18 = or i1 %16, %17
br i1 %18, label %19, label %23
19: ; preds = %0
%20 = load i32, i32* @stderr
%21 = call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
%22 = call i32 @exit(i32 -1)
unreachable
23: ; preds = %0
%24 = call i32 @Read_matrix(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), double* %10, i32 %6, i32 %7)
%25 = load i32, i32* %2
%26 = call i32 @Read_vector(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), double* %12, i32 %25)
%27 = load i32, i32* %1
%28 = load i32, i32* %2
%29 = call i32 @Mat_vect_mult(double* %10, double* %12, double* %13, i32 %27, i32 %28)
%30 = load i32, i32* %1
%31 = call i32 @Print_vector(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), double* %13, i32 %30)
%32 = call i32 @free(double* %10)
%33 = call i32 @free(double* %12)
%34 = call i32 @free(double* %13)
ret i32 0
}