; 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] }
%struct.AdjListNode = type { i32, float, i32, ptr }

@graph = external dso_local global ptr, align 8

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

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #1

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

; Function Attrs: nounwind allocsize(1)
declare ptr @realloc(ptr noundef, i64 noundef) #2

; Function Attrs: nounwind uwtable
declare dso_local void @reverseArray(ptr noundef, i32 noundef, i32 noundef) #3

; Function Attrs: nounwind uwtable
define dso_local ptr @getDirection(ptr noundef %0, i32 noundef %1, i32 noundef %2, ptr noundef %3) #3 {
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca float, align 4
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !9
  store i32 %2, ptr %7, align 4, !tbaa !9
  store ptr %3, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  store float 0x41E0000000000000, ptr %9, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  store ptr null, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  %15 = call noalias ptr @malloc(i64 noundef 4) #5
  store ptr %15, ptr %11, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #4
  store i32 0, ptr %12, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #4
  %16 = load i32, ptr %7, align 4, !tbaa !9
  store i32 %16, ptr %13, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #4
  %17 = load i32, ptr %7, align 4, !tbaa !9
  store i32 %17, ptr %14, align 4, !tbaa !9
  br label %18

18:                                               ; preds = %74, %4
  %19 = load i32, ptr %14, align 4, !tbaa !9
  %20 = load i32, ptr %6, align 4, !tbaa !9
  %21 = icmp ne i32 %19, %20
  br i1 %21, label %22, label %76

22:                                               ; preds = %18
  %23 = load i32, ptr %12, align 4, !tbaa !9
  %24 = add nsw i32 %23, 1
  store i32 %24, ptr %12, align 4, !tbaa !9
  %25 = load ptr, ptr %11, align 8, !tbaa !5
  %26 = load i32, ptr %12, align 4, !tbaa !9
  %27 = sext i32 %26 to i64
  %28 = mul i64 %27, 4
  %29 = call ptr @realloc(ptr noundef %25, i64 noundef %28) #6
  store ptr %29, ptr %11, align 8, !tbaa !5
  %30 = load ptr, ptr %5, align 8, !tbaa !5
  %31 = load i32, ptr %13, align 4, !tbaa !9
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds i32, ptr %30, i64 %32
  %34 = load i32, ptr %33, align 4, !tbaa !9
  store i32 %34, ptr %14, align 4, !tbaa !9
  store float 0x41E0000000000000, ptr %9, align 4, !tbaa !11
  %35 = load ptr, ptr @graph, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.Graph, ptr %35, i32 0, i32 1
  %37 = load ptr, ptr %36, align 8, !tbaa !13
  %38 = load i32, ptr %14, align 4, !tbaa !9
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds %struct.AdjList, ptr %37, i64 %39
  %41 = getelementptr inbounds %struct.AdjList, ptr %40, i32 0, i32 0
  %42 = load ptr, ptr %41, align 8, !tbaa !15
  store ptr %42, ptr %10, align 8, !tbaa !5
  br label %43

43:                                               ; preds = %70, %22
  %44 = load ptr, ptr %10, align 8, !tbaa !5
  %45 = icmp ne ptr %44, null
  br i1 %45, label %46, label %74

46:                                               ; preds = %43
  %47 = load ptr, ptr %10, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.AdjListNode, ptr %47, i32 0, i32 0
  %49 = load i32, ptr %48, align 8, !tbaa !17
  %50 = load i32, ptr %13, align 4, !tbaa !9
  %51 = icmp eq i32 %49, %50
  br i1 %51, label %52, label %70

52:                                               ; preds = %46
  %53 = load ptr, ptr %10, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.AdjListNode, ptr %53, i32 0, i32 1
  %55 = load float, ptr %54, align 4, !tbaa !19
  %56 = load float, ptr %9, align 4, !tbaa !11
  %57 = fcmp olt float %55, %56
  br i1 %57, label %58, label %70

58:                                               ; preds = %52
  %59 = load ptr, ptr %10, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.AdjListNode, ptr %59, i32 0, i32 1
  %61 = load float, ptr %60, align 4, !tbaa !19
  store float %61, ptr %9, align 4, !tbaa !11
  %62 = load ptr, ptr %10, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.AdjListNode, ptr %62, i32 0, i32 2
  %64 = load i32, ptr %63, align 8, !tbaa !20
  %65 = load ptr, ptr %11, align 8, !tbaa !5
  %66 = load i32, ptr %12, align 4, !tbaa !9
  %67 = sub nsw i32 %66, 1
  %68 = sext i32 %67 to i64
  %69 = getelementptr inbounds i32, ptr %65, i64 %68
  store i32 %64, ptr %69, align 4, !tbaa !9
  br label %70

70:                                               ; preds = %58, %52, %46
  %71 = load ptr, ptr %10, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.AdjListNode, ptr %71, i32 0, i32 3
  %73 = load ptr, ptr %72, align 8, !tbaa !21
  store ptr %73, ptr %10, align 8, !tbaa !5
  br label %43, !llvm.loop !22

74:                                               ; preds = %43
  %75 = load i32, ptr %14, align 4, !tbaa !9
  store i32 %75, ptr %13, align 4, !tbaa !9
  br label %18, !llvm.loop !24

76:                                               ; preds = %18
  %77 = load ptr, ptr %11, align 8, !tbaa !5
  %78 = load i32, ptr %12, align 4, !tbaa !9
  %79 = sub nsw i32 %78, 1
  call void @reverseArray(ptr noundef %77, i32 noundef 0, i32 noundef %79)
  %80 = load i32, ptr %12, align 4, !tbaa !9
  %81 = load ptr, ptr %8, align 8, !tbaa !5
  store i32 %80, ptr %81, align 4, !tbaa !9
  %82 = load ptr, ptr %11, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  ret ptr %82
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nounwind allocsize(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 allocsize(1) "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 #3 = { 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 #4 = { nounwind }
attributes #5 = { nounwind allocsize(0) }
attributes #6 = { nounwind allocsize(1) }

!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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"float", !7, i64 0}
!13 = !{!14, !6, i64 8}
!14 = !{!"Graph", !10, i64 0, !6, i64 8}
!15 = !{!16, !6, i64 0}
!16 = !{!"AdjList", !6, i64 0, !12, i64 8, !12, i64 12, !10, i64 16, !7, i64 20}
!17 = !{!18, !10, i64 0}
!18 = !{!"AdjListNode", !10, i64 0, !12, i64 4, !10, i64 8, !6, i64 16}
!19 = !{!18, !12, i64 4}
!20 = !{!18, !10, i64 8}
!21 = !{!18, !6, i64 16}
!22 = distinct !{!22, !23}
!23 = !{!"llvm.loop.mustprogress"}
!24 = distinct !{!24, !23}


