#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 slow_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 j = 0; j < 500; j++)
      for (int k = 0; k < 500; k++)
        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\nslow ", res);
}


x86 assembly (clang, -O0):
<slow_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 <slow_matrix_multiplication+0x112>
movl   $0x0,-0xf425c(%rbp)
cmpl   $0x1f4,-0xf425c(%rbp)
jge    1209 <slow_matrix_multiplication+0xf9>
movl   $0x0,-0xf4260(%rbp)
cmpl   $0x1f4,-0xf4260(%rbp)
jge    11f0 <slow_matrix_multiplication+0xe0>
mov    -0x8(%rbp),%rax
movslq -0xf4258(%rbp),%rcx
imul   $0x7d0,%rcx,%rcx
add    %rcx,%rax
movslq -0xf4260(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
mov    -0x10(%rbp),%rax
movslq -0xf4260(%rbp),%rcx
imul   $0x7d0,%rcx,%rcx
add    %rcx,%rax
movslq -0xf425c(%rbp),%rcx
imul   (%rax,%rcx,4),%edx
movslq -0xf4258(%rbp),%rcx
lea    -0xf4250(%rbp),%rax
imul   $0x7d0,%rcx,%rcx
add    %rcx,%rax
movslq -0xf425c(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0xf4260(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xf4260(%rbp)
jmp    116b <slow_matrix_multiplication+0x5b>
jmp    11f5 <slow_matrix_multiplication+0xe5>
mov    -0xf425c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xf425c(%rbp)
jmp    1151 <slow_matrix_multiplication+0x41>
jmp    120e <slow_matrix_multiplication+0xfe>
mov    -0xf4258(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xf4258(%rbp)
jmp    1137 <slow_matrix_multiplication+0x27>
movl   $0x0,-0xf4264(%rbp)
cmpl   $0x1f4,-0xf4264(%rbp)
jge    12b1 <slow_matrix_multiplication+0x1a1>
movl   $0x0,-0xf4268(%rbp)
cmpl   $0x1f4,-0xf4268(%rbp)
jge    1298 <slow_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 <slow_matrix_multiplication+0x136>
jmp    129d <slow_matrix_multiplication+0x18d>
mov    -0xf4264(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xf4264(%rbp)
jmp    122c <slow_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):
<slow_matrix_multiplication>:
push   %r14
push   %rbx
sub    $0xf41c8,%rsp
mov    0xf4230(%rsi),%r8d
mov    0xf4234(%rsi),%r9d
mov    0xf4238(%rsi),%r11d
mov    0xf423c(%rsi),%r10d
lea    -0x50(%rsp),%rcx
xor    %eax,%eax
nopl   (%rax)
imul   $0x7d0,%rax,%r14
mov    0x7cc(%rdi,%r14,1),%ebx
movd   %ebx,%xmm0
pshufd $0x0,%xmm0,%xmm0
xor    %edx,%edx
nopw   0x0(%rax,%rax,1)
movdqu 0xf3a70(%rsi,%rdx,4),%xmm1
movdqu 0xf3a80(%rsi,%rdx,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(%rcx,%rdx,4)
movdqa %xmm2,-0x20(%rcx,%rdx,4)
movdqu 0xf3a90(%rsi,%rdx,4),%xmm2
movdqu 0xf3aa0(%rsi,%rdx,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(%rcx,%rdx,4)
movdqa %xmm3,(%rcx,%rdx,4)
add    $0x10,%rdx
cmp    $0x1f0,%rdx
jne    1160 <slow_matrix_multiplication+0x50>
mov    %r8d,%edx
imul   %ebx,%edx
mov    %edx,0x740(%rsp,%r14,1)
mov    %r9d,%edx
imul   %ebx,%edx
mov    %edx,0x744(%rsp,%r14,1)
mov    %r11d,%edx
imul   %ebx,%edx
mov    %edx,0x748(%rsp,%r14,1)
imul   %r10d,%ebx
mov    %ebx,0x74c(%rsp,%r14,1)
add    $0x1,%rax
add    $0x7d0,%rcx
cmp    $0x1f4,%rax
jne    1140 <slow_matrix_multiplication+0x30>
xor    %eax,%eax
lea    -0x80(%rsp),%rcx
xor    %esi,%esi
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
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    1290 <slow_matrix_multiplication+0x180>
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    1280 <slow_matrix_multiplication+0x170>
lea    0xcf1(%rip),%rdi
add    $0xf41c8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <printf@plt>

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