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

/* Variables and functions */
int EXIT_SUCCESS;
int /*<<< orphan*/ printf(char *, ...);
int main(void) {
  int i, j;
  int matrix_a[2][3] = {{0}};
  int matrix_b[2][3] = {{10, 20, 30}, {40, 50, 60}};
  int n_bytes = sizeof(matrix_a);
  int n_elem = n_bytes / sizeof(int);
  int n_cols = sizeof(matrix_a[0]) / sizeof(int);
  int n_rows = n_elem / n_cols;
  printf("Matrix elements: %d\n", n_elem);
  printf("Matrix bytes: %d\n", n_bytes);
  printf("Matrix cols: %d\n", n_cols);
  printf("Matrix rows: %d\n", n_rows);
  matrix_a[1][2] = 39;
  matrix_a[2][0] = 99;
  matrix_a[0][0] = 10;
  matrix_a[0][1] = 86;
  printf("Print each element of matrix_a, scanning by rows:\n");
  for (i = 0; i < 2; i++) {
    printf("row %d: ", i);
    for (j = 0; j < 3; j++)
      printf("%2d | ", matrix_a[i][j]);
    printf("\n");
  }
  printf("Print each element of matrix_b, scanning by cols:\n");
  for (i = 0; i < 3; i++) {
    printf("col %d: ", i);
    for (j = 0; j < 2; j++)
      printf("%2d | ", matrix_b[j][i]);
    printf("\n");
  }
  return (EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1040 <memset@plt>
mov    0xeba(%rip),%rax
mov    %rax,-0x50(%rbp)
mov    0xeb7(%rip),%rax
mov    %rax,-0x48(%rbp)
mov    0xeb4(%rip),%rax
mov    %rax,-0x40(%rbp)
movl   $0x18,-0x54(%rbp)
movslq -0x54(%rbp),%rax
shr    $0x2,%rax
mov    %eax,-0x58(%rbp)
movl   $0x3,-0x5c(%rbp)
mov    -0x58(%rbp),%eax
cltd
idivl  -0x5c(%rbp)
mov    %eax,-0x60(%rbp)
mov    -0x58(%rbp),%esi
lea    0xe8b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x54(%rbp),%esi
lea    0xe8f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x5c(%rbp),%esi
lea    0xe90(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x60(%rbp),%esi
lea    0xe90(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x27,-0x1c(%rbp)
movl   $0x63,-0x18(%rbp)
movl   $0xa,-0x30(%rbp)
movl   $0x56,-0x2c(%rbp)
lea    0xe77(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x8(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    1272 <main+0x152>
mov    -0x8(%rbp),%esi
lea    0xe88(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0xc(%rbp)
cmpl   $0x3,-0xc(%rbp)
jge    1256 <main+0x136>
movslq -0x8(%rbp),%rcx
lea    -0x30(%rbp),%rax
imul   $0xc,%rcx,%rcx
add    %rcx,%rax
movslq -0xc(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xe5c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    121a <main+0xfa>
lea    0xe78(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    11f8 <main+0xd8>
lea    0xe2b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x8(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    1301 <main+0x1e1>
mov    -0x8(%rbp),%esi
lea    0xe3c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0xc(%rbp)
cmpl   $0x2,-0xc(%rbp)
jge    12e5 <main+0x1c5>
movslq -0xc(%rbp),%rcx
lea    -0x50(%rbp),%rax
imul   $0xc,%rcx,%rcx
add    %rcx,%rax
movslq -0x8(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xdcd(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    12a9 <main+0x189>
lea    0xde9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1287 <main+0x167>
mov    0x2cd8(%rip),%rax
mov    (%rax),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
lea    0xec5(%rip),%rdi
mov    $0x6,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xec7(%rip),%rdi
mov    $0x18,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xec6(%rip),%rdi
mov    $0x3,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xec4(%rip),%rdi
mov    $0x2,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xedb(%rip),%rdi
call   1040 <puts@plt>
lea    0xeb6(%rip),%r14
mov    %r14,%rdi
xor    %esi,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xeac(%rip),%rbx
mov    %rbx,%rdi
mov    $0xa,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
mov    $0x56,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
xor    %esi,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %r14,%rdi
mov    $0x1,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
xor    %esi,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
xor    %esi,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
mov    $0x27,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0xe73(%rip),%rdi
call   1040 <puts@plt>
lea    0xe2c(%rip),%r14
mov    %r14,%rdi
xor    %esi,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
mov    $0xa,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
mov    $0x28,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %r14,%rdi
mov    $0x1,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
mov    $0x14,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
mov    $0x32,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %r14,%rdi
mov    $0x2,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
mov    $0x1e,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
mov    $0x3c,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    0x2d0a(%rip),%rax
mov    (%rax),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@__const.main.matrix_b = [2 x [3 x i32]] [[3 x i32] [i32 10, i32 20, i32 30], [3 x i32] [i32 40, i32 50, i32 60]]
@.str = [21 x i8] c"Matrix elements: %d\0A\00"
@.str.1 = [18 x i8] c"Matrix bytes: %d\0A\00"
@.str.2 = [17 x i8] c"Matrix cols: %d\0A\00"
@.str.3 = [17 x i8] c"Matrix rows: %d\0A\00"
@.str.4 = [51 x i8] c"Print each element of matrix_a, scanning by rows:\0A\00"
@.str.5 = [9 x i8] c"row %d: \00"
@.str.6 = [7 x i8] c"%2d | \00"
@.str.7 = [2 x i8] c"\0A\00"
@.str.8 = [51 x i8] c"Print each element of matrix_b, scanning by cols:\0A\00"
@.str.9 = [9 x i8] c"col %d: \00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca [2 x [3 x i32]]
%5 = alloca [2 x [3 x i32]]
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %1
%10 = bitcast [2 x [3 x i32]]* %4 to i8*
%11 = bitcast [2 x [3 x i32]]* %5 to i8*
store i32 24, i32* %6
%12 = load i32, i32* %6
%13 = sext i32 %12 to i64
%14 = udiv i64 %13, 4
%15 = trunc i64 %14 to i32
store i32 %15, i32* %7
store i32 3, i32* %8
%16 = load i32, i32* %7
%17 = load i32, i32* %8
%18 = sdiv i32 %16, %17
store i32 %18, i32* %9
%19 = load i32, i32* %7
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i32 %19)
%21 = load i32, i32* %6
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i32 %21)
%23 = load i32, i32* %8
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i32 %23)
%25 = load i32, i32* %9
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i32 %25)
%27 = getelementptr inbounds [2 x [3 x i32]], [2 x [3 x i32]]* %4, i64 0, i64 1
%28 = getelementptr inbounds [3 x i32], [3 x i32]* %27, i64 0, i64 2
store i32 39, i32* %28
%29 = getelementptr inbounds [2 x [3 x i32]], [2 x [3 x i32]]* %4, i64 0, i64 2
%30 = getelementptr inbounds [3 x i32], [3 x i32]* %29, i64 0, i64 0
store i32 99, i32* %30
%31 = getelementptr inbounds [2 x [3 x i32]], [2 x [3 x i32]]* %4, i64 0, i64 0
%32 = getelementptr inbounds [3 x i32], [3 x i32]* %31, i64 0, i64 0
store i32 10, i32* %32
%33 = getelementptr inbounds [2 x [3 x i32]], [2 x [3 x i32]]* %4, i64 0, i64 0
%34 = getelementptr inbounds [3 x i32], [3 x i32]* %33, i64 0, i64 1
store i32 86, i32* %34
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.4, i64 0, i64 0))
store i32 0, i32* %2
br label %36
36: ; preds = %59, %0
%37 = load i32, i32* %2
%38 = icmp slt i32 %37, 2
br i1 %38, label %39, label %62
39: ; preds = %36
%40 = load i32, i32* %2
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i32 %40)
store i32 0, i32* %3
br label %42
42: ; preds = %54, %39
%43 = load i32, i32* %3
%44 = icmp slt i32 %43, 3
br i1 %44, label %45, label %57
45: ; preds = %42
%46 = load i32, i32* %2
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds [2 x [3 x i32]], [2 x [3 x i32]]* %4, i64 0, i64 %47
%49 = load i32, i32* %3
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds [3 x i32], [3 x i32]* %48, i64 0, i64 %50
%52 = load i32, i32* %51
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0), i32 %52)
br label %54
54: ; preds = %45
%55 = load i32, i32* %3
%56 = add nsw i32 %55, 1
store i32 %56, i32* %3
br label %42
57: ; preds = %42
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
br label %59
59: ; preds = %57
%60 = load i32, i32* %2
%61 = add nsw i32 %60, 1
store i32 %61, i32* %2
br label %36
62: ; preds = %36
%63 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.8, i64 0, i64 0))
store i32 0, i32* %2
br label %64
64: ; preds = %87, %62
%65 = load i32, i32* %2
%66 = icmp slt i32 %65, 3
br i1 %66, label %67, label %90
67: ; preds = %64
%68 = load i32, i32* %2
%69 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.9, i64 0, i64 0), i32 %68)
store i32 0, i32* %3
br label %70
70: ; preds = %82, %67
%71 = load i32, i32* %3
%72 = icmp slt i32 %71, 2
br i1 %72, label %73, label %85
73: ; preds = %70
%74 = load i32, i32* %3
%75 = sext i32 %74 to i64
%76 = getelementptr inbounds [2 x [3 x i32]], [2 x [3 x i32]]* %5, i64 0, i64 %75
%77 = load i32, i32* %2
%78 = sext i32 %77 to i64
%79 = getelementptr inbounds [3 x i32], [3 x i32]* %76, i64 0, i64 %78
%80 = load i32, i32* %79
%81 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0), i32 %80)
br label %82
82: ; preds = %73
%83 = load i32, i32* %3
%84 = add nsw i32 %83, 1
store i32 %84, i32* %3
br label %70
85: ; preds = %70
%86 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
br label %87
87: ; preds = %85
%88 = load i32, i32* %2
%89 = add nsw i32 %88, 1
store i32 %89, i32* %2
br label %64
90: ; preds = %64
%91 = load i32, i32* @EXIT_SUCCESS
ret i32 %91
}

