; LLVM IR from ADJA/algos :: DataStructures/SegmentTree(Add-Min-Max).ll (Z3addiiiiii)

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

@tree = external dso_local global [4000400 x %struct.node], align 16

; Function Attrs: mustprogress uwtable
define dso_local void @_Z3addiiiiii(i32 noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4, i32 noundef %5) #0 {
  %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 i32, align 4
  %14 = alloca i32, align 4
  %15 = alloca i32, align 4
  %16 = alloca i32, align 4
  %17 = alloca i32, align 4
  %18 = alloca i32, align 4
  store i32 %0, ptr %7, align 4, !tbaa !5
  store i32 %1, ptr %8, align 4, !tbaa !5
  store i32 %2, ptr %9, align 4, !tbaa !5
  store i32 %3, ptr %10, align 4, !tbaa !5
  store i32 %4, ptr %11, align 4, !tbaa !5
  store i32 %5, ptr %12, align 4, !tbaa !5
  %19 = load i32, ptr %10, align 4, !tbaa !5
  %20 = load i32, ptr %11, align 4, !tbaa !5
  %21 = icmp sgt i32 %19, %20
  br i1 %21, label %22, label %23

22:                                               ; preds = %6
  br label %139

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

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

31:                                               ; preds = %27
  %32 = load i32, ptr %12, align 4, !tbaa !5
  %33 = load i32, ptr %7, align 4, !tbaa !5
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds [4000400 x %struct.node], ptr @tree, i64 0, i64 %34
  %36 = getelementptr inbounds %struct.node, ptr %35, i32 0, i32 2
  %37 = load i32, ptr %36, align 4, !tbaa !9
  %38 = add nsw i32 %37, %32
  store i32 %38, ptr %36, align 4, !tbaa !9
  br label %139

