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

; 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: 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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z4downiii(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
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  %8 = load i32, ptr %5, align 4, !tbaa !5
  %9 = load i32, ptr %6, align 4, !tbaa !5
  %10 = add nsw i32 %8, %9
  %11 = sdiv i32 %10, 2
  store i32 %11, ptr %7, align 4, !tbaa !5
  %12 = load i32, ptr %4, align 4, !tbaa !5
  %13 = sext i32 %12 to i64
  %14 = getelementptr inbounds [800004 x %struct.tdata], ptr @st, i64 0, i64 %13
  %15 = getelementptr inbounds %struct.tdata, ptr %14, i32 0, i32 3
  %16 = load i8, ptr %15, align 8, !tbaa !9, !range !13, !noundef !14
  %17 = trunc i8 %16 to i1
  br i1 %17, label %18, label %75

18:                                               ; preds = %3
  %19 = load i32, ptr %4, align 4, !tbaa !5
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds [800004 x %struct.tdata], ptr @st, i64 0, i64 %20
  %22 = load i32, ptr %4, align 4, !tbaa !5
  %23 = mul nsw i32 2, %22
  %24 = add nsw i32 %23, 1
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds [800004 x %struct.tdata], ptr @st, i64 0, i64 %25
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %26, ptr align 16 %21, i64 25, i1 false), !tbaa.struct !15
  %27 = load i32, ptr %4, align 4, !tbaa !5
  %28 = mul nsw i32 2, %27
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds [800004 x %struct.tdata], ptr @st, i64 0, i64 %29
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %30, ptr align 8 %26, i64 25, i1 false), !tbaa.struct !15
  %31 = load i32, ptr %4, align 4, !tbaa !5
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds [800004 x %struct.tdata], ptr @st, i64 0, i64 %32
  %34 = getelementptr inbounds %struct.tdata, ptr %33, i32 0, i32 1
  %35 = load i64, ptr %34, align 8, !tbaa !18
  %36 = load i32, ptr %4, align 4, !tbaa !5
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds [800004 x %struct.tdata], ptr @st, i64 0, i64 %37
  %39 = getelementptr inbounds %struct.tdata, ptr %38, i32 0, i32 2
  %40 = load i64, ptr %39, align 16, !tbaa !19
  %41 = add nsw i64 %35, %40
  %42 = load i32, ptr %7, align 4, !tbaa !5
  %43 = load i32, ptr %5, align 4, !tbaa !5
  %44 = sub nsw i32 %42, %43
  %45 = add nsw i32 %44, 1
  %46 = sext i32 %45 to i64
  %47 = mul nsw i64 %41, %46
  %48 = load i32, ptr %4, align 4, !tbaa !5
  %49 = mul nsw i32 2, %48
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds [800004 x %struct.tdata], ptr @st, i64 0, i64 %50
  %52 = getelementptr inbounds %struct.tdata, ptr %51, i32 0, i32 0
  store i64 %47, ptr %52, align 16, !tbaa !20
  %53 = load i32, ptr %4, align 4, !tbaa !5
  %54 = sext i32 %53 to i64
  %55 = getelementptr inbounds [800004 x %struct.tdata], ptr @st, i64 0, i64 %54
  %56 = getelementptr inbounds %struct.tdata, ptr %55, i32 0, i32 1
  %57 = load i64, ptr %56, align 8, !tbaa !18
  %58 = load i32, ptr %4, align 4, !tbaa !5
  %59 = sext i32 %58 to i64
  %60 = getelementptr inbounds [800004 x %struct.tdata], ptr @st, i64 0, i64 %59
  %61 = getelementptr inbounds %struct.tdata, ptr %60, i32 0, i32 2
  %62 = load i64, ptr %61, align 16, !tbaa !19
  %63 = add nsw i64 %57, %62
  %64 = load i32, ptr %6, align 4, !tbaa !5
  %65 = load i32, ptr %7, align 4, !tbaa !5
  %66 = sub nsw i32 %64, %65
  %67 = sext i32 %66 to i64
  %68 = mul nsw i64 %63, %67
  %69 = load i32, ptr %4, align 4, !tbaa !5
  %70 = mul nsw i32 2, %69
  %71 = add nsw i32 %70, 1
  %72 = sext i32 %71 to i64
  %73 = getelementptr inbounds [800004 x %struct.tdata], ptr @st, i64 0, i64 %72
  %74 = getelementptr inbounds %struct.tdata, ptr %73, i32 0, i32 0
  store i64 %68, ptr %74, align 16, !tbaa !20
  br label %137

