#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*/ free(int *);
int *malloc(int);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ putchar(char);
int /*<<< orphan*/ scanf(char *, int);
int main(void) {
  int m = 2;
  int n = 3;
  int *ptr = malloc(m * n * sizeof(int));
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < n; j++) {
      *(ptr + n * i + j) = i + j;
    }
  }
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < n; j++) {
      printf("%d\t", *(ptr + n * i + j));
    }
    putchar('\n');
  }
  free(ptr);
  int ddd;
  scanf("%d", ddd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x2,-0x8(%rbp)
movl   $0x3,-0xc(%rbp)
mov    -0x8(%rbp),%eax
imul   -0xc(%rbp),%eax
cltq
shl    $0x2,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11ee <main+0x9e>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11db <main+0x8b>
mov    -0x1c(%rbp),%edx
add    -0x20(%rbp),%edx
mov    -0x18(%rbp),%rax
mov    -0xc(%rbp),%ecx
imul   -0x1c(%rbp),%ecx
movslq %ecx,%rcx
shl    $0x2,%rcx
add    %rcx,%rax
movslq -0x20(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    119f <main+0x4f>
jmp    11e0 <main+0x90>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    118c <main+0x3c>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1262 <main+0x112>
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    124a <main+0xfa>
mov    -0x18(%rbp),%rax
mov    -0xc(%rbp),%ecx
imul   -0x24(%rbp),%ecx
movslq %ecx,%rcx
shl    $0x2,%rcx
add    %rcx,%rax
movslq -0x28(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xdc9(%rip),%rdi
call   1050 <printf@plt>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1208 <main+0xb8>
mov    $0xa,%edi
call   1040 <putchar@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11f5 <main+0xa5>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x2c(%rbp),%esi
lea    0xd8f(%rip),%rdi
call   1070 <scanf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    $0x18,%edi
call   1060 <malloc@plt>
mov    %rax,%r14
movaps 0xe98(%rip),%xmm0
movups %xmm0,(%rax)
movabs $0x300000002,%rax
mov    %rax,0x10(%r14)
lea    0xe90(%rip),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
call   1050 <printf@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
call   1050 <printf@plt>
mov    %rbx,%rdi
mov    $0x2,%esi
call   1050 <printf@plt>
mov    $0xa,%edi
call   1040 <putchar@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
call   1050 <printf@plt>
mov    %rbx,%rdi
mov    $0x2,%esi
call   1050 <printf@plt>
mov    %rbx,%rdi
mov    $0x3,%esi
call   1050 <printf@plt>
mov    $0xa,%edi
call   1040 <putchar@plt>
mov    %r14,%rdi
call   1030 <free@plt>
lea    0xe26(%rip),%rdi
call   1070 <scanf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%d\09\00"
@.str.1 = [3 x i8] c"%d\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %1
store i32 2, i32* %2
store i32 3, i32* %3
%10 = load i32, i32* %2
%11 = load i32, i32* %3
%12 = mul nsw i32 %10, %11
%13 = sext i32 %12 to i64
%14 = mul i64 %13, 4
%15 = trunc i64 %14 to i32
%16 = call i32* @malloc(i32 %15)
store i32* %16, i32** %4
store i32 0, i32* %5
br label %17
17: ; preds = %43, %0
%18 = load i32, i32* %5
%19 = load i32, i32* %2
%20 = icmp slt i32 %18, %19
br i1 %20, label %21, label %46
21: ; preds = %17
store i32 0, i32* %6
br label %22
22: ; preds = %39, %21
%23 = load i32, i32* %6
%24 = load i32, i32* %3
%25 = icmp slt i32 %23, %24
br i1 %25, label %26, label %42
26: ; preds = %22
%27 = load i32, i32* %5
%28 = load i32, i32* %6
%29 = add nsw i32 %27, %28
%30 = load i32*, i32** %4
%31 = load i32, i32* %3
%32 = load i32, i32* %5
%33 = mul nsw i32 %31, %32
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i32, i32* %30, i64 %34
%36 = load i32, i32* %6
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i32, i32* %35, i64 %37
store i32 %29, i32* %38
br label %39
39: ; preds = %26
%40 = load i32, i32* %6
%41 = add nsw i32 %40, 1
store i32 %41, i32* %6
br label %22
42: ; preds = %22
br label %43
43: ; preds = %42
%44 = load i32, i32* %5
%45 = add nsw i32 %44, 1
store i32 %45, i32* %5
br label %17
46: ; preds = %17
store i32 0, i32* %7
br label %47
47: ; preds = %73, %46
%48 = load i32, i32* %7
%49 = load i32, i32* %2
%50 = icmp slt i32 %48, %49
br i1 %50, label %51, label %76
51: ; preds = %47
store i32 0, i32* %8
br label %52
52: ; preds = %68, %51
%53 = load i32, i32* %8
%54 = load i32, i32* %3
%55 = icmp slt i32 %53, %54
br i1 %55, label %56, label %71
56: ; preds = %52
%57 = load i32*, i32** %4
%58 = load i32, i32* %3
%59 = load i32, i32* %7
%60 = mul nsw i32 %58, %59
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds i32, i32* %57, i64 %61
%63 = load i32, i32* %8
%64 = sext i32 %63 to i64
%65 = getelementptr inbounds i32, i32* %62, i64 %64
%66 = load i32, i32* %65
%67 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %66)
br label %68
68: ; preds = %56
%69 = load i32, i32* %8
%70 = add nsw i32 %69, 1
store i32 %70, i32* %8
br label %52
71: ; preds = %52
%72 = call i32 @putchar(i8 signext 10)
br label %73
73: ; preds = %71
%74 = load i32, i32* %7
%75 = add nsw i32 %74, 1
store i32 %75, i32* %7
br label %47
76: ; preds = %47
%77 = load i32*, i32** %4
%78 = call i32 @free(i32* %77)
%79 = load i32, i32* %9
%80 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %79)
ret i32 0
}

LLVM IR (-O2):
@.str = [4 x i8] c"%d\09\00"
@.str.1 = [3 x i8] c"%d\00"
define i32 @main() {
%1 = tail call i32* @malloc(i32 24)
%2 = bitcast i32* %1 to <4 x i32>*
store <4 x i32> <i32 0, i32 1, i32 2, i32 1>, <4 x i32>* %2
%3 = getelementptr inbounds i32, i32* %1, i64 4
store i32 2, i32* %3
%4 = getelementptr inbounds i32, i32* %1, i64 5
store i32 3, i32* %4
%5 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 0)
%6 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 1)
%7 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 2)
%8 = tail call i32 @putchar(i8 signext 10)
%9 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 1)
%10 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 2)
%11 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 3)
%12 = tail call i32 @putchar(i8 signext 10)
%13 = tail call i32 @free(i32* %1)
%14 = tail call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 undef)
ret i32 0
}