#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 */
typedef int uint64_t;

/* Variables and functions */
int bench_time();
int /*<<< orphan*/ genmatrix(int);
int /*<<< orphan*/ matmult(int, int, int);
int /*<<< orphan*/ printf(char *, int, int, int, int, long long, long long);
int main1(int argc, char **argv) {
  int nbi = 4;
  int nbj = 4;
  int nth = nbi * nbj;
  int dim = 1024;
  int i;
  int niter = 10;
  uint64_t tt = 0;
  for (i = 0; i < niter; ++i) {
    genmatrix(i);
    uint64_t ts = bench_time();
    matmult(nbi, nbj, dim);
    tt += bench_time() - ts;
  }
  tt /= niter;
  printf("blksize %dx%d thr %d itr %d: %lld.%09lld\n", dim / nbi, dim / nbj,
         nth, niter, (long long)tt / 1000000000, (long long)tt % 1000000000);
  return 0;
}


x86 assembly (clang, -O0):
<main1>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x4,-0x14(%rbp)
movl   $0x4,-0x18(%rbp)
mov    -0x14(%rbp),%eax
imul   -0x18(%rbp),%eax
mov    %eax,-0x1c(%rbp)
movl   $0x400,-0x20(%rbp)
movl   $0xa,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x28(%rbp),%eax
jge    11cd <main1+0x8d>
mov    -0x24(%rbp),%edi
call   1050 <genmatrix@plt>
mov    $0x0,%al
call   1060 <bench_time@plt>
mov    %eax,-0x30(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x18(%rbp),%esi
mov    -0x20(%rbp),%edx
call   1040 <matmult@plt>
mov    $0x0,%al
call   1060 <bench_time@plt>
sub    -0x30(%rbp),%eax
add    -0x2c(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1183 <main1+0x43>
mov    -0x28(%rbp),%ecx
mov    -0x2c(%rbp),%eax
cltd
idiv   %ecx
mov    %eax,-0x2c(%rbp)
mov    -0x20(%rbp),%eax
cltd
idivl  -0x14(%rbp)
mov    %eax,%esi
mov    -0x20(%rbp),%eax
cltd
idivl  -0x18(%rbp)
mov    %eax,-0x34(%rbp)
mov    -0x1c(%rbp),%ecx
mov    -0x28(%rbp),%r8d
movslq -0x2c(%rbp),%rax
mov    $0x3b9aca00,%edi
cqto
idiv   %rdi
mov    %rax,%r9
movslq -0x2c(%rbp),%rax
mov    $0x3b9aca00,%edi
cqto
idiv   %rdi
mov    %rdx,%rax
mov    -0x34(%rbp),%edx
lea    0xde1(%rip),%rdi
mov    %rax,(%rsp)
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main1>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
xor    %edi,%edi
call   1050 <genmatrix@plt>
xor    %eax,%eax
call   1060 <bench_time@plt>
mov    %eax,%r15d
mov    $0x4,%edi
mov    $0x4,%esi
mov    $0x400,%edx
call   1040 <matmult@plt>
xor    %eax,%eax
call   1060 <bench_time@plt>
mov    %eax,%r14d
mov    $0x1,%edi
call   1050 <genmatrix@plt>
xor    %eax,%eax
call   1060 <bench_time@plt>
mov    %eax,%ebp
mov    $0x4,%edi
mov    $0x4,%esi
mov    $0x400,%edx
call   1040 <matmult@plt>
xor    %eax,%eax
call   1060 <bench_time@plt>
mov    %eax,%ebx
add    %r15d,%ebp
mov    $0x2,%edi
call   1050 <genmatrix@plt>
xor    %eax,%eax
call   1060 <bench_time@plt>
mov    %eax,%r15d
mov    $0x4,%edi
mov    $0x4,%esi
mov    $0x400,%edx
call   1040 <matmult@plt>
xor    %eax,%eax
call   1060 <bench_time@plt>
mov    %eax,%r12d
add    %r14d,%ebx
add    %ebp,%r15d
mov    $0x3,%edi
call   1050 <genmatrix@plt>
xor    %eax,%eax
call   1060 <bench_time@plt>
mov    %eax,%ebp
mov    $0x4,%edi
mov    $0x4,%esi
mov    $0x400,%edx
call   1040 <matmult@plt>
xor    %eax,%eax
call   1060 <bench_time@plt>
mov    %eax,%r14d
add    %r12d,%ebx
add    %r15d,%ebp
mov    $0x4,%edi
call   1050 <genmatrix@plt>
xor    %eax,%eax
call   1060 <bench_time@plt>
mov    %eax,%r15d
mov    $0x4,%edi
mov    $0x4,%esi
mov    $0x400,%edx
call   1040 <matmult@plt>
xor    %eax,%eax
call   1060 <bench_time@plt>
mov    %eax,%r12d
add    %r14d,%ebx
add    %ebp,%r15d
mov    $0x5,%edi
call   1050 <genmatrix@plt>
xor    %eax,%eax
call   1060 <bench_time@plt>
mov    %eax,%r14d
mov    $0x4,%edi
mov    $0x4,%esi
mov    $0x400,%edx
call   1040 <matmult@plt>
xor    %eax,%eax
call   1060 <bench_time@plt>
mov    %eax,%r13d
add    %r12d,%ebx
add    %r15d,%r14d
mov    $0x6,%edi
call   1050 <genmatrix@plt>
xor    %eax,%eax
call   1060 <bench_time@plt>
mov    %eax,%ebp
mov    $0x4,%edi
mov    $0x4,%esi
mov    $0x400,%edx
call   1040 <matmult@plt>
xor    %eax,%eax
call   1060 <bench_time@plt>
mov    %eax,%r15d
add    %r13d,%ebx
add    %r14d,%ebp
mov    $0x7,%edi
call   1050 <genmatrix@plt>
xor    %eax,%eax
call   1060 <bench_time@plt>
mov    %eax,%r14d
mov    $0x4,%edi
mov    $0x4,%esi
mov    $0x400,%edx
call   1040 <matmult@plt>
xor    %eax,%eax
call   1060 <bench_time@plt>
mov    %eax,%r12d
add    %r15d,%ebx
add    %ebp,%r14d
mov    $0x8,%edi
call   1050 <genmatrix@plt>
xor    %eax,%eax
call   1060 <bench_time@plt>
mov    %eax,%r13d
mov    $0x4,%edi
mov    $0x4,%esi
mov    $0x400,%edx
call   1040 <matmult@plt>
xor    %eax,%eax
call   1060 <bench_time@plt>
mov    %eax,%r15d
add    %r12d,%ebx
add    %r14d,%r13d
mov    $0x9,%edi
call   1050 <genmatrix@plt>
xor    %eax,%eax
call   1060 <bench_time@plt>
mov    %eax,%ebp
mov    $0x4,%edi
mov    $0x4,%esi
mov    $0x400,%edx
call   1040 <matmult@plt>
xor    %eax,%eax
call   1060 <bench_time@plt>
add    %r15d,%ebx
add    %r13d,%ebp
sub    %ebp,%ebx
add    %eax,%ebx
movslq %ebx,%rax
imul   $0x66666667,%rax,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x22,%rax
add    %ecx,%eax
cltq
mov    %rax,(%rsp)
lea    0xc71(%rip),%rdi
mov    $0x100,%esi
mov    $0x100,%edx
mov    $0x10,%ecx
mov    $0xa,%r8d
xor    %r9d,%r9d
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [42 x i8] c"blksize %dx%d thr %d itr %d: %lld.%09lld\0A\00"
define i32 @main1(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store i32 %0, i32* %3
store i8** %1, i8*** %4
store i32 4, i32* %5
store i32 4, i32* %6
%13 = load i32, i32* %5
%14 = load i32, i32* %6
%15 = mul nsw i32 %13, %14
store i32 %15, i32* %7
store i32 1024, i32* %8
store i32 10, i32* %10
store i32 0, i32* %11
store i32 0, i32* %9
br label %16
16: ; preds = %33, %2
%17 = load i32, i32* %9
%18 = load i32, i32* %10
%19 = icmp slt i32 %17, %18
br i1 %19, label %20, label %36
20: ; preds = %16
%21 = load i32, i32* %9
%22 = call i32 @genmatrix(i32 %21)
%23 = call i32 (...) @bench_time()
store i32 %23, i32* %12
%24 = load i32, i32* %5
%25 = load i32, i32* %6
%26 = load i32, i32* %8
%27 = call i32 @matmult(i32 %24, i32 %25, i32 %26)
%28 = call i32 (...) @bench_time()
%29 = load i32, i32* %12
%30 = sub nsw i32 %28, %29
%31 = load i32, i32* %11
%32 = add nsw i32 %31, %30
store i32 %32, i32* %11
br label %33
33: ; preds = %20
%34 = load i32, i32* %9
%35 = add nsw i32 %34, 1
store i32 %35, i32* %9
br label %16
36: ; preds = %16
%37 = load i32, i32* %10
%38 = load i32, i32* %11
%39 = sdiv i32 %38, %37
store i32 %39, i32* %11
%40 = load i32, i32* %8
%41 = load i32, i32* %5
%42 = sdiv i32 %40, %41
%43 = load i32, i32* %8
%44 = load i32, i32* %6
%45 = sdiv i32 %43, %44
%46 = load i32, i32* %7
%47 = load i32, i32* %10
%48 = load i32, i32* %11
%49 = sext i32 %48 to i64
%50 = sdiv i64 %49, 1000000000
%51 = load i32, i32* %11
%52 = sext i32 %51 to i64
%53 = srem i64 %52, 1000000000
%54 = call i32 @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0), i32 %42, i32 %45, i32 %46, i32 %47, i64 %50, i64 %53)
ret i32 0
}

LLVM IR (-O2):
@.str = [42 x i8] c"blksize %dx%d thr %d itr %d: %lld.%09lld\0A\00"
define i32 @main1(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32 @genmatrix(i32 0)
%4 = tail call i32 (...) @bench_time()
%5 = tail call i32 @matmult(i32 4, i32 4, i32 1024)
%6 = tail call i32 (...) @bench_time()
%7 = tail call i32 @genmatrix(i32 1)
%8 = tail call i32 (...) @bench_time()
%9 = tail call i32 @matmult(i32 4, i32 4, i32 1024)
%10 = tail call i32 (...) @bench_time()
%11 = add i32 %4, %8
%12 = tail call i32 @genmatrix(i32 2)
%13 = tail call i32 (...) @bench_time()
%14 = tail call i32 @matmult(i32 4, i32 4, i32 1024)
%15 = tail call i32 (...) @bench_time()
%16 = add i32 %6, %10
%17 = add i32 %11, %13
%18 = tail call i32 @genmatrix(i32 3)
%19 = tail call i32 (...) @bench_time()
%20 = tail call i32 @matmult(i32 4, i32 4, i32 1024)
%21 = tail call i32 (...) @bench_time()
%22 = add i32 %16, %15
%23 = add i32 %17, %19
%24 = tail call i32 @genmatrix(i32 4)
%25 = tail call i32 (...) @bench_time()
%26 = tail call i32 @matmult(i32 4, i32 4, i32 1024)
%27 = tail call i32 (...) @bench_time()
%28 = add i32 %22, %21
%29 = add i32 %23, %25
%30 = tail call i32 @genmatrix(i32 5)
%31 = tail call i32 (...) @bench_time()
%32 = tail call i32 @matmult(i32 4, i32 4, i32 1024)
%33 = tail call i32 (...) @bench_time()
%34 = add i32 %28, %27
%35 = add i32 %29, %31
%36 = tail call i32 @genmatrix(i32 6)
%37 = tail call i32 (...) @bench_time()
%38 = tail call i32 @matmult(i32 4, i32 4, i32 1024)
%39 = tail call i32 (...) @bench_time()
%40 = add i32 %34, %33
%41 = add i32 %35, %37
%42 = tail call i32 @genmatrix(i32 7)
%43 = tail call i32 (...) @bench_time()
%44 = tail call i32 @matmult(i32 4, i32 4, i32 1024)
%45 = tail call i32 (...) @bench_time()
%46 = add i32 %40, %39
%47 = add i32 %41, %43
%48 = tail call i32 @genmatrix(i32 8)
%49 = tail call i32 (...) @bench_time()
%50 = tail call i32 @matmult(i32 4, i32 4, i32 1024)
%51 = tail call i32 (...) @bench_time()
%52 = add i32 %46, %45
%53 = add i32 %47, %49
%54 = tail call i32 @genmatrix(i32 9)
%55 = tail call i32 (...) @bench_time()
%56 = tail call i32 @matmult(i32 4, i32 4, i32 1024)
%57 = tail call i32 (...) @bench_time()
%58 = add i32 %52, %51
%59 = add i32 %53, %55
%60 = sub i32 %58, %59
%61 = add i32 %60, %57
%62 = sdiv i32 %61, 10
%63 = sext i32 %62 to i64
%64 = tail call i32 @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0), i32 256, i32 256, i32 16, i32 10, i64 0, i64 %63)
ret i32 0
}