#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 */
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, int, int);
int /*<<< orphan*/ scanf(char *, int *);
int **readmat(int sizegr) {
  int **adj_mat;
  int i, j;
  adj_mat = (int **)malloc(sizeof(int *) * sizegr);
  for (i = 0; i < sizegr; i++) {
    *(adj_mat + i) = (int *)malloc(sizeof(int) * sizegr);
  }
  for (i = 0; i < sizegr; i++) {
    for (j = 0; j < sizegr; j++) {
      printf("\nadj_mat[%d][%d]=", i, j);
      scanf("%d", *(adj_mat + i) + j);
    }
  }
  return adj_mat;
}


x86 assembly (clang, -O0):
<readmat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
movslq -0x4(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    118d <readmat+0x5d>
movslq -0x4(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,%rdx
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1155 <readmat+0x25>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    1209 <readmat+0xd9>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11f6 <readmat+0xc6>
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
lea    0xe40(%rip),%rdi
call   1030 <printf@plt>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
movslq -0x18(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe2f(%rip),%rdi
call   1050 <scanf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11a7 <readmat+0x77>
jmp    11fb <readmat+0xcb>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1194 <readmat+0x64>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readmat>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %edi,%r15d
lea    0x0(,%r15,8),%edi
call   1040 <malloc@plt>
mov    %rax,0x8(%rsp)
test   %r15d,%r15d
jle    11f6 <readmat+0xc6>
lea    0x0(,%r15,4),%r12d
mov    %r15d,%r14d
xor    %ebx,%ebx
mov    0x8(%rsp),%rbp
xchg   %ax,%ax
mov    %r12d,%edi
call   1040 <malloc@plt>
mov    %rax,0x0(%rbp,%rbx,8)
add    $0x1,%rbx
cmp    %rbx,%r14
jne    1170 <readmat+0x40>
mov    %r14,%rbp
mov    %r14,0x10(%rsp)
test   %r15d,%r15d
jle    11f6 <readmat+0xc6>
mov    0x10(%rsp),%rax
lea    0x0(,%rax,4),%r13
xor    %ebx,%ebx
lea    0xe57(%rip),%r12
mov    0x8(%rsp),%r14
xchg   %ax,%ax
xor    %r15d,%r15d
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r12,%rdi
mov    %ebx,%esi
mov    %ebp,%edx
call   1030 <printf@plt>
mov    (%r14,%rbx,8),%rsi
add    %r15,%rsi
lea    0xe38(%rip),%rdi
call   1050 <scanf@plt>
add    $0x1,%ebp
add    $0x4,%r15
cmp    %r15,%r13
jne    11c0 <readmat+0x90>
add    $0x1,%rbx
cmp    0x10(%rsp),%rbx
jne    11b0 <readmat+0x80>
mov    0x8(%rsp),%rax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [18 x i8] c"\0Aadj_mat[%d][%d]=\00"
@.str.1 = [3 x i8] c"%d\00"
define i32** @readmat(i32 %0) {
%2 = shl i32 %0, 3
%3 = tail call i64 @malloc(i32 %2)
%4 = inttoptr i64 %3 to i32**
%5 = icmp sgt i32 %0, 0
br i1 %5, label %6, label %35
6: ; preds = %1
%7 = shl i32 %0, 2
%8 = zext i32 %0 to i64
br label %12
9: ; preds = %12
br i1 %5, label %10, label %35
10: ; preds = %9
%11 = zext i32 %0 to i64
br label %19
12: ; preds = %6, %12
%13 = phi i64 [ 0, %6 ], [ %17, %12 ]
%14 = tail call i64 @malloc(i32 %7)
%15 = inttoptr i64 %14 to i32*
%16 = getelementptr inbounds i32*, i32** %4, i64 %13
store i32* %15, i32** %16
%17 = add nuw nsw i64 %13, 1
%18 = icmp eq i64 %17, %8
br i1 %18, label %9, label %12
19: ; preds = %32, %10
%20 = phi i64 [ 0, %10 ], [ %33, %32 ]
%21 = getelementptr inbounds i32*, i32** %4, i64 %20
%22 = trunc i64 %20 to i32
br label %23
23: ; preds = %19, %23
%24 = phi i64 [ 0, %19 ], [ %30, %23 ]
%25 = trunc i64 %24 to i32
%26 = tail call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 %22, i32 %25)
%27 = load i32*, i32** %21
%28 = getelementptr inbounds i32, i32* %27, i64 %24
%29 = tail call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %28)
%30 = add nuw nsw i64 %24, 1
%31 = icmp eq i64 %30, %11
br i1 %31, label %32, label %23
32: ; preds = %23
%33 = add nuw nsw i64 %20, 1
%34 = icmp eq i64 %33, %11
br i1 %34, label %35, label %19
35: ; preds = %32, %1, %9
ret i32** %4
}