; LLVM IR from dynexcoin/Dynex :: src/Common/StringView.ll (ZNK6Common10StringView8findLastES0_)

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

%"class.Common::StringView" = type { ptr, i64 }

@.str = external hidden unnamed_addr constant [29 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [75 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [41 x i8], align 1
@__PRETTY_FUNCTION__._ZNK6Common10StringView8findLastES0_ = external hidden unnamed_addr constant [64 x i8], align 1

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #0

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

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i64 @_ZNK6Common10StringView8findLastES0_(ptr noundef nonnull align 8 dereferenceable(16) %0, ptr noundef %1) #2 align 2 {
  %3 = alloca i64, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  %8 = alloca i32, align 4
  %9 = alloca i64, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  %10 = load ptr, ptr %4, align 8
  %11 = getelementptr inbounds %"class.Common::StringView", ptr %10, i32 0, i32 0
  %12 = load ptr, ptr %11, align 8, !tbaa !9
  %13 = icmp ne ptr %12, null
  br i1 %13, label %18, label %14

14:                                               ; preds = %2
  %15 = getelementptr inbounds %"class.Common::StringView", ptr %10, i32 0, i32 1
  %16 = load i64, ptr %15, align 8, !tbaa !12
  %17 = icmp eq i64 %16, 0
  br label %18

18:                                               ; preds = %14, %2
  %19 = phi i1 [ true, %2 ], [ %17, %14 ]
  br i1 %19, label %20, label %21

20:                                               ; preds = %18
  br label %23

21:                                               ; preds = %18
  call void @__assert_fail(ptr noundef @.str, ptr noundef @.str.2, i32 noundef 311, ptr noundef @__PRETTY_FUNCTION__._ZNK6Common10StringView8findLastES0_) #3
  unreachable

22:                                               ; No predecessors!
  br label %23

23:                                               ; preds = %22, %20
  %24 = getelementptr inbounds %"class.Common::StringView", ptr %1, i32 0, i32 0
  %25 = load ptr, ptr %24, align 8, !tbaa !9
  %26 = icmp ne ptr %25, null
  br i1 %26, label %31, label %27

27:                                               ; preds = %23
  %28 = getelementptr inbounds %"class.Common::StringView", ptr %1, i32 0, i32 1
  %29 = load i64, ptr %28, align 8, !tbaa !12
  %30 = icmp eq i64 %29, 0
  br label %31

31:                                               ; preds = %27, %23
  %32 = phi i1 [ true, %23 ], [ %30, %27 ]
  br i1 %32, label %33, label %34

33:                                               ; preds = %31
  br label %36

34:                                               ; preds = %31
  call void @__assert_fail(ptr noundef @.str.3, ptr noundef @.str.2, i32 noundef 312, ptr noundef @__PRETTY_FUNCTION__._ZNK6Common10StringView8findLastES0_) #3
  unreachable

35:                                               ; No predecessors!
  br label %36

36:                                               ; preds = %35, %33
  %37 = getelementptr inbounds %"class.Common::StringView", ptr %10, i32 0, i32 1
  %38 = load i64, ptr %37, align 8, !tbaa !12
  %39 = getelementptr inbounds %"class.Common::StringView", ptr %1, i32 0, i32 1
  %40 = load i64, ptr %39, align 8, !tbaa !12
  %41 = icmp uge i64 %38, %40
  br i1 %41, label %42, label %99

42:                                               ; preds = %36
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  %43 = getelementptr inbounds %"class.Common::StringView", ptr %10, i32 0, i32 1
  %44 = load i64, ptr %43, align 8, !tbaa !12
  %45 = getelementptr inbounds %"class.Common::StringView", ptr %1, i32 0, i32 1
  %46 = load i64, ptr %45, align 8, !tbaa !12
  %47 = sub i64 %44, %46
  store i64 %47, ptr %6, align 8, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  store i64 0, ptr %7, align 8, !tbaa !13
  br label %48

48:                                               ; preds = %90, %42
  %49 = load i64, ptr %6, align 8, !tbaa !13
  %50 = load i64, ptr %7, align 8, !tbaa !13
  %51 = icmp ult i64 %49, %50
  %52 = xor i1 %51, true
  br i1 %52, label %54, label %53

53:                                               ; preds = %48
  store i32 2, ptr %8, align 4
  br label %93

54:                                               ; preds = %48
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  store i64 0, ptr %9, align 8, !tbaa !13
  br label %55

55:                                               ; preds = %84, %54
  %56 = load i64, ptr %9, align 8, !tbaa !13
  %57 = getelementptr inbounds %"class.Common::StringView", ptr %1, i32 0, i32 1
  %58 = load i64, ptr %57, align 8, !tbaa !12
  %59 = icmp eq i64 %56, %58
  br i1 %59, label %60, label %64

60:                                               ; preds = %55
  %61 = load i64, ptr %6, align 8, !tbaa !13
  %62 = load i64, ptr %7, align 8, !tbaa !13
  %63 = sub i64 %61, %62
  store i64 %63, ptr %3, align 8
  store i32 1, ptr %8, align 4
  br label %87

64:                                               ; preds = %55
  %65 = getelementptr inbounds %"class.Common::StringView", ptr %10, i32 0, i32 0
  %66 = load ptr, ptr %65, align 8, !tbaa !9
  %67 = load i64, ptr %6, align 8, !tbaa !13
  %68 = load i64, ptr %7, align 8, !tbaa !13
  %69 = sub i64 %67, %68
  %70 = load i64, ptr %9, align 8, !tbaa !13
  %71 = add i64 %69, %70
  %72 = getelementptr inbounds i8, ptr %66, i64 %71
  %73 = load i8, ptr %72, align 1, !tbaa !14
  %74 = sext i8 %73 to i32
  %75 = getelementptr inbounds %"class.Common::StringView", ptr %1, i32 0, i32 0
  %76 = load ptr, ptr %75, align 8, !tbaa !9
  %77 = load i64, ptr %9, align 8, !tbaa !13
  %78 = getelementptr inbounds i8, ptr %76, i64 %77
  %79 = load i8, ptr %78, align 1, !tbaa !14
  %80 = sext i8 %79 to i32
  %81 = icmp eq i32 %74, %80
  br i1 %81, label %83, label %82

82:                                               ; preds = %64
  store i32 5, ptr %8, align 4
  br label %87

83:                                               ; preds = %64
  br label %84

84:                                               ; preds = %83
  %85 = load i64, ptr %9, align 8, !tbaa !13
  %86 = add i64 %85, 1
  store i64 %86, ptr %9, align 8, !tbaa !13
  br label %55, !llvm.loop !15

87:                                               ; preds = %82, %60
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  %88 = load i32, ptr %8, align 4
  switch i32 %88, label %93 [
    i32 5, label %89
  ]

89:                                               ; preds = %87
  br label %90

90:                                               ; preds = %89
  %91 = load i64, ptr %7, align 8, !tbaa !13
  %92 = add i64 %91, 1
  store i64 %92, ptr %7, align 8, !tbaa !13
  br label %48, !llvm.loop !17

93:                                               ; preds = %87, %53
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  %94 = load i32, ptr %8, align 4
  switch i32 %94, label %96 [
    i32 2, label %95
  ]

95:                                               ; preds = %93
  store i32 0, ptr %8, align 4
  br label %96

96:                                               ; preds = %95, %93
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  %97 = load i32, ptr %8, align 4
  switch i32 %97, label %102 [
    i32 0, label %98
    i32 1, label %100
  ]

98:                                               ; preds = %96
  br label %99

99:                                               ; preds = %98, %36
  store i64 -1, ptr %3, align 8
  br label %100

100:                                              ; preds = %99, %96
  %101 = load i64, ptr %3, align 8
  ret i64 %101

102:                                              ; preds = %96
  unreachable
}

attributes #0 = { noreturn nounwind "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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #3 = { noreturn nounwind }
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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !6, i64 0}
!10 = !{!"_ZTSN6Common10StringViewE", !6, i64 0, !11, i64 8}
!11 = !{!"long", !7, i64 0}
!12 = !{!10, !11, i64 8}
!13 = !{!11, !11, i64 0}
!14 = !{!7, !7, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = distinct !{!17, !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"

@.str = external hidden unnamed_addr constant [29 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [75 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [41 x i8], align 1
@__PRETTY_FUNCTION__._ZNK6Common10StringView8findLastES0_ = external hidden unnamed_addr constant [64 x i8], align 1

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i64 @_ZNK6Common10StringView8findLastES0_(ptr nocapture noundef nonnull readonly align 8 dereferenceable(16) %0, ptr nocapture noundef readonly %1) local_unnamed_addr #1 align 2 {
  %3 = load ptr, ptr %0, align 8, !tbaa !5
  %.not = icmp ne ptr %3, null
  %4 = getelementptr inbounds i8, ptr %0, i64 8
  %5 = load i64, ptr %4, align 8
  %6 = icmp eq i64 %5, 0
  %or.cond = select i1 %.not, i1 true, i1 %6
  br i1 %or.cond, label %.critedge, label %7

7:                                                ; preds = %2
  tail call void @__assert_fail(ptr noundef nonnull @.str, ptr noundef nonnull @.str.2, i32 noundef 311, ptr noundef nonnull @__PRETTY_FUNCTION__._ZNK6Common10StringView8findLastES0_) #2
  unreachable

.critedge:                                        ; preds = %2
  %8 = load ptr, ptr %1, align 8, !tbaa !5
  %.not24 = icmp eq ptr %8, null
  %9 = getelementptr inbounds i8, ptr %1, i64 8
  %10 = load i64, ptr %9, align 8, !tbaa !11
  br i1 %.not24, label %11, label %.critedge3

11:                                               ; preds = %.critedge
  %12 = icmp eq i64 %10, 0
  br i1 %12, label %.preheader._crit_edge, label %13

13:                                               ; preds = %11
  tail call void @__assert_fail(ptr noundef nonnull @.str.3, ptr noundef nonnull @.str.2, i32 noundef 312, ptr noundef nonnull @__PRETTY_FUNCTION__._ZNK6Common10StringView8findLastES0_) #2
  unreachable

.critedge3:                                       ; preds = %.critedge
  %.not25 = icmp ult i64 %5, %10
  br i1 %.not25, label %.thread32, label %14

14:                                               ; preds = %.critedge3
  %15 = sub i64 %5, %10
  %.not2738 = icmp eq i64 %10, 0
  br i1 %.not2738, label %.preheader._crit_edge, label %.preheader

.preheader:                                       ; preds = %14, %26
  %.01941 = phi i64 [ %27, %26 ], [ 0, %14 ]
  %16 = sub i64 %15, %.01941
  %17 = getelementptr i8, ptr %3, i64 %16
  br label %20

18:                                               ; preds = %20
  %19 = add nuw i64 %.039, 1
  %.not27 = icmp eq i64 %19, %10
  br i1 %.not27, label %.preheader._crit_edge, label %20, !llvm.loop !12

20:                                               ; preds = %.preheader, %18
  %.039 = phi i64 [ 0, %.preheader ], [ %19, %18 ]
  %21 = getelementptr i8, ptr %17, i64 %.039
  %22 = load i8, ptr %21, align 1, !tbaa !14
  %23 = getelementptr inbounds i8, ptr %8, i64 %.039
  %24 = load i8, ptr %23, align 1, !tbaa !14
  %25 = icmp eq i8 %22, %24
  br i1 %25, label %18, label %26

26:                                               ; preds = %20
  %27 = add i64 %.01941, 1
  %.not26 = icmp ult i64 %15, %27
  br i1 %.not26, label %.thread32, label %.preheader, !llvm.loop !15

.preheader._crit_edge:                            ; preds = %18, %11, %14
  %28 = phi i64 [ %15, %14 ], [ %5, %11 ], [ %15, %18 ]
  %.019.lcssa37 = phi i64 [ 0, %14 ], [ 0, %11 ], [ %.01941, %18 ]
  %29 = sub i64 %28, %.019.lcssa37
  br label %.thread32

.thread32:                                        ; preds = %26, %.critedge3, %.preheader._crit_edge
  %.3 = phi i64 [ %29, %.preheader._crit_edge ], [ -1, %.critedge3 ], [ -1, %26 ]
  ret i64 %.3
}

attributes #0 = { noreturn nounwind "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 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 = { noreturn 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, !7, i64 0}
!6 = !{!"_ZTSN6Common10StringViewE", !7, i64 0, !10, i64 8}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!6, !10, i64 8}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = !{!8, !8, i64 0}
!15 = distinct !{!15, !13}


; Effective O3 passes: BDCEPass,CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopInstSimplifyPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass