; LLVM IR from ShahjalalShohag/code-library :: Graph Theory/Dijkstra on Segment Tree.ll (Z5buildiii)

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

@add = external dso_local global i32, align 4

; Function Attrs: mustprogress uwtable
define dso_local void @_Z5buildiii(i32 noundef %0, i32 noundef %1, i32 noundef %2) #0 {
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  store i32 %0, ptr %4, align 4, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !5
  store i32 %2, ptr %6, align 4, !tbaa !5
  %8 = load i32, ptr %5, align 4, !tbaa !5
  %9 = load i32, ptr %6, align 4, !tbaa !5
  %10 = icmp eq i32 %8, %9
  br i1 %10, label %11, label %21

11:                                               ; preds = %3
  %12 = load i32, ptr %5, align 4, !tbaa !5
  %13 = load i32, ptr %4, align 4, !tbaa !5
  %14 = load i32, ptr @add, align 4, !tbaa !5
  %15 = add nsw i32 %13, %14
  call void @_Z8add_edgeiii(i32 noundef %12, i32 noundef %15, i32 noundef 0)
  %16 = load i32, ptr %4, align 4, !tbaa !5
  %17 = load i32, ptr @add, align 4, !tbaa !5
  %18 = mul nsw i32 %17, 5
  %19 = add nsw i32 %16, %18
  %20 = load i32, ptr %5, align 4, !tbaa !5
  call void @_Z8add_edgeiii(i32 noundef %19, i32 noundef %20, i32 noundef 0)
  br label %70

21:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  %22 = load i32, ptr %5, align 4, !tbaa !5
  %23 = load i32, ptr %6, align 4, !tbaa !5
  %24 = add nsw i32 %22, %23
  %25 = ashr i32 %24, 1
  store i32 %25, ptr %7, align 4, !tbaa !5
  %26 = load i32, ptr %4, align 4, !tbaa !5
  %27 = mul nsw i32 2, %26
  %28 = load i32, ptr @add, align 4, !tbaa !5
  %29 = add nsw i32 %27, %28
  %30 = load i32, ptr %4, align 4, !tbaa !5
  %31 = load i32, ptr @add, align 4, !tbaa !5
  %32 = add nsw i32 %30, %31
  call void @_Z8add_edgeiii(i32 noundef %29, i32 noundef %32, i32 noundef 0)
  %33 = load i32, ptr %4, align 4, !tbaa !5
  %34 = mul nsw i32 2, %33
  %35 = add nsw i32 %34, 1
  %36 = load i32, ptr @add, align 4, !tbaa !5
  %37 = add nsw i32 %35, %36
  %38 = load i32, ptr %4, align 4, !tbaa !5
  %39 = load i32, ptr @add, align 4, !tbaa !5
  %40 = add nsw i32 %38, %39
  call void @_Z8add_edgeiii(i32 noundef %37, i32 noundef %40, i32 noundef 0)
  %41 = load i32, ptr %4, align 4, !tbaa !5
  %42 = load i32, ptr @add, align 4, !tbaa !5
  %43 = mul nsw i32 5, %42
  %44 = add nsw i32 %41, %43
  %45 = load i32, ptr %4, align 4, !tbaa !5
  %46 = mul nsw i32 2, %45
  %47 = load i32, ptr @add, align 4, !tbaa !5
  %48 = mul nsw i32 5, %47
  %49 = add nsw i32 %46, %48
  call void @_Z8add_edgeiii(i32 noundef %44, i32 noundef %49, i32 noundef 0)
  %50 = load i32, ptr %4, align 4, !tbaa !5
  %51 = load i32, ptr @add, align 4, !tbaa !5
  %52 = mul nsw i32 5, %51
  %53 = add nsw i32 %50, %52
  %54 = load i32, ptr %4, align 4, !tbaa !5
  %55 = mul nsw i32 2, %54
  %56 = add nsw i32 %55, 1
  %57 = load i32, ptr @add, align 4, !tbaa !5
  %58 = mul nsw i32 5, %57
  %59 = add nsw i32 %56, %58
  call void @_Z8add_edgeiii(i32 noundef %53, i32 noundef %59, i32 noundef 0)
  %60 = load i32, ptr %4, align 4, !tbaa !5
  %61 = mul nsw i32 2, %60
  %62 = load i32, ptr %5, align 4, !tbaa !5
  %63 = load i32, ptr %7, align 4, !tbaa !5
  call void @_Z5buildiii(i32 noundef %61, i32 noundef %62, i32 noundef %63)
  %64 = load i32, ptr %4, align 4, !tbaa !5
  %65 = mul nsw i32 2, %64
  %66 = add nsw i32 %65, 1
  %67 = load i32, ptr %7, align 4, !tbaa !5
  %68 = add nsw i32 %67, 1
  %69 = load i32, ptr %6, align 4, !tbaa !5
  call void @_Z5buildiii(i32 noundef %66, i32 noundef %68, i32 noundef %69)
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  br label %70

70:                                               ; preds = %21, %11
  ret void
}

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_Z8add_edgeiii(i32 noundef, i32 noundef, i32 noundef) #1

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

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

attributes #0 = { mustprogress 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 = { inlinehint mustprogress 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 nosync 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}


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

@add = external dso_local local_unnamed_addr global i32, align 4

; Function Attrs: mustprogress uwtable
define dso_local void @_Z5buildiii(i32 noundef %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = icmp eq i32 %1, %2
  br i1 %4, label %tailrecurse._crit_edge, label %tailrecurse

tailrecurse._crit_edge:                           ; preds = %tailrecurse, %3
  %.tr.lcssa = phi i32 [ %0, %3 ], [ %16, %tailrecurse ]
  %.tr23.lcssa = phi i32 [ %1, %3 ], [ %2, %tailrecurse ]
  %5 = load i32, ptr @add, align 4, !tbaa !5
  %6 = add nsw i32 %5, %.tr.lcssa
  tail call void @_Z8add_edgeiii(i32 noundef %.tr23.lcssa, i32 noundef %6, i32 noundef 0)
  %7 = load i32, ptr @add, align 4, !tbaa !5
  %8 = mul nsw i32 %7, 5
  %9 = add nsw i32 %8, %.tr.lcssa
  tail call void @_Z8add_edgeiii(i32 noundef %9, i32 noundef %.tr23.lcssa, i32 noundef 0)
  ret void

tailrecurse:                                      ; preds = %3, %tailrecurse
  %.tr2326 = phi i32 [ %28, %tailrecurse ], [ %1, %3 ]
  %.tr25 = phi i32 [ %16, %tailrecurse ], [ %0, %3 ]
  %10 = add nsw i32 %.tr2326, %2
  %11 = ashr i32 %10, 1
  %12 = shl nsw i32 %.tr25, 1
  %13 = load i32, ptr @add, align 4, !tbaa !5
  %14 = add nsw i32 %13, %12
  %15 = add nsw i32 %13, %.tr25
  tail call void @_Z8add_edgeiii(i32 noundef %14, i32 noundef %15, i32 noundef 0)
  %16 = or disjoint i32 %12, 1
  %17 = load i32, ptr @add, align 4, !tbaa !5
  %18 = add nsw i32 %17, %16
  %19 = add nsw i32 %17, %.tr25
  tail call void @_Z8add_edgeiii(i32 noundef %18, i32 noundef %19, i32 noundef 0)
  %20 = load i32, ptr @add, align 4, !tbaa !5
  %21 = mul nsw i32 %20, 5
  %22 = add nsw i32 %21, %.tr25
  %23 = add nsw i32 %21, %12
  tail call void @_Z8add_edgeiii(i32 noundef %22, i32 noundef %23, i32 noundef 0)
  %24 = load i32, ptr @add, align 4, !tbaa !5
  %25 = mul nsw i32 %24, 5
  %26 = add nsw i32 %25, %.tr25
  %27 = add nsw i32 %25, %16
  tail call void @_Z8add_edgeiii(i32 noundef %26, i32 noundef %27, i32 noundef 0)
  tail call void @_Z5buildiii(i32 noundef %12, i32 noundef %.tr2326, i32 noundef %11)
  %28 = add nsw i32 %11, 1
  %29 = icmp eq i32 %28, %2
  br i1 %29, label %tailrecurse._crit_edge, label %tailrecurse
}

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_Z8add_edgeiii(i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #1

attributes #0 = { mustprogress 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 = { inlinehint mustprogress 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}


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