#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 *, int, ...);
int /*<<< orphan*/ scanf(char *, int *);
void read_matrix(int **mat, int m, int n) {
  int i, j;
  for (i = 0; i < m; i++) {
    for (j = 0; j <= n; j++) {
      if (j == 0) {
        printf("insira o tamanho do vetor %d \n", i + 1);
        scanf("%d", &mat[i][j]);
        n = mat[i][j];
      } else {
        printf("insira o elemento %d do vetor %d\n", j, i + 1);
        scanf("%d", &mat[i][j]);
      }
    }
  }
}


x86 assembly (clang, -O0):
<read_matrix>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1214 <read_matrix+0xf4>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x10(%rbp),%eax
jg     1201 <read_matrix+0xe1>
cmpl   $0x0,-0x18(%rbp)
jne    11b4 <read_matrix+0x94>
mov    -0x14(%rbp),%esi
add    $0x1,%esi
lea    0xe91(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
movslq -0x18(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe8b(%rip),%rdi
call   1040 <scanf@plt>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x10(%rbp)
jmp    11ee <read_matrix+0xce>
mov    -0x18(%rbp),%esi
mov    -0x14(%rbp),%edx
add    $0x1,%edx
lea    0xe5e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
movslq -0x18(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe36(%rip),%rdi
call   1040 <scanf@plt>
jmp    11f3 <read_matrix+0xd3>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    114c <read_matrix+0x2c>
jmp    1206 <read_matrix+0xe6>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1139 <read_matrix+0x19>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_matrix>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
test   %esi,%esi
jle    11fe <read_matrix+0xde>
mov    %rdi,%r13
mov    %esi,%r14d
lea    0xedc(%rip),%r15
xor    %ebp,%ebp
mov    %r14,0x10(%rsp)
jmp    1159 <read_matrix+0x39>
nopl   0x0(%rax)
cmp    %r14,%rbp
je     11fe <read_matrix+0xde>
mov    %rbp,%r12
add    $0x1,%rbp
test   %edx,%edx
js     1150 <read_matrix+0x30>
lea    0xe95(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    0x0(%r13,%r12,8),%rsi
mov    %r15,%rdi
call   1040 <scanf@plt>
mov    0x0(%r13,%r12,8),%rax
movslq (%rax),%rdx
test   %rdx,%rdx
jle    1150 <read_matrix+0x30>
mov    %rbp,0x8(%rsp)
mov    %r13,%rbp
mov    %r15,%r13
mov    $0x4,%r15d
xor    %r14d,%r14d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
add    $0x1,%r14
lea    0xe67(%rip),%rdi
mov    %r14d,%esi
mov    %rdx,%rbx
mov    0x8(%rsp),%rdx
xor    %eax,%eax
call   1030 <printf@plt>
mov    0x0(%rbp,%r12,8),%rsi
add    %r15,%rsi
mov    %r13,%rdi
call   1040 <scanf@plt>
mov    %rbx,%rdx
add    $0x4,%r15
cmp    %rbx,%r14
jl     11b0 <read_matrix+0x90>
mov    0x10(%rsp),%r14
mov    %r13,%r15
mov    %rbp,%r13
mov    0x8(%rsp),%rbp
jmp    1150 <read_matrix+0x30>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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