; LLVM IR from lzyrapx/Competitive-Programming :: HDUOJ/4820（线段树）.ll (Z15seg_erase_rightii)

; 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.Segment = type { i32, i32, i32, i32, i64, i8 }

@seg = external dso_local global [1000002 x %struct.Segment], 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: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z7seg_idxii(i32 noundef, i32 noundef) #1

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_Z8seg_downiii(i32 noundef, i32 noundef, i32 noundef) #1

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_Z6seg_upiii(i32 noundef, i32 noundef, i32 noundef) #2

; Function Attrs: mustprogress uwtable
define dso_local void @_Z15seg_erase_rightii(i32 noundef %0, i32 noundef %1) #3 {
  %3 = alloca i32, align 4
  %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
  store i32 %0, ptr %3, align 4, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  %9 = load i32, ptr %3, align 4, !tbaa !5
  %10 = load i32, ptr %4, align 4, !tbaa !5
  %11 = call noundef i32 @_Z7seg_idxii(i32 noundef %9, i32 noundef %10)
  store i32 %11, ptr %5, align 4, !tbaa !5
  %12 = load i32, ptr %5, align 4, !tbaa !5
  %13 = sext i32 %12 to i64
  %14 = getelementptr inbounds [1000002 x %struct.Segment], ptr @seg, i64 0, i64 %13
  %15 = getelementptr inbounds %struct.Segment, ptr %14, i32 0, i32 0
  %16 = load i32, ptr %15, align 16, !tbaa !9
  %17 = icmp sgt i32 %16, 0
  br i1 %17, label %18, label %39

18:                                               ; preds = %2
  %19 = load i32, ptr %5, align 4, !tbaa !5
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds [1000002 x %struct.Segment], ptr @seg, i64 0, i64 %20
  %22 = getelementptr inbounds %struct.Segment, ptr %21, i32 0, i32 2
  store i32 0, ptr %22, align 8, !tbaa !13
  %23 = load i32, ptr %5, align 4, !tbaa !5
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds [1000002 x %struct.Segment], ptr @seg, i64 0, i64 %24
  %26 = getelementptr inbounds %struct.Segment, ptr %25, i32 0, i32 1
  store i32 0, ptr %26, align 4, !tbaa !14
  %27 = load i32, ptr %5, align 4, !tbaa !5
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds [1000002 x %struct.Segment], ptr @seg, i64 0, i64 %28
  %30 = getelementptr inbounds %struct.Segment, ptr %29, i32 0, i32 0
  store i32 0, ptr %30, align 16, !tbaa !9
  %31 = load i32, ptr %5, align 4, !tbaa !5
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds [1000002 x %struct.Segment], ptr @seg, i64 0, i64 %32
  %34 = getelementptr inbounds %struct.Segment, ptr %33, i32 0, i32 4
  store i64 0, ptr %34, align 16, !tbaa !15
  %35 = load i32, ptr %5, align 4, !tbaa !5
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds [1000002 x %struct.Segment], ptr @seg, i64 0, i64 %36
  %38 = getelementptr inbounds %struct.Segment, ptr %37, i32 0, i32 5
  store i8 1, ptr %38, align 8, !tbaa !16
  br label %78

39:                                               ; preds = %2
  %40 = load i32, ptr %5, align 4, !tbaa !5
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds [1000002 x %struct.Segment], ptr @seg, i64 0, i64 %41
  %43 = getelementptr inbounds %struct.Segment, ptr %42, i32 0, i32 1
  %44 = load i32, ptr %43, align 4, !tbaa !14
  %45 = icmp sgt i32 %44, 0
  br i1 %45, label %46, label %77

46:                                               ; preds = %39
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  %47 = load i32, ptr %3, align 4, !tbaa !5
  %48 = load i32, ptr %4, align 4, !tbaa !5
  %49 = add nsw i32 %47, %48
  %50 = ashr i32 %49, 1
  store i32 %50, ptr %6, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  %51 = load i32, ptr %3, align 4, !tbaa !5
  %52 = load i32, ptr %6, align 4, !tbaa !5
  %53 = call noundef i32 @_Z7seg_idxii(i32 noundef %51, i32 noundef %52)
  store i32 %53, ptr %7, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  %54 = load i32, ptr %6, align 4, !tbaa !5
  %55 = add nsw i32 %54, 1
  %56 = load i32, ptr %4, align 4, !tbaa !5
  %57 = call noundef i32 @_Z7seg_idxii(i32 noundef %55, i32 noundef %56)
  store i32 %57, ptr %8, align 4, !tbaa !5
  %58 = load i32, ptr %5, align 4, !tbaa !5
  %59 = load i32, ptr %7, align 4, !tbaa !5
  %60 = load i32, ptr %8, align 4, !tbaa !5
  call void @_Z8seg_downiii(i32 noundef %58, i32 noundef %59, i32 noundef %60)
  %61 = load i32, ptr %7, align 4, !tbaa !5
  %62 = sext i32 %61 to i64
  %63 = getelementptr inbounds [1000002 x %struct.Segment], ptr @seg, i64 0, i64 %62
  %64 = getelementptr inbounds %struct.Segment, ptr %63, i32 0, i32 1
  %65 = load i32, ptr %64, align 4, !tbaa !14
  %66 = icmp sgt i32 %65, 0
  br i1 %66, label %67, label %70

67:                                               ; preds = %46
  %68 = load i32, ptr %3, align 4, !tbaa !5
  %69 = load i32, ptr %6, align 4, !tbaa !5
  call void @_Z15seg_erase_rightii(i32 noundef %68, i32 noundef %69)
  br label %70

70:                                               ; preds = %67, %46
  %71 = load i32, ptr %6, align 4, !tbaa !5
  %72 = add nsw i32 %71, 1
  %73 = load i32, ptr %4, align 4, !tbaa !5
  call void @_Z15seg_erase_rightii(i32 noundef %72, i32 noundef %73)
  %74 = load i32, ptr %5, align 4, !tbaa !5
  %75 = load i32, ptr %7, align 4, !tbaa !5
  %76 = load i32, ptr %8, align 4, !tbaa !5
  call void @_Z6seg_upiii(i32 noundef %74, i32 noundef %75, i32 noundef %76)
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  br label %77

77:                                               ; preds = %70, %39
  br label %78

78:                                               ; preds = %77, %18
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { inlinehint 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 #3 = { 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 #4 = { 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 0}
!10 = !{!"_ZTS7Segment", !6, i64 0, !6, i64 4, !6, i64 8, !6, i64 12, !11, i64 16, !12, i64 24}
!11 = !{!"long long", !7, i64 0}
!12 = !{!"bool", !7, i64 0}
!13 = !{!10, !6, i64 8}
!14 = !{!10, !6, i64 4}
!15 = !{!10, !11, i64 16}
!16 = !{!10, !12, i64 24}


; 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.Segment = type { i32, i32, i32, i32, i64, i8 }

@seg = external dso_local local_unnamed_addr global [1000002 x %struct.Segment], align 16

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z7seg_idxii(i32 noundef, i32 noundef) local_unnamed_addr #0

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

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_Z6seg_upiii(i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
define dso_local void @_Z15seg_erase_rightii(i32 noundef %0, i32 noundef %1) local_unnamed_addr #2 {
  %3 = tail call noundef i32 @_Z7seg_idxii(i32 noundef %0, i32 noundef %1)
  %4 = sext i32 %3 to i64
  %5 = getelementptr inbounds [1000002 x %struct.Segment], ptr @seg, i64 0, i64 %4
  %6 = load i32, ptr %5, align 16, !tbaa !5
  %7 = icmp sgt i32 %6, 0
  br i1 %7, label %8, label %13

8:                                                ; preds = %2
  %9 = getelementptr inbounds i8, ptr %5, i64 8
  store i32 0, ptr %9, align 8, !tbaa !12
  %10 = getelementptr inbounds i8, ptr %5, i64 4
  store i32 0, ptr %10, align 4, !tbaa !13
  store i32 0, ptr %5, align 16, !tbaa !5
  %11 = getelementptr inbounds i8, ptr %5, i64 16
  store i64 0, ptr %11, align 16, !tbaa !14
  %12 = getelementptr inbounds i8, ptr %5, i64 24
  store i8 1, ptr %12, align 8, !tbaa !15
  br label %common.ret26

13:                                               ; preds = %2
  %14 = getelementptr inbounds i8, ptr %5, i64 4
  %15 = load i32, ptr %14, align 4, !tbaa !13
  %16 = icmp sgt i32 %15, 0
  br i1 %16, label %17, label %common.ret26

17:                                               ; preds = %13
  %18 = add nsw i32 %1, %0
  %19 = ashr i32 %18, 1
  %20 = tail call noundef i32 @_Z7seg_idxii(i32 noundef %0, i32 noundef %19)
  %21 = add nsw i32 %19, 1
  %22 = tail call noundef i32 @_Z7seg_idxii(i32 noundef %21, i32 noundef %1)
  tail call void @_Z8seg_downiii(i32 noundef %3, i32 noundef %20, i32 noundef %22)
  %23 = sext i32 %20 to i64
  %24 = getelementptr inbounds [1000002 x %struct.Segment], ptr @seg, i64 0, i64 %23, i32 1
  %25 = load i32, ptr %24, align 4, !tbaa !13
  %26 = icmp sgt i32 %25, 0
  br i1 %26, label %27, label %28

27:                                               ; preds = %17
  tail call void @_Z15seg_erase_rightii(i32 noundef %0, i32 noundef %19)
  br label %28

common.ret26:                                     ; preds = %13, %8, %28
  ret void

28:                                               ; preds = %27, %17
  tail call void @_Z15seg_erase_rightii(i32 noundef %21, i32 noundef %1)
  tail call void @_Z6seg_upiii(i32 noundef %3, i32 noundef %20, i32 noundef %22)
  br label %common.ret26
}

attributes #0 = { 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 #1 = { inlinehint 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 #2 = { 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, !7, i64 0}
!6 = !{!"_ZTS7Segment", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12, !10, i64 16, !11, i64 24}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"long long", !8, i64 0}
!11 = !{!"bool", !8, i64 0}
!12 = !{!6, !7, i64 8}
!13 = !{!6, !7, i64 4}
!14 = !{!6, !10, i64 16}
!15 = !{!6, !11, i64 24}


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