#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 calcula_custo(int **, int *, int);
int /*<<< orphan*/ completa_vetor(int *, int);
int /*<<< orphan*/ imprime_vetor(int *, int);
scalar_t__ malloc(int);
int /*<<< orphan*/ pede_dados(int **, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int main(int argc, char *argv[]) {
  int **matriz, *itinerario, custo = 0, ordem, i, tamanho_do_vetor = 0;
  scanf("%d", &ordem);
  tamanho_do_vetor = ordem * 2;
  itinerario = (int *)(malloc(tamanho_do_vetor * sizeof(int)));
  matriz = (int **)malloc(ordem * sizeof(int *));
  for (i = 0; i < ordem; i++) {
    matriz[i] = (int *)malloc(ordem * sizeof(int));
  }
  pede_dados(matriz, ordem);
  completa_vetor(itinerario, tamanho_do_vetor);
  custo = calcula_custo(matriz, itinerario, tamanho_do_vetor);
  printf("o custo do itinerário ");
  imprime_vetor(itinerario, tamanho_do_vetor);
  printf("é\n %d", custo);
  return 0;
}


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)
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x30(%rbp)
lea    0xe81(%rip),%rdi
lea    -0x28(%rbp),%rsi
call   1090 <scanf@plt>
mov    -0x28(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x30(%rbp)
movslq -0x30(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x20(%rbp)
movslq -0x28(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x28(%rbp),%eax
jge    1212 <main+0xa2>
movslq -0x28(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,%rdx
mov    -0x18(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11da <main+0x6a>
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%esi
call   1040 <pede_dados@plt>
mov    -0x20(%rbp),%rdi
mov    -0x30(%rbp),%esi
call   1070 <completa_vetor@plt>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x30(%rbp),%edx
call   1080 <calcula_custo@plt>
mov    %eax,-0x24(%rbp)
lea    0xdbc(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x20(%rbp),%rdi
mov    -0x30(%rbp),%esi
call   1030 <imprime_vetor@plt>
mov    -0x24(%rbp),%esi
lea    0xdb7(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
lea    0xe9e(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1090 <scanf@plt>
mov    0x4(%rsp),%edi
lea    (%rdi,%rdi,1),%r14d
shl    $0x3,%edi
call   1060 <malloc@plt>
mov    %rax,%r15
mov    0x4(%rsp),%edi
shl    $0x3,%edi
call   1060 <malloc@plt>
mov    %rax,%rbp
mov    0x4(%rsp),%esi
test   %esi,%esi
jle    11dd <main+0x6d>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
shl    $0x2,%esi
mov    %esi,%edi
call   1060 <malloc@plt>
mov    %rax,0x0(%rbp,%rbx,8)
add    $0x1,%rbx
movslq 0x4(%rsp),%rsi
cmp    %rsi,%rbx
jl     11c0 <main+0x50>
mov    %rbp,%rdi
call   1040 <pede_dados@plt>
mov    %r15,%rdi
mov    %r14d,%esi
call   1070 <completa_vetor@plt>
mov    %rbp,%rdi
mov    %r15,%rsi
mov    %r14d,%edx
call   1080 <calcula_custo@plt>
mov    %eax,%ebp
lea    0xdf9(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r15,%rdi
mov    %r14d,%esi
call   1030 <imprime_vetor@plt>
lea    0xdf8(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@.str.1 = [24 x i8] c"o custo do itiner\C3\A1rio \00"
@.str.2 = [7 x i8] c"\C3\A9\0A %d\00"
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
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %8
store i32 0, i32* %11
%12 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %9)
%13 = load i32, i32* %9
%14 = mul nsw i32 %13, 2
store i32 %14, i32* %11
%15 = load i32, i32* %11
%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** %7
%21 = load i32, i32* %9
%22 = sext i32 %21 to i64
%23 = mul i64 %22, 8
%24 = trunc i64 %23 to i32
%25 = call i64 @malloc(i32 %24)
%26 = inttoptr i64 %25 to i32**
store i32** %26, i32*** %6
store i32 0, i32* %10
br label %27
27: ; preds = %42, %2
%28 = load i32, i32* %10
%29 = load i32, i32* %9
%30 = icmp slt i32 %28, %29
br i1 %30, label %31, label %45
31: ; preds = %27
%32 = load i32, i32* %9
%33 = sext i32 %32 to i64
%34 = mul i64 %33, 4
%35 = trunc i64 %34 to i32
%36 = call i64 @malloc(i32 %35)
%37 = inttoptr i64 %36 to i32*
%38 = load i32**, i32*** %6
%39 = load i32, i32* %10
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i32*, i32** %38, i64 %40
store i32* %37, i32** %41
br label %42
42: ; preds = %31
%43 = load i32, i32* %10
%44 = add nsw i32 %43, 1
store i32 %44, i32* %10
br label %27
45: ; preds = %27
%46 = load i32**, i32*** %6
%47 = load i32, i32* %9
%48 = call i32 @pede_dados(i32** %46, i32 %47)
%49 = load i32*, i32** %7
%50 = load i32, i32* %11
%51 = call i32 @completa_vetor(i32* %49, i32 %50)
%52 = load i32**, i32*** %6
%53 = load i32*, i32** %7
%54 = load i32, i32* %11
%55 = call i32 @calcula_custo(i32** %52, i32* %53, i32 %54)
store i32 %55, i32* %8
%56 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
%57 = load i32*, i32** %7
%58 = load i32, i32* %11
%59 = call i32 @imprime_vetor(i32* %57, i32 %58)
%60 = load i32, i32* %8
%61 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 %60)
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.1 = [24 x i8] c"o custo do itiner\C3\A1rio \00"
@.str.2 = [7 x i8] c"\C3\A9\0A %d\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %3)
%6 = load i32, i32* %3
%7 = shl nsw i32 %6, 1
%8 = shl i32 %6, 3
%9 = call i64 @malloc(i32 %8)
%10 = inttoptr i64 %9 to i32*
%11 = load i32, i32* %3
%12 = shl i32 %11, 3
%13 = call i64 @malloc(i32 %12)
%14 = inttoptr i64 %13 to i32**
%15 = load i32, i32* %3
%16 = icmp sgt i32 %15, 0
br i1 %16, label %17, label %28
17: ; preds = %2, %17
%18 = phi i64 [ %24, %17 ], [ 0, %2 ]
%19 = phi i32 [ %25, %17 ], [ %15, %2 ]
%20 = shl i32 %19, 2
%21 = call i64 @malloc(i32 %20)
%22 = inttoptr i64 %21 to i32*
%23 = getelementptr inbounds i32*, i32** %14, i64 %18
store i32* %22, i32** %23
%24 = add nuw nsw i64 %18, 1
%25 = load i32, i32* %3
%26 = sext i32 %25 to i64
%27 = icmp slt i64 %24, %26
br i1 %27, label %17, label %28
28: ; preds = %17, %2
%29 = phi i32 [ %15, %2 ], [ %25, %17 ]
%30 = call i32 @pede_dados(i32** %14, i32 %29)
%31 = call i32 @completa_vetor(i32* %10, i32 %7)
%32 = call i32 @calcula_custo(i32** %14, i32* %10, i32 %7)
%33 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
%34 = call i32 @imprime_vetor(i32* %10, i32 %7)
%35 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 %32)
ret i32 0
}