int main(void) {
  int img[3][4] = {{1, 2, 3, 0}, {4, 5, 6, 0}, {7, 8, 9, 0}};
  int **s = (int **)img;
  rotate(s, 3, 4);
  for (int i = 0; i < 4; i++) {
    for (int j = 0; j < 3; j++) {
      printf("%d ", *(s + i * 3 + j));
    }
    printf("\n");
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x40(%rbp),%rdi
lea    0xeb6(%rip),%rsi
mov    $0x30,%edx
call   1040 <memcpy@plt>
lea    -0x40(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rdi
mov    $0x3,%esi
mov    $0x4,%edx
mov    $0x0,%al
call   1050 <rotate@plt>
movl   $0x0,-0x4c(%rbp)
cmpl   $0x4,-0x4c(%rbp)
jge    11e5 <main+0xb5>
movl   $0x0,-0x50(%rbp)
cmpl   $0x3,-0x50(%rbp)
jge    11c9 <main+0x99>
mov    -0x48(%rbp),%rax
imul   $0x3,-0x4c(%rbp),%ecx
movslq %ecx,%rcx
shl    $0x3,%rcx
add    %rcx,%rax
movslq -0x50(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
lea    0xe7c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x50(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x50(%rbp)
jmp    1189 <main+0x59>
lea    0xe64(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x4c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4c(%rbp)
jmp    1178 <main+0x48>
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x30,%rsp
movaps 0xee4(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movaps 0xec8(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps 0xeac(%rip),%xmm0
movaps %xmm0,(%rsp)
mov    %rsp,%rdi
mov    $0x3,%esi
mov    $0x4,%edx
xor    %eax,%eax
call   1050 <rotate@plt>
mov    (%rsp),%rsi
lea    0xeb9(%rip),%rbx
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x8(%rsp),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x10(%rsp),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    0x18(%rsp),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x20(%rsp),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x28(%rsp),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    0x30(%rsp),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x38(%rsp),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x40(%rsp),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    0x48(%rsp),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x50(%rsp),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x58(%rsp),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@__const.main.img = [3 x [4 x i32]] [[4 x i32] [i32 1, i32 2, i32 3, i32 0], [4 x i32] [i32 4, i32 5, i32 6, i32 0], [4 x i32] [i32 7, i32 8, i32 9, i32 0]]
@.str = [4 x i8] c"%d \00"
@.str.1 = [2 x i8] c"\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [3 x [4 x i32]]
%3 = alloca i32**
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
%6 = bitcast [3 x [4 x i32]]* %2 to i8*
%7 = getelementptr inbounds [3 x [4 x i32]], [3 x [4 x i32]]* %2, i64 0, i64 0
%8 = bitcast [4 x i32]* %7 to i32**
store i32** %8, i32*** %3
%9 = load i32**, i32*** %3
%10 = call i32 (i32**, i32, i32, ...) bitcast (i32 (...)* @rotate to i32 (i32**, i32, i32, ...)*)(i32** %9, i32 3, i32 4)
store i32 0, i32* %4
br label %11
11: ; preds = %34, %0
%12 = load i32, i32* %4
%13 = icmp slt i32 %12, 4
br i1 %13, label %14, label %37
14: ; preds = %11
store i32 0, i32* %5
br label %15
15: ; preds = %29, %14
%16 = load i32, i32* %5
%17 = icmp slt i32 %16, 3
br i1 %17, label %18, label %32
18: ; preds = %15
%19 = load i32**, i32*** %3
%20 = load i32, i32* %4
%21 = mul nsw i32 %20, 3
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i32*, i32** %19, i64 %22
%24 = load i32, i32* %5
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i32*, i32** %23, i64 %25
%27 = load i32*, i32** %26
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32* %27)
br label %29
29: ; preds = %18
%30 = load i32, i32* %5
%31 = add nsw i32 %30, 1
store i32 %31, i32* %5
br label %15
32: ; preds = %15
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %34
34: ; preds = %32
%35 = load i32, i32* %4
%36 = add nsw i32 %35, 1
store i32 %36, i32* %4
br label %11
37: ; preds = %11
%38 = load i32, i32* %1
ret i32 %38
}

LLVM IR (-O2):
@__const.main.img = [3 x [4 x i32]] [[4 x i32] [i32 1, i32 2, i32 3, i32 0], [4 x i32] [i32 4, i32 5, i32 6, i32 0], [4 x i32] [i32 7, i32 8, i32 9, i32 0]]
@.str = [4 x i8] c"%d \00"
define i32 @main() {
%1 = alloca [3 x [4 x i32]]
%2 = bitcast [3 x [4 x i32]]* %1 to i8*
%3 = bitcast [3 x [4 x i32]]* %1 to i32**
%4 = call i32 (i32**, i32, i32, ...) bitcast (i32 (...)* @rotate to i32 (i32**, i32, i32, ...)*)(i32** %3, i32 3, i32 4)
%5 = load i32*, i32** %3
%6 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32* %5)
%7 = getelementptr inbounds [3 x [4 x i32]], [3 x [4 x i32]]* %1, i64 0, i64 0, i64 2
%8 = bitcast i32* %7 to i32**
%9 = load i32*, i32** %8
%10 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32* %9)
%11 = getelementptr inbounds [3 x [4 x i32]], [3 x [4 x i32]]* %1, i64 0, i64 1
%12 = bitcast [4 x i32]* %11 to i32**
%13 = load i32*, i32** %12
%14 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32* %13)
%15 = call i32 @putchar(i32 10)
%16 = getelementptr inbounds [3 x [4 x i32]], [3 x [4 x i32]]* %1, i64 0, i64 1, i64 2
%17 = bitcast i32* %16 to i32**
%18 = load i32*, i32** %17
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32* %18)
%20 = getelementptr inbounds [3 x [4 x i32]], [3 x [4 x i32]]* %1, i64 0, i64 1, i64 4
%21 = bitcast i32* %20 to i32**
%22 = load i32*, i32** %21
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32* %22)
%24 = getelementptr inbounds [3 x [4 x i32]], [3 x [4 x i32]]* %1, i64 0, i64 1, i64 6
%25 = bitcast i32* %24 to i32**
%26 = load i32*, i32** %25
%27 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32* %26)
%28 = call i32 @putchar(i32 10)
%29 = getelementptr inbounds [3 x [4 x i32]], [3 x [4 x i32]]* %1, i64 1
%30 = bitcast [3 x [4 x i32]]* %29 to i32**
%31 = load i32*, i32** %30
%32 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32* %31)
%33 = getelementptr inbounds [3 x [4 x i32]], [3 x [4 x i32]]* %1, i64 1, i64 0, i64 2
%34 = bitcast i32* %33 to i32**
%35 = load i32*, i32** %34
%36 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32* %35)
%37 = getelementptr inbounds [3 x [4 x i32]], [3 x [4 x i32]]* %1, i64 1, i64 1
%38 = bitcast [4 x i32]* %37 to i32**
%39 = load i32*, i32** %38
%40 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32* %39)
%41 = call i32 @putchar(i32 10)
%42 = getelementptr inbounds [3 x [4 x i32]], [3 x [4 x i32]]* %1, i64 1, i64 1, i64 2
%43 = bitcast i32* %42 to i32**
%44 = load i32*, i32** %43
%45 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32* %44)
%46 = getelementptr inbounds [3 x [4 x i32]], [3 x [4 x i32]]* %1, i64 1, i64 1, i64 4
%47 = bitcast i32* %46 to i32**
%48 = load i32*, i32** %47
%49 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32* %48)
%50 = getelementptr inbounds [3 x [4 x i32]], [3 x [4 x i32]]* %1, i64 1, i64 1, i64 6
%51 = bitcast i32* %50 to i32**
%52 = load i32*, i32** %51
%53 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32* %52)
%54 = call i32 @putchar(i32 10)
ret i32 0
}