; LLVM IR from CodersForLife/Data-Structures-Algorithms :: Segment Tree/SegmentTree.ll (Z6updateiPiiiS_ii)

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

; 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: mustprogress uwtable
define dso_local noundef i32 @_Z6updateiPiiiS_ii(i32 noundef %0, ptr noundef %1, i32 noundef %2, i32 noundef %3, ptr noundef %4, i32 noundef %5, i32 noundef %6) #1 {
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca ptr, align 8
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  %15 = alloca i32, align 4
  store i32 %0, ptr %8, align 4, !tbaa !5
  store ptr %1, ptr %9, align 8, !tbaa !9
  store i32 %2, ptr %10, align 4, !tbaa !5
  store i32 %3, ptr %11, align 4, !tbaa !5
  store ptr %4, ptr %12, align 8, !tbaa !9
  store i32 %5, ptr %13, align 4, !tbaa !5
  store i32 %6, ptr %14, align 4, !tbaa !5
  %16 = load i32, ptr %10, align 4, !tbaa !5
  %17 = load i32, ptr %11, align 4, !tbaa !5
  %18 = icmp eq i32 %16, %17
  br i1 %18, label %19, label %30

19:                                               ; preds = %7
  %20 = load i32, ptr %14, align 4, !tbaa !5
  %21 = load ptr, ptr %12, align 8, !tbaa !9
  %22 = load i32, ptr %13, align 4, !tbaa !5
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds i32, ptr %21, i64 %23
  store i32 %20, ptr %24, align 4, !tbaa !5
  %25 = load i32, ptr %14, align 4, !tbaa !5
  %26 = load ptr, ptr %9, align 8, !tbaa !9
  %27 = load i32, ptr %8, align 4, !tbaa !5
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds i32, ptr %26, i64 %28
  store i32 %25, ptr %29, align 4, !tbaa !5
  br label %84

30:                                               ; preds = %7
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #3
  %31 = load i32, ptr %10, align 4, !tbaa !5
  %32 = load i32, ptr %11, align 4, !tbaa !5
  %33 = add nsw i32 %31, %32
  %34 = sdiv i32 %33, 2
  store i32 %34, ptr %15, align 4, !tbaa !5
  %35 = load i32, ptr %13, align 4, !tbaa !5
  %36 = load i32, ptr %10, align 4, !tbaa !5
  %37 = icmp sge i32 %35, %36
  br i1 %37, label %38, label %53

38:                                               ; preds = %30
  %39 = load i32, ptr %15, align 4, !tbaa !5
  %40 = load i32, ptr %13, align 4, !tbaa !5
  %41 = icmp sge i32 %39, %40
  br i1 %41, label %42, label %53

42:                                               ; preds = %38
  %43 = load i32, ptr %8, align 4, !tbaa !5
  %44 = mul nsw i32 2, %43
  %45 = add nsw i32 %44, 1
  %46 = load ptr, ptr %9, align 8, !tbaa !9
  %47 = load i32, ptr %10, align 4, !tbaa !5
  %48 = load i32, ptr %15, align 4, !tbaa !5
  %49 = load ptr, ptr %12, align 8, !tbaa !9
  %50 = load i32, ptr %13, align 4, !tbaa !5
  %51 = load i32, ptr %14, align 4, !tbaa !5
  %52 = call noundef i32 @_Z6updateiPiiiS_ii(i32 noundef %45, ptr noundef %46, i32 noundef %47, i32 noundef %48, ptr noundef %49, i32 noundef %50, i32 noundef %51)
  br label %65

53:                                               ; preds = %38, %30
  %54 = load i32, ptr %8, align 4, !tbaa !5
  %55 = mul nsw i32 2, %54
  %56 = add nsw i32 %55, 2
  %57 = load ptr, ptr %9, align 8, !tbaa !9
  %58 = load i32, ptr %15, align 4, !tbaa !5
  %59 = add nsw i32 %58, 1
  %60 = load i32, ptr %11, align 4, !tbaa !5
  %61 = load ptr, ptr %12, align 8, !tbaa !9
  %62 = load i32, ptr %13, align 4, !tbaa !5
  %63 = load i32, ptr %14, align 4, !tbaa !5
  %64 = call noundef i32 @_Z6updateiPiiiS_ii(i32 noundef %56, ptr noundef %57, i32 noundef %59, i32 noundef %60, ptr noundef %61, i32 noundef %62, i32 noundef %63)
  br label %65

