#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*/ printf(char *, ...);
main() {
  int arr[3][3] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
  int *pa;
  int i, j, k;
  printf("\nBefore...\n");
  pa = (int *)arr;
  for (i = 0; i < 9; i++) {
    printf("%d, ", *pa++);
    if (!((i + 1) % 3))
      printf("\n");
  }
  printf("\nAfter...\n");
  pa = (int *)arr;
  k = 0;
  for (i = 0; i < 9; i++) {
    j = i * 3 - k;
    printf("%d, ", *(pa + j));
    if (!((i + 1) % 3)) {
      printf("\n");
      k += 8;
    }
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x30(%rbp),%rdi
lea    0xec6(%rip),%rsi
mov    $0x24,%edx
call   1040 <memcpy@plt>
lea    0xed9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x30(%rbp),%rax
mov    %rax,-0x38(%rbp)
movl   $0x0,-0x3c(%rbp)
cmpl   $0x9,-0x3c(%rbp)
jge    11c2 <main+0xa2>
mov    -0x38(%rbp),%rax
mov    %rax,%rcx
add    $0x4,%rcx
mov    %rcx,-0x38(%rbp)
mov    (%rax),%esi
lea    0xead(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    $0x3,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    11af <main+0x8f>
lea    0xe86(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11b4 <main+0x94>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    1161 <main+0x41>
lea    0xe6c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x30(%rbp),%rax
mov    %rax,-0x38(%rbp)
movl   $0x0,-0x44(%rbp)
movl   $0x0,-0x3c(%rbp)
cmpl   $0x9,-0x3c(%rbp)
jge    1254 <main+0x134>
imul   $0x3,-0x3c(%rbp),%eax
sub    -0x44(%rbp),%eax
mov    %eax,-0x40(%rbp)
mov    -0x38(%rbp),%rax
movslq -0x40(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xe24(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    $0x3,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    1241 <main+0x121>
lea    0xdfd(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x44(%rbp),%eax
add    $0x8,%eax
mov    %eax,-0x44(%rbp)
jmp    1246 <main+0x126>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    11e6 <main+0xc6>
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xee7(%rip),%rdi
call   1040 <puts@plt>
lea    0xed6(%rip),%rbx
mov    %rbx,%rdi
mov    $0x1,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
mov    $0x2,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
mov    $0x3,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %rbx,%rdi
mov    $0x4,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
mov    $0x5,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
mov    $0x6,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %rbx,%rdi
mov    $0x7,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
mov    $0x8,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
mov    $0x9,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0xe3a(%rip),%rdi
call   1040 <puts@plt>
mov    $0xff,%r12b
mov    $0x1,%bl
lea    0xdf5(%rip),%r15
xor    %ebp,%ebp
xor    %r13d,%r13d
jmp    1230 <main+0x100>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
add    $0xc,%rbp
add    $0xff,%r12b
add    $0x1,%bl
cmp    $0x6c,%ebp
je     1274 <main+0x144>
movzbl %bl,%eax
imul   $0xab,%eax,%eax
shr    $0x9,%eax
lea    (%rax,%rax,2),%r14d
movslq %r13d,%rax
shl    $0x2,%rax
mov    %rbp,%rcx
sub    %rax,%rcx
mov    (%rcx,%r15,1),%esi
lea    0xdcc(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
add    %r12b,%r14b
jne    1220 <main+0xf0>
mov    $0xa,%edi
call   1030 <putchar@plt>
add    $0x8,%r13d
jmp    1220 <main+0xf0>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@__const.main.arr = [3 x [3 x i32]] [[3 x i32] [i32 1, i32 2, i32 3], [3 x i32] [i32 4, i32 5, i32 6], [3 x i32] [i32 7, i32 8, i32 9]]
@.str.1 = [5 x i8] c"%d, \00"
@str = [11 x i8] c"\0ABefore...\00"
@str.4 = [10 x i8] c"\0AAfter...\00"
define i32 @main() {
%1 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str, i64 0, i64 0))
%2 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 1)
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 2)
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 3)
%5 = tail call i32 @putchar(i32 10)
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 4)
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 5)
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 6)
%9 = tail call i32 @putchar(i32 10)
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 7)
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 8)
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 9)
%13 = tail call i32 @putchar(i32 10)
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str.4, i64 0, i64 0))
br label %15
15: ; preds = %0, %31
%16 = phi i32 [ 0, %0 ], [ %32, %31 ]
%17 = phi i32 [ 0, %0 ], [ %24, %31 ]
%18 = mul nuw nsw i32 %17, 3
%19 = sub nsw i32 %18, %16
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds [3 x [3 x i32]], [3 x [3 x i32]]* @__const.main.arr, i64 0, i64 0, i64 %20
%22 = load i32, i32* %21
%23 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %22)
%24 = add nuw nsw i32 %17, 1
%25 = trunc i32 %24 to i8
%26 = urem i8 %25, 3
%27 = icmp eq i8 %26, 0
br i1 %27, label %28, label %31
28: ; preds = %15
%29 = tail call i32 @putchar(i32 10)
%30 = add nsw i32 %16, 8
br label %31
31: ; preds = %15, %28
%32 = phi i32 [ %16, %15 ], [ %30, %28 ]
%33 = icmp eq i32 %24, 9
br i1 %33, label %34, label %15
34: ; preds = %31
ret i32 0
}