; LLVM IR from AlgoGenesis/C :: Searching Algorithms/Best-First Search (Program)

; 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.PriorityQueue = type { [100 x ptr], i32 }
%struct.Node = type { i32, i32, ptr }

; Function Attrs: nounwind uwtable
declare dso_local ptr @createNode(i32 noundef, i32 noundef) #0

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

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

; Function Attrs: nounwind uwtable
define dso_local void @enqueue(ptr noundef %0, i32 noundef %1, i32 noundef %2) #0 {
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  store i32 %2, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  %10 = load i32, ptr %5, align 4, !tbaa !9
  %11 = load i32, ptr %6, align 4, !tbaa !9
  %12 = call ptr @createNode(i32 noundef %10, i32 noundef %11)
  store ptr %12, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  store i32 0, ptr %8, align 4, !tbaa !9
  br label %13

13:                                               ; preds = %32, %3
  %14 = load i32, ptr %8, align 4, !tbaa !9
  %15 = load ptr, ptr %4, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.PriorityQueue, ptr %15, i32 0, i32 1
  %17 = load i32, ptr %16, align 8, !tbaa !11
  %18 = icmp slt i32 %14, %17
  br i1 %18, label %19, label %35

19:                                               ; preds = %13
  %20 = load ptr, ptr %4, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.PriorityQueue, ptr %20, i32 0, i32 0
  %22 = load i32, ptr %8, align 4, !tbaa !9
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds [100 x ptr], ptr %21, i64 0, i64 %23
  %25 = load ptr, ptr %24, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.Node, ptr %25, i32 0, i32 1
  %27 = load i32, ptr %26, align 4, !tbaa !13
  %28 = load i32, ptr %6, align 4, !tbaa !9
  %29 = icmp sgt i32 %27, %28
  br i1 %29, label %30, label %31

30:                                               ; preds = %19
  br label %35

31:                                               ; preds = %19
  br label %32

32:                                               ; preds = %31
  %33 = load i32, ptr %8, align 4, !tbaa !9
  %34 = add nsw i32 %33, 1
  store i32 %34, ptr %8, align 4, !tbaa !9
  br label %13, !llvm.loop !15

35:                                               ; preds = %30, %13
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #2
  %36 = load ptr, ptr %4, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.PriorityQueue, ptr %36, i32 0, i32 1
  %38 = load i32, ptr %37, align 8, !tbaa !11
  store i32 %38, ptr %9, align 4, !tbaa !9
  br label %39

39:                                               ; preds = %57, %35
  %40 = load i32, ptr %9, align 4, !tbaa !9
  %41 = load i32, ptr %8, align 4, !tbaa !9
  %42 = icmp sgt i32 %40, %41
  br i1 %42, label %44, label %43

43:                                               ; preds = %39
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #2
  br label %60

44:                                               ; preds = %39
  %45 = load ptr, ptr %4, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.PriorityQueue, ptr %45, i32 0, i32 0
  %47 = load i32, ptr %9, align 4, !tbaa !9
  %48 = sub nsw i32 %47, 1
  %49 = sext i32 %48 to i64
  %50 = getelementptr inbounds [100 x ptr], ptr %46, i64 0, i64 %49
  %51 = load ptr, ptr %50, align 8, !tbaa !5
  %52 = load ptr, ptr %4, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.PriorityQueue, ptr %52, i32 0, i32 0
  %54 = load i32, ptr %9, align 4, !tbaa !9
  %55 = sext i32 %54 to i64
  %56 = getelementptr inbounds [100 x ptr], ptr %53, i64 0, i64 %55
  store ptr %51, ptr %56, align 8, !tbaa !5
  br label %57

57:                                               ; preds = %44
  %58 = load i32, ptr %9, align 4, !tbaa !9
  %59 = add nsw i32 %58, -1
  store i32 %59, ptr %9, align 4, !tbaa !9
  br label %39, !llvm.loop !17

60:                                               ; preds = %43
  %61 = load ptr, ptr %7, align 8, !tbaa !5
  %62 = load ptr, ptr %4, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.PriorityQueue, ptr %62, i32 0, i32 0
  %64 = load i32, ptr %8, align 4, !tbaa !9
  %65 = sext i32 %64 to i64
  %66 = getelementptr inbounds [100 x ptr], ptr %63, i64 0, i64 %65
  store ptr %61, ptr %66, align 8, !tbaa !5
  %67 = load ptr, ptr %4, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.PriorityQueue, ptr %67, i32 0, i32 1
  %69 = load i32, ptr %68, align 8, !tbaa !11
  %70 = add nsw i32 %69, 1
  store i32 %70, ptr %68, align 8, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  ret void
}

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!"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, !10, i64 800}
!12 = !{!"", !7, i64 0, !10, i64 800}
!13 = !{!14, !10, i64 4}
!14 = !{!"Node", !10, i64 0, !10, i64 4, !6, i64 8}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = distinct !{!17, !16}


; 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"

; Function Attrs: nounwind uwtable
declare dso_local ptr @createNode(i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @enqueue(ptr nocapture noundef %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = tail call ptr @createNode(i32 noundef %1, i32 noundef %2)
  %5 = getelementptr inbounds i8, ptr %0, i64 800
  %6 = load i32, ptr %5, align 8, !tbaa !5
  %7 = icmp sgt i32 %6, 0
  br i1 %7, label %.lr.ph.preheader, label %._crit_edge29

.lr.ph.preheader:                                 ; preds = %3
  %wide.trip.count = zext nneg i32 %6 to i64
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %13
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next, %13 ]
  %8 = getelementptr inbounds [100 x ptr], ptr %0, i64 0, i64 %indvars.iv
  %9 = load ptr, ptr %8, align 8, !tbaa !10
  %10 = getelementptr inbounds i8, ptr %9, i64 4
  %11 = load i32, ptr %10, align 4, !tbaa !12
  %12 = icmp sgt i32 %11, %2
  br i1 %12, label %._crit_edge, label %13

13:                                               ; preds = %.lr.ph
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge29, label %.lr.ph, !llvm.loop !14

._crit_edge:                                      ; preds = %.lr.ph
  %14 = trunc nuw nsw i64 %indvars.iv to i32
  %15 = icmp sgt i32 %6, %14
  br i1 %15, label %.lr.ph28.preheader, label %._crit_edge29

.lr.ph28.preheader:                               ; preds = %._crit_edge
  %16 = zext nneg i32 %6 to i64
  %sext = shl i64 %indvars.iv, 32
  %17 = ashr exact i64 %sext, 32
  %18 = sub nsw i64 %wide.trip.count, %indvars.iv
  %min.iters.check = icmp ult i64 %18, 4
  br i1 %min.iters.check, label %.lr.ph28.preheader47, label %vector.ph

.lr.ph28.preheader47:                             ; preds = %middle.block, %.lr.ph28.preheader
  %indvars.iv32.ph = phi i64 [ %16, %.lr.ph28.preheader ], [ %ind.end, %middle.block ]
  br label %.lr.ph28

vector.ph:                                        ; preds = %.lr.ph28.preheader
  %n.vec = and i64 %18, -4
  %ind.end = sub i64 %16, %n.vec
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %offset.idx = sub i64 %16, %index
  %19 = add nsw i64 %offset.idx, -1
  %20 = getelementptr inbounds [100 x ptr], ptr %0, i64 0, i64 %19
  %21 = getelementptr inbounds i8, ptr %20, i64 -8
  %22 = getelementptr inbounds i8, ptr %20, i64 -24
  %wide.load = load <2 x ptr>, ptr %21, align 8, !tbaa !10
  %wide.load43 = load <2 x ptr>, ptr %22, align 8, !tbaa !10
  %23 = getelementptr inbounds [100 x ptr], ptr %0, i64 0, i64 %offset.idx
  %24 = getelementptr inbounds i8, ptr %23, i64 -8
  %25 = getelementptr inbounds i8, ptr %23, i64 -24
  store <2 x ptr> %wide.load, ptr %24, align 8, !tbaa !10
  store <2 x ptr> %wide.load43, ptr %25, align 8, !tbaa !10
  %index.next = add nuw i64 %index, 4
  %26 = icmp eq i64 %index.next, %n.vec
  br i1 %26, label %middle.block, label %vector.body, !llvm.loop !16

middle.block:                                     ; preds = %vector.body
  %cmp.n = icmp eq i64 %18, %n.vec
  br i1 %cmp.n, label %._crit_edge29, label %.lr.ph28.preheader47

._crit_edge29:                                    ; preds = %13, %.lr.ph28, %middle.block, %3, %._crit_edge
  %.019.lcssa36 = phi i32 [ %14, %._crit_edge ], [ 0, %3 ], [ %14, %middle.block ], [ %14, %.lr.ph28 ], [ %6, %13 ]
  %27 = zext nneg i32 %.019.lcssa36 to i64
  %28 = getelementptr inbounds [100 x ptr], ptr %0, i64 0, i64 %27
  store ptr %4, ptr %28, align 8, !tbaa !10
  %29 = add nsw i32 %6, 1
  store i32 %29, ptr %5, align 8, !tbaa !5
  ret void

.lr.ph28:                                         ; preds = %.lr.ph28.preheader47, %.lr.ph28
  %indvars.iv32 = phi i64 [ %indvars.iv.next33, %.lr.ph28 ], [ %indvars.iv32.ph, %.lr.ph28.preheader47 ]
  %indvars.iv.next33 = add nsw i64 %indvars.iv32, -1
  %30 = getelementptr inbounds [100 x ptr], ptr %0, i64 0, i64 %indvars.iv.next33
  %31 = load ptr, ptr %30, align 8, !tbaa !10
  %32 = getelementptr inbounds [100 x ptr], ptr %0, i64 0, i64 %indvars.iv32
  store ptr %31, ptr %32, align 8, !tbaa !10
  %33 = icmp sgt i64 %indvars.iv.next33, %17
  br i1 %33, label %.lr.ph28, label %._crit_edge29, !llvm.loop !19
}

attributes #0 = { 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" }

!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, !9, i64 800}
!6 = !{!"", !7, i64 0, !9, i64 800}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!"int", !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"any pointer", !7, i64 0}
!12 = !{!13, !9, i64 4}
!13 = !{!"Node", !9, i64 0, !9, i64 4, !11, i64 8}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = distinct !{!16, !15, !17, !18}
!17 = !{!"llvm.loop.isvectorized", i32 1}
!18 = !{!"llvm.loop.unroll.runtime.disable"}
!19 = distinct !{!19, !15, !18, !17}


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