39:                                               ; preds = %27, %23
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #3
  %40 = load i32, ptr %8, align 4, !tbaa !5
  %41 = load i32, ptr %9, align 4, !tbaa !5
  %42 = load i32, ptr %8, align 4, !tbaa !5
  %43 = sub nsw i32 %41, %42
  %44 = sdiv i32 %43, 2
  %45 = add nsw i32 %40, %44
  store i32 %45, ptr %13, align 4, !tbaa !5
  %46 = load i32, ptr %7, align 4, !tbaa !5
  %47 = mul nsw i32 2, %46
  %48 = add nsw i32 %47, 1
  %49 = load i32, ptr %8, align 4, !tbaa !5
  %50 = load i32, ptr %13, align 4, !tbaa !5
  %51 = load i32, ptr %10, align 4, !tbaa !5
  %52 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %13, ptr noundef nonnull align 4 dereferenceable(4) %11)
  %53 = load i32, ptr %52, align 4, !tbaa !5
  %54 = load i32, ptr %12, align 4, !tbaa !5
  call void @_Z3addiiiiii(i32 noundef %48, i32 noundef %49, i32 noundef %50, i32 noundef %51, i32 noundef %53, i32 noundef %54)
  %55 = load i32, ptr %7, align 4, !tbaa !5
  %56 = mul nsw i32 2, %55
  %57 = add nsw i32 %56, 2
  %58 = load i32, ptr %13, align 4, !tbaa !5
  %59 = add nsw i32 %58, 1
  %60 = load i32, ptr %9, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #3
  %61 = load i32, ptr %13, align 4, !tbaa !5
  %62 = add nsw i32 %61, 1
  store i32 %62, ptr %14, align 4, !tbaa !5
  %63 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %14, ptr noundef nonnull align 4 dereferenceable(4) %10)
  %64 = load i32, ptr %63, align 4, !tbaa !5
  %65 = load i32, ptr %11, align 4, !tbaa !5
  %66 = load i32, ptr %12, align 4, !tbaa !5
  call void @_Z3addiiiiii(i32 noundef %57, i32 noundef %59, i32 noundef %60, i32 noundef %64, i32 noundef %65, i32 noundef %66)
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #3
  %67 = load i32, ptr %7, 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 [4000400 x %struct.node], ptr @tree, i64 0, i64 %70
  %72 = getelementptr inbounds %struct.node, ptr %71, i32 0, i32 0
  %73 = load i32, ptr %72, align 4, !tbaa !11
  %74 = load i32, ptr %7, align 4, !tbaa !5
  %75 = mul nsw i32 2, %74
  %76 = add nsw i32 %75, 1
  %77 = sext i32 %76 to i64
  %78 = getelementptr inbounds [4000400 x %struct.node], ptr @tree, i64 0, i64 %77
  %79 = getelementptr inbounds %struct.node, ptr %78, i32 0, i32 2
  %80 = load i32, ptr %79, align 4, !tbaa !9
  %81 = add nsw i32 %73, %80
  store i32 %81, ptr %15, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %16) #3
  %82 = load i32, ptr %7, align 4, !tbaa !5
  %83 = mul nsw i32 2, %82
  %84 = add nsw i32 %83, 2
  %85 = sext i32 %84 to i64
  %86 = getelementptr inbounds [4000400 x %struct.node], ptr @tree, i64 0, i64 %85
  %87 = getelementptr inbounds %struct.node, ptr %86, i32 0, i32 0
  %88 = load i32, ptr %87, align 4, !tbaa !11
  %89 = load i32, ptr %7, align 4, !tbaa !5
  %90 = mul nsw i32 2, %89
  %91 = add nsw i32 %90, 2
  %92 = sext i32 %91 to i64
  %93 = getelementptr inbounds [4000400 x %struct.node], ptr @tree, i64 0, i64 %92
  %94 = getelementptr inbounds %struct.node, ptr %93, i32 0, i32 2
  %95 = load i32, ptr %94, align 4, !tbaa !9
  %96 = add nsw i32 %88, %95
  store i32 %96, ptr %16, align 4, !tbaa !5
  %97 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %15, ptr noundef nonnull align 4 dereferenceable(4) %16)
  %98 = load i32, ptr %97, align 4, !tbaa !5
  %99 = load i32, ptr %7, align 4, !tbaa !5
  %100 = sext i32 %99 to i64
  %101 = getelementptr inbounds [4000400 x %struct.node], ptr @tree, i64 0, i64 %100
  %102 = getelementptr inbounds %struct.node, ptr %101, i32 0, i32 0
  store i32 %98, ptr %102, align 4, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %17) #3
  %103 = load i32, ptr %7, align 4, !tbaa !5
  %104 = mul nsw i32 2, %103
  %105 = add nsw i32 %104, 1
  %106 = sext i32 %105 to i64
  %107 = getelementptr inbounds [4000400 x %struct.node], ptr @tree, i64 0, i64 %106
  %108 = getelementptr inbounds %struct.node, ptr %107, i32 0, i32 1
  %109 = load i32, ptr %108, align 4, !tbaa !12
  %110 = load i32, ptr %7, align 4, !tbaa !5
  %111 = mul nsw i32 2, %110
  %112 = add nsw i32 %111, 1
  %113 = sext i32 %112 to i64
  %114 = getelementptr inbounds [4000400 x %struct.node], ptr @tree, i64 0, i64 %113
  %115 = getelementptr inbounds %struct.node, ptr %114, i32 0, i32 2
  %116 = load i32, ptr %115, align 4, !tbaa !9
  %117 = add nsw i32 %109, %116
  store i32 %117, ptr %17, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %18) #3
  %118 = load i32, ptr %7, align 4, !tbaa !5
  %119 = mul nsw i32 2, %118
  %120 = add nsw i32 %119, 2
  %121 = sext i32 %120 to i64
  %122 = getelementptr inbounds [4000400 x %struct.node], ptr @tree, i64 0, i64 %121
  %123 = getelementptr inbounds %struct.node, ptr %122, i32 0, i32 1
  %124 = load i32, ptr %123, align 4, !tbaa !12
  %125 = load i32, ptr %7, align 4, !tbaa !5
  %126 = mul nsw i32 2, %125
  %127 = add nsw i32 %126, 2
  %128 = sext i32 %127 to i64
  %129 = getelementptr inbounds [4000400 x %struct.node], ptr @tree, i64 0, i64 %128
  %130 = getelementptr inbounds %struct.node, ptr %129, i32 0, i32 2
  %131 = load i32, ptr %130, align 4, !tbaa !9
  %132 = add nsw i32 %124, %131
  store i32 %132, ptr %18, align 4, !tbaa !5
  %133 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %17, ptr noundef nonnull align 4 dereferenceable(4) %18)
  %134 = load i32, ptr %133, align 4, !tbaa !5
  %135 = load i32, ptr %7, align 4, !tbaa !5
  %136 = sext i32 %135 to i64
  %137 = getelementptr inbounds [4000400 x %struct.node], ptr @tree, i64 0, i64 %136
  %138 = getelementptr inbounds %struct.node, ptr %137, i32 0, i32 1
  store i32 %134, ptr %138, align 4, !tbaa !12
  call void @llvm.lifetime.end.p0(i64 4, ptr %18) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %17) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #3
  br label %139

139:                                              ; preds = %39, %31, %22
  ret void
}

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

; 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

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

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

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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, !6, i64 8}
!10 = !{!"_ZTS4node", !6, i64 0, !6, i64 4, !6, i64 8}
!11 = !{!10, !6, i64 0}
!12 = !{!10, !6, i64 4}


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