75:                                               ; preds = %3
  %76 = load i32, ptr %4, align 4, !tbaa !5
  %77 = sext i32 %76 to i64
  %78 = getelementptr inbounds [800004 x %struct.tdata], ptr @st, i64 0, i64 %77
  %79 = getelementptr inbounds %struct.tdata, ptr %78, i32 0, i32 2
  %80 = load i64, ptr %79, align 16, !tbaa !19
  %81 = load i32, ptr %4, align 4, !tbaa !5
  %82 = mul nsw i32 2, %81
  %83 = sext i32 %82 to i64
  %84 = getelementptr inbounds [800004 x %struct.tdata], ptr @st, i64 0, i64 %83
  %85 = getelementptr inbounds %struct.tdata, ptr %84, i32 0, i32 2
  %86 = load i64, ptr %85, align 16, !tbaa !19
  %87 = add nsw i64 %86, %80
  store i64 %87, ptr %85, align 16, !tbaa !19
  %88 = load i32, ptr %4, align 4, !tbaa !5
  %89 = sext i32 %88 to i64
  %90 = getelementptr inbounds [800004 x %struct.tdata], ptr @st, i64 0, i64 %89
  %91 = getelementptr inbounds %struct.tdata, ptr %90, i32 0, i32 2
  %92 = load i64, ptr %91, align 16, !tbaa !19
  %93 = load i32, ptr %4, align 4, !tbaa !5
  %94 = mul nsw i32 2, %93
  %95 = add nsw i32 %94, 1
  %96 = sext i32 %95 to i64
  %97 = getelementptr inbounds [800004 x %struct.tdata], ptr @st, i64 0, i64 %96
  %98 = getelementptr inbounds %struct.tdata, ptr %97, i32 0, i32 2
  %99 = load i64, ptr %98, align 16, !tbaa !19
  %100 = add nsw i64 %99, %92
  store i64 %100, ptr %98, align 16, !tbaa !19
  %101 = load i32, ptr %4, align 4, !tbaa !5
  %102 = sext i32 %101 to i64
  %103 = getelementptr inbounds [800004 x %struct.tdata], ptr @st, i64 0, i64 %102
  %104 = getelementptr inbounds %struct.tdata, ptr %103, i32 0, i32 2
  %105 = load i64, ptr %104, align 16, !tbaa !19
  %106 = load i32, ptr %7, align 4, !tbaa !5
  %107 = load i32, ptr %5, align 4, !tbaa !5
  %108 = sub nsw i32 %106, %107
  %109 = add nsw i32 %108, 1
  %110 = sext i32 %109 to i64
  %111 = mul nsw i64 %105, %110
  %112 = load i32, ptr %4, align 4, !tbaa !5
  %113 = mul nsw i32 2, %112
  %114 = sext i32 %113 to i64
  %115 = getelementptr inbounds [800004 x %struct.tdata], ptr @st, i64 0, i64 %114
  %116 = getelementptr inbounds %struct.tdata, ptr %115, i32 0, i32 0
  %117 = load i64, ptr %116, align 16, !tbaa !20
  %118 = add nsw i64 %117, %111
  store i64 %118, ptr %116, align 16, !tbaa !20
  %119 = load i32, ptr %4, align 4, !tbaa !5
  %120 = sext i32 %119 to i64
  %121 = getelementptr inbounds [800004 x %struct.tdata], ptr @st, i64 0, i64 %120
  %122 = getelementptr inbounds %struct.tdata, ptr %121, i32 0, i32 2
  %123 = load i64, ptr %122, align 16, !tbaa !19
  %124 = load i32, ptr %6, align 4, !tbaa !5
  %125 = load i32, ptr %7, align 4, !tbaa !5
  %126 = sub nsw i32 %124, %125
  %127 = sext i32 %126 to i64
  %128 = mul nsw i64 %123, %127
  %129 = load i32, ptr %4, align 4, !tbaa !5
  %130 = mul nsw i32 2, %129
  %131 = add nsw i32 %130, 1
  %132 = sext i32 %131 to i64
  %133 = getelementptr inbounds [800004 x %struct.tdata], ptr @st, i64 0, i64 %132
  %134 = getelementptr inbounds %struct.tdata, ptr %133, i32 0, i32 0
  %135 = load i64, ptr %134, align 16, !tbaa !20
  %136 = add nsw i64 %135, %128
  store i64 %136, ptr %134, align 16, !tbaa !20
  br label %137

