#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 */
struct node {
  int dummy;
};

/* Variables and functions */
struct node *addEdge(struct node *, int, int);
int /*<<< orphan*/ dijkstra(struct node **, int, int, int *, int *);
int /*<<< orphan*/ printPath(int *, int, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *, ...);
int main() {
  int vertices, edges, i, j, v1, v2, w, startVertex;
  printf("Enter the Number of Vertices -\n");
  scanf("%d", &vertices);
  printf("Enter the Number of Edges -\n");
  scanf("%d", &edges);
  struct node *adjacencyList[vertices + 1];
  int distances[vertices + 1];
  int parent[vertices + 1];
  for (i = 0; i <= vertices; ++i) {
    adjacencyList[i] = NULL;
  }
  for (i = 1; i <= edges; ++i) {
    scanf("%d%d%d", &v1, &v2, &w);
    adjacencyList[v1] = addEdge(adjacencyList[v1], v2, w);
  }
  printf("Enter start vertex -\n");
  scanf("%d", &startVertex);
  dijkstra(adjacencyList, vertices, startVertex, distances, parent);
  printf("Shortest distances -\n");
  for (i = 1; i <= vertices; ++i) {
    printf("Vertex %d, Distance = %d, Parent = %d, ", i, distances[i],
           parent[i]);
    printf("Path = ");
    printPath(parent, i, startVertex);
    printf("\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe9a(%rip),%rdi
xor    %eax,%eax
mov    %al,-0x61(%rbp)
call   1030 <printf@plt>
mov    -0x61(%rbp),%al
lea    0xec7(%rip),%rdi
mov    %rdi,-0x70(%rbp)
lea    -0x8(%rbp),%rsi
call   1050 <scanf@plt>
mov    -0x61(%rbp),%al
lea    0xe8f(%rip),%rdi
call   1030 <printf@plt>
mov    -0x70(%rbp),%rdi
mov    -0x61(%rbp),%al
lea    -0xc(%rbp),%rsi
call   1050 <scanf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %rsp,%rcx
mov    %rcx,-0x30(%rbp)
lea    0xf(,%rax,8),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x60(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x38(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
lea    0xf(,%rax,4),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x58(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x40(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
lea    0xf(,%rax,4),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x50(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x48(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x8(%rbp),%eax
jg     1247 <main+0xf7>
mov    -0x60(%rbp),%rax
movslq -0x10(%rbp),%rcx
movq   $0x0,(%rax,%rcx,8)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    121d <main+0xcd>
movl   $0x1,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jg     12a8 <main+0x158>
lea    0xddc(%rip),%rdi
lea    -0x18(%rbp),%rsi
lea    -0x1c(%rbp),%rdx
lea    -0x20(%rbp),%rcx
mov    $0x0,%al
call   1050 <scanf@plt>
mov    -0x60(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x1c(%rbp),%esi
mov    -0x20(%rbp),%edx
call   1040 <addEdge@plt>
mov    %rax,%rdx
mov    -0x60(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    124e <main+0xfe>
lea    0xd95(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xd84(%rip),%rdi
lea    -0x24(%rbp),%rsi
mov    $0x0,%al
call   1050 <scanf@plt>
mov    -0x60(%rbp),%rdi
mov    -0x58(%rbp),%rcx
mov    -0x50(%rbp),%r8
mov    -0x8(%rbp),%esi
mov    -0x24(%rbp),%edx
call   1060 <dijkstra@plt>
lea    0xd74(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x8(%rbp),%eax
jg     1360 <main+0x210>
mov    -0x50(%rbp),%rax
mov    -0x58(%rbp),%rcx
mov    -0x10(%rbp),%esi
movslq -0x10(%rbp),%rdx
mov    (%rcx,%rdx,4),%edx
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,4),%ecx
lea    0xd50(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xd6a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x50(%rbp),%rdi
mov    -0x10(%rbp),%esi
mov    -0x24(%rbp),%edx
call   1070 <printPath@plt>
lea    0xcd3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    12f4 <main+0x1a4>
movl   $0x0,-0x4(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
lea    0xe9f(%rip),%rdi
call   1040 <puts@plt>
lea    0xe60(%rip),%rbx
lea    -0x2c(%rbp),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1080 <scanf@plt>
lea    0xe9d(%rip),%rdi
call   1040 <puts@plt>
lea    -0x38(%rbp),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1080 <scanf@plt>
mov    %rsp,-0x50(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %rsp,%rbx
lea    0xf(,%rax,8),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    -0x2c(%rbp),%eax
lea    0x1(%rax),%ecx
mov    %rsp,%rdx
lea    0xf(,%rcx,4),%rcx
and    $0xfffffffffffffff0,%rcx
sub    %rcx,%rdx
mov    %rdx,-0x48(%rbp)
mov    %rdx,%rsp
mov    %rsp,%r15
sub    %rcx,%r15
mov    %r15,%rsp
test   %eax,%eax
js     1229 <main+0xa9>
lea    0x8(,%rax,8),%rdx
mov    %rbx,%rdi
xor    %esi,%esi
call   1060 <memset@plt>
cmpl   $0x0,-0x38(%rbp)
jle    127d <main+0xfd>
lea    -0x40(%rbp),%r14
lea    -0x3c(%rbp),%r12
xor    %r13d,%r13d
nopw   0x0(%rax,%rax,1)
lea    0xdb9(%rip),%rdi
lea    -0x34(%rbp),%rsi
mov    %r14,%rdx
mov    %r12,%rcx
xor    %eax,%eax
call   1080 <scanf@plt>
movslq -0x34(%rbp),%rax
mov    (%rbx,%rax,8),%rdi
mov    -0x40(%rbp),%esi
mov    -0x3c(%rbp),%edx
call   1070 <addEdge@plt>
movslq -0x34(%rbp),%rcx
mov    %rax,(%rbx,%rcx,8)
add    $0x1,%r13d
cmp    -0x38(%rbp),%r13d
jl     1240 <main+0xc0>
lea    0xdee(%rip),%rdi
call   1040 <puts@plt>
lea    0xd74(%rip),%rdi
lea    -0x30(%rbp),%rsi
xor    %eax,%eax
call   1080 <scanf@plt>
mov    -0x2c(%rbp),%esi
mov    -0x30(%rbp),%edx
mov    %rbx,%rdi
mov    -0x48(%rbp),%r14
mov    %r14,%rcx
mov    %r15,%r8
call   1090 <dijkstra@plt>
lea    0xdcd(%rip),%rdi
call   1040 <puts@plt>
cmpl   $0x0,-0x2c(%rbp)
jle    1325 <main+0x1a5>
mov    $0x1,%ebx
lea    0xd36(%rip),%r12
lea    0xd57(%rip),%r13
nopl   0x0(%rax,%rax,1)
mov    (%r14,%rbx,4),%edx
mov    (%r15,%rbx,4),%ecx
mov    %r12,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r13,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    -0x30(%rbp),%edx
mov    %r15,%rdi
mov    %ebx,%esi
call   10a0 <printPath@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0x1(%rbx),%rax
movslq -0x2c(%rbp),%rcx
cmp    %rcx,%rbx
mov    %rax,%rbx
jl     12e0 <main+0x160>
mov    -0x50(%rbp),%rsp
xor    %eax,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.node = type { i32 }
@.str = [32 x i8] c"Enter the Number of Vertices -\0A\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [29 x i8] c"Enter the Number of Edges -\0A\00"
@.str.3 = [7 x i8] c"%d%d%d\00"
@.str.4 = [22 x i8] c"Enter start vertex -\0A\00"
@.str.5 = [22 x i8] c"Shortest distances -\0A\00"
@.str.6 = [40 x i8] c"Vertex %d, Distance = %d, Parent = %d, \00"
@.str.7 = [8 x i8] c"Path = \00"
@.str.8 = [2 x i8] c"\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i64
%12 = alloca i64
%13 = alloca i64
store i32 0, i32* %1
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
%15 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
%17 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%18 = load i32, i32* %2
%19 = add nsw i32 %18, 1
%20 = zext i32 %19 to i64
%21 = call i8* @llvm.stacksave()
store i8* %21, i8** %10
%22 = alloca %struct.node*, i64 %20
store i64 %20, i64* %11
%23 = load i32, i32* %2
%24 = add nsw i32 %23, 1
%25 = zext i32 %24 to i64
%26 = alloca i32, i64 %25
store i64 %25, i64* %12
%27 = load i32, i32* %2
%28 = add nsw i32 %27, 1
%29 = zext i32 %28 to i64
%30 = alloca i32, i64 %29
store i64 %29, i64* %13
store i32 0, i32* %4
br label %31
31: ; preds = %39, %0
%32 = load i32, i32* %4
%33 = load i32, i32* %2
%34 = icmp sle i32 %32, %33
br i1 %34, label %35, label %42
35: ; preds = %31
%36 = load i32, i32* %4
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds %struct.node*, %struct.node** %22, i64 %37
store %struct.node* null, %struct.node** %38
br label %39
39: ; preds = %35
%40 = load i32, i32* %4
%41 = add nsw i32 %40, 1
store i32 %41, i32* %4
br label %31
42: ; preds = %31
store i32 1, i32* %4
br label %43
43: ; preds = %59, %42
%44 = load i32, i32* %4
%45 = load i32, i32* %3
%46 = icmp sle i32 %44, %45
br i1 %46, label %47, label %62
47: ; preds = %43
%48 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32* %6, i32* %7, i32* %8)
%49 = load i32, i32* %6
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds %struct.node*, %struct.node** %22, i64 %50
%52 = load %struct.node*, %struct.node** %51
%53 = load i32, i32* %7
%54 = load i32, i32* %8
%55 = call %struct.node* @addEdge(%struct.node* %52, i32 %53, i32 %54)
%56 = load i32, i32* %6
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds %struct.node*, %struct.node** %22, i64 %57
store %struct.node* %55, %struct.node** %58
br label %59
59: ; preds = %47
%60 = load i32, i32* %4
%61 = add nsw i32 %60, 1
store i32 %61, i32* %4
br label %43
62: ; preds = %43
%63 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0))
%64 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %9)
%65 = load i32, i32* %2
%66 = load i32, i32* %9
%67 = call i32 @dijkstra(%struct.node** %22, i32 %65, i32 %66, i32* %26, i32* %30)
%68 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0))
store i32 1, i32* %4
br label %69
69: ; preds = %89, %62
%70 = load i32, i32* %4
%71 = load i32, i32* %2
%72 = icmp sle i32 %70, %71
br i1 %72, label %73, label %92
73: ; preds = %69
%74 = load i32, i32* %4
%75 = load i32, i32* %4
%76 = sext i32 %75 to i64
%77 = getelementptr inbounds i32, i32* %26, i64 %76
%78 = load i32, i32* %77
%79 = load i32, i32* %4
%80 = sext i32 %79 to i64
%81 = getelementptr inbounds i32, i32* %30, i64 %80
%82 = load i32, i32* %81
%83 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.6, i64 0, i64 0), i32 %74, i32 %78, i32 %82)
%84 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i64 0, i64 0))
%85 = load i32, i32* %4
%86 = load i32, i32* %9
%87 = call i32 @printPath(i32* %30, i32 %85, i32 %86)
%88 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0))
br label %89
89: ; preds = %73
%90 = load i32, i32* %4
%91 = add nsw i32 %90, 1
store i32 %91, i32* %4
br label %69
92: ; preds = %69
store i32 0, i32* %1
%93 = load i8*, i8** %10
%94 = load i32, i32* %1
ret i32 %94
}

LLVM IR (-O2):
%struct.node = type { i32 }
@.str.1 = [3 x i8] c"%d\00"
@.str.3 = [7 x i8] c"%d%d%d\00"
@.str.6 = [40 x i8] c"Vertex %d, Distance = %d, Parent = %d, \00"
@.str.7 = [8 x i8] c"Path = \00"
@str = [31 x i8] c"Enter the Number of Vertices -\00"
@str.9 = [28 x i8] c"Enter the Number of Edges -\00"
@str.10 = [21 x i8] c"Enter start vertex -\00"
@str.11 = [21 x i8] c"Shortest distances -\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = bitcast i32* %1 to i8*
%8 = bitcast i32* %2 to i8*
%9 = bitcast i32* %3 to i8*
%10 = bitcast i32* %4 to i8*
%11 = bitcast i32* %5 to i8*
%12 = bitcast i32* %6 to i8*
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str, i64 0, i64 0))
%14 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%15 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str.9, i64 0, i64 0))
%16 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%17 = load i32, i32* %1
%18 = add nsw i32 %17, 1
%19 = zext i32 %18 to i64
%20 = call i8* @llvm.stacksave()
%21 = alloca %struct.node*, i64 %19
%22 = load i32, i32* %1
%23 = add nsw i32 %22, 1
%24 = zext i32 %23 to i64
%25 = alloca i32, i64 %24
%26 = alloca i32, i64 %24
%27 = icmp slt i32 %22, 0
br i1 %27, label %33, label %28
28: ; preds = %0
%29 = bitcast %struct.node** %21 to i8*
%30 = zext i32 %22 to i64
%31 = shl nuw nsw i64 %30, 3
%32 = add nuw nsw i64 %31, 8
br label %33
33: ; preds = %28, %0
%34 = load i32, i32* %2
%35 = icmp slt i32 %34, 1
br i1 %35, label %52, label %36
36: ; preds = %33, %36
%37 = phi i32 [ %49, %36 ], [ 1, %33 ]
%38 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32* %3, i32* %4, i32* %5)
%39 = load i32, i32* %3
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds %struct.node*, %struct.node** %21, i64 %40
%42 = load %struct.node*, %struct.node** %41
%43 = load i32, i32* %4
%44 = load i32, i32* %5
%45 = call %struct.node* @addEdge(%struct.node* %42, i32 %43, i32 %44)
%46 = load i32, i32* %3
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds %struct.node*, %struct.node** %21, i64 %47
store %struct.node* %45, %struct.node** %48
%49 = add nuw nsw i32 %37, 1
%50 = load i32, i32* %2
%51 = icmp slt i32 %37, %50
br i1 %51, label %36, label %52
52: ; preds = %36, %33
%53 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str.10, i64 0, i64 0))
%54 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %6)
%55 = load i32, i32* %1
%56 = load i32, i32* %6
%57 = call i32 @dijkstra(%struct.node** %21, i32 %55, i32 %56, i32* %25, i32* %26)
%58 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str.11, i64 0, i64 0))
%59 = load i32, i32* %1
%60 = icmp slt i32 %59, 1
br i1 %60, label %77, label %61
61: ; preds = %52, %61
%62 = phi i64 [ %73, %61 ], [ 1, %52 ]
%63 = getelementptr inbounds i32, i32* %25, i64 %62
%64 = load i32, i32* %63
%65 = getelementptr inbounds i32, i32* %26, i64 %62
%66 = load i32, i32* %65
%67 = trunc i64 %62 to i32
%68 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str.6, i64 0, i64 0), i32 %67, i32 %64, i32 %66)
%69 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i64 0, i64 0))
%70 = load i32, i32* %6
%71 = call i32 @printPath(i32* %26, i32 %67, i32 %70)
%72 = call i32 @putchar(i32 10)
%73 = add nuw nsw i64 %62, 1
%74 = load i32, i32* %1
%75 = sext i32 %74 to i64
%76 = icmp slt i64 %62, %75
br i1 %76, label %61, label %77
77: ; preds = %61, %52
ret i32 0
}