#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*/ printf(char *, int);
void fast_matrix_multiplication(int a[500][500], int b[500][500]) {
  int c[500][500];
  int res = 0;
  for (int i = 0; i < 500; i++)
    for (int k = 0; k < 500; k++)
      for (int j = 0; j < 500; j++)
        c[i][j] = a[i][k] * b[k][j];
  for (int m = 0; m < 500; m++) {
    for (int n = 0; n < 500; n++)
      res += c[m][n];
  }
  printf("res: %d\nfast ", res);
}


x86 assembly (clang, -O0):
<fast_matrix_multiplication>:
push   %rbp
mov    %rsp,%rbp
sub    $0xf4270,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0xf4254(%rbp)
movl   $0x0,-0xf4258(%rbp)
cmpl   $0x1f4,-0xf4258(%rbp)
jge    1222 <fast_matrix_multiplication+0x112>
movl   $0x0,-0xf425c(%rbp)
cmpl   $0x1f4,-0xf425c(%rbp)
jge    1209 <fast_matrix_multiplication+0xf9>
movl   $0x0,-0xf4260(%rbp)
cmpl   $0x1f4,-0xf4260(%rbp)
jge    11f0 <fast_matrix_multiplication+0xe0>
mov    -0x8(%rbp),%rax
movslq -0xf4258(%rbp),%rcx
imul   $0x7d0,%rcx,%rcx
add    %rcx,%rax
movslq -0xf425c(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
mov    -0x10(%rbp),%rax
movslq -0xf425c(%rbp),%rcx
imul   $0x7d0,%rcx,%rcx
add    %rcx,%rax
movslq -0xf4260(%rbp),%rcx
imul   (%rax,%rcx,4),%edx
movslq -0xf4258(%rbp),%rcx
lea    -0xf4250(%rbp),%rax
imul   $0x7d0,%rcx,%rcx
add    %rcx,%rax
movslq -0xf4260(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0xf4260(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xf4260(%rbp)
jmp    116b <fast_matrix_multiplication+0x5b>
jmp    11f5 <fast_matrix_multiplication+0xe5>
mov    -0xf425c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xf425c(%rbp)
jmp    1151 <fast_matrix_multiplication+0x41>
jmp    120e <fast_matrix_multiplication+0xfe>
mov    -0xf4258(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xf4258(%rbp)
jmp    1137 <fast_matrix_multiplication+0x27>
movl   $0x0,-0xf4264(%rbp)
cmpl   $0x1f4,-0xf4264(%rbp)
jge    12b1 <fast_matrix_multiplication+0x1a1>
movl   $0x0,-0xf4268(%rbp)
cmpl   $0x1f4,-0xf4268(%rbp)
jge    1298 <fast_matrix_multiplication+0x188>
movslq -0xf4264(%rbp),%rcx
lea    -0xf4250(%rbp),%rax
imul   $0x7d0,%rcx,%rcx
add    %rcx,%rax
movslq -0xf4268(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
add    -0xf4254(%rbp),%eax
mov    %eax,-0xf4254(%rbp)
mov    -0xf4268(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xf4268(%rbp)
jmp    1246 <fast_matrix_multiplication+0x136>
jmp    129d <fast_matrix_multiplication+0x18d>
mov    -0xf4264(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xf4264(%rbp)
jmp    122c <fast_matrix_multiplication+0x11c>
mov    -0xf4254(%rbp),%esi
lea    0xd42(%rip),%rdi
call   1030 <printf@plt>
add    $0xf4270,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fast_matrix_multiplication>:
push   %rbp
push   %rbx
sub    $0xf41c8,%rsp
lea    -0x80(%rsp),%rax
xor    %r8d,%r8d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
imul   $0x7d0,%r8,%r9
lea    (%rsp,%r9,1),%r10
add    $0x740,%r10
mov    %rsi,%rdx
xor    %r11d,%r11d
nopl   0x0(%rax,%rax,1)
lea    (%rdi,%r9,1),%rcx
mov    (%rcx,%r11,4),%ecx
movd   %ecx,%xmm0
pshufd $0x0,%xmm0,%xmm0
mov    $0xc,%ebx
cs nopw 0x0(%rax,%rax,1)
movdqu -0x30(%rdx,%rbx,4),%xmm1
movdqu -0x20(%rdx,%rbx,4),%xmm2
pshufd $0xf5,%xmm1,%xmm3
pmuludq %xmm0,%xmm1
pshufd $0xe8,%xmm1,%xmm4
pshufd $0xf5,%xmm0,%xmm1
pmuludq %xmm1,%xmm3
pshufd $0xe8,%xmm3,%xmm3
punpckldq %xmm3,%xmm4
pshufd $0xf5,%xmm2,%xmm3
pmuludq %xmm0,%xmm2
pshufd $0xe8,%xmm2,%xmm2
pmuludq %xmm1,%xmm3
pshufd $0xe8,%xmm3,%xmm3
punpckldq %xmm3,%xmm2
movdqa %xmm4,-0x30(%rax,%rbx,4)
movdqa %xmm2,-0x20(%rax,%rbx,4)
movdqu -0x10(%rdx,%rbx,4),%xmm2
movdqu (%rdx,%rbx,4),%xmm3
pshufd $0xf5,%xmm2,%xmm4
pmuludq %xmm0,%xmm2
pshufd $0xe8,%xmm2,%xmm2
pmuludq %xmm1,%xmm4
pshufd $0xe8,%xmm4,%xmm4
punpckldq %xmm4,%xmm2
pshufd $0xf5,%xmm3,%xmm4
pmuludq %xmm0,%xmm3
pshufd $0xe8,%xmm3,%xmm3
pmuludq %xmm1,%xmm4
pshufd $0xe8,%xmm4,%xmm1
punpckldq %xmm1,%xmm3
movdqa %xmm2,-0x10(%rax,%rbx,4)
movdqa %xmm3,(%rax,%rbx,4)
add    $0x10,%rbx
cmp    $0x1fc,%rbx
jne    1170 <fast_matrix_multiplication+0x60>
imul   $0x7d0,%r11,%rbx
mov    0x7c0(%rsi,%rbx,1),%ebp
imul   %ecx,%ebp
mov    %ebp,(%r10)
mov    0x7c4(%rsi,%rbx,1),%ebp
imul   %ecx,%ebp
mov    %ebp,0x4(%r10)
mov    0x7c8(%rsi,%rbx,1),%ebp
imul   %ecx,%ebp
mov    %ebp,0x8(%r10)
imul   0x7cc(%rsi,%rbx,1),%ecx
mov    %ecx,0xc(%r10)
add    $0x1,%r11
add    $0x7d0,%rdx
cmp    $0x1f4,%r11
jne    1150 <fast_matrix_multiplication+0x40>
add    $0x1,%r8
add    $0x7d0,%rax
cmp    $0x1f4,%r8
jne    1130 <fast_matrix_multiplication+0x20>
xor    %eax,%eax
lea    -0x80(%rsp),%rcx
xor    %esi,%esi
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movd   %esi,%xmm1
pxor   %xmm0,%xmm0
mov    $0xc,%edx
nopl   (%rax)
paddd  -0x30(%rcx,%rdx,4),%xmm1
paddd  -0x20(%rcx,%rdx,4),%xmm0
paddd  -0x10(%rcx,%rdx,4),%xmm1
paddd  (%rcx,%rdx,4),%xmm0
add    $0x10,%rdx
cmp    $0x1fc,%rdx
jne    12b0 <fast_matrix_multiplication+0x1a0>
paddd  %xmm1,%xmm0
pshufd $0xee,%xmm0,%xmm1
paddd  %xmm0,%xmm1
pshufd $0x55,%xmm1,%xmm0
paddd  %xmm1,%xmm0
movd   %xmm0,%esi
imul   $0x7d0,%rax,%rdx
add    0x740(%rsp,%rdx,1),%esi
add    0x744(%rsp,%rdx,1),%esi
add    0x748(%rsp,%rdx,1),%esi
add    0x74c(%rsp,%rdx,1),%esi
add    $0x1,%rax
add    $0x7d0,%rcx
cmp    $0x1f4,%rax
jne    12a0 <fast_matrix_multiplication+0x190>
lea    0xcd1(%rip),%rdi
add    $0xf41c8,%rsp
pop    %rbx
pop    %rbp
jmp    1030 <printf@plt>

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

LLVM IR (-O2):
@.str = [14 x i8] c"res: %d\0Afast \00"
define void @fast_matrix_multiplication([500 x i32]* nocapture %0, [500 x i32]* nocapture %1) {
%3 = alloca [500 x [500 x i32]]
%4 = bitcast [500 x [500 x i32]]* %3 to i8*
br label %5
5: ; preds = %2, %48
%6 = phi i64 [ 0, %2 ], [ %49, %48 ]
%7 = getelementptr inbounds [500 x [500 x i32]], [500 x [500 x i32]]* %3, i64 0, i64 %6, i64 496
%8 = getelementptr inbounds [500 x [500 x i32]], [500 x [500 x i32]]* %3, i64 0, i64 %6, i64 497
%9 = getelementptr inbounds [500 x [500 x i32]], [500 x [500 x i32]]* %3, i64 0, i64 %6, i64 498
%10 = getelementptr inbounds [500 x [500 x i32]], [500 x [500 x i32]]* %3, i64 0, i64 %6, i64 499
br label %11
11: ; preds = %5, %51
%12 = phi i64 [ 0, %5 ], [ %64, %51 ]
%13 = getelementptr inbounds [500 x i32], [500 x i32]* %0, i64 %6, i64 %12
%14 = load i32, i32* %13
%15 = insertelement <4 x i32> poison, i32 %14, i64 0
%16 = shufflevector <4 x i32> %15, <4 x i32> poison, <4 x i32> zeroinitializer
%17 = insertelement <4 x i32> poison, i32 %14, i64 0
%18 = shufflevector <4 x i32> %17, <4 x i32> poison, <4 x i32> zeroinitializer
br label %19
19: ; preds = %19, %11
%20 = phi i64 [ 0, %11 ], [ %46, %19 ]
%21 = getelementptr inbounds [500 x i32], [500 x i32]* %1, i64 %12, i64 %20
%22 = bitcast i32* %21 to <4 x i32>*
%23 = load <4 x i32>, <4 x i32>* %22
%24 = getelementptr inbounds i32, i32* %21, i64 4
%25 = bitcast i32* %24 to <4 x i32>*
%26 = load <4 x i32>, <4 x i32>* %25
%27 = mul nsw <4 x i32> %23, %16
%28 = mul nsw <4 x i32> %26, %18
%29 = getelementptr inbounds [500 x [500 x i32]], [500 x [500 x i32]]* %3, i64 0, i64 %6, i64 %20
%30 = bitcast i32* %29 to <4 x i32>*
store <4 x i32> %27, <4 x i32>* %30
%31 = getelementptr inbounds i32, i32* %29, i64 4
%32 = bitcast i32* %31 to <4 x i32>*
store <4 x i32> %28, <4 x i32>* %32
%33 = or i64 %20, 8
%34 = getelementptr inbounds [500 x i32], [500 x i32]* %1, i64 %12, i64 %33
%35 = bitcast i32* %34 to <4 x i32>*
%36 = load <4 x i32>, <4 x i32>* %35
%37 = getelementptr inbounds i32, i32* %34, i64 4
%38 = bitcast i32* %37 to <4 x i32>*
%39 = load <4 x i32>, <4 x i32>* %38
%40 = mul nsw <4 x i32> %36, %16
%41 = mul nsw <4 x i32> %39, %18
%42 = getelementptr inbounds [500 x [500 x i32]], [500 x [500 x i32]]* %3, i64 0, i64 %6, i64 %33
%43 = bitcast i32* %42 to <4 x i32>*
store <4 x i32> %40, <4 x i32>* %43
%44 = getelementptr inbounds i32, i32* %42, i64 4
%45 = bitcast i32* %44 to <4 x i32>*
store <4 x i32> %41, <4 x i32>* %45
%46 = add nuw nsw i64 %20, 16
%47 = icmp eq i64 %46, 496
br i1 %47, label %51, label %19
48: ; preds = %51
%49 = add nuw nsw i64 %6, 1
%50 = icmp eq i64 %49, 500
br i1 %50, label %66, label %5
51: ; preds = %19
%52 = getelementptr inbounds [500 x i32], [500 x i32]* %1, i64 %12, i64 496
%53 = load i32, i32* %52
%54 = mul nsw i32 %53, %14
store i32 %54, i32* %7
%55 = getelementptr inbounds [500 x i32], [500 x i32]* %1, i64 %12, i64 497
%56 = load i32, i32* %55
%57 = mul nsw i32 %56, %14
store i32 %57, i32* %8
%58 = getelementptr inbounds [500 x i32], [500 x i32]* %1, i64 %12, i64 498
%59 = load i32, i32* %58
%60 = mul nsw i32 %59, %14
store i32 %60, i32* %9
%61 = getelementptr inbounds [500 x i32], [500 x i32]* %1, i64 %12, i64 499
%62 = load i32, i32* %61
%63 = mul nsw i32 %62, %14
store i32 %63, i32* %10
%64 = add nuw nsw i64 %12, 1
%65 = icmp eq i64 %64, 500
br i1 %65, label %48, label %11
66: ; preds = %48, %95
%67 = phi i64 [ %110, %95 ], [ 0, %48 ]
%68 = phi i32 [ %109, %95 ], [ 0, %48 ]
%69 = insertelement <4 x i32> <i32 poison, i32 0, i32 0, i32 0>, i32 %68, i64 0
br label %70
70: ; preds = %70, %66
%71 = phi i64 [ 0, %66 ], [ %91, %70 ]
%72 = phi <4 x i32> [ %69, %66 ], [ %89, %70 ]
%73 = phi <4 x i32> [ zeroinitializer, %66 ], [ %90, %70 ]
%74 = getelementptr inbounds [500 x [500 x i32]], [500 x [500 x i32]]* %3, i64 0, i64 %67, i64 %71
%75 = bitcast i32* %74 to <4 x i32>*
%76 = load <4 x i32>, <4 x i32>* %75
%77 = getelementptr inbounds i32, i32* %74, i64 4
%78 = bitcast i32* %77 to <4 x i32>*
%79 = load <4 x i32>, <4 x i32>* %78
%80 = add <4 x i32> %76, %72
%81 = add <4 x i32> %79, %73
%82 = or i64 %71, 8
%83 = getelementptr inbounds [500 x [500 x i32]], [500 x [500 x i32]]* %3, i64 0, i64 %67, i64 %82
%84 = bitcast i32* %83 to <4 x i32>*
%85 = load <4 x i32>, <4 x i32>* %84
%86 = getelementptr inbounds i32, i32* %83, i64 4
%87 = bitcast i32* %86 to <4 x i32>*
%88 = load <4 x i32>, <4 x i32>* %87
%89 = add <4 x i32> %85, %80
%90 = add <4 x i32> %88, %81
%91 = add nuw nsw i64 %71, 16
%92 = icmp eq i64 %91, 496
br i1 %92, label %95, label %70
93: ; preds = %95
%94 = tail call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %109)
ret void
95: ; preds = %70
%96 = add <4 x i32> %90, %89
%97 = call i32 @llvm.vector.reduce.add.v4i32(<4 x i32> %96)
%98 = getelementptr inbounds [500 x [500 x i32]], [500 x [500 x i32]]* %3, i64 0, i64 %67, i64 496
%99 = load i32, i32* %98
%100 = add nsw i32 %99, %97
%101 = getelementptr inbounds [500 x [500 x i32]], [500 x [500 x i32]]* %3, i64 0, i64 %67, i64 497
%102 = load i32, i32* %101
%103 = add nsw i32 %102, %100
%104 = getelementptr inbounds [500 x [500 x i32]], [500 x [500 x i32]]* %3, i64 0, i64 %67, i64 498
%105 = load i32, i32* %104
%106 = add nsw i32 %105, %103
%107 = getelementptr inbounds [500 x [500 x i32]], [500 x [500 x i32]]* %3, i64 0, i64 %67, i64 499
%108 = load i32, i32* %107
%109 = add nsw i32 %108, %106
%110 = add nuw nsw i64 %67, 1
%111 = icmp eq i64 %110, 500
br i1 %111, label %93, label %66
}