65:                                               ; preds = %53, %42
  %66 = load ptr, ptr %9, align 8, !tbaa !9
  %67 = load i32, ptr %8, align 4, !tbaa !5
  %68 = mul nsw i32 2, %67
  %69 = add nsw i32 %68, 1
  %70 = sext i32 %69 to i64
  %71 = getelementptr inbounds i32, ptr %66, i64 %70
  %72 = load ptr, ptr %9, align 8, !tbaa !9
  %73 = load i32, ptr %8, align 4, !tbaa !5
  %74 = mul nsw i32 2, %73
  %75 = add nsw i32 %74, 2
  %76 = sext i32 %75 to i64
  %77 = getelementptr inbounds i32, ptr %72, i64 %76
  %78 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %71, ptr noundef nonnull align 4 dereferenceable(4) %77)
  %79 = load i32, ptr %78, align 4, !tbaa !5
  %80 = load ptr, ptr %9, align 8, !tbaa !9
  %81 = load i32, ptr %8, align 4, !tbaa !5
  %82 = sext i32 %81 to i64
  %83 = getelementptr inbounds i32, ptr %80, i64 %82
  store i32 %79, ptr %83, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #3
  br label %84

84:                                               ; preds = %65, %19
  ret i32 0
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 = { 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 #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, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}


; 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: mustprogress nounwind uwtable
define dso_local noundef i32 @_Z6updateiPiiiS_ii(i32 noundef %0, ptr noundef %1, i32 noundef %2, i32 noundef %3, ptr noundef %4, i32 noundef %5, i32 noundef %6) local_unnamed_addr #0 {
  %8 = icmp eq i32 %2, %3
  br i1 %8, label %9, label %12

9:                                                ; preds = %7
  %10 = sext i32 %5 to i64
  %11 = getelementptr inbounds i32, ptr %4, i64 %10
  store i32 %6, ptr %11, align 4, !tbaa !5
  br label %31

12:                                               ; preds = %7
  %13 = add nsw i32 %3, %2
  %14 = sdiv i32 %13, 2
  %.not = icmp slt i32 %5, %2
  %.not36 = icmp slt i32 %14, %5
  %or.cond = select i1 %.not, i1 true, i1 %.not36
  %15 = shl nsw i32 %0, 1
  br i1 %or.cond, label %19, label %16

16:                                               ; preds = %12
  %17 = or disjoint i32 %15, 1
  %18 = tail call noundef i32 @_Z6updateiPiiiS_ii(i32 noundef %17, ptr noundef %1, i32 noundef %2, i32 noundef %14, ptr noundef %4, i32 noundef %5, i32 noundef %6)
  br label %23

19:                                               ; preds = %12
  %20 = add nsw i32 %15, 2
  %21 = add nsw i32 %14, 1
  %22 = tail call noundef i32 @_Z6updateiPiiiS_ii(i32 noundef %20, ptr noundef %1, i32 noundef %21, i32 noundef %3, ptr noundef %4, i32 noundef %5, i32 noundef %6)
  %.pre = or disjoint i32 %15, 1
  br label %23

23:                                               ; preds = %19, %16
  %.pre-phi37 = phi i32 [ %.pre, %19 ], [ %17, %16 ]
  %24 = sext i32 %.pre-phi37 to i64
  %25 = getelementptr inbounds i32, ptr %1, i64 %24
  %26 = sext i32 %15 to i64
  %27 = getelementptr i32, ptr %1, i64 %26
  %28 = getelementptr i8, ptr %27, i64 8
  %29 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %25, ptr noundef nonnull align 4 dereferenceable(4) %28)
  %30 = load i32, ptr %29, align 4, !tbaa !5
  br label %31

31:                                               ; preds = %23, %9
  %.sink = phi i32 [ %30, %23 ], [ %6, %9 ]
  %32 = sext i32 %0 to i64
  %33 = getelementptr inbounds i32, ptr %1, i64 %32
  store i32 %.sink, ptr %33, align 4, !tbaa !5
  ret i32 0
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #1

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

!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,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass