#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*/ Dijkstra(int *, int *, int *, int);
int /*<<< orphan*/ Print_dists(int *, int);
int /*<<< orphan*/ Print_paths(int *, int);
int /*<<< orphan*/ Read_matrix(int *, int);
int /*<<< orphan*/ free(int *);
int *malloc(int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ scanf(char *, int *);
int main(void) {
  int n;
  int *mat, *dist, *pred;
  printf("How many vertices?\n");
  scanf("%d", &n);
  mat = malloc(n * n * sizeof(int));
  dist = malloc(n * sizeof(int));
  pred = malloc(n * sizeof(int));
  printf("Enter the matrix\n");
  Read_matrix(mat, n);
  Dijkstra(mat, dist, pred, n);
  printf("The distance from 0 to each vertex is:\n");
  Print_dists(dist, n);
  printf("The shortest path from 0 to each vertex is:\n");
  Print_paths(pred, n);
  free(mat);
  free(dist);
  free(pred);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe6a(%rip),%rdi
call   1050 <printf@plt>
lea    0xe72(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   10a0 <scanf@plt>
mov    -0x8(%rbp),%eax
imul   -0x8(%rbp),%eax
cltq
shl    $0x2,%rax
mov    %eax,%edi
call   1090 <malloc@plt>
mov    %rax,-0x10(%rbp)
movslq -0x8(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1090 <malloc@plt>
mov    %rax,-0x18(%rbp)
movslq -0x8(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1090 <malloc@plt>
mov    %rax,-0x20(%rbp)
lea    0xe27(%rip),%rdi
call   1050 <printf@plt>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%esi
call   1070 <Read_matrix@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x8(%rbp),%ecx
call   1040 <Dijkstra@plt>
lea    0xe0d(%rip),%rdi
call   1050 <printf@plt>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%esi
call   1060 <Print_dists@plt>
lea    0xe1d(%rip),%rdi
call   1050 <printf@plt>
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%esi
call   1080 <Print_paths@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
lea    0xe73(%rip),%rdi
call   1040 <puts@plt>
lea    0xe64(%rip),%rdi
lea    0xc(%rsp),%rsi
call   10a0 <scanf@plt>
mov    0xc(%rsp),%edi
lea    0x0(,%rdi,4),%ebx
imul   %ebx,%edi
call   1090 <malloc@plt>
mov    %rax,%r14
mov    %ebx,%edi
call   1090 <malloc@plt>
mov    %rax,%r15
mov    %ebx,%edi
call   1090 <malloc@plt>
mov    %rax,%rbx
lea    0xe3f(%rip),%rdi
call   1040 <puts@plt>
mov    0xc(%rsp),%esi
mov    %r14,%rdi
call   1070 <Read_matrix@plt>
mov    0xc(%rsp),%ecx
mov    %r14,%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
call   1050 <Dijkstra@plt>
lea    0xe26(%rip),%rdi
call   1040 <puts@plt>
mov    0xc(%rsp),%esi
mov    %r15,%rdi
call   1060 <Print_dists@plt>
lea    0xe35(%rip),%rdi
call   1040 <puts@plt>
mov    0xc(%rsp),%esi
mov    %rbx,%rdi
call   1080 <Print_paths@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %r15,%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [20 x i8] c"How many vertices?\0A\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [18 x i8] c"Enter the matrix\0A\00"
@.str.3 = [40 x i8] c"The distance from 0 to each vertex is:\0A\00"
@.str.4 = [45 x i8] c"The shortest path from 0 to each vertex is:\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca i32*
store i32 0, i32* %1
%6 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%7 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%8 = load i32, i32* %2
%9 = load i32, i32* %2
%10 = mul nsw i32 %8, %9
%11 = sext i32 %10 to i64
%12 = mul i64 %11, 4
%13 = trunc i64 %12 to i32
%14 = call i32* @malloc(i32 %13)
store i32* %14, i32** %3
%15 = load i32, i32* %2
%16 = sext i32 %15 to i64
%17 = mul i64 %16, 4
%18 = trunc i64 %17 to i32
%19 = call i32* @malloc(i32 %18)
store i32* %19, i32** %4
%20 = load i32, i32* %2
%21 = sext i32 %20 to i64
%22 = mul i64 %21, 4
%23 = trunc i64 %22 to i32
%24 = call i32* @malloc(i32 %23)
store i32* %24, i32** %5
%25 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
%26 = load i32*, i32** %3
%27 = load i32, i32* %2
%28 = call i32 @Read_matrix(i32* %26, i32 %27)
%29 = load i32*, i32** %3
%30 = load i32*, i32** %4
%31 = load i32*, i32** %5
%32 = load i32, i32* %2
%33 = call i32 @Dijkstra(i32* %29, i32* %30, i32* %31, i32 %32)
%34 = call i32 @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.3, i64 0, i64 0))
%35 = load i32*, i32** %4
%36 = load i32, i32* %2
%37 = call i32 @Print_dists(i32* %35, i32 %36)
%38 = call i32 @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.4, i64 0, i64 0))
%39 = load i32*, i32** %5
%40 = load i32, i32* %2
%41 = call i32 @Print_paths(i32* %39, i32 %40)
%42 = load i32*, i32** %3
%43 = call i32 @free(i32* %42)
%44 = load i32*, i32** %4
%45 = call i32 @free(i32* %44)
%46 = load i32*, i32** %5
%47 = call i32 @free(i32* %46)
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"%d\00"
@str = [19 x i8] c"How many vertices?\00"
@str.5 = [17 x i8] c"Enter the matrix\00"
@str.6 = [39 x i8] c"The distance from 0 to each vertex is:\00"
@str.7 = [44 x i8] c"The shortest path from 0 to each vertex is:\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str, i64 0, i64 0))
%4 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%5 = load i32, i32* %1
%6 = shl i32 %5, 2
%7 = mul i32 %6, %5
%8 = call i32* @malloc(i32 %7)
%9 = call i32* @malloc(i32 %6)
%10 = call i32* @malloc(i32 %6)
%11 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str.5, i64 0, i64 0))
%12 = load i32, i32* %1
%13 = call i32 @Read_matrix(i32* %8, i32 %12)
%14 = load i32, i32* %1
%15 = call i32 @Dijkstra(i32* %8, i32* %9, i32* %10, i32 %14)
%16 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @str.6, i64 0, i64 0))
%17 = load i32, i32* %1
%18 = call i32 @Print_dists(i32* %9, i32 %17)
%19 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @str.7, i64 0, i64 0))
%20 = load i32, i32* %1
%21 = call i32 @Print_paths(i32* %10, i32 %20)
%22 = call i32 @free(i32* %8)
%23 = call i32 @free(i32* %9)
%24 = call i32 @free(i32* %10)
ret i32 0
}