#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*/ dijsktra(int **, int, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int main() {
  printf("Dijsktra Algorithm\n");
  int adj[100][100], N, source;
  int i, j;
  printf("Enter number of vertices\n");
  scanf("%d", &N);
  printf("Enter %d X %d adj matrix\n", N, N);
  for (i = 0; i < N; i++)
    for (j = 0; j < N; j++)
      scanf("%d", &adj[i][j]);
  printf("Enter source\n");
  scanf("%d", &source);
  dijsktra(adj, N, source);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x9c60,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeb7(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xebd(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xec9(%rip),%rdi
lea    -0x9c54(%rbp),%rsi
call   1050 <scanf@plt>
mov    -0x9c54(%rbp),%esi
mov    -0x9c54(%rbp),%edx
lea    0xead(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x9c5c(%rbp)
mov    -0x9c5c(%rbp),%eax
cmp    -0x9c54(%rbp),%eax
jge    1222 <main+0xf2>
movl   $0x0,-0x9c60(%rbp)
mov    -0x9c60(%rbp),%eax
cmp    -0x9c54(%rbp),%eax
jge    1209 <main+0xd9>
movslq -0x9c5c(%rbp),%rax
lea    -0x9c50(%rbp),%rsi
imul   $0x190,%rax,%rax
add    %rax,%rsi
movslq -0x9c60(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe3e(%rip),%rdi
call   1050 <scanf@plt>
mov    -0x9c60(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x9c60(%rbp)
jmp    11b1 <main+0x81>
jmp    120e <main+0xde>
mov    -0x9c5c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x9c5c(%rbp)
jmp    1195 <main+0x65>
lea    0xe22(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xdf7(%rip),%rdi
lea    -0x9c58(%rbp),%rsi
call   1050 <scanf@plt>
lea    -0x9c50(%rbp),%rdi
mov    -0x9c54(%rbp),%esi
mov    -0x9c58(%rbp),%edx
call   1030 <dijsktra@plt>
xor    %eax,%eax
add    $0x9c60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x9c50,%rsp
lea    0xec6(%rip),%rdi
call   1030 <puts@plt>
lea    0xecd(%rip),%rdi
call   1030 <puts@plt>
lea    0xe91(%rip),%rdi
lea    0x8(%rsp),%rsi
call   1060 <scanf@plt>
mov    0x8(%rsp),%edx
lea    0xe7f(%rip),%rdi
mov    %edx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x8(%rsp),%eax
test   %eax,%eax
jle    11ef <main+0xaf>
lea    0x10(%rsp),%r15
xor    %r12d,%r12d
lea    0xe5c(%rip),%r14
jmp    11c3 <main+0x83>
cs nopw 0x0(%rax,%rax,1)
movslq %eax,%rcx
add    $0x1,%r12
add    $0x190,%r15
cmp    %rcx,%r12
jge    11ef <main+0xaf>
test   %eax,%eax
jle    11b0 <main+0x70>
mov    %r15,%r13
xor    %ebx,%ebx
nopl   0x0(%rax)
mov    %r14,%rdi
mov    %r13,%rsi
call   1060 <scanf@plt>
add    $0x1,%rbx
movslq 0x8(%rsp),%rax
add    $0x4,%r13
cmp    %rax,%rbx
jl     11d0 <main+0x90>
jmp    11b0 <main+0x70>
lea    0xe53(%rip),%rdi
call   1030 <puts@plt>
lea    0xdfe(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1060 <scanf@plt>
mov    0x8(%rsp),%esi
mov    0xc(%rsp),%edx
lea    0x10(%rsp),%rdi
call   1040 <dijsktra@plt>
xor    %eax,%eax
add    $0x9c50,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [20 x i8] c"Dijsktra Algorithm\0A\00"
@.str.1 = [26 x i8] c"Enter number of vertices\0A\00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [26 x i8] c"Enter %d X %d adj matrix\0A\00"
@.str.4 = [14 x i8] c"Enter source\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [100 x [100 x i32]]
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 0, i32* %1
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
%9 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %3)
%10 = load i32, i32* %3
%11 = load i32, i32* %3
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i32 %10, i32 %11)
store i32 0, i32* %5
br label %13
13: ; preds = %34, %0
%14 = load i32, i32* %5
%15 = load i32, i32* %3
%16 = icmp slt i32 %14, %15
br i1 %16, label %17, label %37
17: ; preds = %13
store i32 0, i32* %6
br label %18
18: ; preds = %30, %17
%19 = load i32, i32* %6
%20 = load i32, i32* %3
%21 = icmp slt i32 %19, %20
br i1 %21, label %22, label %33
22: ; preds = %18
%23 = load i32, i32* %5
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds [100 x [100 x i32]], [100 x [100 x i32]]* %2, i64 0, i64 %24
%26 = load i32, i32* %6
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds [100 x i32], [100 x i32]* %25, i64 0, i64 %27
%29 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %28)
br label %30
30: ; preds = %22
%31 = load i32, i32* %6
%32 = add nsw i32 %31, 1
store i32 %32, i32* %6
br label %18
33: ; preds = %18
br label %34
34: ; preds = %33
%35 = load i32, i32* %5
%36 = add nsw i32 %35, 1
store i32 %36, i32* %5
br label %13
37: ; preds = %13
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0))
%39 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %4)
%40 = getelementptr inbounds [100 x [100 x i32]], [100 x [100 x i32]]* %2, i64 0, i64 0
%41 = bitcast [100 x i32]* %40 to i32**
%42 = load i32, i32* %3
%43 = load i32, i32* %4
%44 = call i32 @dijsktra(i32** %41, i32 %42, i32 %43)
ret i32 0
}

LLVM IR (-O2):
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [26 x i8] c"Enter %d X %d adj matrix\0A\00"
@str = [19 x i8] c"Dijsktra Algorithm\00"
@str.5 = [25 x i8] c"Enter number of vertices\00"
@str.6 = [13 x i8] c"Enter source\00"
define i32 @main() {
%1 = alloca [100 x [100 x i32]]
%2 = alloca i32
%3 = alloca i32
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str, i64 0, i64 0))
%5 = bitcast [100 x [100 x i32]]* %1 to i8*
%6 = bitcast i32* %2 to i8*
%7 = bitcast i32* %3 to i8*
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str.5, i64 0, i64 0))
%9 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %2)
%10 = load i32, i32* %2
%11 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i32 %10, i32 %10)
%12 = load i32, i32* %2
%13 = icmp sgt i32 %12, 0
br i1 %13, label %14, label %31
14: ; preds = %0, %26
%15 = phi i32 [ %27, %26 ], [ %12, %0 ]
%16 = phi i64 [ %29, %26 ], [ 0, %0 ]
%17 = icmp sgt i32 %15, 0
br i1 %17, label %18, label %26
18: ; preds = %14, %18
%19 = phi i64 [ %22, %18 ], [ 0, %14 ]
%20 = getelementptr inbounds [100 x [100 x i32]], [100 x [100 x i32]]* %1, i64 0, i64 %16, i64 %19
%21 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %20)
%22 = add nuw nsw i64 %19, 1
%23 = load i32, i32* %2
%24 = sext i32 %23 to i64
%25 = icmp slt i64 %22, %24
br i1 %25, label %18, label %26
26: ; preds = %18, %14
%27 = phi i32 [ %15, %14 ], [ %23, %18 ]
%28 = sext i32 %27 to i64
%29 = add nuw nsw i64 %16, 1
%30 = icmp slt i64 %29, %28
br i1 %30, label %14, label %31
31: ; preds = %26, %0
%32 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str.6, i64 0, i64 0))
%33 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %3)
%34 = bitcast [100 x [100 x i32]]* %1 to i32**
%35 = load i32, i32* %2
%36 = load i32, i32* %3
%37 = call i32 @dijsktra(i32** %34, i32 %35, i32 %36)
ret i32 0
}