; LLVM IR from Vishnuparammal/maze_runner :: src (maze)

; Unoptimized IR (clang -disable-llvm-passes):
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

%struct.Graph = type { i32, ptr }
%struct.AdjList = type { ptr, float, float, i32, [4 x float] }

@graph = external dso_local global ptr, align 8
@currentNode = external dso_local global i32, align 4

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nounwind uwtable
define dso_local i32 @ruleNESW() #1 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #2
  store i32 0, ptr %2, align 4, !tbaa !5
  br label %4

4:                                                ; preds = %24, %0
  %5 = load i32, ptr %2, align 4, !tbaa !5
  %6 = icmp slt i32 %5, 4
  br i1 %6, label %8, label %7

7:                                                ; preds = %4
  store i32 2, ptr %3, align 4
  br label %27

8:                                                ; preds = %4
  %9 = load ptr, ptr @graph, align 8, !tbaa !9
  %10 = getelementptr inbounds %struct.Graph, ptr %9, i32 0, i32 1
  %11 = load ptr, ptr %10, align 8, !tbaa !11
  %12 = load i32, ptr @currentNode, align 4, !tbaa !5
  %13 = sext i32 %12 to i64
  %14 = getelementptr inbounds %struct.AdjList, ptr %11, i64 %13
  %15 = getelementptr inbounds %struct.AdjList, ptr %14, i32 0, i32 4
  %16 = load i32, ptr %2, align 4, !tbaa !5
  %17 = sext i32 %16 to i64
  %18 = getelementptr inbounds [4 x float], ptr %15, i64 0, i64 %17
  %19 = load float, ptr %18, align 4, !tbaa !13
  %20 = fcmp oeq float %19, 0.000000e+00
  br i1 %20, label %21, label %23

21:                                               ; preds = %8
  %22 = load i32, ptr %2, align 4, !tbaa !5
  store i32 %22, ptr %1, align 4
  store i32 1, ptr %3, align 4
  br label %27

23:                                               ; preds = %8
  br label %24

24:                                               ; preds = %23
  %25 = load i32, ptr %2, align 4, !tbaa !5
  %26 = add nsw i32 %25, 1
  store i32 %26, ptr %2, align 4, !tbaa !5
  br label %4, !llvm.loop !15

27:                                               ; preds = %21, %7
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #2
  %28 = load i32, ptr %3, align 4
  switch i32 %28, label %32 [
    i32 2, label %29
    i32 1, label %30
  ]

29:                                               ; preds = %27
  store i32 -1, ptr %1, align 4
  br label %30

30:                                               ; preds = %29, %27
  %31 = load i32, ptr %1, align 4
  ret i32 %31

32:                                               ; preds = %27
  unreachable
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #2 = { nounwind }

!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !10, i64 8}
!12 = !{!"Graph", !6, i64 0, !10, i64 8}
!13 = !{!14, !14, i64 0}
!14 = !{!"float", !7, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}


; Optimized IR (opt -passes='default<O3>'):
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

%struct.AdjList = type { ptr, float, float, i32, [4 x float] }

@graph = external dso_local local_unnamed_addr global ptr, align 8
@currentNode = external dso_local local_unnamed_addr global i32, align 4

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(read, inaccessiblemem: none) uwtable
define dso_local noundef i32 @ruleNESW() local_unnamed_addr #0 {
  %1 = load ptr, ptr @graph, align 8, !tbaa !5
  %2 = getelementptr inbounds i8, ptr %1, i64 8
  %3 = load ptr, ptr %2, align 8, !tbaa !9
  %4 = load i32, ptr @currentNode, align 4, !tbaa !12
  %5 = sext i32 %4 to i64
  %6 = getelementptr inbounds %struct.AdjList, ptr %3, i64 %5, i32 4, i64 0
  %7 = load float, ptr %6, align 4, !tbaa !13
  %8 = fcmp oeq float %7, 0.000000e+00
  br i1 %8, label %22, label %9

9:                                                ; preds = %0
  %10 = getelementptr inbounds %struct.AdjList, ptr %3, i64 %5, i32 4, i64 1
  %11 = load float, ptr %10, align 4, !tbaa !13
  %12 = fcmp oeq float %11, 0.000000e+00
  br i1 %12, label %22, label %13

13:                                               ; preds = %9
  %14 = getelementptr inbounds %struct.AdjList, ptr %3, i64 %5, i32 4, i64 2
  %15 = load float, ptr %14, align 4, !tbaa !13
  %16 = fcmp oeq float %15, 0.000000e+00
  br i1 %16, label %22, label %17

17:                                               ; preds = %13
  %18 = getelementptr inbounds %struct.AdjList, ptr %3, i64 %5, i32 4, i64 3
  %19 = load float, ptr %18, align 4, !tbaa !13
  %20 = fcmp oeq float %19, 0.000000e+00
  br i1 %20, label %22, label %21

21:                                               ; preds = %17
  br label %22

22:                                               ; preds = %21, %17, %13, %9, %0
  %spec.select = phi i32 [ 0, %0 ], [ 1, %9 ], [ 2, %13 ], [ 3, %17 ], [ -1, %21 ]
  ret i32 %spec.select
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(read, inaccessiblemem: none) uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }

!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !6, i64 8}
!10 = !{!"Graph", !11, i64 0, !6, i64 8}
!11 = !{!"int", !7, i64 0}
!12 = !{!11, !11, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"float", !7, i64 0}


; Effective O3 passes: CorrelatedValuePropagationPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LICMPass,LoopRotatePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass