; LLVM IR from Dev-XYS/Algorithms :: Segment-Tree(Minimum).ll (Z6updateiii)

; 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.node = type { i32, i32, i32, i32 }

@T = external dso_local global [4000010 x %struct.node], align 16
@delta = external dso_local global i32, align 4

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z3minii(i32 noundef, i32 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: mustprogress uwtable
define dso_local void @_Z6updateiii(i32 noundef %0, i32 noundef %1, i32 noundef %2) #2 {
  %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 %6, align 4, !tbaa !5
  %9 = sext i32 %8 to i64
  %10 = getelementptr inbounds [4000010 x %struct.node], ptr @T, i64 0, i64 %9
  %11 = getelementptr inbounds %struct.node, ptr %10, i32 0, i32 0
  %12 = load i32, ptr %11, align 16, !tbaa !9
  %13 = load i32, ptr %4, align 4, !tbaa !5
  %14 = icmp eq i32 %12, %13
  br i1 %14, label %15, label %38

15:                                               ; preds = %3
  %16 = load i32, ptr %6, align 4, !tbaa !5
  %17 = sext i32 %16 to i64
  %18 = getelementptr inbounds [4000010 x %struct.node], ptr @T, i64 0, i64 %17
  %19 = getelementptr inbounds %struct.node, ptr %18, i32 0, i32 1
  %20 = load i32, ptr %19, align 4, !tbaa !11
  %21 = load i32, ptr %5, align 4, !tbaa !5
  %22 = icmp eq i32 %20, %21
  br i1 %22, label %23, label %38

23:                                               ; preds = %15
  %24 = load i32, ptr @delta, align 4, !tbaa !5
  %25 = load i32, ptr %6, align 4, !tbaa !5
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds [4000010 x %struct.node], ptr @T, i64 0, i64 %26
  %28 = getelementptr inbounds %struct.node, ptr %27, i32 0, i32 3
  %29 = load i32, ptr %28, align 4, !tbaa !12
  %30 = add nsw i32 %29, %24
  store i32 %30, ptr %28, align 4, !tbaa !12
  %31 = load i32, ptr @delta, align 4, !tbaa !5
  %32 = load i32, ptr %6, align 4, !tbaa !5
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds [4000010 x %struct.node], ptr @T, i64 0, i64 %33
  %35 = getelementptr inbounds %struct.node, ptr %34, i32 0, i32 2
  %36 = load i32, ptr %35, align 8, !tbaa !13
  %37 = add nsw i32 %36, %31
  store i32 %37, ptr %35, align 8, !tbaa !13
  br label %100

38:                                               ; preds = %15, %3
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  %39 = load i32, ptr %6, align 4, !tbaa !5
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds [4000010 x %struct.node], ptr @T, i64 0, i64 %40
  %42 = getelementptr inbounds %struct.node, ptr %41, i32 0, i32 0
  %43 = load i32, ptr %42, align 16, !tbaa !9
  %44 = load i32, ptr %6, align 4, !tbaa !5
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds [4000010 x %struct.node], ptr @T, i64 0, i64 %45
  %47 = getelementptr inbounds %struct.node, ptr %46, i32 0, i32 1
  %48 = load i32, ptr %47, align 4, !tbaa !11
  %49 = add nsw i32 %43, %48
  %50 = ashr i32 %49, 1
  store i32 %50, ptr %7, align 4, !tbaa !5
  %51 = load i32, ptr %5, align 4, !tbaa !5
  %52 = load i32, ptr %7, align 4, !tbaa !5
  %53 = icmp sle i32 %51, %52
  br i1 %53, label %54, label %59

54:                                               ; preds = %38
  %55 = load i32, ptr %4, align 4, !tbaa !5
  %56 = load i32, ptr %5, align 4, !tbaa !5
  %57 = load i32, ptr %6, align 4, !tbaa !5
  %58 = shl i32 %57, 1
  call void @_Z6updateiii(i32 noundef %55, i32 noundef %56, i32 noundef %58)
  br label %81

59:                                               ; preds = %38
  %60 = load i32, ptr %4, align 4, !tbaa !5
  %61 = load i32, ptr %7, align 4, !tbaa !5
  %62 = icmp sgt i32 %60, %61
  br i1 %62, label %63, label %69

63:                                               ; preds = %59
  %64 = load i32, ptr %4, align 4, !tbaa !5
  %65 = load i32, ptr %5, align 4, !tbaa !5
  %66 = load i32, ptr %6, align 4, !tbaa !5
  %67 = shl i32 %66, 1
  %68 = add nsw i32 %67, 1
  call void @_Z6updateiii(i32 noundef %64, i32 noundef %65, i32 noundef %68)
  br label %80

69:                                               ; preds = %59
  %70 = load i32, ptr %4, align 4, !tbaa !5
  %71 = load i32, ptr %7, align 4, !tbaa !5
  %72 = load i32, ptr %6, align 4, !tbaa !5
  %73 = shl i32 %72, 1
  call void @_Z6updateiii(i32 noundef %70, i32 noundef %71, i32 noundef %73)
  %74 = load i32, ptr %7, align 4, !tbaa !5
  %75 = add nsw i32 %74, 1
  %76 = load i32, ptr %5, align 4, !tbaa !5
  %77 = load i32, ptr %6, align 4, !tbaa !5
  %78 = shl i32 %77, 1
  %79 = add nsw i32 %78, 1
  call void @_Z6updateiii(i32 noundef %75, i32 noundef %76, i32 noundef %79)
  br label %80

80:                                               ; preds = %69, %63
  br label %81

81:                                               ; preds = %80, %54
  %82 = load i32, ptr %6, align 4, !tbaa !5
  %83 = shl i32 %82, 1
  %84 = sext i32 %83 to i64
  %85 = getelementptr inbounds [4000010 x %struct.node], ptr @T, i64 0, i64 %84
  %86 = getelementptr inbounds %struct.node, ptr %85, i32 0, i32 2
  %87 = load i32, ptr %86, align 8, !tbaa !13
  %88 = load i32, ptr %6, align 4, !tbaa !5
  %89 = shl i32 %88, 1
  %90 = add nsw i32 %89, 1
  %91 = sext i32 %90 to i64
  %92 = getelementptr inbounds [4000010 x %struct.node], ptr @T, i64 0, i64 %91
  %93 = getelementptr inbounds %struct.node, ptr %92, i32 0, i32 2
  %94 = load i32, ptr %93, align 8, !tbaa !13
  %95 = call noundef i32 @_Z3minii(i32 noundef %87, i32 noundef %94)
  %96 = load i32, ptr %6, align 4, !tbaa !5
  %97 = sext i32 %96 to i64
  %98 = getelementptr inbounds [4000010 x %struct.node], ptr @T, i64 0, i64 %97
  %99 = getelementptr inbounds %struct.node, ptr %98, i32 0, i32 2
  store i32 %95, ptr %99, align 8, !tbaa !13
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  br label %100

100:                                              ; preds = %81, %23
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { inlinehint mustprogress 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 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 }

!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"}
!9 = !{!10, !6, i64 0}
!10 = !{!"_ZTS4node", !6, i64 0, !6, i64 4, !6, i64 8, !6, i64 12}
!11 = !{!10, !6, i64 4}
!12 = !{!10, !6, i64 12}
!13 = !{!10, !6, i64 8}


; 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.node = type { i32, i32, i32, i32 }

@T = external dso_local local_unnamed_addr global [4000010 x %struct.node], align 16
@delta = external dso_local local_unnamed_addr global i32, align 4

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z3minii(i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z6updateiii(i32 noundef %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #1 {
  %4 = sext i32 %2 to i64
  %5 = getelementptr inbounds [4000010 x %struct.node], ptr @T, i64 0, i64 %4
  %6 = load i32, ptr %5, align 16, !tbaa !5
  %7 = icmp eq i32 %6, %0
  %8 = getelementptr inbounds i8, ptr %5, i64 4
  %9 = load i32, ptr %8, align 4, !tbaa !10
  %10 = icmp eq i32 %9, %1
  %or.cond = select i1 %7, i1 %10, i1 false
  br i1 %or.cond, label %11, label %._crit_edge

11:                                               ; preds = %3
  %12 = load i32, ptr @delta, align 4, !tbaa !11
  %13 = getelementptr inbounds i8, ptr %5, i64 8
  %14 = load <2 x i32>, ptr %13, align 8, !tbaa !11
  %15 = insertelement <2 x i32> poison, i32 %12, i64 0
  %16 = shufflevector <2 x i32> %15, <2 x i32> poison, <2 x i32> zeroinitializer
  %17 = add nsw <2 x i32> %14, %16
  store <2 x i32> %17, ptr %13, align 8, !tbaa !11
  br label %39

._crit_edge:                                      ; preds = %3
  %18 = add nsw i32 %9, %6
  %19 = ashr i32 %18, 1
  %.not = icmp slt i32 %19, %1
  br i1 %.not, label %22, label %20

20:                                               ; preds = %._crit_edge
  %21 = shl i32 %2, 1
  tail call void @_Z6updateiii(i32 noundef %0, i32 noundef %1, i32 noundef %21)
  %.pre30 = or disjoint i32 %21, 1
  br label %30

22:                                               ; preds = %._crit_edge
  %23 = icmp slt i32 %19, %0
  %24 = shl i32 %2, 1
  br i1 %23, label %25, label %27

25:                                               ; preds = %22
  %26 = or disjoint i32 %24, 1
  tail call void @_Z6updateiii(i32 noundef %0, i32 noundef %1, i32 noundef %26)
  br label %30

27:                                               ; preds = %22
  tail call void @_Z6updateiii(i32 noundef %0, i32 noundef %19, i32 noundef %24)
  %28 = add nsw i32 %19, 1
  %29 = or disjoint i32 %24, 1
  tail call void @_Z6updateiii(i32 noundef %28, i32 noundef %1, i32 noundef %29)
  br label %30

30:                                               ; preds = %25, %27, %20
  %.pre-phi31 = phi i32 [ %26, %25 ], [ %29, %27 ], [ %.pre30, %20 ]
  %.pre-phi = phi i32 [ %24, %25 ], [ %24, %27 ], [ %21, %20 ]
  %31 = sext i32 %.pre-phi to i64
  %32 = getelementptr inbounds [4000010 x %struct.node], ptr @T, i64 0, i64 %31, i32 2
  %33 = load i32, ptr %32, align 8, !tbaa !12
  %34 = sext i32 %.pre-phi31 to i64
  %35 = getelementptr inbounds [4000010 x %struct.node], ptr @T, i64 0, i64 %34, i32 2
  %36 = load i32, ptr %35, align 8, !tbaa !12
  %37 = tail call noundef i32 @_Z3minii(i32 noundef %33, i32 noundef %36)
  %38 = getelementptr inbounds i8, ptr %5, i64 8
  store i32 %37, ptr %38, align 8, !tbaa !12
  br label %39

39:                                               ; preds = %30, %11
  ret void
}

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


; Effective O3 passes: BDCEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,TailCallElimPass