; LLVM IR from AlgoGenesis/C :: Searching Algorithms/Uniform_Cost_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.Edge = type { i32, i32 }
%struct.PriorityQueue = type { [100 x %struct.Edge], i32 }

; Function Attrs: nounwind uwtable
define dso_local void @push(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 i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca %struct.Edge, 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
  %10 = load i32, ptr %5, align 4, !tbaa !9
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.PriorityQueue, ptr %11, i32 0, i32 0
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.PriorityQueue, ptr %13, i32 0, i32 1
  %15 = load i32, ptr %14, align 4, !tbaa !11
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds [100 x %struct.Edge], ptr %12, i64 0, i64 %16
  %18 = getelementptr inbounds %struct.Edge, ptr %17, i32 0, i32 0
  store i32 %10, ptr %18, align 4, !tbaa !13
  %19 = load i32, ptr %6, align 4, !tbaa !9
  %20 = load ptr, ptr %4, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.PriorityQueue, ptr %20, i32 0, i32 0
  %22 = load ptr, ptr %4, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.PriorityQueue, ptr %22, i32 0, i32 1
  %24 = load i32, ptr %23, align 4, !tbaa !11
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds [100 x %struct.Edge], ptr %21, i64 0, i64 %25
  %27 = getelementptr inbounds %struct.Edge, ptr %26, i32 0, i32 1
  store i32 %19, ptr %27, align 4, !tbaa !15
  %28 = load ptr, ptr %4, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.PriorityQueue, ptr %28, i32 0, i32 1
  %30 = load i32, ptr %29, align 4, !tbaa !11
  %31 = add nsw i32 %30, 1
  store i32 %31, ptr %29, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  %32 = load ptr, ptr %4, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.PriorityQueue, ptr %32, i32 0, i32 1
  %34 = load i32, ptr %33, align 4, !tbaa !11
  %35 = sub nsw i32 %34, 1
  store i32 %35, ptr %7, align 4, !tbaa !9
  br label %36

36:                                               ; preds = %82, %3
  %37 = load i32, ptr %7, align 4, !tbaa !9
  %38 = icmp sgt i32 %37, 0
  br i1 %38, label %40, label %39

39:                                               ; preds = %36
  store i32 2, ptr %8, align 4
  br label %85

40:                                               ; preds = %36
  %41 = load ptr, ptr %4, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.PriorityQueue, ptr %41, i32 0, i32 0
  %43 = load i32, ptr %7, align 4, !tbaa !9
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds [100 x %struct.Edge], ptr %42, i64 0, i64 %44
  %46 = getelementptr inbounds %struct.Edge, ptr %45, i32 0, i32 1
  %47 = load i32, ptr %46, align 4, !tbaa !15
  %48 = load ptr, ptr %4, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.PriorityQueue, ptr %48, i32 0, i32 0
  %50 = load i32, ptr %7, align 4, !tbaa !9
  %51 = sub nsw i32 %50, 1
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds [100 x %struct.Edge], ptr %49, i64 0, i64 %52
  %54 = getelementptr inbounds %struct.Edge, ptr %53, i32 0, i32 1
  %55 = load i32, ptr %54, align 4, !tbaa !15
  %56 = icmp slt i32 %47, %55
  br i1 %56, label %57, label %80

57:                                               ; preds = %40
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  %58 = load ptr, ptr %4, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.PriorityQueue, ptr %58, i32 0, i32 0
  %60 = load i32, ptr %7, align 4, !tbaa !9
  %61 = sext i32 %60 to i64
  %62 = getelementptr inbounds [100 x %struct.Edge], ptr %59, i64 0, i64 %61
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %9, ptr align 4 %62, i64 8, i1 false), !tbaa.struct !16
  %63 = load ptr, ptr %4, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.PriorityQueue, ptr %63, i32 0, i32 0
  %65 = load i32, ptr %7, align 4, !tbaa !9
  %66 = sext i32 %65 to i64
  %67 = getelementptr inbounds [100 x %struct.Edge], ptr %64, i64 0, i64 %66
  %68 = load ptr, ptr %4, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.PriorityQueue, ptr %68, i32 0, i32 0
  %70 = load i32, ptr %7, align 4, !tbaa !9
  %71 = sub nsw i32 %70, 1
  %72 = sext i32 %71 to i64
  %73 = getelementptr inbounds [100 x %struct.Edge], ptr %69, i64 0, i64 %72
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %67, ptr align 4 %73, i64 8, i1 false), !tbaa.struct !16
  %74 = load ptr, ptr %4, align 8, !tbaa !5
  %75 = getelementptr inbounds %struct.PriorityQueue, ptr %74, i32 0, i32 0
  %76 = load i32, ptr %7, align 4, !tbaa !9
  %77 = sub nsw i32 %76, 1
  %78 = sext i32 %77 to i64
  %79 = getelementptr inbounds [100 x %struct.Edge], ptr %75, i64 0, i64 %78
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %79, ptr align 4 %9, i64 8, i1 false), !tbaa.struct !16
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  br label %81

