; LLVM IR from upupming/algorithm :: acwing/算法竞赛进阶指南/0x43-线段树/247. 亚特兰蒂斯.ll (Z6pushupi)

; 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.SegmentTree = type { i32, i32, i32, double }

@raw = external dso_local global [20020 x double], align 16
@tree = external dso_local global [80080 x %struct.SegmentTree], align 16

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z6pushupi(i32 noundef %0) #0 {
  %2 = alloca i32, align 4
  store i32 %0, ptr %2, align 4, !tbaa !5
  %3 = load i32, ptr %2, align 4, !tbaa !5
  %4 = sext i32 %3 to i64
  %5 = getelementptr inbounds [80080 x %struct.SegmentTree], ptr @tree, i64 0, i64 %4
  %6 = getelementptr inbounds %struct.SegmentTree, ptr %5, i32 0, i32 2
  %7 = load i32, ptr %6, align 8, !tbaa !9
  %8 = icmp sgt i32 %7, 0
  br i1 %8, label %9, label %32

9:                                                ; preds = %1
  %10 = load i32, ptr %2, align 4, !tbaa !5
  %11 = sext i32 %10 to i64
  %12 = getelementptr inbounds [80080 x %struct.SegmentTree], ptr @tree, i64 0, i64 %11
  %13 = getelementptr inbounds %struct.SegmentTree, ptr %12, i32 0, i32 1
  %14 = load i32, ptr %13, align 4, !tbaa !12
  %15 = add nsw i32 %14, 1
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds [20020 x double], ptr @raw, i64 0, i64 %16
  %18 = load double, ptr %17, align 8, !tbaa !13
  %19 = load i32, ptr %2, align 4, !tbaa !5
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds [80080 x %struct.SegmentTree], ptr @tree, i64 0, i64 %20
  %22 = getelementptr inbounds %struct.SegmentTree, ptr %21, i32 0, i32 0
  %23 = load i32, ptr %22, align 8, !tbaa !14
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds [20020 x double], ptr @raw, i64 0, i64 %24
  %26 = load double, ptr %25, align 8, !tbaa !13
  %27 = fsub double %18, %26
  %28 = load i32, ptr %2, align 4, !tbaa !5
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds [80080 x %struct.SegmentTree], ptr @tree, i64 0, i64 %29
  %31 = getelementptr inbounds %struct.SegmentTree, ptr %30, i32 0, i32 3
  store double %27, ptr %31, align 8, !tbaa !15
  br label %69

32:                                               ; preds = %1
  %33 = load i32, ptr %2, align 4, !tbaa !5
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds [80080 x %struct.SegmentTree], ptr @tree, i64 0, i64 %34
  %36 = getelementptr inbounds %struct.SegmentTree, ptr %35, i32 0, i32 0
  %37 = load i32, ptr %36, align 8, !tbaa !14
  %38 = load i32, ptr %2, align 4, !tbaa !5
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds [80080 x %struct.SegmentTree], ptr @tree, i64 0, i64 %39
  %41 = getelementptr inbounds %struct.SegmentTree, ptr %40, i32 0, i32 1
  %42 = load i32, ptr %41, align 4, !tbaa !12
  %43 = icmp eq i32 %37, %42
  br i1 %43, label %44, label %49

44:                                               ; preds = %32
  %45 = load i32, ptr %2, align 4, !tbaa !5
  %46 = sext i32 %45 to i64
  %47 = getelementptr inbounds [80080 x %struct.SegmentTree], ptr @tree, i64 0, i64 %46
  %48 = getelementptr inbounds %struct.SegmentTree, ptr %47, i32 0, i32 3
  store double 0.000000e+00, ptr %48, align 8, !tbaa !15
  br label %68

49:                                               ; preds = %32
  %50 = load i32, ptr %2, align 4, !tbaa !5
  %51 = mul nsw i32 2, %50
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds [80080 x %struct.SegmentTree], ptr @tree, i64 0, i64 %52
  %54 = getelementptr inbounds %struct.SegmentTree, ptr %53, i32 0, i32 3
  %55 = load double, ptr %54, align 8, !tbaa !15
  %56 = load i32, ptr %2, align 4, !tbaa !5
  %57 = mul nsw i32 2, %56
  %58 = add nsw i32 %57, 1
  %59 = sext i32 %58 to i64
  %60 = getelementptr inbounds [80080 x %struct.SegmentTree], ptr @tree, i64 0, i64 %59
  %61 = getelementptr inbounds %struct.SegmentTree, ptr %60, i32 0, i32 3
  %62 = load double, ptr %61, align 8, !tbaa !15
  %63 = fadd double %55, %62
  %64 = load i32, ptr %2, align 4, !tbaa !5
  %65 = sext i32 %64 to i64
  %66 = getelementptr inbounds [80080 x %struct.SegmentTree], ptr @tree, i64 0, i64 %65
  %67 = getelementptr inbounds %struct.SegmentTree, ptr %66, i32 0, i32 3
  store double %63, ptr %67, align 8, !tbaa !15
  br label %68

68:                                               ; preds = %49, %44
  br label %69

69:                                               ; preds = %68, %9
  ret void
}

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

!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 = !{!"_ZTS11SegmentTree", !6, i64 0, !6, i64 4, !6, i64 8, !11, i64 16}
!11 = !{!"double", !7, i64 0}
!12 = !{!10, !6, i64 4}
!13 = !{!11, !11, i64 0}
!14 = !{!10, !6, i64 0}
!15 = !{!10, !11, i64 16}


; 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.SegmentTree = type { i32, i32, i32, double }

@raw = external dso_local local_unnamed_addr global [20020 x double], align 16
@tree = external dso_local local_unnamed_addr global [80080 x %struct.SegmentTree], align 16

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(readwrite, argmem: none, inaccessiblemem: none) uwtable
define dso_local void @_Z6pushupi(i32 noundef %0) local_unnamed_addr #0 {
  %2 = sext i32 %0 to i64
  %3 = getelementptr inbounds [80080 x %struct.SegmentTree], ptr @tree, i64 0, i64 %2
  %4 = getelementptr inbounds i8, ptr %3, i64 8
  %5 = load i32, ptr %4, align 8, !tbaa !5
  %6 = icmp sgt i32 %5, 0
  br i1 %6, label %7, label %19

7:                                                ; preds = %1
  %8 = getelementptr inbounds i8, ptr %3, i64 4
  %9 = load i32, ptr %8, align 4, !tbaa !11
  %10 = add nsw i32 %9, 1
  %11 = sext i32 %10 to i64
  %12 = getelementptr inbounds [20020 x double], ptr @raw, i64 0, i64 %11
  %13 = load double, ptr %12, align 8, !tbaa !12
  %14 = load i32, ptr %3, align 8, !tbaa !13
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds [20020 x double], ptr @raw, i64 0, i64 %15
  %17 = load double, ptr %16, align 8, !tbaa !12
  %18 = fsub double %13, %17
  br label %34

19:                                               ; preds = %1
  %20 = load i32, ptr %3, align 8, !tbaa !13
  %21 = getelementptr inbounds i8, ptr %3, i64 4
  %22 = load i32, ptr %21, align 4, !tbaa !11
  %23 = icmp eq i32 %20, %22
  br i1 %23, label %34, label %24

24:                                               ; preds = %19
  %25 = shl nsw i32 %0, 1
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds [80080 x %struct.SegmentTree], ptr @tree, i64 0, i64 %26, i32 3
  %28 = load double, ptr %27, align 16, !tbaa !14
  %29 = or disjoint i32 %25, 1
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [80080 x %struct.SegmentTree], ptr @tree, i64 0, i64 %30, i32 3
  %32 = load double, ptr %31, align 8, !tbaa !14
  %33 = fadd double %28, %32
  br label %34

34:                                               ; preds = %19, %24, %7
  %.sink = phi double [ %33, %24 ], [ %18, %7 ], [ 0.000000e+00, %19 ]
  %35 = getelementptr inbounds i8, ptr %3, i64 16
  store double %.sink, ptr %35, align 8, !tbaa !14
  ret void
}

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

!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, !7, i64 8}
!6 = !{!"_ZTS11SegmentTree", !7, i64 0, !7, i64 4, !7, i64 8, !10, i64 16}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"double", !8, i64 0}
!11 = !{!6, !7, i64 4}
!12 = !{!10, !10, i64 0}
!13 = !{!6, !7, i64 0}
!14 = !{!6, !10, i64 16}


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