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

@.str = external hidden unnamed_addr constant [21 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [18 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [25 x i8], align 1

; 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
declare dso_local void @initQueue(ptr noundef) #1

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

; Function Attrs: nounwind uwtable
declare dso_local ptr @dequeue(ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local void @bestFirstSearch(ptr noundef %0, i32 noundef %1, i32 noundef %2) #1 {
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca %struct.PriorityQueue, align 8
  %8 = alloca [100 x i32], align 16
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = 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 808, ptr %7) #4
  call void @initQueue(ptr noundef %7)
  call void @llvm.lifetime.start.p0(i64 400, ptr %8) #4
  call void @llvm.memset.p0.i64(ptr align 16 %8, i8 0, i64 400, i1 false)
  %13 = load i32, ptr %5, align 4, !tbaa !9
  %14 = load ptr, ptr %4, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.Graph, ptr %14, i32 0, i32 2
  %16 = load i32, ptr %5, align 4, !tbaa !9
  %17 = sext i32 %16 to i64
  %18 = getelementptr inbounds [100 x i32], ptr %15, i64 0, i64 %17
  %19 = load i32, ptr %18, align 4, !tbaa !9
  call void @enqueue(ptr noundef %7, i32 noundef %13, i32 noundef %19)
  br label %20

20:                                               ; preds = %87, %3
  %21 = getelementptr inbounds %struct.PriorityQueue, ptr %7, i32 0, i32 1
  %22 = load i32, ptr %21, align 8, !tbaa !11
  %23 = icmp sgt i32 %22, 0
  br i1 %23, label %24, label %88

24:                                               ; preds = %20
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %25 = call ptr @dequeue(ptr noundef %7)
  store ptr %25, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  %26 = load ptr, ptr %9, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.Node, ptr %26, i32 0, i32 0
  %28 = load i32, ptr %27, align 8, !tbaa !13
  store i32 %28, ptr %10, align 4, !tbaa !9
  %29 = load i32, ptr %10, align 4, !tbaa !9
  %30 = load i32, ptr %6, align 4, !tbaa !9
  %31 = icmp eq i32 %29, %30
  br i1 %31, label %32, label %35

32:                                               ; preds = %24
  %33 = load i32, ptr %6, align 4, !tbaa !9
  %34 = call i32 (ptr, ...) @printf(ptr noundef @.str, i32 noundef %33)
  store i32 1, ptr %11, align 4
  br label %85

35:                                               ; preds = %24
  %36 = load i32, ptr %10, align 4, !tbaa !9
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds [100 x i32], ptr %8, i64 0, i64 %37
  %39 = load i32, ptr %38, align 4, !tbaa !9
  %40 = icmp ne i32 %39, 0
  br i1 %40, label %84, label %41

41:                                               ; preds = %35
  %42 = load i32, ptr %10, align 4, !tbaa !9
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds [100 x i32], ptr %8, i64 0, i64 %43
  store i32 1, ptr %44, align 4, !tbaa !9
  %45 = load i32, ptr %10, align 4, !tbaa !9
  %46 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i32 noundef %45)
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #4
  store i32 0, ptr %12, align 4, !tbaa !9
  br label %47

47:                                               ; preds = %80, %41
  %48 = load i32, ptr %12, align 4, !tbaa !9
  %49 = load ptr, ptr %4, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.Graph, ptr %49, i32 0, i32 1
  %51 = load i32, ptr %50, align 4, !tbaa !15
  %52 = icmp slt i32 %48, %51
  br i1 %52, label %54, label %53

53:                                               ; preds = %47
  store i32 4, ptr %11, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #4
  br label %83

54:                                               ; preds = %47
  %55 = load ptr, ptr %4, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.Graph, ptr %55, i32 0, i32 0
  %57 = load i32, ptr %10, align 4, !tbaa !9
  %58 = sext i32 %57 to i64
  %59 = getelementptr inbounds [100 x [100 x i32]], ptr %56, i64 0, i64 %58
  %60 = load i32, ptr %12, align 4, !tbaa !9
  %61 = sext i32 %60 to i64
  %62 = getelementptr inbounds [100 x i32], ptr %59, i64 0, i64 %61
  %63 = load i32, ptr %62, align 4, !tbaa !9
  %64 = icmp eq i32 %63, 1
  br i1 %64, label %65, label %79

65:                                               ; preds = %54
  %66 = load i32, ptr %12, align 4, !tbaa !9
  %67 = sext i32 %66 to i64
  %68 = getelementptr inbounds [100 x i32], ptr %8, i64 0, i64 %67
  %69 = load i32, ptr %68, align 4, !tbaa !9
  %70 = icmp ne i32 %69, 0
  br i1 %70, label %79, label %71

71:                                               ; preds = %65
  %72 = load i32, ptr %12, align 4, !tbaa !9
  %73 = load ptr, ptr %4, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct.Graph, ptr %73, i32 0, i32 2
  %75 = load i32, ptr %12, align 4, !tbaa !9
  %76 = sext i32 %75 to i64
  %77 = getelementptr inbounds [100 x i32], ptr %74, i64 0, i64 %76
  %78 = load i32, ptr %77, align 4, !tbaa !9
  call void @enqueue(ptr noundef %7, i32 noundef %72, i32 noundef %78)
  br label %79

79:                                               ; preds = %71, %65, %54
  br label %80

80:                                               ; preds = %79
  %81 = load i32, ptr %12, align 4, !tbaa !9
  %82 = add nsw i32 %81, 1
  store i32 %82, ptr %12, align 4, !tbaa !9
  br label %47, !llvm.loop !17

83:                                               ; preds = %53
  br label %84

84:                                               ; preds = %83, %35
  store i32 0, ptr %11, align 4
  br label %85

85:                                               ; preds = %84, %32
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  %86 = load i32, ptr %11, align 4
  switch i32 %86, label %91 [
    i32 0, label %87
  ]

87:                                               ; preds = %85
  br label %20, !llvm.loop !19

88:                                               ; preds = %20
  %89 = load i32, ptr %6, align 4, !tbaa !9
  %90 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i32 noundef %89)
  store i32 0, ptr %11, align 4
  br label %91

91:                                               ; preds = %88, %85
  call void @llvm.lifetime.end.p0(i64 400, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 808, ptr %7) #4
  %92 = load i32, ptr %11, align 4
  switch i32 %92, label %94 [
    i32 0, label %93
    i32 1, label %93
  ]

93:                                               ; preds = %91, %91
  ret void

94:                                               ; preds = %91
  unreachable
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

declare i32 @printf(ptr noundef, ...) #3

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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { "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 }

!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 0}
!14 = !{!"Node", !10, i64 0, !10, i64 4, !6, i64 8}
!15 = !{!16, !10, i64 40000}
!16 = !{!"Graph", !7, i64 0, !10, i64 40000, !7, i64 40004}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = distinct !{!19, !18}


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

@.str = external hidden unnamed_addr constant [21 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [18 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [25 x i8], align 1

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

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

; Function Attrs: nounwind uwtable
declare dso_local void @initQueue(ptr noundef) local_unnamed_addr #1

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

; Function Attrs: nounwind uwtable
declare dso_local ptr @dequeue(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local void @bestFirstSearch(ptr nocapture noundef readonly %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #1 {
  %4 = alloca %struct.PriorityQueue, align 8
  %5 = alloca [100 x i32], align 16
  call void @llvm.lifetime.start.p0(i64 808, ptr nonnull %4) #4
  call void @initQueue(ptr noundef nonnull %4)
  call void @llvm.lifetime.start.p0(i64 400, ptr nonnull %5) #4
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(400) %5, i8 0, i64 400, i1 false)
  %6 = getelementptr inbounds i8, ptr %0, i64 40004
  %7 = sext i32 %1 to i64
  %8 = getelementptr inbounds [100 x i32], ptr %6, i64 0, i64 %7
  %9 = load i32, ptr %8, align 4, !tbaa !5
  call void @enqueue(ptr noundef nonnull %4, i32 noundef %1, i32 noundef %9)
  %10 = getelementptr inbounds i8, ptr %4, i64 800
  %11 = getelementptr inbounds i8, ptr %0, i64 40000
  %12 = load i32, ptr %10, align 8, !tbaa !9
  %13 = icmp sgt i32 %12, 0
  br i1 %13, label %.lr.ph29, label %.loopexit26

.lr.ph29:                                         ; preds = %3, %.loopexit
  %14 = call ptr @dequeue(ptr noundef nonnull %4)
  %15 = load i32, ptr %14, align 8, !tbaa !11
  %.not25 = icmp eq i32 %15, %2
  br i1 %.not25, label %.loopexit26, label %16

16:                                               ; preds = %.lr.ph29
  %17 = sext i32 %15 to i64
  %18 = getelementptr inbounds [100 x i32], ptr %5, i64 0, i64 %17
  %19 = load i32, ptr %18, align 4, !tbaa !5
  %.not = icmp eq i32 %19, 0
  br i1 %.not, label %20, label %.loopexit

20:                                               ; preds = %16
  store i32 1, ptr %18, align 4, !tbaa !5
  %21 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %15)
  %22 = load i32, ptr %11, align 4, !tbaa !14
  %23 = icmp sgt i32 %22, 0
  br i1 %23, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %20, %35
  %24 = phi i32 [ %36, %35 ], [ %22, %20 ]
  %indvars.iv = phi i64 [ %indvars.iv.next, %35 ], [ 0, %20 ]
  %25 = getelementptr inbounds [100 x [100 x i32]], ptr %0, i64 0, i64 %17, i64 %indvars.iv
  %26 = load i32, ptr %25, align 4, !tbaa !5
  %27 = icmp eq i32 %26, 1
  br i1 %27, label %28, label %35

28:                                               ; preds = %.lr.ph
  %29 = getelementptr inbounds [100 x i32], ptr %5, i64 0, i64 %indvars.iv
  %30 = load i32, ptr %29, align 4, !tbaa !5
  %.not24 = icmp eq i32 %30, 0
  br i1 %.not24, label %31, label %35

31:                                               ; preds = %28
  %32 = getelementptr inbounds [100 x i32], ptr %6, i64 0, i64 %indvars.iv
  %33 = load i32, ptr %32, align 4, !tbaa !5
  %34 = trunc nuw nsw i64 %indvars.iv to i32
  call void @enqueue(ptr noundef nonnull %4, i32 noundef %34, i32 noundef %33)
  %.pre = load i32, ptr %11, align 4, !tbaa !14
  br label %35

35:                                               ; preds = %.lr.ph, %28, %31
  %36 = phi i32 [ %24, %.lr.ph ], [ %24, %28 ], [ %.pre, %31 ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %37 = sext i32 %36 to i64
  %38 = icmp slt i64 %indvars.iv.next, %37
  br i1 %38, label %.lr.ph, label %.loopexit, !llvm.loop !16

.loopexit:                                        ; preds = %35, %20, %16
  %39 = load i32, ptr %10, align 8, !tbaa !9
  %40 = icmp sgt i32 %39, 0
  br i1 %40, label %.lr.ph29, label %.loopexit26

.loopexit26:                                      ; preds = %.lr.ph29, %.loopexit, %3
  %.str.sink = phi ptr [ @.str.2, %3 ], [ @.str, %.lr.ph29 ], [ @.str.2, %.loopexit ]
  %41 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) %.str.sink, i32 noundef %2)
  call void @llvm.lifetime.end.p0(i64 400, ptr nonnull %5) #4
  call void @llvm.lifetime.end.p0(i64 808, ptr nonnull %4) #4
  ret void
}

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #3

attributes #0 = { mustprogress 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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { nofree nounwind "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 }

!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, !6, i64 800}
!10 = !{!"", !7, i64 0, !6, i64 800}
!11 = !{!12, !6, i64 0}
!12 = !{!"Node", !6, i64 0, !6, i64 4, !13, i64 8}
!13 = !{!"any pointer", !7, i64 0}
!14 = !{!15, !6, i64 40000}
!15 = !{!"Graph", !7, i64 0, !6, i64 40000, !7, i64 40004}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}


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