#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*/ printMatrix(int **);
int /*<<< orphan*/ printMatrixPointer(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ returnRotateMatrix(int **);
int /*<<< orphan*/ rotateMatrix(int **);
int main() {
  int array[3][3];
  for (int i = 0; i < 3; i++)
    for (int j = 0; j < 3; j++)
      array[i][j] = (j + 1) + 3 * i;
  printf("Original matrix:\n");
  printMatrix(array);
  printf("\nRotating with return:\n");
  printMatrixPointer(returnRotateMatrix(array));
  printf("\nRotating with void:\n");
  rotateMatrix(array);
  printMatrix(array);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x34(%rbp)
cmpl   $0x3,-0x34(%rbp)
jge    11c4 <main+0x74>
movl   $0x0,-0x38(%rbp)
cmpl   $0x3,-0x38(%rbp)
jge    11b1 <main+0x61>
mov    -0x38(%rbp),%edx
add    $0x1,%edx
imul   $0x3,-0x34(%rbp),%eax
add    %eax,%edx
movslq -0x34(%rbp),%rcx
lea    -0x30(%rbp),%rax
imul   $0xc,%rcx,%rcx
add    %rcx,%rax
movslq -0x38(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    1177 <main+0x27>
jmp    11b6 <main+0x66>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1166 <main+0x16>
lea    0xe35(%rip),%rdi
call   1040 <printf@plt>
lea    -0x30(%rbp),%rdi
call   1060 <printMatrix@plt>
lea    0xe32(%rip),%rdi
call   1040 <printf@plt>
lea    -0x30(%rbp),%rdi
call   1050 <returnRotateMatrix@plt>
mov    %eax,%edi
call   1070 <printMatrixPointer@plt>
lea    0xe2e(%rip),%rdi
call   1040 <printf@plt>
lea    -0x30(%rbp),%rdi
call   1030 <rotateMatrix@plt>
lea    -0x30(%rbp),%rdi
call   1060 <printMatrix@plt>
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x30,%rsp
movaps 0xea4(%rip),%xmm0
movaps %xmm0,(%rsp)
movaps 0xea9(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movl   $0x9,0x20(%rsp)
lea    0xea5(%rip),%rdi
call   1040 <puts@plt>
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1060 <printMatrix@plt>
lea    0xe9f(%rip),%rdi
call   1040 <puts@plt>
mov    %rbx,%rdi
call   1050 <returnRotateMatrix@plt>
mov    %eax,%edi
call   1070 <printMatrixPointer@plt>
lea    0xe9b(%rip),%rdi
call   1040 <puts@plt>
mov    %rbx,%rdi
call   1030 <rotateMatrix@plt>
mov    %rbx,%rdi
call   1060 <printMatrix@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [18 x i8] c"Original matrix:\0A\00"
@.str.1 = [24 x i8] c"\0ARotating with return:\0A\00"
@.str.2 = [22 x i8] c"\0ARotating with void:\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [3 x [3 x i32]]
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %3
br label %5
5: ; preds = %28, %0
%6 = load i32, i32* %3
%7 = icmp slt i32 %6, 3
br i1 %7, label %8, label %31
8: ; preds = %5
store i32 0, i32* %4
br label %9
9: ; preds = %24, %8
%10 = load i32, i32* %4
%11 = icmp slt i32 %10, 3
br i1 %11, label %12, label %27
12: ; preds = %9
%13 = load i32, i32* %4
%14 = add nsw i32 %13, 1
%15 = load i32, i32* %3
%16 = mul nsw i32 3, %15
%17 = add nsw i32 %14, %16
%18 = load i32, i32* %3
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds [3 x [3 x i32]], [3 x [3 x i32]]* %2, i64 0, i64 %19
%21 = load i32, i32* %4
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds [3 x i32], [3 x i32]* %20, i64 0, i64 %22
store i32 %17, i32* %23
br label %24
24: ; preds = %12
%25 = load i32, i32* %4
%26 = add nsw i32 %25, 1
store i32 %26, i32* %4
br label %9
27: ; preds = %9
br label %28
28: ; preds = %27
%29 = load i32, i32* %3
%30 = add nsw i32 %29, 1
store i32 %30, i32* %3
br label %5
31: ; preds = %5
%32 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%33 = getelementptr inbounds [3 x [3 x i32]], [3 x [3 x i32]]* %2, i64 0, i64 0
%34 = bitcast [3 x i32]* %33 to i32**
%35 = call i32 @printMatrix(i32** %34)
%36 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
%37 = getelementptr inbounds [3 x [3 x i32]], [3 x [3 x i32]]* %2, i64 0, i64 0
%38 = bitcast [3 x i32]* %37 to i32**
%39 = call i32 @returnRotateMatrix(i32** %38)
%40 = call i32 @printMatrixPointer(i32 %39)
%41 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0))
%42 = getelementptr inbounds [3 x [3 x i32]], [3 x [3 x i32]]* %2, i64 0, i64 0
%43 = bitcast [3 x i32]* %42 to i32**
%44 = call i32 @rotateMatrix(i32** %43)
%45 = getelementptr inbounds [3 x [3 x i32]], [3 x [3 x i32]]* %2, i64 0, i64 0
%46 = bitcast [3 x i32]* %45 to i32**
%47 = call i32 @printMatrix(i32** %46)
%48 = load i32, i32* %1
ret i32 %48
}

LLVM IR (-O2):
@str = [17 x i8] c"Original matrix:\00"
@str.3 = [23 x i8] c"\0ARotating with return:\00"
@str.4 = [21 x i8] c"\0ARotating with void:\00"
define i32 @main() {
%1 = alloca [3 x [3 x i32]]
%2 = bitcast [3 x [3 x i32]]* %1 to i8*
%3 = bitcast [3 x [3 x i32]]* %1 to <4 x i32>*
store <4 x i32> <i32 1, i32 2, i32 3, i32 4>, <4 x i32>* %3
%4 = getelementptr inbounds [3 x [3 x i32]], [3 x [3 x i32]]* %1, i64 0, i64 1, i64 1
%5 = bitcast i32* %4 to <4 x i32>*
store <4 x i32> <i32 5, i32 6, i32 7, i32 8>, <4 x i32>* %5
%6 = getelementptr inbounds [3 x [3 x i32]], [3 x [3 x i32]]* %1, i64 0, i64 2, i64 2
store i32 9, i32* %6
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str, i64 0, i64 0))
%8 = bitcast [3 x [3 x i32]]* %1 to i32**
%9 = call i32 @printMatrix(i32** %8)
%10 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str.3, i64 0, i64 0))
%11 = call i32 @returnRotateMatrix(i32** %8)
%12 = call i32 @printMatrixPointer(i32 %11)
%13 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str.4, i64 0, i64 0))
%14 = call i32 @rotateMatrix(i32** %8)
%15 = call i32 @printMatrix(i32** %8)
ret i32 0
}