LLVM IR (-O2):
@.str = [21 x i8] c"Matrix elements: %d\0A\00"
@.str.1 = [18 x i8] c"Matrix bytes: %d\0A\00"
@.str.2 = [17 x i8] c"Matrix cols: %d\0A\00"
@.str.3 = [17 x i8] c"Matrix rows: %d\0A\00"
@.str.5 = [9 x i8] c"row %d: \00"
@.str.6 = [7 x i8] c"%2d | \00"
@.str.9 = [9 x i8] c"col %d: \00"
@EXIT_SUCCESS = global i32 0
@str = [50 x i8] c"Print each element of matrix_a, scanning by rows:\00"
@str.10 = [50 x i8] c"Print each element of matrix_b, scanning by cols:\00"
define i32 @main() {
%1 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i32 6)
%2 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i32 24)
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i32 3)
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i32 2)
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([50 x i8], [50 x i8]* @str, i64 0, i64 0))
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i32 0)
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0), i32 10)
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0), i32 86)
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0), i32 0)
%10 = tail call i32 @putchar(i32 10)
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i32 1)
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0), i32 0)
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0), i32 0)
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0), i32 39)
%15 = tail call i32 @putchar(i32 10)
%16 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([50 x i8], [50 x i8]* @str.10, i64 0, i64 0))
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.9, i64 0, i64 0), i32 0)
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0), i32 10)
%19 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0), i32 40)
%20 = tail call i32 @putchar(i32 10)
%21 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.9, i64 0, i64 0), i32 1)
%22 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0), i32 20)
%23 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0), i32 50)
%24 = tail call i32 @putchar(i32 10)
%25 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.9, i64 0, i64 0), i32 2)
%26 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0), i32 30)
%27 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0), i32 60)
%28 = tail call i32 @putchar(i32 10)
%29 = load i32, i32* @EXIT_SUCCESS
ret i32 %29
}