@tree = external dso_local local_unnamed_addr global [4000400 x %struct.node], align 16

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z3addiiiiii(i32 noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4, i32 noundef %5) local_unnamed_addr #0 {
  %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 i32, align 4
  %14 = alloca i32, align 4
  store i32 %3, ptr %7, align 4, !tbaa !5
  store i32 %4, ptr %8, align 4, !tbaa !5
  %15 = icmp sgt i32 %3, %4
  br i1 %15, label %65, label %16

16:                                               ; preds = %6
  %17 = icmp eq i32 %1, %3
  %18 = icmp eq i32 %2, %4
  %or.cond = and i1 %17, %18
  br i1 %or.cond, label %19, label %24

19:                                               ; preds = %16
  %20 = sext i32 %0 to i64
  %21 = getelementptr inbounds [4000400 x %struct.node], ptr @tree, i64 0, i64 %20, i32 2
  %22 = load i32, ptr %21, align 4, !tbaa !9
  %23 = add nsw i32 %22, %5
  store i32 %23, ptr %21, align 4, !tbaa !9
  br label %65

24:                                               ; preds = %16
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %9) #3
  %25 = sub nsw i32 %2, %1
  %26 = sdiv i32 %25, 2
  %27 = add nsw i32 %26, %1
  store i32 %27, ptr %9, align 4, !tbaa !5
  %28 = shl nsw i32 %0, 1
  %29 = or disjoint i32 %28, 1
  %30 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %9, ptr noundef nonnull align 4 dereferenceable(4) %8)
  %31 = load i32, ptr %30, align 4, !tbaa !5
  call void @_Z3addiiiiii(i32 noundef %29, i32 noundef %1, i32 noundef %27, i32 noundef %3, i32 noundef %31, i32 noundef %5)
  %32 = add nsw i32 %28, 2
  %33 = load i32, ptr %9, align 4, !tbaa !5
  %34 = add nsw i32 %33, 1
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %10) #3
  store i32 %34, ptr %10, align 4, !tbaa !5
  %35 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %10, ptr noundef nonnull align 4 dereferenceable(4) %7)
  %36 = load i32, ptr %35, align 4, !tbaa !5
  %37 = load i32, ptr %8, align 4, !tbaa !5
  call void @_Z3addiiiiii(i32 noundef %32, i32 noundef %34, i32 noundef %2, i32 noundef %36, i32 noundef %37, i32 noundef %5)
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %10) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %11) #3
  %38 = sext i32 %29 to i64
  %39 = getelementptr inbounds [4000400 x %struct.node], ptr @tree, i64 0, i64 %38
  %40 = load i32, ptr %39, align 4, !tbaa !11
  %41 = getelementptr inbounds i8, ptr %39, i64 8
  %42 = load i32, ptr %41, align 4, !tbaa !9
  %43 = add nsw i32 %42, %40
  store i32 %43, ptr %11, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %12) #3
  %44 = sext i32 %32 to i64
  %45 = getelementptr inbounds [4000400 x %struct.node], ptr @tree, i64 0, i64 %44
  %46 = load i32, ptr %45, align 8, !tbaa !11
  %47 = getelementptr inbounds i8, ptr %45, i64 8
  %48 = load i32, ptr %47, align 8, !tbaa !9
  %49 = add nsw i32 %48, %46
  store i32 %49, ptr %12, align 4, !tbaa !5
  %50 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %11, ptr noundef nonnull align 4 dereferenceable(4) %12)
  %51 = load i32, ptr %50, align 4, !tbaa !5
  %52 = sext i32 %0 to i64
  %53 = getelementptr inbounds [4000400 x %struct.node], ptr @tree, i64 0, i64 %52
  store i32 %51, ptr %53, align 4, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %12) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %11) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %13) #3
  %54 = getelementptr inbounds i8, ptr %39, i64 4
  %55 = load i32, ptr %54, align 8, !tbaa !12
  %56 = load i32, ptr %41, align 4, !tbaa !9
  %57 = add nsw i32 %56, %55
  store i32 %57, ptr %13, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %14) #3
  %58 = getelementptr inbounds i8, ptr %45, i64 4
  %59 = load i32, ptr %58, align 4, !tbaa !12
  %60 = load i32, ptr %47, align 8, !tbaa !9
  %61 = add nsw i32 %60, %59
  store i32 %61, ptr %14, align 4, !tbaa !5
  %62 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %13, ptr noundef nonnull align 4 dereferenceable(4) %14)
  %63 = load i32, ptr %62, align 4, !tbaa !5
  %64 = getelementptr inbounds i8, ptr %53, i64 4
  store i32 %63, ptr %64, align 4, !tbaa !12
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %14) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %13) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %9) #3
  br label %65

65:                                               ; preds = %6, %24, %19
  ret void
}

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

; 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 #2

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

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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, !6, i64 8}
!10 = !{!"_ZTS4node", !6, i64 0, !6, i64 4, !6, i64 8}
!11 = !{!10, !6, i64 0}
!12 = !{!10, !6, i64 4}


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