80:                                               ; preds = %40
  store i32 2, ptr %8, align 4
  br label %85

81:                                               ; preds = %57
  br label %82

82:                                               ; preds = %81
  %83 = load i32, ptr %7, align 4, !tbaa !9
  %84 = add nsw i32 %83, -1
  store i32 %84, ptr %7, align 4, !tbaa !9
  br label %36, !llvm.loop !17

85:                                               ; preds = %80, %39
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  br label %86

86:                                               ; preds = %85
  ret void
}

; 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 nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

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

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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 = !{!"", !10, i64 0, !10, i64 4}
!15 = !{!14, !10, i64 4}
!16 = !{i64 0, i64 4, !9, i64 4, i64 4, !9}
!17 = distinct !{!17, !18}
!18 = !{!"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.Edge = type { i32, i32 }

; Function Attrs: nofree norecurse nosync nounwind memory(argmem: readwrite) uwtable
define dso_local void @push(ptr nocapture noundef %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = getelementptr inbounds i8, ptr %0, i64 800
  %5 = load i32, ptr %4, align 4, !tbaa !5
  %6 = sext i32 %5 to i64
  %7 = getelementptr inbounds [100 x %struct.Edge], ptr %0, i64 0, i64 %6
  store i32 %1, ptr %7, align 4, !tbaa !10
  %8 = getelementptr inbounds [100 x %struct.Edge], ptr %0, i64 0, i64 %6, i32 1
  store i32 %2, ptr %8, align 4, !tbaa !12
  %9 = add nsw i32 %5, 1
  store i32 %9, ptr %4, align 4, !tbaa !5
  %10 = icmp sgt i32 %5, 0
  br i1 %10, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %3
  %.phi.trans.insert = zext nneg i32 %5 to i64
  %.phi.trans.insert24 = getelementptr inbounds [100 x %struct.Edge], ptr %0, i64 0, i64 %.phi.trans.insert, i32 1
  %.pre = load i32, ptr %.phi.trans.insert24, align 4, !tbaa !12
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %18
  %11 = phi i32 [ %25, %18 ], [ %.pre, %.lr.ph.preheader ]
  %.021 = phi i32 [ %12, %18 ], [ %5, %.lr.ph.preheader ]
  %12 = add nsw i32 %.021, -1
  %13 = zext nneg i32 %12 to i64
  %14 = getelementptr inbounds [100 x %struct.Edge], ptr %0, i64 0, i64 %13
  %15 = getelementptr inbounds i8, ptr %14, i64 4
  %16 = load i32, ptr %15, align 4, !tbaa !12
  %17 = icmp slt i32 %11, %16
  br i1 %17, label %18, label %._crit_edge

18:                                               ; preds = %.lr.ph
  %19 = zext nneg i32 %.021 to i64
  %20 = getelementptr inbounds [100 x %struct.Edge], ptr %0, i64 0, i64 %19
  %21 = load i64, ptr %20, align 4
  %22 = load i64, ptr %14, align 4
  store i64 %22, ptr %20, align 4
  store i64 %21, ptr %14, align 4
  %23 = icmp ugt i32 %.021, 1
  %24 = lshr i64 %21, 32
  %25 = trunc nuw i64 %24 to i32
  br i1 %23, label %.lr.ph, label %._crit_edge, !llvm.loop !13

._crit_edge:                                      ; preds = %18, %.lr.ph, %3
  ret void
}

attributes #0 = { nofree norecurse nosync nounwind memory(argmem: readwrite) 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, !9, i64 0}
!11 = !{!"", !9, i64 0, !9, i64 4}
!12 = !{!11, !9, i64 4}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: BDCEPass,CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SCCPPass,SROAPass,SimplifyCFGPass