#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 omp_get_max_threads();
void dgemm_block_omp(double *a, double *b, double *c, int n) {
  int i, j, k, i0, j0, k0;
  int BS = 2;
  double *c0, *a0, *b0;
  int nthr, chunk;
  nthr = omp_get_max_threads();
  chunk = n / (nthr * 4);
#pragma omp parallel for num_threads(nthr) private(                            \
    i, j, k, i0, j0, k0, c0, a0, b0) schedule(dynamic, chunk)
  for (i = 0; i < n; i += BS) {
    for (j = 0; j < n; j += BS) {
      for (k = 0; k < n; k += BS) {
        for (i0 = 0, c0 = (c + i * n + j), a0 = (a + i * n + k); i0 < BS;
             ++i0, c0 += n, a0 += n) {
          for (k0 = 0, b0 = (b + k * n + j); k0 < BS; ++k0, b0 += n) {
            for (j0 = 0; j0 < BS; ++j0) {
              c0[j0] += a0[k0] * b0[j0];
            }
          }
        }
      }
    }
  }
}


x86 assembly (clang, -O0):
<dgemm_block_omp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
movl   $0x2,-0x38(%rbp)
mov    $0x0,%al
call   1030 <omp_get_max_threads@plt>
mov    %eax,-0x54(%rbp)
mov    -0x1c(%rbp),%eax
mov    -0x54(%rbp),%ecx
shl    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x58(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1305 <dgemm_block_omp+0x1f5>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    12f2 <dgemm_block_omp+0x1e2>
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    12df <dgemm_block_omp+0x1cf>
movl   $0x0,-0x2c(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%ecx
imul   -0x1c(%rbp),%ecx
movslq %ecx,%rcx
shl    $0x3,%rcx
add    %rcx,%rax
movslq -0x24(%rbp),%rcx
shl    $0x3,%rcx
add    %rcx,%rax
mov    %rax,-0x40(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%ecx
imul   -0x1c(%rbp),%ecx
movslq %ecx,%rcx
shl    $0x3,%rcx
add    %rcx,%rax
movslq -0x28(%rbp),%rcx
shl    $0x3,%rcx
add    %rcx,%rax
mov    %rax,-0x48(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x38(%rbp),%eax
jge    12cc <dgemm_block_omp+0x1bc>
movl   $0x0,-0x34(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x28(%rbp),%ecx
imul   -0x1c(%rbp),%ecx
movslq %ecx,%rcx
shl    $0x3,%rcx
add    %rcx,%rax
movslq -0x24(%rbp),%rcx
shl    $0x3,%rcx
add    %rcx,%rax
mov    %rax,-0x50(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x38(%rbp),%eax
jge    128f <dgemm_block_omp+0x17f>
movl   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x38(%rbp),%eax
jge    1267 <dgemm_block_omp+0x157>
mov    -0x48(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x50(%rbp),%rax
movslq -0x30(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm2
mov    -0x40(%rbp),%rax
movslq -0x30(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    1219 <dgemm_block_omp+0x109>
jmp    126c <dgemm_block_omp+0x15c>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
mov    -0x1c(%rbp),%ecx
mov    -0x50(%rbp),%rax
movslq %ecx,%rcx
shl    $0x3,%rcx
add    %rcx,%rax
mov    %rax,-0x50(%rbp)
jmp    1206 <dgemm_block_omp+0xf6>
jmp    1294 <dgemm_block_omp+0x184>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x1c(%rbp),%ecx
mov    -0x40(%rbp),%rax
movslq %ecx,%rcx
shl    $0x3,%rcx
add    %rcx,%rax
mov    %rax,-0x40(%rbp)
mov    -0x1c(%rbp),%ecx
mov    -0x48(%rbp),%rax
movslq %ecx,%rcx
shl    $0x3,%rcx
add    %rcx,%rax
mov    %rax,-0x48(%rbp)
jmp    11cf <dgemm_block_omp+0xbf>
jmp    12d1 <dgemm_block_omp+0x1c1>
mov    -0x38(%rbp),%eax
add    -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
jmp    1174 <dgemm_block_omp+0x64>
jmp    12e4 <dgemm_block_omp+0x1d4>
mov    -0x38(%rbp),%eax
add    -0x24(%rbp),%eax
mov    %eax,-0x24(%rbp)
jmp    1161 <dgemm_block_omp+0x51>
jmp    12f7 <dgemm_block_omp+0x1e7>
mov    -0x38(%rbp),%eax
add    -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
jmp    114e <dgemm_block_omp+0x3e>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dgemm_block_omp>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %ecx,%ebp
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
xor    %eax,%eax
call   1030 <omp_get_max_threads@plt>
test   %ebp,%ebp
jle    1258 <dgemm_block_omp+0x148>
mov    %ebp,%eax
add    $0x8,%r15
mov    %rax,%rcx
shl    $0x4,%rcx
lea    (%rbx,%rax,8),%rdx
add    $0x8,%rdx
add    $0x8,%rbx
xor    %r8d,%r8d
nopl   (%rax)
mov    %r8,%rsi
imul   %rax,%rsi
lea    (%r14,%rsi,8),%r9
mov    %r15,%r10
xor    %r11d,%r11d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
lea    (%r9,%r11,8),%rdi
mov    %r10,%rbp
xor    %esi,%esi
nopl   0x0(%rax)
movsd  -0x8(%rbx,%rsi,8),%xmm0
mulsd  -0x8(%rbp),%xmm0
addsd  (%rdi),%xmm0
movsd  %xmm0,(%rdi)
movsd  -0x8(%rbx,%rsi,8),%xmm1
mulsd  0x0(%rbp),%xmm1
addsd  0x8(%rdi),%xmm1
movsd  %xmm1,0x8(%rdi)
movsd  (%rbx,%rsi,8),%xmm2
mulsd  -0x8(%rbp,%rax,8),%xmm2
addsd  %xmm0,%xmm2
movsd  %xmm2,(%rdi)
movsd  (%rbx,%rsi,8),%xmm0
mulsd  0x0(%rbp,%rax,8),%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,0x8(%rdi)
movsd  -0x8(%rdx,%rsi,8),%xmm0
mulsd  -0x8(%rbp),%xmm0
addsd  (%rdi,%rax,8),%xmm0
movsd  %xmm0,(%rdi,%rax,8)
movsd  -0x8(%rdx,%rsi,8),%xmm1
mulsd  0x0(%rbp),%xmm1
addsd  0x8(%rdi,%rax,8),%xmm1
movsd  %xmm1,0x8(%rdi,%rax,8)
movsd  (%rdx,%rsi,8),%xmm2
mulsd  -0x8(%rbp,%rax,8),%xmm2
addsd  %xmm0,%xmm2
movsd  %xmm2,(%rdi,%rax,8)
movsd  (%rdx,%rsi,8),%xmm0
mulsd  0x0(%rbp,%rax,8),%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,0x8(%rdi,%rax,8)
add    $0x2,%rsi
add    %rcx,%rbp
cmp    %rax,%rsi
jb     1180 <dgemm_block_omp+0x70>
add    $0x2,%r11
add    $0x10,%r10
cmp    %rax,%r11
jb     1170 <dgemm_block_omp+0x60>
add    $0x2,%r8
add    %rcx,%rdx
add    %rcx,%rbx
cmp    %rax,%r8
jb     1150 <dgemm_block_omp+0x40>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @dgemm_block_omp(double* %0, double* %1, double* %2, i32 %3) {
%5 = alloca double*
%6 = alloca double*
%7 = alloca double*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca double*
%17 = alloca double*
%18 = alloca double*
%19 = alloca i32
%20 = alloca i32
store double* %0, double** %5
store double* %1, double** %6
store double* %2, double** %7
store i32 %3, i32* %8
store i32 2, i32* %15
%21 = call i32 (...) @omp_get_max_threads()
store i32 %21, i32* %19
%22 = load i32, i32* %8
%23 = load i32, i32* %19
%24 = mul nsw i32 %23, 4
%25 = sdiv i32 %22, %24
store i32 %25, i32* %20
store i32 0, i32* %9
br label %26
26: ; preds = %133, %4
%27 = load i32, i32* %9
%28 = load i32, i32* %8
%29 = icmp slt i32 %27, %28
br i1 %29, label %30, label %137
30: ; preds = %26
store i32 0, i32* %10
br label %31
31: ; preds = %128, %30
%32 = load i32, i32* %10
%33 = load i32, i32* %8
%34 = icmp slt i32 %32, %33
br i1 %34, label %35, label %132
35: ; preds = %31
store i32 0, i32* %11
br label %36
36: ; preds = %123, %35
%37 = load i32, i32* %11
%38 = load i32, i32* %8
%39 = icmp slt i32 %37, %38
br i1 %39, label %40, label %127
40: ; preds = %36
store i32 0, i32* %12
%41 = load double*, double** %7
%42 = load i32, i32* %9
%43 = load i32, i32* %8
%44 = mul nsw i32 %42, %43
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds double, double* %41, i64 %45
%47 = load i32, i32* %10
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds double, double* %46, i64 %48
store double* %49, double** %16
%50 = load double*, double** %5
%51 = load i32, i32* %9
%52 = load i32, i32* %8
%53 = mul nsw i32 %51, %52
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds double, double* %50, i64 %54
%56 = load i32, i32* %11
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds double, double* %55, i64 %57
store double* %58, double** %17
br label %59
59: ; preds = %111, %40
%60 = load i32, i32* %12
%61 = load i32, i32* %15
%62 = icmp slt i32 %60, %61
br i1 %62, label %63, label %122
63: ; preds = %59
store i32 0, i32* %14
%64 = load double*, double** %6
%65 = load i32, i32* %11
%66 = load i32, i32* %8
%67 = mul nsw i32 %65, %66
%68 = sext i32 %67 to i64
%69 = getelementptr inbounds double, double* %64, i64 %68
%70 = load i32, i32* %10
%71 = sext i32 %70 to i64
%72 = getelementptr inbounds double, double* %69, i64 %71
store double* %72, double** %18
br label %73
73: ; preds = %103, %63
%74 = load i32, i32* %14
%75 = load i32, i32* %15
%76 = icmp slt i32 %74, %75
br i1 %76, label %77, label %110
77: ; preds = %73
store i32 0, i32* %13
br label %78
78: ; preds = %99, %77
%79 = load i32, i32* %13
%80 = load i32, i32* %15
%81 = icmp slt i32 %79, %80
br i1 %81, label %82, label %102
82: ; preds = %78
%83 = load double*, double** %17
%84 = load i32, i32* %14
%85 = sext i32 %84 to i64
%86 = getelementptr inbounds double, double* %83, i64 %85
%87 = load double, double* %86
%88 = load double*, double** %18
%89 = load i32, i32* %13
%90 = sext i32 %89 to i64
%91 = getelementptr inbounds double, double* %88, i64 %90
%92 = load double, double* %91
%93 = load double*, double** %16
%94 = load i32, i32* %13
%95 = sext i32 %94 to i64
%96 = getelementptr inbounds double, double* %93, i64 %95
%97 = load double, double* %96
%98 = call double @llvm.fmuladd.f64(double %87, double %92, double %97)
store double %98, double* %96
br label %99
99: ; preds = %82
%100 = load i32, i32* %13
%101 = add nsw i32 %100, 1
store i32 %101, i32* %13
br label %78
102: ; preds = %78
br label %103
103: ; preds = %102
%104 = load i32, i32* %14
%105 = add nsw i32 %104, 1
store i32 %105, i32* %14
%106 = load i32, i32* %8
%107 = load double*, double** %18
%108 = sext i32 %106 to i64
%109 = getelementptr inbounds double, double* %107, i64 %108
store double* %109, double** %18
br label %73
110: ; preds = %73
br label %111
111: ; preds = %110
%112 = load i32, i32* %12
%113 = add nsw i32 %112, 1
store i32 %113, i32* %12
%114 = load i32, i32* %8
%115 = load double*, double** %16
%116 = sext i32 %114 to i64
%117 = getelementptr inbounds double, double* %115, i64 %116
store double* %117, double** %16
%118 = load i32, i32* %8
%119 = load double*, double** %17
%120 = sext i32 %118 to i64
%121 = getelementptr inbounds double, double* %119, i64 %120
store double* %121, double** %17
br label %59
122: ; preds = %59
br label %123
123: ; preds = %122
%124 = load i32, i32* %15
%125 = load i32, i32* %11
%126 = add nsw i32 %125, %124
store i32 %126, i32* %11
br label %36
127: ; preds = %36
br label %128
128: ; preds = %127
%129 = load i32, i32* %15
%130 = load i32, i32* %10
%131 = add nsw i32 %130, %129
store i32 %131, i32* %10
br label %31
132: ; preds = %31
br label %133
133: ; preds = %132
%134 = load i32, i32* %15
%135 = load i32, i32* %9
%136 = add nsw i32 %135, %134
store i32 %136, i32* %9
br label %26
137: ; preds = %26
ret void
}

LLVM IR (-O2):
define void @dgemm_block_omp(double* nocapture %0, double* nocapture %1, double* nocapture %2, i32 %3) {
%5 = tail call i32 (...) @omp_get_max_threads()
%6 = icmp sgt i32 %3, 0
br i1 %6, label %7, label %68
7: ; preds = %4
%8 = zext i32 %3 to i64
br label %9
9: ; preds = %65, %7
%10 = phi i64 [ 0, %7 ], [ %66, %65 ]
%11 = mul nsw i64 %10, %8
%12 = getelementptr inbounds double, double* %2, i64 %11
%13 = getelementptr inbounds double, double* %0, i64 %11
br label %14
14: ; preds = %62, %9
%15 = phi i64 [ 0, %9 ], [ %63, %62 ]
%16 = getelementptr inbounds double, double* %12, i64 %15
%17 = getelementptr inbounds double, double* %1, i64 %15
%18 = getelementptr inbounds double, double* %16, i64 1
%19 = getelementptr inbounds double, double* %16, i64 %8
%20 = getelementptr inbounds double, double* %19, i64 1
br label %21
21: ; preds = %14, %21
%22 = phi i64 [ 0, %14 ], [ %60, %21 ]
%23 = getelementptr inbounds double, double* %13, i64 %22
%24 = mul nsw i64 %22, %8
%25 = getelementptr inbounds double, double* %17, i64 %24
%26 = load double, double* %23
%27 = load double, double* %25
%28 = load double, double* %16
%29 = tail call double @llvm.fmuladd.f64(double %26, double %27, double %28)
store double %29, double* %16
%30 = load double, double* %23
%31 = getelementptr inbounds double, double* %25, i64 1
%32 = load double, double* %31
%33 = load double, double* %18
%34 = tail call double @llvm.fmuladd.f64(double %30, double %32, double %33)
store double %34, double* %18
%35 = getelementptr inbounds double, double* %25, i64 %8
%36 = getelementptr inbounds double, double* %23, i64 1
%37 = load double, double* %36
%38 = load double, double* %35
%39 = tail call double @llvm.fmuladd.f64(double %37, double %38, double %29)
store double %39, double* %16
%40 = load double, double* %36
%41 = getelementptr inbounds double, double* %35, i64 1
%42 = load double, double* %41
%43 = tail call double @llvm.fmuladd.f64(double %40, double %42, double %34)
store double %43, double* %18
%44 = getelementptr inbounds double, double* %23, i64 %8
%45 = load double, double* %44
%46 = load double, double* %25
%47 = load double, double* %19
%48 = tail call double @llvm.fmuladd.f64(double %45, double %46, double %47)
store double %48, double* %19
%49 = load double, double* %44
%50 = load double, double* %31
%51 = load double, double* %20
%52 = tail call double @llvm.fmuladd.f64(double %49, double %50, double %51)
store double %52, double* %20
%53 = getelementptr inbounds double, double* %44, i64 1
%54 = load double, double* %53
%55 = load double, double* %35
%56 = tail call double @llvm.fmuladd.f64(double %54, double %55, double %48)
store double %56, double* %19
%57 = load double, double* %53
%58 = load double, double* %41
%59 = tail call double @llvm.fmuladd.f64(double %57, double %58, double %52)
store double %59, double* %20
%60 = add nuw nsw i64 %22, 2
%61 = icmp ult i64 %60, %8
br i1 %61, label %21, label %62
62: ; preds = %21
%63 = add nuw nsw i64 %15, 2
%64 = icmp ult i64 %63, %8
br i1 %64, label %14, label %65
65: ; preds = %62
%66 = add nuw nsw i64 %10, 2
%67 = icmp ult i64 %66, %8
br i1 %67, label %9, label %68
68: ; preds = %65, %4
ret void
}