#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*/ dij(int, int, int **, int *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int /*<<< orphan*/ system(char *);
int main(void) {
  system("COLOR F0");
  int n, v, i, j, cost[10][10], dist[10];
  printf("\nEnter the number of nodes:");
  scanf("%d", &n);
  printf("\nEnter the cost matrix:\n");
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= n; j++) {
      scanf("%d", &cost[i][j]);
      if (cost[i][j] == 0)
        cost[i][j] = 999;
    }
  }
  printf("\nEnter the source matrix:");
  scanf("%d", &v);
  dij(n, v, cost, dist);
  printf("\nShortest path:\n");
  for (i = 1; i <= n; i++)
    if (i != v)
      printf("\nFor %d->%d shortest distance is %d", v, i, dist[i]);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1e0,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xea7(%rip),%rdi
call   1030 <system@plt>
lea    0xea4(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xf17(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1060 <scanf@plt>
lea    0xea2(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x8(%rbp),%eax
jg     123c <main+0xfc>
movl   $0x1,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jg     1229 <main+0xe9>
movslq -0x10(%rbp),%rax
lea    -0x1b0(%rbp),%rsi
imul   $0x28,%rax,%rax
add    %rax,%rsi
movslq -0x14(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
lea    0xeb6(%rip),%rdi
call   1060 <scanf@plt>
movslq -0x10(%rbp),%rcx
lea    -0x1b0(%rbp),%rax
imul   $0x28,%rcx,%rcx
add    %rcx,%rax
movslq -0x14(%rbp),%rcx
cmpl   $0x0,(%rax,%rcx,4)
jne    1216 <main+0xd6>
movslq -0x10(%rbp),%rcx
lea    -0x1b0(%rbp),%rax
imul   $0x28,%rcx,%rcx
add    %rcx,%rax
movslq -0x14(%rbp),%rcx
movl   $0x3e7,(%rax,%rcx,4)
jmp    121b <main+0xdb>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11a4 <main+0x64>
jmp    122e <main+0xee>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1191 <main+0x51>
lea    0xdfb(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe39(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   1060 <scanf@plt>
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
lea    -0x1b0(%rbp),%rdx
lea    -0x1e0(%rbp),%rcx
call   1050 <dij@plt>
lea    0xdde(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x8(%rbp),%eax
jg     12d2 <main+0x192>
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
je     12bf <main+0x17f>
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
movslq -0x10(%rbp),%rax
mov    -0x1e0(%rbp,%rax,4),%ecx
lea    0xdb1(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    12c4 <main+0x184>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1288 <main+0x148>
xor    %eax,%eax
add    $0x1e0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1d0,%rsp
lea    0xe99(%rip),%rdi
call   1040 <system@plt>
lea    0xe96(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xedf(%rip),%rdi
lea    0x8(%rsp),%rsi
call   1070 <scanf@plt>
lea    0xed1(%rip),%rdi
call   1030 <puts@plt>
mov    0x8(%rsp),%eax
test   %eax,%eax
jle    120a <main+0xba>
lea    0x6c(%rsp),%r15
mov    $0x1,%r12d
lea    0xeaf(%rip),%r14
jmp    11d4 <main+0x84>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movslq %eax,%rcx
lea    0x1(%r12),%rdx
add    $0x28,%r15
cmp    %rcx,%r12
mov    %rdx,%r12
jge    120a <main+0xba>
test   %eax,%eax
jle    11c0 <main+0x70>
mov    %r15,%rbx
xor    %r13d,%r13d
jmp    11f2 <main+0xa2>
movslq 0x8(%rsp),%rax
add    $0x1,%r13
add    $0x4,%rbx
cmp    %rax,%r13
jge    11c0 <main+0x70>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1070 <scanf@plt>
cmpl   $0x0,(%rbx)
jne    11e0 <main+0x90>
movl   $0x3e7,(%rbx)
jmp    11e0 <main+0x90>
lea    0xe14(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe41(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1070 <scanf@plt>
mov    0x8(%rsp),%edi
mov    0xc(%rsp),%esi
lea    0x40(%rsp),%rdx
lea    0x10(%rsp),%rcx
call   1060 <dij@plt>
lea    0xe34(%rip),%rdi
call   1030 <puts@plt>
mov    0x8(%rsp),%eax
test   %eax,%eax
jle    129e <main+0x14e>
mov    $0x1,%ebx
lea    0xddf(%rip),%r14
jmp    127f <main+0x12f>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
lea    0x1(%rbx),%rcx
movslq %eax,%rdx
cmp    %rdx,%rbx
mov    %rcx,%rbx
jge    129e <main+0x14e>
mov    0xc(%rsp),%esi
cmp    %rsi,%rbx
je     1270 <main+0x120>
mov    0x10(%rsp,%rbx,4),%ecx
mov    %r14,%rdi
mov    %ebx,%edx
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x8(%rsp),%eax
jmp    1270 <main+0x120>
xor    %eax,%eax
add    $0x1d0,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [9 x i8] c"COLOR F0\00"
@.str.1 = [28 x i8] c"\0AEnter the number of nodes:\00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [25 x i8] c"\0AEnter the cost matrix:\0A\00"
@.str.4 = [26 x i8] c"\0AEnter the source matrix:\00"
@.str.5 = [17 x i8] c"\0AShortest path:\0A\00"
@.str.6 = [36 x i8] c"\0AFor %d->%d shortest distance is %d\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca [10 x [10 x i32]]
%7 = alloca [10 x i32]
store i32 0, i32* %1
%8 = call i32 @system(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
%10 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %2)
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0))
store i32 1, i32* %4
br label %12
12: ; preds = %49, %0
%13 = load i32, i32* %4
%14 = load i32, i32* %2
%15 = icmp sle i32 %13, %14
br i1 %15, label %16, label %52
16: ; preds = %12
store i32 1, i32* %5
br label %17
17: ; preds = %45, %16
%18 = load i32, i32* %5
%19 = load i32, i32* %2
%20 = icmp sle i32 %18, %19
br i1 %20, label %21, label %48
21: ; preds = %17
%22 = load i32, i32* %4
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds [10 x [10 x i32]], [10 x [10 x i32]]* %6, i64 0, i64 %23
%25 = load i32, i32* %5
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds [10 x i32], [10 x i32]* %24, i64 0, i64 %26
%28 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %27)
%29 = load i32, i32* %4
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds [10 x [10 x i32]], [10 x [10 x i32]]* %6, i64 0, i64 %30
%32 = load i32, i32* %5
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds [10 x i32], [10 x i32]* %31, i64 0, i64 %33
%35 = load i32, i32* %34
%36 = icmp eq i32 %35, 0
br i1 %36, label %37, label %44
37: ; preds = %21
%38 = load i32, i32* %4
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds [10 x [10 x i32]], [10 x [10 x i32]]* %6, i64 0, i64 %39
%41 = load i32, i32* %5
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds [10 x i32], [10 x i32]* %40, i64 0, i64 %42
store i32 999, i32* %43
br label %44
44: ; preds = %37, %21
br label %45
45: ; preds = %44
%46 = load i32, i32* %5
%47 = add nsw i32 %46, 1
store i32 %47, i32* %5
br label %17
48: ; preds = %17
br label %49
49: ; preds = %48
%50 = load i32, i32* %4
%51 = add nsw i32 %50, 1
store i32 %51, i32* %4
br label %12
52: ; preds = %12
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0))
%54 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %3)
%55 = load i32, i32* %2
%56 = load i32, i32* %3
%57 = getelementptr inbounds [10 x [10 x i32]], [10 x [10 x i32]]* %6, i64 0, i64 0
%58 = bitcast [10 x i32]* %57 to i32**
%59 = getelementptr inbounds [10 x i32], [10 x i32]* %7, i64 0, i64 0
%60 = call i32 @dij(i32 %55, i32 %56, i32** %58, i32* %59)
%61 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0))
store i32 1, i32* %4
br label %62
62: ; preds = %79, %52
%63 = load i32, i32* %4
%64 = load i32, i32* %2
%65 = icmp sle i32 %63, %64
br i1 %65, label %66, label %82
66: ; preds = %62
%67 = load i32, i32* %4
%68 = load i32, i32* %3
%69 = icmp ne i32 %67, %68
br i1 %69, label %70, label %78
70: ; preds = %66
%71 = load i32, i32* %3
%72 = load i32, i32* %4
%73 = load i32, i32* %4
%74 = sext i32 %73 to i64
%75 = getelementptr inbounds [10 x i32], [10 x i32]* %7, i64 0, i64 %74
%76 = load i32, i32* %75
%77 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.6, i64 0, i64 0), i32 %71, i32 %72, i32 %76)
br label %78
78: ; preds = %70, %66
br label %79
79: ; preds = %78
%80 = load i32, i32* %4
%81 = add nsw i32 %80, 1
store i32 %81, i32* %4
br label %62
82: ; preds = %62
ret i32 0
}

