; LLVM IR from upupming/algorithm :: acwing/算法竞赛进阶指南/0x49-总结与练习/261. 旅馆.ll (Z3askii)

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

@tree = external dso_local global [200040 x %struct.SegmentTree], 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
declare dso_local void @_Z6spreadi(i32 noundef) #1

; Function Attrs: mustprogress uwtable
define dso_local noundef i64 @_Z3askii(i32 noundef %0, i32 noundef %1) #2 {
  %3 = alloca i64, align 8
  %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
  store i32 %0, ptr %4, align 4, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !5
  %10 = load i32, ptr %4, align 4, !tbaa !5
  %11 = sext i32 %10 to i64
  %12 = getelementptr inbounds [200040 x %struct.SegmentTree], ptr @tree, i64 0, i64 %11
  %13 = getelementptr inbounds %struct.SegmentTree, ptr %12, i32 0, i32 2
  %14 = load i64, ptr %13, align 8, !tbaa !9
  %15 = load i32, ptr %5, align 4, !tbaa !5
  %16 = sext i32 %15 to i64
  %17 = icmp slt i64 %14, %16
  br i1 %17, label %18, label %19

18:                                               ; preds = %2
  store i64 0, ptr %3, align 8
  br label %94

19:                                               ; preds = %2
  %20 = load i32, ptr %4, align 4, !tbaa !5
  call void @_Z6spreadi(i32 noundef %20)
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  %21 = load i32, ptr %4, align 4, !tbaa !5
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [200040 x %struct.SegmentTree], ptr @tree, i64 0, i64 %22
  %24 = getelementptr inbounds %struct.SegmentTree, ptr %23, i32 0, i32 0
  %25 = load i32, ptr %24, align 8, !tbaa !12
  %26 = load i32, ptr %4, align 4, !tbaa !5
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds [200040 x %struct.SegmentTree], ptr @tree, i64 0, i64 %27
  %29 = getelementptr inbounds %struct.SegmentTree, ptr %28, i32 0, i32 1
  %30 = load i32, ptr %29, align 4, !tbaa !13
  %31 = add nsw i32 %25, %30
  %32 = ashr i32 %31, 1
  store i32 %32, ptr %6, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  %33 = load i32, ptr %4, align 4, !tbaa !5
  %34 = mul nsw i32 2, %33
  store i32 %34, ptr %7, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  %35 = load i32, ptr %4, align 4, !tbaa !5
  %36 = mul nsw i32 2, %35
  %37 = add nsw i32 %36, 1
  store i32 %37, ptr %8, align 4, !tbaa !5
  %38 = load i32, ptr %7, align 4, !tbaa !5
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds [200040 x %struct.SegmentTree], ptr @tree, i64 0, i64 %39
  %41 = getelementptr inbounds %struct.SegmentTree, ptr %40, i32 0, i32 2
  %42 = load i64, ptr %41, align 8, !tbaa !9
  %43 = load i32, ptr %5, align 4, !tbaa !5
  %44 = sext i32 %43 to i64
  %45 = icmp sge i64 %42, %44
  br i1 %45, label %46, label %50

46:                                               ; preds = %19
  %47 = load i32, ptr %7, align 4, !tbaa !5
  %48 = load i32, ptr %5, align 4, !tbaa !5
  %49 = call noundef i64 @_Z3askii(i32 noundef %47, i32 noundef %48)
  store i64 %49, ptr %3, align 8
  store i32 1, ptr %9, align 4
  br label %93

50:                                               ; preds = %19
  %51 = load i32, ptr %7, align 4, !tbaa !5
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds [200040 x %struct.SegmentTree], ptr @tree, i64 0, i64 %52
  %54 = getelementptr inbounds %struct.SegmentTree, ptr %53, i32 0, i32 4
  %55 = load i64, ptr %54, align 8, !tbaa !14
  %56 = load i32, ptr %8, align 4, !tbaa !5
  %57 = sext i32 %56 to i64
  %58 = getelementptr inbounds [200040 x %struct.SegmentTree], ptr @tree, i64 0, i64 %57
  %59 = getelementptr inbounds %struct.SegmentTree, ptr %58, i32 0, i32 3
  %60 = load i64, ptr %59, align 8, !tbaa !15
  %61 = add nsw i64 %55, %60
  %62 = load i32, ptr %5, align 4, !tbaa !5
  %63 = sext i32 %62 to i64
  %64 = icmp sge i64 %61, %63
  br i1 %64, label %65, label %79

65:                                               ; preds = %50
  %66 = load i32, ptr %7, align 4, !tbaa !5
  %67 = sext i32 %66 to i64
  %68 = getelementptr inbounds [200040 x %struct.SegmentTree], ptr @tree, i64 0, i64 %67
  %69 = getelementptr inbounds %struct.SegmentTree, ptr %68, i32 0, i32 1
  %70 = load i32, ptr %69, align 4, !tbaa !13
  %71 = sext i32 %70 to i64
  %72 = load i32, ptr %7, align 4, !tbaa !5
  %73 = sext i32 %72 to i64
  %74 = getelementptr inbounds [200040 x %struct.SegmentTree], ptr @tree, i64 0, i64 %73
  %75 = getelementptr inbounds %struct.SegmentTree, ptr %74, i32 0, i32 4
  %76 = load i64, ptr %75, align 8, !tbaa !14
  %77 = sub nsw i64 %71, %76
  %78 = add nsw i64 %77, 1
  store i64 %78, ptr %3, align 8
  store i32 1, ptr %9, align 4
  br label %93

79:                                               ; preds = %50
  %80 = load i32, ptr %8, align 4, !tbaa !5
  %81 = sext i32 %80 to i64
  %82 = getelementptr inbounds [200040 x %struct.SegmentTree], ptr @tree, i64 0, i64 %81
  %83 = getelementptr inbounds %struct.SegmentTree, ptr %82, i32 0, i32 2
  %84 = load i64, ptr %83, align 8, !tbaa !9
  %85 = load i32, ptr %5, align 4, !tbaa !5
  %86 = sext i32 %85 to i64
  %87 = icmp sge i64 %84, %86
  br i1 %87, label %88, label %92

88:                                               ; preds = %79
  %89 = load i32, ptr %8, align 4, !tbaa !5
  %90 = load i32, ptr %5, align 4, !tbaa !5
  %91 = call noundef i64 @_Z3askii(i32 noundef %89, i32 noundef %90)
  store i64 %91, ptr %3, align 8
  store i32 1, ptr %9, align 4
  br label %93

92:                                               ; preds = %79
  store i64 0, ptr %3, align 8
  store i32 1, ptr %9, align 4
  br label %93

93:                                               ; preds = %92, %88, %65, %46
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  br label %94

94:                                               ; preds = %93, %18
  %95 = load i64, ptr %3, align 8
  ret i64 %95
}

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

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

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef range(i64 -9223372036854775807, -9223372036854775808) i64 @_Z3askii(i32 noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = sext i32 %1 to i64
  %4 = sext i32 %0 to i64
  %5 = getelementptr inbounds [200040 x %struct.SegmentTree], ptr @tree, i64 0, i64 %4, i32 2
  %6 = load i64, ptr %5, align 8, !tbaa !5
  %7 = icmp slt i64 %6, %3
  br i1 %7, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %2, %tailrecurse.backedge
  %.tr26 = phi i32 [ %.tr.be, %tailrecurse.backedge ], [ %0, %2 ]
  tail call void @_Z6spreadi(i32 noundef %.tr26)
  %8 = shl nsw i32 %.tr26, 1
  %9 = or disjoint i32 %8, 1
  %10 = sext i32 %8 to i64
  %11 = getelementptr inbounds [200040 x %struct.SegmentTree], ptr @tree, i64 0, i64 %10
  %12 = getelementptr inbounds i8, ptr %11, i64 8
  %13 = load i64, ptr %12, align 8, !tbaa !5
  %.not = icmp slt i64 %13, %3
  br i1 %.not, label %17, label %tailrecurse.backedge

tailrecurse.backedge:                             ; preds = %.lr.ph, %30
  %.pre-phi = phi i64 [ %10, %.lr.ph ], [ %20, %30 ]
  %.tr.be = phi i32 [ %8, %.lr.ph ], [ %9, %30 ]
  %14 = getelementptr inbounds [200040 x %struct.SegmentTree], ptr @tree, i64 0, i64 %.pre-phi, i32 2
  %15 = load i64, ptr %14, align 8, !tbaa !5
  %16 = icmp slt i64 %15, %3
  br i1 %16, label %.loopexit, label %.lr.ph

17:                                               ; preds = %.lr.ph
  %18 = getelementptr inbounds i8, ptr %11, i64 24
  %19 = load i64, ptr %18, align 8, !tbaa !11
  %20 = sext i32 %9 to i64
  %21 = getelementptr inbounds [200040 x %struct.SegmentTree], ptr @tree, i64 0, i64 %20
  %22 = getelementptr inbounds i8, ptr %21, i64 16
  %23 = load i64, ptr %22, align 8, !tbaa !12
  %24 = add nsw i64 %23, %19
  %.not22 = icmp slt i64 %24, %3
  br i1 %.not22, label %30, label %25

25:                                               ; preds = %17
  %26 = getelementptr inbounds i8, ptr %11, i64 4
  %27 = load i32, ptr %26, align 4, !tbaa !13
  %28 = sext i32 %27 to i64
  %reass.sub = sub i64 %28, %19
  %29 = add i64 %reass.sub, 1
  br label %.loopexit

30:                                               ; preds = %17
  %31 = getelementptr inbounds i8, ptr %21, i64 8
  %32 = load i64, ptr %31, align 16, !tbaa !5
  %.not23 = icmp slt i64 %32, %3
  br i1 %.not23, label %.loopexit, label %tailrecurse.backedge

.loopexit:                                        ; preds = %tailrecurse.backedge, %30, %2, %25
  %.1 = phi i64 [ %29, %25 ], [ 0, %2 ], [ 0, %30 ], [ 0, %tailrecurse.backedge ]
  ret i64 %.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" }

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


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