#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 /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int random();
int /*<<< orphan*/ srandom(int);
int generate_matrices(FILE *f, int nra, int nca, int nrb, int ncb, int seed,
                      int limit) {
  int i;
  srandom(seed);
  fprintf(f, "/** Generated by \'matrix_gen\' as test data for inclusion\n"
             " * in \'matrix_mul.c\' during compilation.\n"
             " */\n");
  fprintf(f,
          "#define NROWS_A (%d)\n"
          "#define NCOLS_A (%d)\n"
          "int matrix_a[] = {",
          nra, nca);
  fprintf(f, "%ld", random() % limit);
  for (i = 1; i < nra * nca; i++)
    fprintf(f, ", %ld", random() % limit);
  fprintf(f, "};\n\n");
  fprintf(f,
          "#define NROWS_B (%d)\n"
          "#define NCOLS_B (%d)\n"
          "int matrix_b[] = {",
          nrb, ncb);
  fprintf(f, "%ld", random() % limit);
  for (i = 1; i < nrb * ncb; i++)
    fprintf(f, ", %ld", random() % limit);
  fprintf(f, "};\n");
  return 0;
}


x86 assembly (clang, -O0):
<generate_matrices>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    0x10(%rbp),%eax
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    %r8d,-0x18(%rbp)
mov    %r9d,-0x1c(%rbp)
mov    -0x1c(%rbp),%edi
call   1030 <srandom@plt>
mov    -0x8(%rbp),%rdi
lea    0xe9d(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%edx
mov    -0x10(%rbp),%ecx
lea    0xeec(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    $0x0,%al
call   1050 <random@plt>
mov    -0x28(%rbp),%rdi
cltd
idivl  0x10(%rbp)
lea    0xf06(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0x1,-0x20(%rbp)
mov    -0x20(%rbp),%eax
mov    -0xc(%rbp),%ecx
imul   -0x10(%rbp),%ecx
cmp    %ecx,%eax
jge    11f3 <generate_matrices+0xc3>
mov    -0x8(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    $0x0,%al
call   1050 <random@plt>
mov    -0x30(%rbp),%rdi
cltd
idivl  0x10(%rbp)
lea    0xec6(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    11ae <generate_matrices+0x7e>
mov    -0x8(%rbp),%rdi
lea    0xeac(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%edx
mov    -0x18(%rbp),%ecx
lea    0xe99(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    $0x0,%al
call   1050 <random@plt>
mov    -0x38(%rbp),%rdi
cltd
idivl  0x10(%rbp)
lea    0xe6b(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0x1,-0x20(%rbp)
mov    -0x20(%rbp),%eax
mov    -0x14(%rbp),%ecx
imul   -0x18(%rbp),%ecx
cmp    %ecx,%eax
jge    128e <generate_matrices+0x15e>
mov    -0x8(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    $0x0,%al
call   1050 <random@plt>
mov    -0x40(%rbp),%rdi
cltd
idivl  0x10(%rbp)
lea    0xe2b(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1249 <generate_matrices+0x119>
mov    -0x8(%rbp),%rdi
lea    0xe53(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<generate_matrices>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r8d,%ebp
mov    %ecx,%r14d
mov    %edx,%ebx
mov    %esi,%r12d
mov    %rdi,%r15
mov    0x40(%rsp),%r13d
mov    %r9d,%edi
call   1030 <srandom@plt>
lea    0xe93(%rip),%rdi
mov    $0x66,%esi
mov    $0x1,%edx
mov    %r15,%rcx
call   1060 <fwrite@plt>
lea    0xee1(%rip),%rsi
mov    %r15,%rdi
mov    %r12d,%edx
mov    %ebx,%ecx
xor    %eax,%eax
call   1040 <fprintf@plt>
xor    %eax,%eax
call   1050 <random@plt>
cltd
idiv   %r13d
lea    0xeff(%rip),%rsi
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <fprintf@plt>
imul   %r12d,%ebx
cmp    $0x2,%ebx
jl     11ed <generate_matrices+0xad>
add    $0xffffffff,%ebx
lea    0xee0(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
xor    %eax,%eax
call   1050 <random@plt>
cltd
idiv   %r13d
mov    %r15,%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
add    $0xffffffff,%ebx
jne    11d0 <generate_matrices+0x90>
lea    0xeb6(%rip),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %r15,%rcx
call   1060 <fwrite@plt>
lea    0xea2(%rip),%rsi
mov    %r15,%rdi
mov    %r14d,%edx
mov    %ebp,%ecx
xor    %eax,%eax
call   1040 <fprintf@plt>
xor    %eax,%eax
call   1050 <random@plt>
cltd
idiv   %r13d
lea    0xe78(%rip),%rsi
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <fprintf@plt>
imul   %r14d,%ebp
cmp    $0x2,%ebp
jl     126d <generate_matrices+0x12d>
add    $0xffffffff,%ebp
lea    0xe59(%rip),%rbx
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1050 <random@plt>
cltd
idiv   %r13d
mov    %r15,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
add    $0xffffffff,%ebp
jne    1250 <generate_matrices+0x110>
lea    0xe78(%rip),%rdi
mov    $0x3,%esi
mov    $0x1,%edx
mov    %r15,%rcx
call   1060 <fwrite@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [103 x i8] c"/** Generated by 'matrix_gen' as test data for inclusion\0A * in 'matrix_mul.c' during compilation.\0A */\0A\00"
@.str.1 = [61 x i8] c"#define NROWS_A (%d)\0A#define NCOLS_A (%d)\0Aint matrix_a[] = {\00"
@.str.2 = [4 x i8] c"%ld\00"
@.str.3 = [6 x i8] c", %ld\00"
@.str.4 = [5 x i8] c"};\0A\0A\00"
@.str.5 = [61 x i8] c"#define NROWS_B (%d)\0A#define NCOLS_B (%d)\0Aint matrix_b[] = {\00"
@.str.6 = [4 x i8] c"};\0A\00"
define i32 @generate_matrices(i32* %0, i32 %1, i32 %2, i32 %3, i32 %4, i32 %5, i32 %6) {
%8 = alloca i32*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
store i32* %0, i32** %8
store i32 %1, i32* %9
store i32 %2, i32* %10
store i32 %3, i32* %11
store i32 %4, i32* %12
store i32 %5, i32* %13
store i32 %6, i32* %14
%16 = load i32, i32* %13
%17 = call i32 @srandom(i32 %16)
%18 = load i32*, i32** %8
%19 = call i32 (i32*, i8*, ...) @fprintf(i32* %18, i8* getelementptr inbounds ([103 x i8], [103 x i8]* @.str, i64 0, i64 0))
%20 = load i32*, i32** %8
%21 = load i32, i32* %9
%22 = load i32, i32* %10
%23 = call i32 (i32*, i8*, ...) @fprintf(i32* %20, i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.1, i64 0, i64 0), i32 %21, i32 %22)
%24 = load i32*, i32** %8
%25 = call i32 (...) @random()
%26 = load i32, i32* %14
%27 = srem i32 %25, %26
%28 = call i32 (i32*, i8*, ...) @fprintf(i32* %24, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %27)
store i32 1, i32* %15
br label %29
29: ; preds = %41, %7
%30 = load i32, i32* %15
%31 = load i32, i32* %9
%32 = load i32, i32* %10
%33 = mul nsw i32 %31, %32
%34 = icmp slt i32 %30, %33
br i1 %34, label %35, label %44
35: ; preds = %29
%36 = load i32*, i32** %8
%37 = call i32 (...) @random()
%38 = load i32, i32* %14
%39 = srem i32 %37, %38
%40 = call i32 (i32*, i8*, ...) @fprintf(i32* %36, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 %39)
br label %41
41: ; preds = %35
%42 = load i32, i32* %15
%43 = add nsw i32 %42, 1
store i32 %43, i32* %15
br label %29
44: ; preds = %29
%45 = load i32*, i32** %8
%46 = call i32 (i32*, i8*, ...) @fprintf(i32* %45, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%47 = load i32*, i32** %8
%48 = load i32, i32* %11
%49 = load i32, i32* %12
%50 = call i32 (i32*, i8*, ...) @fprintf(i32* %47, i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.5, i64 0, i64 0), i32 %48, i32 %49)
%51 = load i32*, i32** %8
%52 = call i32 (...) @random()
%53 = load i32, i32* %14
%54 = srem i32 %52, %53
%55 = call i32 (i32*, i8*, ...) @fprintf(i32* %51, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %54)
store i32 1, i32* %15
br label %56
56: ; preds = %68, %44
%57 = load i32, i32* %15
%58 = load i32, i32* %11
%59 = load i32, i32* %12
%60 = mul nsw i32 %58, %59
%61 = icmp slt i32 %57, %60
br i1 %61, label %62, label %71
62: ; preds = %56
%63 = load i32*, i32** %8
%64 = call i32 (...) @random()
%65 = load i32, i32* %14
%66 = srem i32 %64, %65
%67 = call i32 (i32*, i8*, ...) @fprintf(i32* %63, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 %66)
br label %68
68: ; preds = %62
%69 = load i32, i32* %15
%70 = add nsw i32 %69, 1
store i32 %70, i32* %15
br label %56
71: ; preds = %56
%72 = load i32*, i32** %8
%73 = call i32 (i32*, i8*, ...) @fprintf(i32* %72, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str = [103 x i8] c"/** Generated by 'matrix_gen' as test data for inclusion\0A * in 'matrix_mul.c' during compilation.\0A */\0A\00"
@.str.1 = [61 x i8] c"#define NROWS_A (%d)\0A#define NCOLS_A (%d)\0Aint matrix_a[] = {\00"
@.str.2 = [4 x i8] c"%ld\00"
@.str.3 = [6 x i8] c", %ld\00"
@.str.4 = [5 x i8] c"};\0A\0A\00"
@.str.5 = [61 x i8] c"#define NROWS_B (%d)\0A#define NCOLS_B (%d)\0Aint matrix_b[] = {\00"
@.str.6 = [4 x i8] c"};\0A\00"
define i32 @generate_matrices(i32* nocapture %0, i32 %1, i32 %2, i32 %3, i32 %4, i32 %5, i32 %6) {
%8 = tail call i32 @srandom(i32 %5)
%9 = tail call i64 @fwrite(i8* getelementptr inbounds ([103 x i8], [103 x i8]* @.str, i64 0, i64 0), i64 102, i64 1, i32* %0)
%10 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.1, i64 0, i64 0), i32 %1, i32 %2)
%11 = tail call i32 (...) @random()
%12 = srem i32 %11, %6
%13 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %12)
%14 = mul i32 %2, %1
%15 = icmp sgt i32 %14, 1
br i1 %15, label %16, label %23
16: ; preds = %7, %16
%17 = phi i32 [ %21, %16 ], [ 1, %7 ]
%18 = tail call i32 (...) @random()
%19 = srem i32 %18, %6
%20 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 %19)
%21 = add nuw nsw i32 %17, 1
%22 = icmp eq i32 %21, %14
br i1 %22, label %23, label %16
23: ; preds = %16, %7
%24 = tail call i64 @fwrite(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i64 4, i64 1, i32* %0)
%25 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.5, i64 0, i64 0), i32 %3, i32 %4)
%26 = tail call i32 (...) @random()
%27 = srem i32 %26, %6
%28 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %27)
%29 = mul i32 %4, %3
%30 = icmp sgt i32 %29, 1
br i1 %30, label %31, label %38
31: ; preds = %23, %31
%32 = phi i32 [ %36, %31 ], [ 1, %23 ]
%33 = tail call i32 (...) @random()
%34 = srem i32 %33, %6
%35 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 %34)
%36 = add nuw nsw i32 %32, 1
%37 = icmp eq i32 %36, %29
br i1 %37, label %38, label %31
38: ; preds = %31, %23
%39 = tail call i64 @fwrite(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i64 3, i64 1, i32* %0)
ret i32 0
}