#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 */
scalar_t__ CLOCKS_PER_SEC;
short breathFirstSearch(short *, int, int, int /*<<< orphan*/, short *, short *,
                        int);
double clock();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, double, int, ...);
scalar_t__ malloc(int);
int /*<<< orphan*/ stderr;
int main(void) {
  double start, end;
  double interval;
  int zoneCount = 5;
  short *graph;
  short *temp1, *temp2;
  short zone;
  graph = (short *)malloc(zoneCount * 3 * sizeof(short));
  temp1 = (short *)malloc(zoneCount * sizeof(short));
  temp2 = (short *)malloc(zoneCount * sizeof(short));
  for (int i = 0; i < zoneCount * 3; i++) {
    graph[i] = -1;
  }
  graph[0 * 3 + 0] = 1;
  graph[1 * 3 + 0] = 0;
  graph[1 * 3 + 1] = 2;
  graph[1 * 3 + 2] = 3;
  graph[2 * 3 + 0] = 1;
  graph[2 * 3 + 1] = 4;
  graph[3 * 3 + 0] = 1;
  graph[3 * 3 + 1] = 4;
  graph[4 * 3 + 0] = 2;
  graph[4 * 3 + 1] = 3;
  start = clock();
  for (int i = 0; i < 1; i++)
    zone = breathFirstSearch(graph, zoneCount, 4, 0, temp1, temp2, 1);
  end = clock() - start;
  interval = end / (double)CLOCKS_PER_SEC;
  fprintf(stderr, "clock cycles: %f seconds elapsed: %f \n", end, interval);
  fprintf(stderr, "next zone towards %3hd from %3hd: %3hd \n", 0, 4, zone);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x5,-0x24(%rbp)
imul   $0x3,-0x24(%rbp),%eax
cltq
shl    $0x1,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x30(%rbp)
movslq -0x24(%rbp),%rax
shl    $0x1,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x38(%rbp)
movslq -0x24(%rbp),%rax
shl    $0x1,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x40(%rbp)
movl   $0x0,-0x48(%rbp)
mov    -0x48(%rbp),%eax
imul   $0x3,-0x24(%rbp),%ecx
cmp    %ecx,%eax
jge    11c3 <main+0x83>
mov    -0x30(%rbp),%rax
movslq -0x48(%rbp),%rcx
movw   $0xffff,(%rax,%rcx,2)
mov    -0x48(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x48(%rbp)
jmp    1198 <main+0x58>
mov    -0x30(%rbp),%rax
movw   $0x1,(%rax)
mov    -0x30(%rbp),%rax
movw   $0x0,0x6(%rax)
mov    -0x30(%rbp),%rax
movw   $0x2,0x8(%rax)
mov    -0x30(%rbp),%rax
movw   $0x3,0xa(%rax)
mov    -0x30(%rbp),%rax
movw   $0x1,0xc(%rax)
mov    -0x30(%rbp),%rax
movw   $0x4,0xe(%rax)
mov    -0x30(%rbp),%rax
movw   $0x1,0x12(%rax)
mov    -0x30(%rbp),%rax
movw   $0x4,0x14(%rax)
mov    -0x30(%rbp),%rax
movw   $0x2,0x18(%rax)
mov    -0x30(%rbp),%rax
movw   $0x3,0x1a(%rax)
mov    $0x0,%al
call   1030 <clock@plt>
movsd  %xmm0,-0x10(%rbp)
movl   $0x0,-0x4c(%rbp)
cmpl   $0x1,-0x4c(%rbp)
jge    1277 <main+0x137>
mov    -0x30(%rbp),%rdi
mov    -0x24(%rbp),%esi
mov    -0x38(%rbp),%r8
mov    -0x40(%rbp),%r9
mov    $0x4,%edx
xor    %ecx,%ecx
movl   $0x1,(%rsp)
call   1060 <breathFirstSearch@plt>
mov    %ax,-0x42(%rbp)
mov    -0x4c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4c(%rbp)
jmp    1239 <main+0xf9>
mov    $0x0,%al
call   1030 <clock@plt>
subsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
mov    0x2d54(%rip),%rax
cvtsi2sdq (%rax),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    0x2d2f(%rip),%rax
mov    (%rax),%edi
movsd  -0x18(%rbp),%xmm0
cvttsd2si -0x20(%rbp),%edx
lea    0xd44(%rip),%rsi
mov    $0x1,%al
call   1040 <fprintf@plt>
mov    0x2d0e(%rip),%rax
mov    (%rax),%edi
movswl -0x42(%rbp),%ecx
lea    0xd50(%rip),%rsi
xorps  %xmm0,%xmm0
mov    $0x4,%edx
mov    $0x1,%al
call   1040 <fprintf@plt>
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    $0x1e,%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
mov    $0xa,%edi
call   1050 <malloc@plt>
mov    %rax,%r14
mov    $0xa,%edi
call   1050 <malloc@plt>
mov    %rax,%r15
pcmpeqd %xmm0,%xmm0
movdqu %xmm0,(%rbx)
movdqu %xmm0,0xe(%rbx)
movw   $0x1,(%rbx)
movabs $0x1000300020000,%rax
mov    %rax,0x6(%rbx)
movw   $0x4,0xe(%rbx)
movl   $0x40001,0x12(%rbx)
movl   $0x30002,0x18(%rbx)
xor    %eax,%eax
call   1030 <clock@plt>
movq   %xmm0,0x10(%rsp)
movl   $0x1,(%rsp)
mov    %rbx,%rdi
mov    $0x5,%esi
mov    $0x4,%edx
xor    %ecx,%ecx
mov    %r14,%r8
mov    %r15,%r9
call   1060 <breathFirstSearch@plt>
movswl %ax,%ebp
xor    %eax,%eax
call   1030 <clock@plt>
subsd  0x10(%rsp),%xmm0
mov    0x2dfe(%rip),%rax
cvtsi2sdq (%rax),%xmm1
movapd %xmm0,%xmm2
divsd  %xmm1,%xmm2
mov    0x2dda(%rip),%rbx
mov    (%rbx),%edi
cvttsd2si %xmm2,%edx
lea    0xdf5(%rip),%rsi
mov    $0x1,%al
call   1040 <fprintf@plt>
mov    (%rbx),%edi
lea    0xe0c(%rip),%rsi
xorpd  %xmm0,%xmm0
mov    $0x4,%edx
mov    %ebp,%ecx
mov    $0x1,%al
call   1040 <fprintf@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@CLOCKS_PER_SEC = global i64 0
@stderr = global i32 0
@.str = [39 x i8] c"clock cycles: %f seconds elapsed: %f \0A\00"
@.str.1 = [41 x i8] c"next zone towards %3hd from %3hd: %3hd \0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca double
%3 = alloca double
%4 = alloca double
%5 = alloca i32
%6 = alloca i16*
%7 = alloca i16*
%8 = alloca i16*
%9 = alloca i16
%10 = alloca i32
%11 = alloca i32
store i32 0, i32* %1
store i32 5, i32* %5
%12 = load i32, i32* %5
%13 = mul nsw i32 %12, 3
%14 = sext i32 %13 to i64
%15 = mul i64 %14, 2
%16 = trunc i64 %15 to i32
%17 = call i64 @malloc(i32 %16)
%18 = inttoptr i64 %17 to i16*
store i16* %18, i16** %6
%19 = load i32, i32* %5
%20 = sext i32 %19 to i64
%21 = mul i64 %20, 2
%22 = trunc i64 %21 to i32
%23 = call i64 @malloc(i32 %22)
%24 = inttoptr i64 %23 to i16*
store i16* %24, i16** %7
%25 = load i32, i32* %5
%26 = sext i32 %25 to i64
%27 = mul i64 %26, 2
%28 = trunc i64 %27 to i32
%29 = call i64 @malloc(i32 %28)
%30 = inttoptr i64 %29 to i16*
store i16* %30, i16** %8
store i32 0, i32* %10
br label %31
31: ; preds = %41, %0
%32 = load i32, i32* %10
%33 = load i32, i32* %5
%34 = mul nsw i32 %33, 3
%35 = icmp slt i32 %32, %34
br i1 %35, label %36, label %44
36: ; preds = %31
%37 = load i16*, i16** %6
%38 = load i32, i32* %10
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i16, i16* %37, i64 %39
store i16 -1, i16* %40
br label %41
41: ; preds = %36
%42 = load i32, i32* %10
%43 = add nsw i32 %42, 1
store i32 %43, i32* %10
br label %31
44: ; preds = %31
%45 = load i16*, i16** %6
%46 = getelementptr inbounds i16, i16* %45, i64 0
store i16 1, i16* %46
%47 = load i16*, i16** %6
%48 = getelementptr inbounds i16, i16* %47, i64 3
store i16 0, i16* %48
%49 = load i16*, i16** %6
%50 = getelementptr inbounds i16, i16* %49, i64 4
store i16 2, i16* %50
%51 = load i16*, i16** %6
%52 = getelementptr inbounds i16, i16* %51, i64 5
store i16 3, i16* %52
%53 = load i16*, i16** %6
%54 = getelementptr inbounds i16, i16* %53, i64 6
store i16 1, i16* %54
%55 = load i16*, i16** %6
%56 = getelementptr inbounds i16, i16* %55, i64 7
store i16 4, i16* %56
%57 = load i16*, i16** %6
%58 = getelementptr inbounds i16, i16* %57, i64 9
store i16 1, i16* %58
%59 = load i16*, i16** %6
%60 = getelementptr inbounds i16, i16* %59, i64 10
store i16 4, i16* %60
%61 = load i16*, i16** %6
%62 = getelementptr inbounds i16, i16* %61, i64 12
store i16 2, i16* %62
%63 = load i16*, i16** %6
%64 = getelementptr inbounds i16, i16* %63, i64 13
store i16 3, i16* %64
%65 = call double (...) @clock()
store double %65, double* %2
store i32 0, i32* %11
br label %66
66: ; preds = %75, %44
%67 = load i32, i32* %11
%68 = icmp slt i32 %67, 1
br i1 %68, label %69, label %78
69: ; preds = %66
%70 = load i16*, i16** %6
%71 = load i32, i32* %5
%72 = load i16*, i16** %7
%73 = load i16*, i16** %8
%74 = call signext i16 @breathFirstSearch(i16* %70, i32 %71, i32 4, i32 0, i16* %72, i16* %73, i32 1)
store i16 %74, i16* %9
br label %75
75: ; preds = %69
%76 = load i32, i32* %11
%77 = add nsw i32 %76, 1
store i32 %77, i32* %11
br label %66
78: ; preds = %66
%79 = call double (...) @clock()
%80 = load double, double* %2
%81 = fsub double %79, %80
store double %81, double* %3
%82 = load double, double* %3
%83 = load i64, i64* @CLOCKS_PER_SEC
%84 = sitofp i64 %83 to double
%85 = fdiv double %82, %84
store double %85, double* %4
%86 = load i32, i32* @stderr
%87 = load double, double* %3
%88 = load double, double* %4
%89 = fptosi double %88 to i32
%90 = call i32 (i32, i8*, double, i32, ...) @fprintf(i32 %86, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), double %87, i32 %89)
%91 = load i32, i32* @stderr
%92 = load i16, i16* %9
%93 = sext i16 %92 to i32
%94 = call i32 (i32, i8*, double, i32, ...) @fprintf(i32 %91, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0), double 0.000000e+00, i32 4, i32 %93)
%95 = load i32, i32* %1
ret i32 %95
}