137:                                              ; preds = %75, %18
  %138 = load i32, ptr %4, align 4, !tbaa !5
  %139 = sext i32 %138 to i64
  %140 = getelementptr inbounds [800004 x %struct.tdata], ptr @st, i64 0, i64 %139
  %141 = getelementptr inbounds %struct.tdata, ptr %140, i32 0, i32 3
  store i8 0, ptr %141, align 8, !tbaa !9
  %142 = load i32, ptr %4, align 4, !tbaa !5
  %143 = sext i32 %142 to i64
  %144 = getelementptr inbounds [800004 x %struct.tdata], ptr @st, i64 0, i64 %143
  %145 = getelementptr inbounds %struct.tdata, ptr %144, i32 0, i32 1
  store i64 0, ptr %145, align 8, !tbaa !18
  %146 = load i32, ptr %4, align 4, !tbaa !5
  %147 = sext i32 %146 to i64
  %148 = getelementptr inbounds [800004 x %struct.tdata], ptr @st, i64 0, i64 %147
  %149 = getelementptr inbounds %struct.tdata, ptr %148, i32 0, i32 2
  store i64 0, ptr %149, align 16, !tbaa !19
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  ret void
}

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

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(readwrite, argmem: none, inaccessiblemem: none) uwtable
define dso_local void @_Z4downiii(i32 noundef %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #1 {
  %4 = add nsw i32 %2, %1
  %5 = sdiv i32 %4, 2
  %6 = sext i32 %0 to i64
  %7 = getelementptr inbounds [800004 x %struct.tdata], ptr @st, i64 0, i64 %6
  %8 = getelementptr inbounds i8, ptr %7, i64 24
  %9 = load i8, ptr %8, align 8, !tbaa !5, !range !11, !noundef !12
  %10 = trunc nuw i8 %9 to i1
  br i1 %10, label %11, label %29

11:                                               ; preds = %3
  %12 = shl nsw i32 %0, 1
  %13 = or disjoint i32 %12, 1
  %14 = sext i32 %13 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 16 dereferenceable(25) %15, ptr noundef nonnull align 16 dereferenceable(25) %7, i64 25, i1 false), !tbaa.struct !13
  %16 = sext i32 %12 to i64
  %17 = getelementptr inbounds [800004 x %struct.tdata], ptr @st, i64 0, i64 %16
  tail call void @llvm.memmove.p0.p0.i64(ptr noundef nonnull align 16 dereferenceable(25) %17, ptr noundef nonnull align 16 dereferenceable(25) %7, i64 25, i1 false)
  %18 = getelementptr inbounds i8, ptr %7, i64 8
  %19 = load i64, ptr %18, align 8, !tbaa !16
  %20 = getelementptr inbounds i8, ptr %7, i64 16
  %21 = load i64, ptr %20, align 16, !tbaa !17
  %22 = add nsw i64 %21, %19
  %reass.sub31 = sub i32 %5, %1
  %23 = add i32 %reass.sub31, 1
  %24 = sext i32 %23 to i64
  %25 = mul nsw i64 %22, %24
  store i64 %25, ptr %17, align 16, !tbaa !18
  %26 = sub nsw i32 %2, %5
  %27 = sext i32 %26 to i64
  %28 = mul nsw i64 %22, %27
  store i64 %28, ptr %15, align 16, !tbaa !18
  br label %56

29:                                               ; preds = %3
  %30 = getelementptr inbounds i8, ptr %7, i64 16
  %31 = load i64, ptr %30, align 16, !tbaa !17
  %32 = shl nsw i32 %0, 1
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds [800004 x %struct.tdata], ptr @st, i64 0, i64 %33
  %35 = getelementptr inbounds i8, ptr %34, i64 16
  %36 = load i64, ptr %35, align 16, !tbaa !17
  %37 = add nsw i64 %36, %31
  store i64 %37, ptr %35, align 16, !tbaa !17
  %38 = load i64, ptr %30, align 16, !tbaa !17
  %39 = or disjoint i32 %32, 1
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds [800004 x %struct.tdata], ptr @st, i64 0, i64 %40
  %42 = getelementptr inbounds i8, ptr %41, i64 16
  %43 = load i64, ptr %42, align 16, !tbaa !17
  %44 = add nsw i64 %43, %38
  store i64 %44, ptr %42, align 16, !tbaa !17
  %45 = load i64, ptr %30, align 16, !tbaa !17
  %reass.sub = sub i32 %5, %1
  %46 = add i32 %reass.sub, 1
  %47 = sext i32 %46 to i64
  %48 = mul nsw i64 %45, %47
  %49 = load i64, ptr %34, align 16, !tbaa !18
  %50 = add nsw i64 %49, %48
  store i64 %50, ptr %34, align 16, !tbaa !18
  %51 = sub nsw i32 %2, %5
  %52 = sext i32 %51 to i64
  %53 = mul nsw i64 %45, %52
  %54 = load i64, ptr %41, align 16, !tbaa !18
  %55 = add nsw i64 %54, %53
  store i64 %55, ptr %41, align 16, !tbaa !18
  br label %56

56:                                               ; preds = %29, %11
  %57 = getelementptr inbounds i8, ptr %7, i64 8
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(17) %57, i8 0, i64 17, i1 false)
  ret void
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memmove.p0.p0.i64(ptr nocapture writeonly, ptr nocapture readonly, i64, i1 immarg) #2

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

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

!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, !10, i64 24}
!6 = !{!"_ZTS5tdata", !7, i64 0, !7, i64 8, !7, i64 16, !10, i64 24}
!7 = !{!"long long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"bool", !8, i64 0}
!11 = !{i8 0, i8 2}
!12 = !{}
!13 = !{i64 0, i64 8, !14, i64 8, i64 8, !14, i64 16, i64 8, !14, i64 24, i64 1, !15}
!14 = !{!7, !7, i64 0}
!15 = !{!10, !10, i64 0}
!16 = !{!6, !7, i64 8}
!17 = !{!6, !7, i64 16}
!18 = !{!6, !7, i64 0}


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