#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 EXIT_SUCCESS;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ free(int *);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int tridiagonal(int *, int);
int main(int argc, char **argv) {
  int *mat;
  int n, i, j, d;
  printf("Digiite o numero de linhas/colunas da matriz: ");
  scanf("%d", &n);
  mat = (int *)malloc(n * n * sizeof(int));
  if (!mat) {
    printf("Erro alocação");
    exit(1);
  }
  printf("\nDigite a matriz:\n");
  for (i = 0; i < n; i++) {
    for (j = 0; j < n; j++) {
      d = i * n + j;
      printf("Digite o valor [%d][%d]: ", i, j);
      scanf("%d", mat + d);
    }
  }
  printf("Retorno: %d ", tridiagonal(mat, n));
  free(mat);
  return (EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe83(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xea4(%rip),%rdi
lea    -0x1c(%rbp),%rsi
call   1070 <scanf@plt>
mov    -0x1c(%rbp),%eax
imul   -0x1c(%rbp),%eax
cltq
shl    $0x2,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11cf <main+0x6f>
lea    0xe74(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
lea    0xe6c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1260 <main+0x100>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    124d <main+0xed>
mov    -0x20(%rbp),%eax
imul   -0x1c(%rbp),%eax
add    -0x24(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x20(%rbp),%esi
mov    -0x24(%rbp),%edx
lea    0xe38(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%rsi
movslq -0x28(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
lea    0xdf5(%rip),%rdi
call   1070 <scanf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11f7 <main+0x97>
jmp    1252 <main+0xf2>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    11e4 <main+0x84>
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1050 <tridiagonal@plt>
mov    %eax,%esi
lea    0xdfa(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    0x2d54(%rip),%rax
mov    (%rax),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xe7e(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe9f(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1080 <scanf@plt>
mov    0x4(%rsp),%edi
imul   %edi,%edi
shl    $0x2,%edi
call   1070 <malloc@plt>
test   %rax,%rax
je     125b <main+0xeb>
mov    %rax,%r12
lea    0xead(%rip),%rdi
call   1040 <puts@plt>
mov    0x4(%rsp),%ebp
test   %ebp,%ebp
jle    1221 <main+0xb1>
lea    0xe72(%rip),%r14
lea    0xe58(%rip),%r15
xor    %r13d,%r13d
jmp    11e9 <main+0x79>
nopl   0x0(%rax)
add    $0x1,%r13d
cmp    %ebp,%r13d
jge    1221 <main+0xb1>
test   %ebp,%ebp
jle    11e0 <main+0x70>
xor    %ebx,%ebx
nop
imul   %r13d,%ebp
add    %ebx,%ebp
mov    %r14,%rdi
mov    %r13d,%esi
mov    %ebx,%edx
xor    %eax,%eax
call   1050 <printf@plt>
movslq %ebp,%rax
lea    (%r12,%rax,4),%rsi
mov    %r15,%rdi
call   1080 <scanf@plt>
add    $0x1,%ebx
mov    0x4(%rsp),%ebp
cmp    %ebp,%ebx
jl     11f0 <main+0x80>
jmp    11e0 <main+0x70>
mov    %r12,%rdi
mov    %ebp,%esi
call   1060 <tridiagonal@plt>
lea    0xe2a(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r12,%rdi
call   1030 <free@plt>
mov    0x2d96(%rip),%rax
mov    (%rax),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdd0(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [47 x i8] c"Digiite o numero de linhas/colunas da matriz: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [16 x i8] c"Erro aloca\C3\A7\C3\A3o\00"
@.str.3 = [19 x i8] c"\0ADigite a matriz:\0A\00"
@.str.4 = [26 x i8] c"Digite o valor [%d][%d]: \00"
@.str.5 = [13 x i8] c"Retorno: %d \00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0))
%12 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %7)
%13 = load i32, i32* %7
%14 = load i32, i32* %7
%15 = mul nsw i32 %13, %14
%16 = sext i32 %15 to i64
%17 = mul i64 %16, 4
%18 = trunc i64 %17 to i32
%19 = call i64 @malloc(i32 %18)
%20 = inttoptr i64 %19 to i32*
store i32* %20, i32** %6
%21 = load i32*, i32** %6
%22 = icmp ne i32* %21, null
br i1 %22, label %26, label %23
23: ; preds = %2
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
%25 = call i32 @exit(i32 1)
unreachable
26: ; preds = %2
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %8
br label %28
28: ; preds = %55, %26
%29 = load i32, i32* %8
%30 = load i32, i32* %7
%31 = icmp slt i32 %29, %30
br i1 %31, label %32, label %58
32: ; preds = %28
store i32 0, i32* %9
br label %33
33: ; preds = %51, %32
%34 = load i32, i32* %9
%35 = load i32, i32* %7
%36 = icmp slt i32 %34, %35
br i1 %36, label %37, label %54
37: ; preds = %33
%38 = load i32, i32* %8
%39 = load i32, i32* %7
%40 = mul nsw i32 %38, %39
%41 = load i32, i32* %9
%42 = add nsw i32 %40, %41
store i32 %42, i32* %10
%43 = load i32, i32* %8
%44 = load i32, i32* %9
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0), i32 %43, i32 %44)
%46 = load i32*, i32** %6
%47 = load i32, i32* %10
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds i32, i32* %46, i64 %48
%50 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %49)
br label %51
51: ; preds = %37
%52 = load i32, i32* %9
%53 = add nsw i32 %52, 1
store i32 %53, i32* %9
br label %33
54: ; preds = %33
br label %55
55: ; preds = %54
%56 = load i32, i32* %8
%57 = add nsw i32 %56, 1
store i32 %57, i32* %8
br label %28
58: ; preds = %28
%59 = load i32*, i32** %6
%60 = load i32, i32* %7
%61 = call i32 @tridiagonal(i32* %59, i32 %60)
%62 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0), i32 %61)
%63 = load i32*, i32** %6
%64 = call i32 @free(i32* %63)
%65 = load i32, i32* @EXIT_SUCCESS
ret i32 %65
}

LLVM IR (-O2):
@.str = [47 x i8] c"Digiite o numero de linhas/colunas da matriz: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [16 x i8] c"Erro aloca\C3\A7\C3\A3o\00"
@.str.4 = [26 x i8] c"Digite o valor [%d][%d]: \00"
@.str.5 = [13 x i8] c"Retorno: %d \00"
@EXIT_SUCCESS = global i32 0
@str = [18 x i8] c"\0ADigite a matriz:\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%7 = load i32, i32* %3
%8 = shl i32 %7, 2
%9 = mul i32 %8, %7
%10 = call i64 @malloc(i32 %9)
%11 = inttoptr i64 %10 to i32*
%12 = icmp eq i64 %10, 0
br i1 %12, label %13, label %16
13: ; preds = %2
%14 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
%15 = call i32 @exit(i32 1)
unreachable
16: ; preds = %2
%17 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str, i64 0, i64 0))
%18 = load i32, i32* %3
%19 = icmp sgt i32 %18, 0
br i1 %19, label %20, label %40
20: ; preds = %16, %36
%21 = phi i32 [ %37, %36 ], [ %18, %16 ]
%22 = phi i32 [ %38, %36 ], [ 0, %16 ]
%23 = icmp sgt i32 %21, 0
br i1 %23, label %24, label %36
24: ; preds = %20, %24
%25 = phi i32 [ %34, %24 ], [ %21, %20 ]
%26 = phi i32 [ %33, %24 ], [ 0, %20 ]
%27 = mul nsw i32 %25, %22
%28 = add nsw i32 %27, %26
%29 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0), i32 %22, i32 %26)
%30 = sext i32 %28 to i64
%31 = getelementptr inbounds i32, i32* %11, i64 %30
%32 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %31)
%33 = add nuw nsw i32 %26, 1
%34 = load i32, i32* %3
%35 = icmp slt i32 %33, %34
br i1 %35, label %24, label %36
36: ; preds = %24, %20
%37 = phi i32 [ %21, %20 ], [ %34, %24 ]
%38 = add nuw nsw i32 %22, 1
%39 = icmp slt i32 %38, %37
br i1 %39, label %20, label %40
40: ; preds = %36, %16
%41 = phi i32 [ %18, %16 ], [ %37, %36 ]
%42 = call i32 @tridiagonal(i32* %11, i32 %41)
%43 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0), i32 %42)
%44 = call i32 @free(i32* %11)
%45 = load i32, i32* @EXIT_SUCCESS
ret i32 %45
}