LLVM IR (-O2):
@CLOCKS_PER_SEC = global i64 0
@stderr = global i32 0
@.str = [39 x i8] c"clock cycles: %f seconds elapsed: %f \0A\00"
@.str.1 = [41 x i8] c"next zone towards %3hd from %3hd: %3hd \0A\00"
define i32 @main() {
%1 = tail call i64 @malloc(i32 30)
%2 = inttoptr i64 %1 to i16*
%3 = inttoptr i64 %1 to i8*
%4 = tail call i64 @malloc(i32 10)
%5 = tail call i64 @malloc(i32 10)
%6 = inttoptr i64 %5 to i16*
%7 = inttoptr i64 %4 to i16*
store i16 1, i16* %2
%8 = getelementptr inbounds i16, i16* %2, i64 3
store i16 0, i16* %8
%9 = getelementptr inbounds i16, i16* %2, i64 4
store i16 2, i16* %9
%10 = getelementptr inbounds i16, i16* %2, i64 5
store i16 3, i16* %10
%11 = getelementptr inbounds i16, i16* %2, i64 6
store i16 1, i16* %11
%12 = getelementptr inbounds i16, i16* %2, i64 7
store i16 4, i16* %12
%13 = getelementptr inbounds i16, i16* %2, i64 9
store i16 1, i16* %13
%14 = getelementptr inbounds i16, i16* %2, i64 10
store i16 4, i16* %14
%15 = getelementptr inbounds i16, i16* %2, i64 12
store i16 2, i16* %15
%16 = getelementptr inbounds i16, i16* %2, i64 13
store i16 3, i16* %16
%17 = tail call double (...) @clock()
%18 = tail call signext i16 @breathFirstSearch(i16* %2, i32 5, i32 4, i32 0, i16* %7, i16* %6, i32 1)
%19 = sext i16 %18 to i32
%20 = tail call double (...) @clock()
%21 = fsub double %20, %17
%22 = load i64, i64* @CLOCKS_PER_SEC
%23 = sitofp i64 %22 to double
%24 = fdiv double %21, %23
%25 = load i32, i32* @stderr
%26 = fptosi double %24 to i32
%27 = tail call i32 (i32, i8*, double, i32, ...) @fprintf(i32 %25, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), double %21, i32 %26)
%28 = load i32, i32* @stderr
%29 = tail call i32 (i32, i8*, double, i32, ...) @fprintf(i32 %28, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0), double 0.000000e+00, i32 4, i32 %19)
ret i32 0
}