LLVM IR (-O2):
@.str = [9 x i8] c"COLOR F0\00"
@.str.1 = [28 x i8] c"\0AEnter the number of nodes:\00"
@.str.2 = [3 x i8] c"%d\00"
@.str.4 = [26 x i8] c"\0AEnter the source matrix:\00"
@.str.6 = [36 x i8] c"\0AFor %d->%d shortest distance is %d\00"
@str = [24 x i8] c"\0AEnter the cost matrix:\00"
@str.7 = [16 x i8] c"\0AShortest path:\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [10 x [10 x i32]]
%4 = alloca [10 x i32]
%5 = tail call i32 @system(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%6 = bitcast i32* %1 to i8*
%7 = bitcast i32* %2 to i8*
%8 = bitcast [10 x [10 x i32]]* %3 to i8*
%9 = bitcast [10 x i32]* %4 to i8*
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
%11 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %1)
%12 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str, i64 0, i64 0))
%13 = load i32, i32* %1
%14 = icmp slt i32 %13, 1
br i1 %14, label %36, label %15
15: ; preds = %0, %31
%16 = phi i32 [ %32, %31 ], [ %13, %0 ]
%17 = phi i64 [ %34, %31 ], [ 1, %0 ]
%18 = icmp slt i32 %16, 1
br i1 %18, label %31, label %19
19: ; preds = %15, %26
%20 = phi i64 [ %27, %26 ], [ 1, %15 ]
%21 = getelementptr inbounds [10 x [10 x i32]], [10 x [10 x i32]]* %3, i64 0, i64 %17, i64 %20
%22 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %21)
%23 = load i32, i32* %21
%24 = icmp eq i32 %23, 0
br i1 %24, label %25, label %26
25: ; preds = %19
store i32 999, i32* %21
br label %26
26: ; preds = %19, %25
%27 = add nuw nsw i64 %20, 1
%28 = load i32, i32* %1
%29 = sext i32 %28 to i64
%30 = icmp slt i64 %20, %29
br i1 %30, label %19, label %31
31: ; preds = %26, %15
%32 = phi i32 [ %16, %15 ], [ %28, %26 ]
%33 = sext i32 %32 to i64
%34 = add nuw nsw i64 %17, 1
%35 = icmp slt i64 %17, %33
br i1 %35, label %15, label %36
36: ; preds = %31, %0
%37 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0))
%38 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %2)
%39 = load i32, i32* %1
%40 = load i32, i32* %2
%41 = bitcast [10 x [10 x i32]]* %3 to i32**
%42 = getelementptr inbounds [10 x i32], [10 x i32]* %4, i64 0, i64 0
%43 = call i32 @dij(i32 %39, i32 %40, i32** %41, i32* %42)
%44 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str.7, i64 0, i64 0))
%45 = load i32, i32* %1
%46 = icmp slt i32 %45, 1
br i1 %46, label %64, label %47
47: ; preds = %36, %59
%48 = phi i32 [ %60, %59 ], [ %45, %36 ]
%49 = phi i64 [ %61, %59 ], [ 1, %36 ]
%50 = load i32, i32* %2
%51 = zext i32 %50 to i64
%52 = icmp eq i64 %49, %51
br i1 %52, label %59, label %53
53: ; preds = %47
%54 = getelementptr inbounds [10 x i32], [10 x i32]* %4, i64 0, i64 %49
%55 = load i32, i32* %54
%56 = trunc i64 %49 to i32
%57 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.6, i64 0, i64 0), i32 %50, i32 %56, i32 %55)
%58 = load i32, i32* %1
br label %59
59: ; preds = %47, %53
%60 = phi i32 [ %48, %47 ], [ %58, %53 ]
%61 = add nuw nsw i64 %49, 1
%62 = sext i32 %60 to i64
%63 = icmp slt i64 %49, %62
br i1 %63, label %47, label %64
64: ; preds = %59, %36
ret i32 0
}