; 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

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind willreturn allockind("realloc") allocsize(1) memory(argmem: readwrite, inaccessiblemem: readwrite)
declare noalias noundef ptr @realloc(ptr allocptr nocapture noundef, i64 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local void @reverseArray(ptr noundef, i32 noundef, i32 noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local noundef ptr @getDirection(ptr nocapture noundef readonly %0, i32 noundef %1, i32 noundef %2, ptr nocapture noundef writeonly %3) local_unnamed_addr #2 {
  %5 = tail call noalias dereferenceable_or_null(4) ptr @malloc(i64 noundef 4) #3
  %.not36 = icmp eq i32 %2, %1
  br i1 %.not36, label %._crit_edge, label %.lr.ph40

.lr.ph40:                                         ; preds = %4
  %6 = load ptr, ptr @graph, align 8, !tbaa !5
  %7 = getelementptr inbounds i8, ptr %6, i64 8
  %.pre = load ptr, ptr %7, align 8, !tbaa !9
  br label %8

.loopexit:                                        ; preds = %27, %8
  %.not = icmp eq i32 %13, %1
  br i1 %.not, label %._crit_edge.loopexit, label %8, !llvm.loop !12

8:                                                ; preds = %.lr.ph40, %.loopexit
  %indvars.iv = phi i64 [ 0, %.lr.ph40 ], [ %indvars.iv.next, %.loopexit ]
  %.039 = phi i32 [ %2, %.lr.ph40 ], [ %13, %.loopexit ]
  %.02737 = phi ptr [ %5, %.lr.ph40 ], [ %10, %.loopexit ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %9 = shl nuw nsw i64 %indvars.iv.next, 2
  %10 = tail call ptr @realloc(ptr noundef %.02737, i64 noundef %9) #4
  %11 = sext i32 %.039 to i64
  %12 = getelementptr inbounds i32, ptr %0, i64 %11
  %13 = load i32, ptr %12, align 4, !tbaa !14
  %14 = sext i32 %13 to i64
  %15 = getelementptr inbounds %struct.AdjList, ptr %.pre, i64 %14
  %.02832 = load ptr, ptr %15, align 8, !tbaa !5
  %.not3133 = icmp eq ptr %.02832, null
  br i1 %.not3133, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %8
  %16 = getelementptr inbounds i32, ptr %10, i64 %indvars.iv
  br label %17

17:                                               ; preds = %.lr.ph, %27
  %.02835 = phi ptr [ %.02832, %.lr.ph ], [ %.028, %27 ]
  %.02934 = phi float [ 0x41E0000000000000, %.lr.ph ], [ %.1, %27 ]
  %18 = load i32, ptr %.02835, align 8, !tbaa !15
  %19 = icmp eq i32 %18, %.039
  br i1 %19, label %20, label %27

20:                                               ; preds = %17
  %21 = getelementptr inbounds i8, ptr %.02835, i64 4
  %22 = load float, ptr %21, align 4, !tbaa !18
  %23 = fcmp olt float %22, %.02934
  br i1 %23, label %24, label %27

24:                                               ; preds = %20
  %25 = getelementptr inbounds i8, ptr %.02835, i64 8
  %26 = load i32, ptr %25, align 8, !tbaa !19
  store i32 %26, ptr %16, align 4, !tbaa !14
  br label %27

27:                                               ; preds = %24, %20, %17
  %.1 = phi float [ %22, %24 ], [ %.02934, %20 ], [ %.02934, %17 ]
  %28 = getelementptr inbounds i8, ptr %.02835, i64 16
  %.028 = load ptr, ptr %28, align 8, !tbaa !5
  %.not31 = icmp eq ptr %.028, null
  br i1 %.not31, label %.loopexit, label %17, !llvm.loop !20

._crit_edge.loopexit:                             ; preds = %.loopexit
  %29 = trunc nuw nsw i64 %indvars.iv.next to i32
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %4
  %.027.lcssa = phi ptr [ %5, %4 ], [ %10, %._crit_edge.loopexit ]
  %.026.lcssa = phi i32 [ 0, %4 ], [ %29, %._crit_edge.loopexit ]
  %30 = add nsw i32 %.026.lcssa, -1
  tail call void @reverseArray(ptr noundef %.027.lcssa, i32 noundef 0, i32 noundef %30)
  store i32 %.026.lcssa, ptr %3, align 4, !tbaa !14
  ret ptr %.027.lcssa
}

attributes #0 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "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 #1 = { mustprogress nounwind willreturn allockind("realloc") allocsize(1) memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" "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 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 #3 = { nounwind allocsize(0) }
attributes #4 = { nounwind allocsize(1) }

!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 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = !{!11, !11, i64 0}
!15 = !{!16, !11, i64 0}
!16 = !{!"AdjListNode", !11, i64 0, !17, i64 4, !11, i64 8, !6, i64 16}
!17 = !{!"float", !7, i64 0}
!18 = !{!16, !17, i64 4}
!19 = !{!16, !11, i64 8}
!20 = distinct !{!20, !13}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass