#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 */
unsigned int **allocArray2D(size_t, size_t);
int **getPointersArrayFrom(int *p, size_t size) {
  unsigned int **index = allocArray2D(size, size), i;
  for (i = 0; i < size; i++)
    index[i] = (int *)p + size * i;
  return index;
}


x86 assembly (clang, -O0):
<getPointersArrayFrom>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <allocArray2D@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x10(%rbp),%rax
jae    1174 <getPointersArrayFrom+0x64>
mov    -0x8(%rbp),%rdx
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%ecx
imul   %rcx,%rax
shl    $0x2,%rax
add    %rax,%rdx
mov    -0x18(%rbp),%rax
mov    -0x1c(%rbp),%ecx
mov    %rdx,(%rax,%rcx,8)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1138 <getPointersArrayFrom+0x28>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getPointersArrayFrom>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
mov    %rsi,%rdi
call   1030 <allocArray2D@plt>
test   %rbx,%rbx
je     1147 <getPointersArrayFrom+0x37>
xor    %ecx,%ecx
nopl   0x0(%rax)
mov    %rcx,%rdx
imul   %rbx,%rdx
lea    (%r14,%rdx,4),%rdx
mov    %rdx,(%rax,%rcx,8)
add    $0x1,%ecx
cmp    %rbx,%rcx
jb     1130 <getPointersArrayFrom+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i32** @getPointersArrayFrom(i32* %0, i64 %1) {
%3 = alloca i32*
%4 = alloca i64
%5 = alloca i32**
%6 = alloca i32
store i32* %0, i32** %3
store i64 %1, i64* %4
%7 = load i64, i64* %4
%8 = load i64, i64* %4
%9 = call i32** @allocArray2D(i64 %7, i64 %8)
store i32** %9, i32*** %5
store i32 0, i32* %6
br label %10
10: ; preds = %26, %2
%11 = load i32, i32* %6
%12 = zext i32 %11 to i64
%13 = load i64, i64* %4
%14 = icmp ult i64 %12, %13
br i1 %14, label %15, label %29
15: ; preds = %10
%16 = load i32*, i32** %3
%17 = load i64, i64* %4
%18 = load i32, i32* %6
%19 = zext i32 %18 to i64
%20 = mul i64 %17, %19
%21 = getelementptr inbounds i32, i32* %16, i64 %20
%22 = load i32**, i32*** %5
%23 = load i32, i32* %6
%24 = zext i32 %23 to i64
%25 = getelementptr inbounds i32*, i32** %22, i64 %24
store i32* %21, i32** %25
br label %26
26: ; preds = %15
%27 = load i32, i32* %6
%28 = add i32 %27, 1
store i32 %28, i32* %6
br label %10
29: ; preds = %10
%30 = load i32**, i32*** %5
ret i32** %30
}

LLVM IR (-O2):
define i32** @getPointersArrayFrom(i32* %0, i64 %1) {
%3 = tail call i32** @allocArray2D(i64 %1, i64 %1)
%4 = icmp eq i64 %1, 0
br i1 %4, label %13, label %5
5: ; preds = %2, %5
%6 = phi i64 [ %11, %5 ], [ 0, %2 ]
%7 = mul i64 %6, %1
%8 = getelementptr inbounds i32, i32* %0, i64 %7
%9 = getelementptr inbounds i32*, i32** %3, i64 %6
store i32* %8, i32** %9
%10 = add nuw nsw i64 %6, 1
%11 = and i64 %10, 4294967295
%12 = icmp ult i64 %11, %1
br i1 %12, label %5, label %13
13: ; preds = %5, %2
ret i32** %3
}