; LLVM IR from ritikbanger/Hacktoberfest2022-DSA :: 22. Segment Tree/Forest_Queries.ll (Z6updatePxxxxxxx)

; 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 void @_Z6updatePxxxxxxx(ptr noundef %0, i64 noundef %1, i64 noundef %2, i64 noundef %3, i64 noundef %4, i64 noundef %5, i64 noundef %6) #1 {
  %8 = alloca ptr, align 8
  %9 = alloca i64, align 8
  %10 = alloca i64, align 8
  %11 = alloca i64, align 8
  %12 = alloca i64, align 8
  %13 = alloca i64, align 8
  %14 = alloca i64, align 8
  %15 = alloca i64, align 8
  store ptr %0, ptr %8, align 8, !tbaa !5
  store i64 %1, ptr %9, align 8, !tbaa !9
  store i64 %2, ptr %10, align 8, !tbaa !9
  store i64 %3, ptr %11, align 8, !tbaa !9
  store i64 %4, ptr %12, align 8, !tbaa !9
  store i64 %5, ptr %13, align 8, !tbaa !9
  store i64 %6, ptr %14, align 8, !tbaa !9
  %16 = load i64, ptr %13, align 8, !tbaa !9
  %17 = load i64, ptr %11, align 8, !tbaa !9
  %18 = icmp sgt i64 %16, %17
  br i1 %18, label %23, label %19

19:                                               ; preds = %7
  %20 = load i64, ptr %14, align 8, !tbaa !9
  %21 = load i64, ptr %10, align 8, !tbaa !9
  %22 = icmp slt i64 %20, %21
  br i1 %22, label %23, label %24

23:                                               ; preds = %19, %7
  br label %62

24:                                               ; preds = %19
  %25 = load i64, ptr %10, align 8, !tbaa !9
  %26 = load i64, ptr %13, align 8, !tbaa !9
  %27 = icmp sle i64 %25, %26
  br i1 %27, label %28, label %39

28:                                               ; preds = %24
  %29 = load i64, ptr %14, align 8, !tbaa !9
  %30 = load i64, ptr %11, align 8, !tbaa !9
  %31 = icmp sle i64 %29, %30
  br i1 %31, label %32, label %39

32:                                               ; preds = %28
  %33 = load i64, ptr %12, align 8, !tbaa !9
  %34 = load ptr, ptr %8, align 8, !tbaa !5
  %35 = load i64, ptr %9, align 8, !tbaa !9
  %36 = getelementptr inbounds i64, ptr %34, i64 %35
  %37 = load i64, ptr %36, align 8, !tbaa !9
  %38 = add nsw i64 %37, %33
  store i64 %38, ptr %36, align 8, !tbaa !9
  br label %62

39:                                               ; preds = %28, %24
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #2
  %40 = load i64, ptr %13, align 8, !tbaa !9
  %41 = load i64, ptr %14, align 8, !tbaa !9
  %42 = add nsw i64 %40, %41
  %43 = sdiv i64 %42, 2
  store i64 %43, ptr %15, align 8, !tbaa !9
  %44 = load ptr, ptr %8, align 8, !tbaa !5
  %45 = load i64, ptr %9, align 8, !tbaa !9
  %46 = mul nsw i64 2, %45
  %47 = load i64, ptr %10, align 8, !tbaa !9
  %48 = load i64, ptr %11, align 8, !tbaa !9
  %49 = load i64, ptr %12, align 8, !tbaa !9
  %50 = load i64, ptr %13, align 8, !tbaa !9
  %51 = load i64, ptr %15, align 8, !tbaa !9
  call void @_Z6updatePxxxxxxx(ptr noundef %44, i64 noundef %46, i64 noundef %47, i64 noundef %48, i64 noundef %49, i64 noundef %50, i64 noundef %51)
  %52 = load ptr, ptr %8, align 8, !tbaa !5
  %53 = load i64, ptr %9, align 8, !tbaa !9
  %54 = mul nsw i64 2, %53
  %55 = add nsw i64 %54, 1
  %56 = load i64, ptr %10, align 8, !tbaa !9
  %57 = load i64, ptr %11, align 8, !tbaa !9
  %58 = load i64, ptr %12, align 8, !tbaa !9
  %59 = load i64, ptr %15, align 8, !tbaa !9
  %60 = add nsw i64 %59, 1
  %61 = load i64, ptr %14, align 8, !tbaa !9
  call void @_Z6updatePxxxxxxx(ptr noundef %52, i64 noundef %55, i64 noundef %56, i64 noundef %57, i64 noundef %58, i64 noundef %60, i64 noundef %61)
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #2
  br label %62

62:                                               ; preds = %39, %32, %23
  ret void
}

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 = { 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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long long", !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 nofree nosync nounwind memory(argmem: readwrite) uwtable
define dso_local void @_Z6updatePxxxxxxx(ptr noundef %0, i64 noundef %1, i64 noundef %2, i64 noundef %3, i64 noundef %4, i64 noundef %5, i64 noundef %6) local_unnamed_addr #0 {
  %8 = icmp slt i64 %6, %2
  %9 = icmp sgt i64 %5, %3
  %or.cond38 = or i1 %8, %9
  br i1 %or.cond38, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %7
  %.not29 = icmp sgt i64 %6, %3
  br i1 %.not29, label %tailrecurse.us, label %.lr.ph.split.split

tailrecurse.us:                                   ; preds = %.lr.ph, %tailrecurse.us
  %.tr3540.us = phi i64 [ %14, %tailrecurse.us ], [ %5, %.lr.ph ]
  %.tr3139.us = phi i64 [ %13, %tailrecurse.us ], [ %1, %.lr.ph ]
  %10 = add nsw i64 %.tr3540.us, %6
  %11 = sdiv i64 %10, 2
  %12 = shl nsw i64 %.tr3139.us, 1
  tail call void @_Z6updatePxxxxxxx(ptr noundef %0, i64 noundef %12, i64 noundef %2, i64 noundef %3, i64 noundef %4, i64 noundef %.tr3540.us, i64 noundef %11)
  %13 = or disjoint i64 %12, 1
  %14 = add nsw i64 %11, 1
  %.not46 = icmp slt i64 %11, %3
  br i1 %.not46, label %tailrecurse.us, label %.loopexit

.lr.ph.split.split:                               ; preds = %.lr.ph, %tailrecurse
  %.tr3540 = phi i64 [ %22, %tailrecurse ], [ %5, %.lr.ph ]
  %.tr3139 = phi i64 [ %21, %tailrecurse ], [ %1, %.lr.ph ]
  %.not = icmp slt i64 %.tr3540, %2
  br i1 %.not, label %tailrecurse, label %.split.us

.split.us:                                        ; preds = %.lr.ph.split.split
  %15 = getelementptr inbounds i64, ptr %0, i64 %.tr3139
  %16 = load i64, ptr %15, align 8, !tbaa !5
  %17 = add nsw i64 %16, %4
  store i64 %17, ptr %15, align 8, !tbaa !5
  br label %.loopexit

tailrecurse:                                      ; preds = %.lr.ph.split.split
  %18 = add nsw i64 %.tr3540, %6
  %19 = sdiv i64 %18, 2
  %20 = shl nsw i64 %.tr3139, 1
  tail call void @_Z6updatePxxxxxxx(ptr noundef %0, i64 noundef %20, i64 noundef %2, i64 noundef %3, i64 noundef %4, i64 noundef %.tr3540, i64 noundef %19)
  %21 = or disjoint i64 %20, 1
  %22 = add nsw i64 %19, 1
  %.not45 = icmp slt i64 %19, %3
  br i1 %.not45, label %.lr.ph.split.split, label %.loopexit

.loopexit:                                        ; preds = %tailrecurse, %tailrecurse.us, %7, %.split.us
  ret void
}

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


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