; LLVM IR from ncduy0303/Competitive-Programming :: Data Structures/Segment Tree/Segment Tree (Lazy Propagation).ll (Z5queryiiiii)

; 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.tdata = type <{ i64, i64, i64, i8, [7 x i8] }>

@st = external dso_local global [800004 x %struct.tdata], align 16

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN5tdataC2Ex(ptr noundef nonnull align 8 dereferenceable(25), i64 noundef) unnamed_addr #1 align 2

; 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) #0

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

; Function Attrs: mustprogress uwtable
define dso_local void @_Z5queryiiiii(ptr dead_on_unwind noalias writable sret(%struct.tdata) align 8 %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4, i32 noundef %5) #3 {
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca %struct.tdata, align 8
  %14 = alloca %struct.tdata, align 8
  store i32 %1, ptr %7, align 4, !tbaa !5
  store i32 %2, ptr %8, align 4, !tbaa !5
  store i32 %3, ptr %9, align 4, !tbaa !5
  store i32 %4, ptr %10, align 4, !tbaa !5
  store i32 %5, ptr %11, align 4, !tbaa !5
  %15 = load i32, ptr %11, align 4, !tbaa !5
  %16 = load i32, ptr %8, align 4, !tbaa !5
  %17 = icmp slt i32 %15, %16
  br i1 %17, label %22, label %18

18:                                               ; preds = %6
  %19 = load i32, ptr %9, align 4, !tbaa !5
  %20 = load i32, ptr %10, align 4, !tbaa !5
  %21 = icmp slt i32 %19, %20
  br i1 %21, label %22, label %23

22:                                               ; preds = %18, %6
  call void @_ZN5tdataC2Ex(ptr noundef nonnull align 8 dereferenceable(25) %0, i64 noundef 0)
  br label %57

23:                                               ; preds = %18
  %24 = load i32, ptr %10, align 4, !tbaa !5
  %25 = load i32, ptr %8, align 4, !tbaa !5
  %26 = icmp sle i32 %24, %25
  br i1 %26, label %27, label %35

27:                                               ; preds = %23
  %28 = load i32, ptr %9, align 4, !tbaa !5
  %29 = load i32, ptr %11, align 4, !tbaa !5
  %30 = icmp sle i32 %28, %29
  br i1 %30, label %31, label %35

31:                                               ; preds = %27
  %32 = load i32, ptr %7, align 4, !tbaa !5
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds [800004 x %struct.tdata], ptr @st, i64 0, i64 %33
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %0, ptr align 16 %34, i64 32, i1 false), !tbaa.struct !9
  br label %57

35:                                               ; preds = %27, %23
  %36 = load i32, ptr %7, align 4, !tbaa !5
  %37 = load i32, ptr %8, align 4, !tbaa !5
  %38 = load i32, ptr %9, align 4, !tbaa !5
  call void @_Z4downiii(i32 noundef %36, i32 noundef %37, i32 noundef %38)
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #4
  %39 = load i32, ptr %8, align 4, !tbaa !5
  %40 = load i32, ptr %9, align 4, !tbaa !5
  %41 = add nsw i32 %39, %40
  %42 = sdiv i32 %41, 2
  store i32 %42, ptr %12, align 4, !tbaa !5
  %43 = load i32, ptr %7, align 4, !tbaa !5
  %44 = mul nsw i32 2, %43
  %45 = load i32, ptr %8, align 4, !tbaa !5
  %46 = load i32, ptr %12, align 4, !tbaa !5
  %47 = load i32, ptr %10, align 4, !tbaa !5
  %48 = load i32, ptr %11, align 4, !tbaa !5
  call void @_Z5queryiiiii(ptr dead_on_unwind writable sret(%struct.tdata) align 8 %13, i32 noundef %44, i32 noundef %45, i32 noundef %46, i32 noundef %47, i32 noundef %48)
  %49 = load i32, ptr %7, align 4, !tbaa !5
  %50 = mul nsw i32 2, %49
  %51 = add nsw i32 %50, 1
  %52 = load i32, ptr %12, align 4, !tbaa !5
  %53 = add nsw i32 %52, 1
  %54 = load i32, ptr %9, align 4, !tbaa !5
  %55 = load i32, ptr %10, align 4, !tbaa !5
  %56 = load i32, ptr %11, align 4, !tbaa !5
  call void @_Z5queryiiiii(ptr dead_on_unwind writable sret(%struct.tdata) align 8 %14, i32 noundef %51, i32 noundef %53, i32 noundef %54, i32 noundef %55, i32 noundef %56)
  call void @_ZN5tdataC2ES_S_(ptr noundef nonnull align 8 dereferenceable(25) %0, ptr noundef byval(%struct.tdata) align 8 %13, ptr noundef byval(%struct.tdata) align 8 %14)
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #4
  br label %57

57:                                               ; preds = %35, %31, %22
  ret void
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN5tdataC2ES_S_(ptr noundef nonnull align 8 dereferenceable(25), ptr noundef byval(%struct.tdata) align 8, ptr noundef byval(%struct.tdata) align 8) unnamed_addr #1 align 2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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" }
attributes #2 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 #4 = { 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 = !{i64 0, i64 8, !10, i64 8, i64 8, !10, i64 16, i64 8, !10, i64 24, i64 1, !12}
!10 = !{!11, !11, i64 0}
!11 = !{!"long long", !7, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"bool", !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"

%struct.tdata = type <{ i64, i64, i64, i8, [7 x i8] }>

@st = external dso_local local_unnamed_addr global [800004 x %struct.tdata], align 16

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN5tdataC2Ex(ptr noundef nonnull align 8 dereferenceable(25), i64 noundef) unnamed_addr #0 align 2

; Function Attrs: mustprogress 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) #1

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z5queryiiiii(ptr dead_on_unwind noalias writable sret(%struct.tdata) align 8 %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4, i32 noundef %5) local_unnamed_addr #0 {
  %7 = alloca %struct.tdata, align 8
  %8 = alloca %struct.tdata, align 8
  %9 = icmp slt i32 %5, %2
  %10 = icmp slt i32 %3, %4
  %or.cond = or i1 %10, %9
  br i1 %or.cond, label %11, label %12

11:                                               ; preds = %6
  tail call void @_ZN5tdataC2Ex(ptr noundef nonnull align 8 dereferenceable(25) %0, i64 noundef 0)
  br label %22

12:                                               ; preds = %6
  %.not = icmp sgt i32 %4, %2
  %.not27 = icmp sgt i32 %3, %5
  %or.cond28 = or i1 %.not, %.not27
  br i1 %or.cond28, label %16, label %13

13:                                               ; preds = %12
  %14 = sext i32 %1 to i64
  %15 = getelementptr inbounds [800004 x %struct.tdata], ptr @st, i64 0, i64 %14
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(32) %0, ptr noundef nonnull align 16 dereferenceable(32) %15, i64 32, i1 false), !tbaa.struct !5
  br label %22

16:                                               ; preds = %12
  tail call void @_Z4downiii(i32 noundef %1, i32 noundef %2, i32 noundef %3)
  %17 = add nsw i32 %3, %2
  %18 = sdiv i32 %17, 2
  %19 = shl nsw i32 %1, 1
  call void @_Z5queryiiiii(ptr dead_on_unwind nonnull writable sret(%struct.tdata) align 8 %7, i32 noundef %19, i32 noundef %2, i32 noundef %18, i32 noundef %4, i32 noundef %5)
  %20 = or disjoint i32 %19, 1
  %21 = add nsw i32 %18, 1
  call void @_Z5queryiiiii(ptr dead_on_unwind nonnull writable sret(%struct.tdata) align 8 %8, i32 noundef %20, i32 noundef %21, i32 noundef %3, i32 noundef %4, i32 noundef %5)
  call void @_ZN5tdataC2ES_S_(ptr noundef nonnull align 8 dereferenceable(25) %0, ptr noundef nonnull byval(%struct.tdata) align 8 %7, ptr noundef nonnull byval(%struct.tdata) align 8 %8)
  br label %22

22:                                               ; preds = %16, %13, %11
  ret void
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN5tdataC2ES_S_(ptr noundef nonnull align 8 dereferenceable(25), ptr noundef byval(%struct.tdata) align 8, ptr noundef byval(%struct.tdata) align 8) unnamed_addr #0 align 2

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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }

!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 = !{i64 0, i64 8, !6, i64 8, i64 8, !6, i64 16, i64 8, !6, i64 24, i64 1, !10}
!6 = !{!7, !7, i64 0}
!7 = !{!"long long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!11, !11, i64 0}
!11 = !{!"bool", !8, i64 0}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass