; LLVM IR from CZWin32768/ACMICPC-Templates-in-Latex :: atl/codes/Tree/Persistent-Segment-Tree.ll (ZN3PST6updateEiii)

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

@_ZN3PST3totE = external dso_local global i32, align 4
@_ZN3PST1nE = external dso_local global i32, align 4
@_ZN3PST4lsonE = external dso_local global [4000200 x i32], align 16
@_ZN3PST4rsonE = external dso_local global [4000200 x i32], align 16
@_ZN3PST1cE = external dso_local global [4000200 x i32], 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 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 noundef i32 @_ZN3PST6updateEiii(i32 noundef %0, i32 noundef %1, i32 noundef %2) #1 {
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %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
  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) #2
  %12 = load i32, ptr @_ZN3PST3totE, align 4, !tbaa !5
  %13 = add nsw i32 %12, 1
  store i32 %13, ptr @_ZN3PST3totE, align 4, !tbaa !5
  store i32 %12, ptr %7, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  %14 = load i32, ptr %7, align 4, !tbaa !5
  store i32 %14, ptr %8, align 4, !tbaa !5
  %15 = load i32, ptr %4, align 4, !tbaa !5
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds [4000200 x i32], ptr @_ZN3PST1cE, i64 0, i64 %16
  %18 = load i32, ptr %17, align 4, !tbaa !5
  %19 = load i32, ptr %6, align 4, !tbaa !5
  %20 = add nsw i32 %18, %19
  %21 = load i32, ptr %7, align 4, !tbaa !5
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [4000200 x i32], ptr @_ZN3PST1cE, i64 0, i64 %22
  store i32 %20, ptr %23, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #2
  store i32 1, ptr %9, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #2
  %24 = load i32, ptr @_ZN3PST1nE, align 4, !tbaa !5
  store i32 %24, ptr %10, align 4, !tbaa !5
  br label %25

25:                                               ; preds = %82, %3
  %26 = load i32, ptr %9, align 4, !tbaa !5
  %27 = load i32, ptr %10, align 4, !tbaa !5
  %28 = icmp slt i32 %26, %27
  br i1 %28, label %29, label %92

29:                                               ; preds = %25
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #2
  %30 = load i32, ptr %9, align 4, !tbaa !5
  %31 = load i32, ptr %10, align 4, !tbaa !5
  %32 = add nsw i32 %30, %31
  %33 = ashr i32 %32, 1
  store i32 %33, ptr %11, align 4, !tbaa !5
  %34 = load i32, ptr %5, align 4, !tbaa !5
  %35 = load i32, ptr %11, align 4, !tbaa !5
  %36 = icmp sle i32 %34, %35
  br i1 %36, label %37, label %59

37:                                               ; preds = %29
  %38 = load i32, ptr @_ZN3PST3totE, align 4, !tbaa !5
  %39 = add nsw i32 %38, 1
  store i32 %39, ptr @_ZN3PST3totE, align 4, !tbaa !5
  %40 = load i32, ptr %7, align 4, !tbaa !5
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds [4000200 x i32], ptr @_ZN3PST4lsonE, i64 0, i64 %41
  store i32 %38, ptr %42, align 4, !tbaa !5
  %43 = load i32, ptr %4, align 4, !tbaa !5
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds [4000200 x i32], ptr @_ZN3PST4rsonE, i64 0, i64 %44
  %46 = load i32, ptr %45, align 4, !tbaa !5
  %47 = load i32, ptr %7, align 4, !tbaa !5
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds [4000200 x i32], ptr @_ZN3PST4rsonE, i64 0, i64 %48
  store i32 %46, ptr %49, align 4, !tbaa !5
  %50 = load i32, ptr %7, align 4, !tbaa !5
  %51 = sext i32 %50 to i64
  %52 = getelementptr inbounds [4000200 x i32], ptr @_ZN3PST4lsonE, i64 0, i64 %51
  %53 = load i32, ptr %52, align 4, !tbaa !5
  store i32 %53, ptr %7, align 4, !tbaa !5
  %54 = load i32, ptr %4, align 4, !tbaa !5
  %55 = sext i32 %54 to i64
  %56 = getelementptr inbounds [4000200 x i32], ptr @_ZN3PST4lsonE, i64 0, i64 %55
  %57 = load i32, ptr %56, align 4, !tbaa !5
  store i32 %57, ptr %4, align 4, !tbaa !5
  %58 = load i32, ptr %11, align 4, !tbaa !5
  store i32 %58, ptr %10, align 4, !tbaa !5
  br label %82

59:                                               ; preds = %29
  %60 = load i32, ptr @_ZN3PST3totE, align 4, !tbaa !5
  %61 = add nsw i32 %60, 1
  store i32 %61, ptr @_ZN3PST3totE, align 4, !tbaa !5
  %62 = load i32, ptr %7, align 4, !tbaa !5
  %63 = sext i32 %62 to i64
  %64 = getelementptr inbounds [4000200 x i32], ptr @_ZN3PST4rsonE, i64 0, i64 %63
  store i32 %60, ptr %64, align 4, !tbaa !5
  %65 = load i32, ptr %4, align 4, !tbaa !5
  %66 = sext i32 %65 to i64
  %67 = getelementptr inbounds [4000200 x i32], ptr @_ZN3PST4lsonE, i64 0, i64 %66
  %68 = load i32, ptr %67, align 4, !tbaa !5
  %69 = load i32, ptr %7, align 4, !tbaa !5
  %70 = sext i32 %69 to i64
  %71 = getelementptr inbounds [4000200 x i32], ptr @_ZN3PST4lsonE, i64 0, i64 %70
  store i32 %68, ptr %71, align 4, !tbaa !5
  %72 = load i32, ptr %7, align 4, !tbaa !5
  %73 = sext i32 %72 to i64
  %74 = getelementptr inbounds [4000200 x i32], ptr @_ZN3PST4rsonE, i64 0, i64 %73
  %75 = load i32, ptr %74, align 4, !tbaa !5
  store i32 %75, ptr %7, align 4, !tbaa !5
  %76 = load i32, ptr %4, align 4, !tbaa !5
  %77 = sext i32 %76 to i64
  %78 = getelementptr inbounds [4000200 x i32], ptr @_ZN3PST4rsonE, i64 0, i64 %77
  %79 = load i32, ptr %78, align 4, !tbaa !5
  store i32 %79, ptr %4, align 4, !tbaa !5
  %80 = load i32, ptr %11, align 4, !tbaa !5
  %81 = add nsw i32 %80, 1
  store i32 %81, ptr %9, align 4, !tbaa !5
  br label %82

82:                                               ; preds = %59, %37
  %83 = load i32, ptr %4, align 4, !tbaa !5
  %84 = sext i32 %83 to i64
  %85 = getelementptr inbounds [4000200 x i32], ptr @_ZN3PST1cE, i64 0, i64 %84
  %86 = load i32, ptr %85, align 4, !tbaa !5
  %87 = load i32, ptr %6, align 4, !tbaa !5
  %88 = add nsw i32 %86, %87
  %89 = load i32, ptr %7, align 4, !tbaa !5
  %90 = sext i32 %89 to i64
  %91 = getelementptr inbounds [4000200 x i32], ptr @_ZN3PST1cE, i64 0, i64 %90
  store i32 %88, ptr %91, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #2
  br label %25, !llvm.loop !9

92:                                               ; preds = %25
  %93 = load i32, ptr %8, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  ret i32 %93
}

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 = { 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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


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

@_ZN3PST3totE = external dso_local local_unnamed_addr global i32, align 4
@_ZN3PST1nE = external dso_local local_unnamed_addr global i32, align 4
@_ZN3PST4lsonE = external dso_local local_unnamed_addr global [4000200 x i32], align 16
@_ZN3PST4rsonE = external dso_local local_unnamed_addr global [4000200 x i32], align 16
@_ZN3PST1cE = external dso_local local_unnamed_addr global [4000200 x i32], align 16

; Function Attrs: mustprogress nofree norecurse nosync nounwind memory(readwrite, argmem: read, inaccessiblemem: none) uwtable
define dso_local noundef i32 @_ZN3PST6updateEiii(i32 noundef %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = load i32, ptr @_ZN3PST3totE, align 4, !tbaa !5
  %5 = add nsw i32 %4, 1
  store i32 %5, ptr @_ZN3PST3totE, align 4, !tbaa !5
  %6 = sext i32 %0 to i64
  %7 = getelementptr inbounds [4000200 x i32], ptr @_ZN3PST1cE, i64 0, i64 %6
  %8 = load i32, ptr %7, align 4, !tbaa !5
  %9 = add nsw i32 %8, %2
  %10 = sext i32 %4 to i64
  %11 = getelementptr inbounds [4000200 x i32], ptr @_ZN3PST1cE, i64 0, i64 %10
  store i32 %9, ptr %11, align 4, !tbaa !5
  %12 = load i32, ptr @_ZN3PST1nE, align 4, !tbaa !5
  %13 = icmp sgt i32 %12, 1
  br i1 %13, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %3, %31
  %.037 = phi i32 [ %.1, %31 ], [ %0, %3 ]
  %.02636 = phi i32 [ %.127, %31 ], [ %12, %3 ]
  %.02835 = phi i32 [ %.129, %31 ], [ 1, %3 ]
  %.03034 = phi i32 [ %14, %31 ], [ %4, %3 ]
  %14 = phi i32 [ %17, %31 ], [ %5, %3 ]
  %15 = add nuw nsw i32 %.02636, %.02835
  %16 = lshr i32 %15, 1
  %.not = icmp slt i32 %16, %1
  %17 = add nsw i32 %14, 1
  %18 = sext i32 %.03034 to i64
  %19 = sext i32 %.037 to i64
  br i1 %.not, label %25, label %20

20:                                               ; preds = %.lr.ph
  %21 = getelementptr inbounds [4000200 x i32], ptr @_ZN3PST4lsonE, i64 0, i64 %18
  store i32 %14, ptr %21, align 4, !tbaa !5
  %22 = getelementptr inbounds [4000200 x i32], ptr @_ZN3PST4rsonE, i64 0, i64 %19
  %23 = load i32, ptr %22, align 4, !tbaa !5
  %24 = getelementptr inbounds [4000200 x i32], ptr @_ZN3PST4rsonE, i64 0, i64 %18
  store i32 %23, ptr %24, align 4, !tbaa !5
  br label %31

25:                                               ; preds = %.lr.ph
  %26 = getelementptr inbounds [4000200 x i32], ptr @_ZN3PST4rsonE, i64 0, i64 %18
  store i32 %14, ptr %26, align 4, !tbaa !5
  %27 = getelementptr inbounds [4000200 x i32], ptr @_ZN3PST4lsonE, i64 0, i64 %19
  %28 = load i32, ptr %27, align 4, !tbaa !5
  %29 = getelementptr inbounds [4000200 x i32], ptr @_ZN3PST4lsonE, i64 0, i64 %18
  store i32 %28, ptr %29, align 4, !tbaa !5
  %30 = add nuw nsw i32 %16, 1
  br label %31

31:                                               ; preds = %25, %20
  %.129 = phi i32 [ %.02835, %20 ], [ %30, %25 ]
  %.127 = phi i32 [ %16, %20 ], [ %.02636, %25 ]
  %_ZN3PST4lsonE.pn = phi ptr [ @_ZN3PST4lsonE, %20 ], [ @_ZN3PST4rsonE, %25 ]
  %.1.in = getelementptr inbounds [4000200 x i32], ptr %_ZN3PST4lsonE.pn, i64 0, i64 %19
  %.1 = load i32, ptr %.1.in, align 4, !tbaa !5
  %32 = sext i32 %.1 to i64
  %33 = getelementptr inbounds [4000200 x i32], ptr @_ZN3PST1cE, i64 0, i64 %32
  %34 = load i32, ptr %33, align 4, !tbaa !5
  %35 = add nsw i32 %34, %2
  %36 = sext i32 %14 to i64
  %37 = getelementptr inbounds [4000200 x i32], ptr @_ZN3PST1cE, i64 0, i64 %36
  store i32 %35, ptr %37, align 4, !tbaa !5
  %38 = icmp slt i32 %.129, %.127
  br i1 %38, label %.lr.ph, label %._crit_edge.loopexit, !llvm.loop !9

._crit_edge.loopexit:                             ; preds = %31
  store i32 %17, ptr @_ZN3PST3totE, align 4, !tbaa !5
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %3
  ret i32 %4
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind memory(readwrite, argmem: read, 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, !6, i64 0}
!6 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass