#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 */
typedef scalar_t__ clock_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
double CLOCKS_PER_SEC;
int /*<<< orphan*/ Dijkstra(int *, int *, int *, int);
int /*<<< orphan*/ Print_dists(int *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ Print_paths(int *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ Read_matrix(int *, int, int /*<<< orphan*/ *);
scalar_t__ clock();
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ free(int *);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, int *);
int *malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char const *argv[]) {
  int n;
  int *mat, *dist, *pred;
  FILE *fpin;
  char *ch = argv[1];
  if (fpin = fopen(ch, "r")) {
  } else {
    printf("Open input file failed\n");
  }
  fscanf(fpin, "%d", &n);
  mat = malloc(n * n * sizeof(int));
  dist = malloc(n * sizeof(int));
  pred = malloc(n * sizeof(int));
  Read_matrix(mat, n, fpin);
  clock_t t1 = clock();
  Dijkstra(mat, dist, pred, n);
  clock_t t2 = clock();
  printf("Serial time used: %f s\n", (double)(t2 - t1) / CLOCKS_PER_SEC);
  FILE *fpout;
  ch = argv[2];
  if (fpout = fopen(ch, "w")) {
    Print_dists(dist, n, fpout);
    Print_paths(pred, n, fpout);
  } else {
    printf("Output file failed.\n");
  }
  free(mat);
  free(dist);
  free(pred);
  fclose(fpin);
  fclose(fpout);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rdi
lea    0xe23(%rip),%rsi
call   10d0 <fopen@plt>
mov    %rax,-0x38(%rbp)
cmp    $0x0,%rax
je     11f5 <main+0x45>
jmp    1203 <main+0x53>
lea    0xe06(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x38(%rbp),%rdi
lea    0xe0c(%rip),%rsi
lea    -0x14(%rbp),%rdx
call   1080 <fscanf@plt>
mov    -0x14(%rbp),%eax
imul   -0x14(%rbp),%eax
cltq
shl    $0x2,%rax
mov    %eax,%edi
call   10c0 <malloc@plt>
mov    %rax,-0x20(%rbp)
movslq -0x14(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   10c0 <malloc@plt>
mov    %rax,-0x28(%rbp)
movslq -0x14(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   10c0 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x38(%rbp),%rdx
call   10a0 <Read_matrix@plt>
mov    $0x0,%al
call   1040 <clock@plt>
mov    %rax,-0x48(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x30(%rbp),%rdx
mov    -0x14(%rbp),%ecx
call   1060 <Dijkstra@plt>
mov    $0x0,%al
call   1040 <clock@plt>
mov    %rax,-0x50(%rbp)
mov    -0x50(%rbp),%rax
sub    -0x48(%rbp),%rax
cvtsi2sd %rax,%xmm0
mov    0x2d45(%rip),%rax
divsd  (%rax),%xmm0
lea    0xd6f(%rip),%rdi
mov    $0x1,%al
call   1070 <printf@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rdi
lea    0xd69(%rip),%rsi
call   10d0 <fopen@plt>
mov    %rax,-0x58(%rbp)
cmp    $0x0,%rax
je     1304 <main+0x154>
mov    -0x28(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x58(%rbp),%rdx
call   1090 <Print_dists@plt>
mov    -0x30(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x58(%rbp),%rdx
call   10b0 <Print_paths@plt>
jmp    1312 <main+0x162>
lea    0xd2c(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x38(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x58(%rbp),%rdi
call   1050 <fclose@plt>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,0x10(%rsp)
mov    0x8(%rsi),%rdi
lea    0xe22(%rip),%rsi
call   10e0 <fopen@plt>
mov    %rax,%r15
test   %rax,%rax
jne    11f7 <main+0x37>
lea    0xe2d(%rip),%rdi
call   1040 <puts@plt>
lea    0xe04(%rip),%rsi
lea    0xc(%rsp),%rdx
mov    %r15,%rdi
call   1090 <fscanf@plt>
mov    0xc(%rsp),%ebx
lea    0x0(,%rbx,4),%ebp
mov    %ebp,%edi
imul   %ebx,%edi
call   10d0 <malloc@plt>
mov    %rax,%r14
mov    %ebp,%edi
call   10d0 <malloc@plt>
mov    %rax,%r12
mov    %ebp,%edi
call   10d0 <malloc@plt>
mov    %rax,%r13
mov    %r14,%rdi
mov    %ebx,%esi
mov    %r15,%rdx
call   10b0 <Read_matrix@plt>
xor    %eax,%eax
call   1050 <clock@plt>
mov    %rax,%rbx
mov    0xc(%rsp),%ecx
mov    %r14,%rdi
mov    %r12,%rsi
mov    %r13,%rdx
call   1070 <Dijkstra@plt>
xor    %eax,%eax
call   1050 <clock@plt>
sub    %rbx,%rax
cvtsi2sd %rax,%xmm0
mov    0x2d72(%rip),%rax
divsd  (%rax),%xmm0
lea    0xd84(%rip),%rdi
mov    $0x1,%al
call   1080 <printf@plt>
mov    0x10(%rsp),%rax
mov    0x10(%rax),%rdi
lea    0xd85(%rip),%rsi
call   10e0 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
je     12c5 <main+0x105>
mov    0xc(%rsp),%esi
mov    %r12,%rdi
mov    %rbx,%rdx
call   10a0 <Print_dists@plt>
mov    0xc(%rsp),%esi
mov    %r13,%rdi
mov    %rbx,%rdx
call   10c0 <Print_paths@plt>
jmp    12d1 <main+0x111>
lea    0xd6a(%rip),%rdi
call   1040 <puts@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %r12,%rdi
call   1030 <free@plt>
mov    %r13,%rdi
call   1030 <free@plt>
mov    %r15,%rdi
call   1060 <fclose@plt>
mov    %rbx,%rdi
call   1060 <fclose@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [24 x i8] c"Open input file failed\0A\00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [24 x i8] c"Serial time used: %f s\0A\00"
@CLOCKS_PER_SEC = global double 0.000000e+00
@.str.4 = [2 x i8] c"w\00"
@.str.5 = [21 x i8] c"Output file failed.\0A\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 i8*
%12 = alloca i64
%13 = alloca i64
%14 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
store i8* %17, i8** %11
%18 = load i8*, i8** %11
%19 = call i32* @fopen(i8* %18, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %19, i32** %10
%20 = icmp ne i32* %19, null
br i1 %20, label %21, label %22
21: ; preds = %2
br label %24
22: ; preds = %2
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
br label %24
24: ; preds = %22, %21
%25 = load i32*, i32** %10
%26 = call i32 @fscanf(i32* %25, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %6)
%27 = load i32, i32* %6
%28 = load i32, i32* %6
%29 = mul nsw i32 %27, %28
%30 = sext i32 %29 to i64
%31 = mul i64 %30, 4
%32 = trunc i64 %31 to i32
%33 = call i32* @malloc(i32 %32)
store i32* %33, i32** %7
%34 = load i32, i32* %6
%35 = sext i32 %34 to i64
%36 = mul i64 %35, 4
%37 = trunc i64 %36 to i32
%38 = call i32* @malloc(i32 %37)
store i32* %38, i32** %8
%39 = load i32, i32* %6
%40 = sext i32 %39 to i64
%41 = mul i64 %40, 4
%42 = trunc i64 %41 to i32
%43 = call i32* @malloc(i32 %42)
store i32* %43, i32** %9
%44 = load i32*, i32** %7
%45 = load i32, i32* %6
%46 = load i32*, i32** %10
%47 = call i32 @Read_matrix(i32* %44, i32 %45, i32* %46)
%48 = call i64 (...) @clock()
store i64 %48, i64* %12
%49 = load i32*, i32** %7
%50 = load i32*, i32** %8
%51 = load i32*, i32** %9
%52 = load i32, i32* %6
%53 = call i32 @Dijkstra(i32* %49, i32* %50, i32* %51, i32 %52)
%54 = call i64 (...) @clock()
store i64 %54, i64* %13
%55 = load i64, i64* %13
%56 = load i64, i64* %12
%57 = sub nsw i64 %55, %56
%58 = sitofp i64 %57 to double
%59 = load double, double* @CLOCKS_PER_SEC
%60 = fdiv double %58, %59
%61 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), double %60)
%62 = load i8**, i8*** %5
%63 = getelementptr inbounds i8*, i8** %62, i64 2
%64 = load i8*, i8** %63
store i8* %64, i8** %11
%65 = load i8*, i8** %11
%66 = call i32* @fopen(i8* %65, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32* %66, i32** %14
%67 = icmp ne i32* %66, null
br i1 %67, label %68, label %77
68: ; preds = %24
%69 = load i32*, i32** %8
%70 = load i32, i32* %6
%71 = load i32*, i32** %14
%72 = call i32 @Print_dists(i32* %69, i32 %70, i32* %71)
%73 = load i32*, i32** %9
%74 = load i32, i32* %6
%75 = load i32*, i32** %14
%76 = call i32 @Print_paths(i32* %73, i32 %74, i32* %75)
br label %79
77: ; preds = %24
%78 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0))
br label %79
79: ; preds = %77, %68
%80 = load i32*, i32** %7
%81 = call i32 @free(i32* %80)
%82 = load i32*, i32** %8
%83 = call i32 @free(i32* %82)
%84 = load i32*, i32** %9
%85 = call i32 @free(i32* %84)
%86 = load i32*, i32** %10
%87 = call i32 @fclose(i32* %86)
%88 = load i32*, i32** %14
%89 = call i32 @fclose(i32* %88)
ret i32 0
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [24 x i8] c"Serial time used: %f s\0A\00"
@CLOCKS_PER_SEC = global double 0.000000e+00
@.str.4 = [2 x i8] c"w\00"
@str = [23 x i8] c"Open input file failed\00"
@str.6 = [20 x i8] c"Output file failed.\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = tail call i32* @fopen(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i32* %7, null
br i1 %8, label %9, label %11
9: ; preds = %2
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str, i64 0, i64 0))
br label %11
11: ; preds = %2, %9
%12 = call i32 @fscanf(i32* %7, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %3)
%13 = load i32, i32* %3
%14 = shl i32 %13, 2
%15 = mul i32 %14, %13
%16 = call i32* @malloc(i32 %15)
%17 = call i32* @malloc(i32 %14)
%18 = call i32* @malloc(i32 %14)
%19 = call i32 @Read_matrix(i32* %16, i32 %13, i32* %7)
%20 = call i64 (...) @clock()
%21 = load i32, i32* %3
%22 = call i32 @Dijkstra(i32* %16, i32* %17, i32* %18, i32 %21)
%23 = call i64 (...) @clock()
%24 = sub nsw i64 %23, %20
%25 = sitofp i64 %24 to double
%26 = load double, double* @CLOCKS_PER_SEC
%27 = fdiv double %25, %26
%28 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), double %27)
%29 = getelementptr inbounds i8*, i8** %1, i64 2
%30 = load i8*, i8** %29
%31 = call i32* @fopen(i8* %30, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%32 = icmp eq i32* %31, null
br i1 %32, label %38, label %33
33: ; preds = %11
%34 = load i32, i32* %3
%35 = call i32 @Print_dists(i32* %17, i32 %34, i32* %31)
%36 = load i32, i32* %3
%37 = call i32 @Print_paths(i32* %18, i32 %36, i32* %31)
br label %40
38: ; preds = %11
%39 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str.6, i64 0, i64 0))
br label %40
40: ; preds = %38, %33
%41 = call i32 @free(i32* %16)
%42 = call i32 @free(i32* %17)
%43 = call i32 @free(i32* %18)
%44 = call i32 @fclose(i32* %7)
%45 = call i32 @fclose(i32* %31)
ret i32 0
}