; LLVM IR from lzyrapx/Competitive-Programming :: LibreOJ/106（Splay）（104基础上加区间）.ll (Z7InsertYRii)

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

@qc = external dso_local global i32, align 4
@tot = external dso_local global i32, align 4
@fa = external dso_local global [1500300 x i32], align 16
@val = external dso_local global [1500300 x i32], align 16
@size = external dso_local global [1500300 x i32], align 16
@tree = external dso_local global [1500300 x [2 x i32]], align 16

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

; Function Attrs: mustprogress uwtable
define dso_local void @_Z7InsertYRii(ptr noundef nonnull align 4 dereferenceable(4) %0, i32 noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !9
  %5 = load ptr, ptr %3, align 8, !tbaa !5
  %6 = load i32, ptr %5, align 4, !tbaa !9
  %7 = icmp ne i32 %6, 0
  br i1 %7, label %26, label %8

8:                                                ; preds = %2
  %9 = load i32, ptr @tot, align 4, !tbaa !9
  %10 = add nsw i32 %9, 1
  store i32 %10, ptr @tot, align 4, !tbaa !9
  %11 = load ptr, ptr %3, align 8, !tbaa !5
  store i32 %10, ptr %11, align 4, !tbaa !9
  %12 = load ptr, ptr %3, align 8, !tbaa !5
  %13 = load i32, ptr %12, align 4, !tbaa !9
  %14 = sext i32 %13 to i64
  %15 = getelementptr inbounds [1500300 x i32], ptr @size, i64 0, i64 %14
  store i32 1, ptr %15, align 4, !tbaa !9
  %16 = load i32, ptr @qc, align 4, !tbaa !9
  %17 = load ptr, ptr %3, align 8, !tbaa !5
  %18 = load i32, ptr %17, align 4, !tbaa !9
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds [1500300 x i32], ptr @val, i64 0, i64 %19
  store i32 %16, ptr %20, align 4, !tbaa !9
  %21 = load i32, ptr %4, align 4, !tbaa !9
  %22 = load ptr, ptr %3, align 8, !tbaa !5
  %23 = load i32, ptr %22, align 4, !tbaa !9
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds [1500300 x i32], ptr @fa, i64 0, i64 %24
  store i32 %21, ptr %25, align 4, !tbaa !9
  br label %53

26:                                               ; preds = %2
  %27 = load i32, ptr @qc, align 4, !tbaa !9
  %28 = load ptr, ptr %3, align 8, !tbaa !5
  %29 = load i32, ptr %28, align 4, !tbaa !9
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [1500300 x i32], ptr @val, i64 0, i64 %30
  %32 = load i32, ptr %31, align 4, !tbaa !9
  %33 = icmp sle i32 %27, %32
  br i1 %33, label %34, label %42

34:                                               ; preds = %26
  %35 = load ptr, ptr %3, align 8, !tbaa !5
  %36 = load i32, ptr %35, align 4, !tbaa !9
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds [1500300 x [2 x i32]], ptr @tree, i64 0, i64 %37
  %39 = getelementptr inbounds [2 x i32], ptr %38, i64 0, i64 0
  %40 = load ptr, ptr %3, align 8, !tbaa !5
  %41 = load i32, ptr %40, align 4, !tbaa !9
  call void @_Z7InsertYRii(ptr noundef nonnull align 4 dereferenceable(4) %39, i32 noundef %41)
  br label %50

42:                                               ; preds = %26
  %43 = load ptr, ptr %3, align 8, !tbaa !5
  %44 = load i32, ptr %43, align 4, !tbaa !9
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds [1500300 x [2 x i32]], ptr @tree, i64 0, i64 %45
  %47 = getelementptr inbounds [2 x i32], ptr %46, i64 0, i64 1
  %48 = load ptr, ptr %3, align 8, !tbaa !5
  %49 = load i32, ptr %48, align 4, !tbaa !9
  call void @_Z7InsertYRii(ptr noundef nonnull align 4 dereferenceable(4) %47, i32 noundef %49)
  br label %50

50:                                               ; preds = %42, %34
  %51 = load ptr, ptr %3, align 8, !tbaa !5
  %52 = load i32, ptr %51, align 4, !tbaa !9
  call void @_Z6Updatei(i32 noundef %52)
  br label %53

53:                                               ; preds = %50, %8
  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" }
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" }

!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 = !{!"int", !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"

@qc = external dso_local local_unnamed_addr global i32, align 4
@tot = external dso_local local_unnamed_addr global i32, align 4
@fa = external dso_local local_unnamed_addr global [1500300 x i32], align 16
@val = external dso_local local_unnamed_addr global [1500300 x i32], align 16
@size = external dso_local local_unnamed_addr global [1500300 x i32], align 16
@tree = external dso_local global [1500300 x [2 x i32]], align 16

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z7InsertYRii(ptr nocapture noundef nonnull align 4 dereferenceable(4) %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = load i32, ptr %0, align 4, !tbaa !5
  %.not = icmp eq i32 %3, 0
  br i1 %.not, label %4, label %16

4:                                                ; preds = %2
  %5 = load i32, ptr @tot, align 4, !tbaa !5
  %6 = add nsw i32 %5, 1
  store i32 %6, ptr @tot, align 4, !tbaa !5
  store i32 %6, ptr %0, align 4, !tbaa !5
  %7 = sext i32 %6 to i64
  %8 = getelementptr inbounds [1500300 x i32], ptr @size, i64 0, i64 %7
  store i32 1, ptr %8, align 4, !tbaa !5
  %9 = load i32, ptr @qc, align 4, !tbaa !5
  %10 = load i32, ptr %0, align 4, !tbaa !5
  %11 = sext i32 %10 to i64
  %12 = getelementptr inbounds [1500300 x i32], ptr @val, i64 0, i64 %11
  store i32 %9, ptr %12, align 4, !tbaa !5
  %13 = load i32, ptr %0, align 4, !tbaa !5
  %14 = sext i32 %13 to i64
  %15 = getelementptr inbounds [1500300 x i32], ptr @fa, i64 0, i64 %14
  store i32 %1, ptr %15, align 4, !tbaa !5
  br label %common.ret

common.ret:                                       ; preds = %4, %16
  ret void

16:                                               ; preds = %2
  %17 = load i32, ptr @qc, align 4, !tbaa !5
  %18 = sext i32 %3 to i64
  %19 = getelementptr inbounds [1500300 x i32], ptr @val, i64 0, i64 %18
  %20 = load i32, ptr %19, align 4, !tbaa !5
  %.not11 = icmp sgt i32 %17, %20
  %21 = getelementptr inbounds [1500300 x [2 x i32]], ptr @tree, i64 0, i64 %18, i64 1
  %22 = getelementptr inbounds [1500300 x [2 x i32]], ptr @tree, i64 0, i64 %18
  %.sink = select i1 %.not11, ptr %21, ptr %22
  tail call void @_Z7InsertYRii(ptr noundef nonnull align 4 dereferenceable(4) %.sink, i32 noundef %3)
  %23 = load i32, ptr %0, align 4, !tbaa !5
  tail call void @_Z6Updatei(i32 noundef %23)
  br label %common.ret
}

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


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