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

; 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__._ZNK6Common10StringView4findES0_ = external hidden unnamed_addr constant [60 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 @_ZNK6Common10StringView4findES0_(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 279, ptr noundef @__PRETTY_FUNCTION__._ZNK6Common10StringView4findES0_) #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 280, ptr noundef @__PRETTY_FUNCTION__._ZNK6Common10StringView4findES0_) #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 %95

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 = %86, %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 %89

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 = %80, %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 %62

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

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

78:                                               ; preds = %62
  store i32 5, ptr %8, align 4
  br label %83

79:                                               ; preds = %62
  br label %80

80:                                               ; preds = %79
  %81 = load i64, ptr %9, align 8, !tbaa !13
  %82 = add i64 %81, 1
  store i64 %82, ptr %9, align 8, !tbaa !13
  br label %55, !llvm.loop !15

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

85:                                               ; preds = %83
  br label %86

86:                                               ; preds = %85
  %87 = load i64, ptr %7, align 8, !tbaa !13
  %88 = add i64 %87, 1
  store i64 %88, ptr %7, align 8, !tbaa !13
  br label %48, !llvm.loop !17

89:                                               ; preds = %83, %53
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  %90 = load i32, ptr %8, align 4
  switch i32 %90, label %92 [
    i32 2, label %91
  ]

91:                                               ; preds = %89
  store i32 0, ptr %8, align 4
  br label %92

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

94:                                               ; preds = %92
  br label %95

95:                                               ; preds = %94, %36
  store i64 -1, ptr %3, align 8
  br label %96

96:                                               ; preds = %95, %92
  %97 = load i64, ptr %3, align 8
  ret i64 %97

98:                                               ; preds = %92
  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__._ZNK6Common10StringView4findES0_ = external hidden unnamed_addr constant [60 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 @_ZNK6Common10StringView4findES0_(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 279, ptr noundef nonnull @__PRETTY_FUNCTION__._ZNK6Common10StringView4findES0_) #2
  unreachable

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

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

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

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

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

.preheader:                                       ; preds = %14, %25
  %.01740 = phi i64 [ %26, %25 ], [ 0, %14 ]
  %16 = getelementptr inbounds i8, ptr %3, i64 %.01740
  br label %19

17:                                               ; preds = %19
  %18 = add nuw i64 %.038, 1
  %.not25 = icmp eq i64 %18, %10
  br i1 %.not25, label %.thread30, label %19, !llvm.loop !12

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

25:                                               ; preds = %19
  %26 = add i64 %.01740, 1
  %.not24 = icmp ult i64 %15, %26
  br i1 %.not24, label %.thread30, label %.preheader, !llvm.loop !15

.thread30:                                        ; preds = %25, %17, %11, %14, %.critedge3
  %.3 = phi i64 [ -1, %.critedge3 ], [ 0, %14 ], [ 0, %11 ], [ %.01740, %17 ], [ -1, %25 ]
  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