#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*/ EXIT_FAILURE;
scalar_t__ calloc(int, int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ stderr;
double **pointwise_multiplication(double **mat1, double scal, int mat1_row,
                                  int mat1_col, double **mat2, int mat2_row,
                                  int mat2_col) {
  if (mat1_row != mat2_row && mat1_col != mat2_col) {
    fprintf(stderr, "ERROR: columns of mat1 and rows of mat2 are not matched!");
    exit(EXIT_FAILURE);
  }
  double **product = (double **)calloc(mat1_row, sizeof(double *));
  for (int i = 0; i < mat1_row; i++)
    product[i] = (double *)calloc(mat1_col, sizeof(double));
  for (int i = 0; i < mat1_row; i++)
    for (int j = 0; j < mat1_col; j++) {
      if (scal && !mat1)
        product[i][j] = scal * mat2[i][j];
      else if (!scal && mat1)
        product[i][j] = mat1[i][j] * mat2[i][j];
      else {
        fprintf(
            stderr,
            "ERROR: Scalar or pointwise matrix multiplication? I'm confused!");
        exit(EXIT_FAILURE);
      }
    }
  return product;
}


x86 assembly (clang, -O0):
<pointwise_multiplication>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
movsd  %xmm0,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
mov    %r9d,-0x28(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x24(%rbp),%eax
je     118e <pointwise_multiplication+0x5e>
mov    -0x18(%rbp),%eax
cmp    -0x28(%rbp),%eax
je     118e <pointwise_multiplication+0x5e>
mov    0x2e6e(%rip),%rax
mov    (%rax),%edi
lea    0xe85(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2e51(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>
mov    -0x14(%rbp),%edi
mov    $0x8,%esi
call   1030 <calloc@plt>
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11dc <pointwise_multiplication+0xac>
mov    -0x18(%rbp),%edi
mov    $0x8,%esi
call   1030 <calloc@plt>
mov    %rax,%rdx
mov    -0x30(%rbp),%rax
movslq -0x34(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    11a6 <pointwise_multiplication+0x76>
movl   $0x0,-0x38(%rbp)
mov    -0x38(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1313 <pointwise_multiplication+0x1e3>
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    1300 <pointwise_multiplication+0x1d0>
movsd  -0x10(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    121f <pointwise_multiplication+0xef>
jp     121f <pointwise_multiplication+0xef>
jmp    125e <pointwise_multiplication+0x12e>
cmpq   $0x0,-0x8(%rbp)
jne    125e <pointwise_multiplication+0x12e>
movsd  -0x10(%rbp),%xmm0
mov    -0x20(%rbp),%rax
movslq -0x38(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x3c(%rbp),%rcx
mulsd  (%rax,%rcx,8),%xmm0
mov    -0x30(%rbp),%rax
movslq -0x38(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x3c(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
jmp    12ed <pointwise_multiplication+0x1bd>
movsd  -0x10(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    12c5 <pointwise_multiplication+0x195>
jp     12c5 <pointwise_multiplication+0x195>
cmpq   $0x0,-0x8(%rbp)
je     12c5 <pointwise_multiplication+0x195>
mov    -0x8(%rbp),%rax
movslq -0x38(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x3c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x20(%rbp),%rax
movslq -0x38(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x3c(%rbp),%rcx
mulsd  (%rax,%rcx,8),%xmm0
mov    -0x30(%rbp),%rax
movslq -0x38(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x3c(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
jmp    12e8 <pointwise_multiplication+0x1b8>
mov    0x2d14(%rip),%rax
mov    (%rax),%edi
lea    0xd64(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2cf7(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>
jmp    12ed <pointwise_multiplication+0x1bd>
jmp    12f2 <pointwise_multiplication+0x1c2>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    11f6 <pointwise_multiplication+0xc6>
jmp    1305 <pointwise_multiplication+0x1d5>
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    11e3 <pointwise_multiplication+0xb3>
mov    -0x30(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pointwise_multiplication>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rcx,0x8(%rsp)
mov    %edx,%r13d
mov    %esi,%r12d
movsd  %xmm0,0x10(%rsp)
mov    %rdi,%rbx
cmp    %r8d,%esi
je     1160 <pointwise_multiplication+0x30>
cmp    %r9d,%r13d
jne    126c <pointwise_multiplication+0x13c>
mov    %r12d,%edi
mov    $0x8,%esi
call   1030 <calloc@plt>
mov    %rax,%r15
test   %r12d,%r12d
jle    1237 <pointwise_multiplication+0x107>
mov    %r12d,%r14d
xor    %ebp,%ebp
xchg   %ax,%ax
mov    %r13d,%edi
mov    $0x8,%esi
call   1030 <calloc@plt>
mov    %rax,(%r15,%rbp,8)
add    $0x1,%rbp
cmp    %rbp,%r14
jne    1180 <pointwise_multiplication+0x50>
test   %r12d,%r12d
mov    0x8(%rsp),%r9
movsd  0x10(%rsp),%xmm1
jle    1237 <pointwise_multiplication+0x107>
mov    %rbx,%r10
xorpd  %xmm0,%xmm0
ucomisd %xmm0,%xmm1
setnp  %al
sete   %r8b
and    %al,%r8b
test   %rbx,%rbx
setne  %al
mov    %eax,%ecx
or     %r8b,%cl
and    %al,%r8b
mov    %r13d,%edx
xor    %esi,%esi
jmp    11e9 <pointwise_multiplication+0xb9>
nopl   0x0(%rax,%rax,1)
add    $0x1,%rsi
cmp    %r14,%rsi
je     1237 <pointwise_multiplication+0x107>
test   %r13d,%r13d
jle    11e0 <pointwise_multiplication+0xb0>
lea    (%r9,%rsi,8),%rbx
lea    (%r10,%rsi,8),%rbp
xor    %eax,%eax
jmp    121a <pointwise_multiplication+0xea>
nopw   0x0(%rax,%rax,1)
mov    (%rdi),%rdi
mulsd  (%rdi,%rax,8),%xmm0
mov    (%r15,%rsi,8),%rdi
movsd  %xmm0,(%rdi,%rax,8)
add    $0x1,%rax
cmp    %rax,%rdx
je     11e0 <pointwise_multiplication+0xb0>
movapd %xmm1,%xmm0
mov    %rbx,%rdi
test   %cl,%cl
je     1200 <pointwise_multiplication+0xd0>
test   %r8b,%r8b
je     1249 <pointwise_multiplication+0x119>
mov    (%rbx),%rdi
movsd  (%rdi,%rax,8),%xmm0
mov    %rbp,%rdi
jmp    1200 <pointwise_multiplication+0xd0>
mov    %r15,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d90(%rip),%rax
mov    (%rax),%edi
lea    0xde0(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2d73(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>
mov    0x2d6d(%rip),%rax
mov    (%rax),%edi
lea    0xd84(%rip),%rsi
jmp    1259 <pointwise_multiplication+0x129>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [57 x i8] c"ERROR: columns of mat1 and rows of mat2 are not matched!\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [64 x i8] c"ERROR: Scalar or pointwise matrix multiplication? I'm confused!\00"
define double** @pointwise_multiplication(double** %0, double %1, i32 %2, i32 %3, double** %4, i32 %5, i32 %6) {
%8 = alloca double**
%9 = alloca double
%10 = alloca i32
%11 = alloca i32
%12 = alloca double**
%13 = alloca i32
%14 = alloca i32
%15 = alloca double**
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32
store double** %0, double*** %8
store double %1, double* %9
store i32 %2, i32* %10
store i32 %3, i32* %11
store double** %4, double*** %12
store i32 %5, i32* %13
store i32 %6, i32* %14
%19 = load i32, i32* %10
%20 = load i32, i32* %13
%21 = icmp ne i32 %19, %20
br i1 %21, label %22, label %31
22: ; preds = %7
%23 = load i32, i32* %11
%24 = load i32, i32* %14
%25 = icmp ne i32 %23, %24
br i1 %25, label %26, label %31
26: ; preds = %22
%27 = load i32, i32* @stderr
%28 = call i32 @fprintf(i32 %27, i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str, i64 0, i64 0))
%29 = load i32, i32* @EXIT_FAILURE
%30 = call i32 @exit(i32 %29)
unreachable
31: ; preds = %22, %7
%32 = load i32, i32* %10
%33 = call i64 @calloc(i32 %32, i32 8)
%34 = inttoptr i64 %33 to double**
store double** %34, double*** %15
store i32 0, i32* %16
br label %35
35: ; preds = %47, %31
%36 = load i32, i32* %16
%37 = load i32, i32* %10
%38 = icmp slt i32 %36, %37
br i1 %38, label %39, label %50
39: ; preds = %35
%40 = load i32, i32* %11
%41 = call i64 @calloc(i32 %40, i32 8)
%42 = inttoptr i64 %41 to double*
%43 = load double**, double*** %15
%44 = load i32, i32* %16
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds double*, double** %43, i64 %45
store double* %42, double** %46
br label %47
47: ; preds = %39
%48 = load i32, i32* %16
%49 = add nsw i32 %48, 1
store i32 %49, i32* %16
br label %35
50: ; preds = %35
store i32 0, i32* %17
br label %51
51: ; preds = %131, %50
%52 = load i32, i32* %17
%53 = load i32, i32* %10
%54 = icmp slt i32 %52, %53
br i1 %54, label %55, label %134
55: ; preds = %51
store i32 0, i32* %18
br label %56
56: ; preds = %127, %55
%57 = load i32, i32* %18
%58 = load i32, i32* %11
%59 = icmp slt i32 %57, %58
br i1 %59, label %60, label %130
60: ; preds = %56
%61 = load double, double* %9
%62 = fcmp une double %61, 0.000000e+00
br i1 %62, label %63, label %86
63: ; preds = %60
%64 = load double**, double*** %8
%65 = icmp ne double** %64, null
br i1 %65, label %86, label %66
66: ; preds = %63
%67 = load double, double* %9
%68 = load double**, double*** %12
%69 = load i32, i32* %17
%70 = sext i32 %69 to i64
%71 = getelementptr inbounds double*, double** %68, i64 %70
%72 = load double*, double** %71
%73 = load i32, i32* %18
%74 = sext i32 %73 to i64
%75 = getelementptr inbounds double, double* %72, i64 %74
%76 = load double, double* %75
%77 = fmul double %67, %76
%78 = load double**, double*** %15
%79 = load i32, i32* %17
%80 = sext i32 %79 to i64
%81 = getelementptr inbounds double*, double** %78, i64 %80
%82 = load double*, double** %81
%83 = load i32, i32* %18
%84 = sext i32 %83 to i64
%85 = getelementptr inbounds double, double* %82, i64 %84
store double %77, double* %85
br label %126
86: ; preds = %63, %60
%87 = load double, double* %9
%88 = fcmp une double %87, 0.000000e+00
br i1 %88, label %120, label %89
89: ; preds = %86
%90 = load double**, double*** %8
%91 = icmp ne double** %90, null
br i1 %91, label %92, label %120
92: ; preds = %89
%93 = load double**, double*** %8
%94 = load i32, i32* %17
%95 = sext i32 %94 to i64
%96 = getelementptr inbounds double*, double** %93, i64 %95
%97 = load double*, double** %96
%98 = load i32, i32* %18
%99 = sext i32 %98 to i64
%100 = getelementptr inbounds double, double* %97, i64 %99
%101 = load double, double* %100
%102 = load double**, double*** %12
%103 = load i32, i32* %17
%104 = sext i32 %103 to i64
%105 = getelementptr inbounds double*, double** %102, i64 %104
%106 = load double*, double** %105
%107 = load i32, i32* %18
%108 = sext i32 %107 to i64
%109 = getelementptr inbounds double, double* %106, i64 %108
%110 = load double, double* %109
%111 = fmul double %101, %110
%112 = load double**, double*** %15
%113 = load i32, i32* %17
%114 = sext i32 %113 to i64
%115 = getelementptr inbounds double*, double** %112, i64 %114
%116 = load double*, double** %115
%117 = load i32, i32* %18
%118 = sext i32 %117 to i64
%119 = getelementptr inbounds double, double* %116, i64 %118
store double %111, double* %119
br label %125
120: ; preds = %89, %86
%121 = load i32, i32* @stderr
%122 = call i32 @fprintf(i32 %121, i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str.1, i64 0, i64 0))
%123 = load i32, i32* @EXIT_FAILURE
%124 = call i32 @exit(i32 %123)
unreachable
125: ; preds = %92
br label %126
126: ; preds = %125, %66
br label %127
127: ; preds = %126
%128 = load i32, i32* %18
%129 = add nsw i32 %128, 1
store i32 %129, i32* %18
br label %56
130: ; preds = %56
br label %131
131: ; preds = %130
%132 = load i32, i32* %17
%133 = add nsw i32 %132, 1
store i32 %133, i32* %17
br label %51
134: ; preds = %51
%135 = load double**, double*** %15
ret double** %135
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [57 x i8] c"ERROR: columns of mat1 and rows of mat2 are not matched!\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [64 x i8] c"ERROR: Scalar or pointwise matrix multiplication? I'm confused!\00"
define double** @pointwise_multiplication(double** %0, double %1, i32 %2, i32 %3, double** nocapture %4, i32 %5, i32 %6) {
%8 = icmp eq i32 %2, %5
%9 = icmp eq i32 %3, %6
%10 = or i1 %8, %9
br i1 %10, label %16, label %11
11: ; preds = %7
%12 = load i32, i32* @stderr
%13 = tail call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str, i64 0, i64 0))
%14 = load i32, i32* @EXIT_FAILURE
%15 = tail call i32 @exit(i32 %14)
unreachable
16: ; preds = %7
%17 = tail call i64 @calloc(i32 %2, i32 8)
%18 = inttoptr i64 %17 to double**
%19 = icmp sgt i32 %2, 0
br i1 %19, label %20, label %44
20: ; preds = %16
%21 = zext i32 %2 to i64
br label %31
22: ; preds = %31
br i1 %19, label %23, label %44
23: ; preds = %22
%24 = icmp sgt i32 %3, 0
%25 = fcmp oeq double %1, 0.000000e+00
%26 = icmp ne double** %0, null
%27 = or i1 %26, %25
%28 = and i1 %26, %25
%29 = zext i32 %2 to i64
%30 = zext i32 %3 to i64
br label %38
31: ; preds = %20, %31
%32 = phi i64 [ 0, %20 ], [ %36, %31 ]
%33 = tail call i64 @calloc(i32 %3, i32 8)
%34 = inttoptr i64 %33 to double*
%35 = getelementptr inbounds double*, double** %18, i64 %32
store double* %34, double** %35
%36 = add nuw nsw i64 %32, 1
%37 = icmp eq i64 %36, %21
br i1 %37, label %22, label %31
38: ; preds = %23, %45
%39 = phi i64 [ 0, %23 ], [ %46, %45 ]
br i1 %24, label %40, label %45
40: ; preds = %38
%41 = getelementptr inbounds double*, double** %4, i64 %39
%42 = getelementptr inbounds double*, double** %18, i64 %39
%43 = getelementptr inbounds double*, double** %0, i64 %39
br label %48
44: ; preds = %45, %16, %22
ret double** %18
45: ; preds = %60, %38
%46 = add nuw nsw i64 %39, 1
%47 = icmp eq i64 %46, %29
br i1 %47, label %44, label %38
48: ; preds = %40, %60
%49 = phi i64 [ 0, %40 ], [ %69, %60 ]
br i1 %27, label %50, label %60
50: ; preds = %48
br i1 %28, label %51, label %55
51: ; preds = %50
%52 = load double*, double** %41
%53 = getelementptr inbounds double, double* %52, i64 %49
%54 = load double, double* %53
br label %60
55: ; preds = %50
%56 = load i32, i32* @stderr
%57 = tail call i32 @fprintf(i32 %56, i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str.1, i64 0, i64 0))
%58 = load i32, i32* @EXIT_FAILURE
%59 = tail call i32 @exit(i32 %58)
unreachable
60: ; preds = %48, %51
%61 = phi double [ %54, %51 ], [ %1, %48 ]
%62 = phi double** [ %43, %51 ], [ %41, %48 ]
%63 = load double*, double** %62
%64 = getelementptr inbounds double, double* %63, i64 %49
%65 = load double, double* %64
%66 = fmul double %65, %61
%67 = load double*, double** %42
%68 = getelementptr inbounds double, double* %67, i64 %49
store double %66, double* %68
%69 = add nuw nsw i64 %49, 1
%70 = icmp eq i64 %69, %30
br i1 %70, label %45, label %48
}