#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 **allocate_2d_array(int, int);
int /*<<< orphan*/ printf(char *, int, int);
int /*<<< orphan*/ scanf(char *, int *);
int **scan_2d_array(int m, int n) {
  int **x = allocate_2d_array(m, n);
  if (x) {
    printf("Elements of the (%d*%d) array:\n", m, n);
    for (int i = 0; i < m; ++i)
      for (int j = 0; j < n; ++j)
        scanf("%d", &x[i][j]);
  }
  return x;
}


x86 assembly (clang, -O0):
<scan_2d_array>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
call   1030 <allocate_2d_array@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11d9 <scan_2d_array+0xa9>
mov    -0x4(%rbp),%esi
mov    -0x8(%rbp),%edx
lea    0xe9b(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11d4 <scan_2d_array+0xa4>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11c1 <scan_2d_array+0x91>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
movslq -0x18(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe72(%rip),%rdi
call   1050 <scanf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1184 <scan_2d_array+0x54>
jmp    11c6 <scan_2d_array+0x96>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1171 <scan_2d_array+0x41>
jmp    11d9 <scan_2d_array+0xa9>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<scan_2d_array>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edi,%ebp
mov    %esi,0x4(%rsp)
call   1030 <allocate_2d_array@plt>
mov    %rax,%r13
test   %rax,%rax
je     11bb <scan_2d_array+0x8b>
lea    0xeab(%rip),%rdi
mov    %ebp,%esi
mov    0x4(%rsp),%edx
call   1040 <printf@plt>
test   %ebp,%ebp
jle    11bb <scan_2d_array+0x8b>
mov    %ebp,%r15d
mov    0x4(%rsp),%ebp
shl    $0x2,%rbp
xor    %ebx,%ebx
lea    0xea8(%rip),%r12
jmp    1189 <scan_2d_array+0x59>
nopw   0x0(%rax,%rax,1)
add    $0x1,%rbx
cmp    %r15,%rbx
je     11bb <scan_2d_array+0x8b>
cmpl   $0x0,0x4(%rsp)
jle    1180 <scan_2d_array+0x50>
xor    %r14d,%r14d
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    0x0(%r13,%rbx,8),%rsi
add    %r14,%rsi
mov    %r12,%rdi
call   1050 <scanf@plt>
add    $0x4,%r14
cmp    %r14,%rbp
jne    11a0 <scan_2d_array+0x70>
jmp    1180 <scan_2d_array+0x50>
mov    %r13,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [32 x i8] c"Elements of the (%d*%d) array:\0A\00"
@.str.1 = [3 x i8] c"%d\00"
define i32** @scan_2d_array(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32**
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%8 = load i32, i32* %3
%9 = load i32, i32* %4
%10 = call i32** @allocate_2d_array(i32 %8, i32 %9)
store i32** %10, i32*** %5
%11 = load i32**, i32*** %5
%12 = icmp ne i32** %11, null
br i1 %12, label %13, label %44
13: ; preds = %2
%14 = load i32, i32* %3
%15 = load i32, i32* %4
%16 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i32 %14, i32 %15)
store i32 0, i32* %6
br label %17
17: ; preds = %40, %13
%18 = load i32, i32* %6
%19 = load i32, i32* %3
%20 = icmp slt i32 %18, %19
br i1 %20, label %21, label %43
21: ; preds = %17
store i32 0, i32* %7
br label %22
22: ; preds = %36, %21
%23 = load i32, i32* %7
%24 = load i32, i32* %4
%25 = icmp slt i32 %23, %24
br i1 %25, label %26, label %39
26: ; preds = %22
%27 = load i32**, i32*** %5
%28 = load i32, i32* %6
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i32*, i32** %27, i64 %29
%31 = load i32*, i32** %30
%32 = load i32, i32* %7
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i32, i32* %31, i64 %33
%35 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %34)
br label %36
36: ; preds = %26
%37 = load i32, i32* %7
%38 = add nsw i32 %37, 1
store i32 %38, i32* %7
br label %22
39: ; preds = %22
br label %40
40: ; preds = %39
%41 = load i32, i32* %6
%42 = add nsw i32 %41, 1
store i32 %42, i32* %6
br label %17
43: ; preds = %17
br label %44
44: ; preds = %43, %2
%45 = load i32**, i32*** %5
ret i32** %45
}

LLVM IR (-O2):
@.str = [32 x i8] c"Elements of the (%d*%d) array:\0A\00"
@.str.1 = [3 x i8] c"%d\00"
define i32** @scan_2d_array(i32 %0, i32 %1) {
%3 = tail call i32** @allocate_2d_array(i32 %0, i32 %1)
%4 = icmp eq i32** %3, null
br i1 %4, label %26, label %5
5: ; preds = %2
%6 = tail call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i32 %0, i32 %1)
%7 = icmp sgt i32 %0, 0
br i1 %7, label %8, label %26
8: ; preds = %5
%9 = icmp sgt i32 %1, 0
%10 = zext i32 %0 to i64
%11 = zext i32 %1 to i64
br label %12
12: ; preds = %8, %16
%13 = phi i64 [ 0, %8 ], [ %17, %16 ]
br i1 %9, label %14, label %16
14: ; preds = %12
%15 = getelementptr inbounds i32*, i32** %3, i64 %13
br label %19
16: ; preds = %19, %12
%17 = add nuw nsw i64 %13, 1
%18 = icmp eq i64 %17, %10
br i1 %18, label %26, label %12
19: ; preds = %14, %19
%20 = phi i64 [ 0, %14 ], [ %24, %19 ]
%21 = load i32*, i32** %15
%22 = getelementptr inbounds i32, i32* %21, i64 %20
%23 = tail call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %22)
%24 = add nuw nsw i64 %20, 1
%25 = icmp eq i64 %24, %11
br i1 %25, label %16, label %19
26: ; preds = %16, %5, %2
ret i32** %3
}