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

; 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__._ZNK6Common10StringView10beginsWithES0_ = external hidden unnamed_addr constant [54 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 zeroext i1 @_ZNK6Common10StringView10beginsWithES0_(ptr noundef nonnull align 8 dereferenceable(16) %0, ptr noundef %1) #2 align 2 {
  %3 = alloca i1, align 1
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  %8 = load ptr, ptr %4, align 8
  %9 = getelementptr inbounds %"class.Common::StringView", ptr %8, i32 0, i32 0
  %10 = load ptr, ptr %9, align 8, !tbaa !9
  %11 = icmp ne ptr %10, null
  br i1 %11, label %16, label %12

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

16:                                               ; preds = %12, %2
  %17 = phi i1 [ true, %2 ], [ %15, %12 ]
  br i1 %17, label %18, label %19

18:                                               ; preds = %16
  br label %21

19:                                               ; preds = %16
  call void @__assert_fail(ptr noundef @.str, ptr noundef @.str.2, i32 noundef 190, ptr noundef @__PRETTY_FUNCTION__._ZNK6Common10StringView10beginsWithES0_) #3
  unreachable

20:                                               ; No predecessors!
  br label %21

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

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

29:                                               ; preds = %25, %21
  %30 = phi i1 [ true, %21 ], [ %28, %25 ]
  br i1 %30, label %31, label %32

31:                                               ; preds = %29
  br label %34

32:                                               ; preds = %29
  call void @__assert_fail(ptr noundef @.str.3, ptr noundef @.str.2, i32 noundef 191, ptr noundef @__PRETTY_FUNCTION__._ZNK6Common10StringView10beginsWithES0_) #3
  unreachable

33:                                               ; No predecessors!
  br label %34

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

40:                                               ; preds = %34
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  store i64 0, ptr %6, align 8, !tbaa !13
  br label %41

41:                                               ; preds = %63, %40
  %42 = load i64, ptr %6, align 8, !tbaa !13
  %43 = getelementptr inbounds %"class.Common::StringView", ptr %1, i32 0, i32 1
  %44 = load i64, ptr %43, align 8, !tbaa !12
  %45 = icmp eq i64 %42, %44
  br i1 %45, label %46, label %47

46:                                               ; preds = %41
  store i1 true, ptr %3, align 1
  store i32 1, ptr %7, align 4
  br label %66

47:                                               ; preds = %41
  %48 = getelementptr inbounds %"class.Common::StringView", ptr %8, i32 0, i32 0
  %49 = load ptr, ptr %48, align 8, !tbaa !9
  %50 = load i64, ptr %6, align 8, !tbaa !13
  %51 = getelementptr inbounds i8, ptr %49, i64 %50
  %52 = load i8, ptr %51, align 1, !tbaa !14
  %53 = sext i8 %52 to i32
  %54 = getelementptr inbounds %"class.Common::StringView", ptr %1, i32 0, i32 0
  %55 = load ptr, ptr %54, align 8, !tbaa !9
  %56 = load i64, ptr %6, align 8, !tbaa !13
  %57 = getelementptr inbounds i8, ptr %55, i64 %56
  %58 = load i8, ptr %57, align 1, !tbaa !14
  %59 = sext i8 %58 to i32
  %60 = icmp eq i32 %53, %59
  br i1 %60, label %62, label %61

61:                                               ; preds = %47
  store i32 2, ptr %7, align 4
  br label %66

62:                                               ; preds = %47
  br label %63

63:                                               ; preds = %62
  %64 = load i64, ptr %6, align 8, !tbaa !13
  %65 = add i64 %64, 1
  store i64 %65, ptr %6, align 8, !tbaa !13
  br label %41, !llvm.loop !15

66:                                               ; preds = %61, %46
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  %67 = load i32, ptr %7, align 4
  switch i32 %67, label %72 [
    i32 1, label %70
    i32 2, label %68
  ]

68:                                               ; preds = %66
  br label %69

69:                                               ; preds = %68, %34
  store i1 false, ptr %3, align 1
  br label %70

70:                                               ; preds = %69, %66
  %71 = load i1, ptr %3, align 1
  ret i1 %71

72:                                               ; preds = %66
  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"}


; 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__._ZNK6Common10StringView10beginsWithES0_ = external hidden unnamed_addr constant [54 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 zeroext i1 @_ZNK6Common10StringView10beginsWithES0_(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 190, ptr noundef nonnull @__PRETTY_FUNCTION__._ZNK6Common10StringView10beginsWithES0_) #2
  unreachable

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

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

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

.critedge2:                                       ; preds = %.critedge
  %.not11 = icmp ult i64 %5, %10
  br i1 %.not11, label %.thread, label %.preheader

.preheader:                                       ; preds = %.critedge2
  %14 = icmp eq i64 %10, 0
  br i1 %14, label %.thread, label %.lr.ph

.lr.ph:                                           ; preds = %.preheader, %.lr.ph
  %.0817 = phi i64 [ %20, %.lr.ph ], [ 0, %.preheader ]
  %15 = getelementptr inbounds i8, ptr %3, i64 %.0817
  %16 = load i8, ptr %15, align 1, !tbaa !12
  %17 = getelementptr inbounds i8, ptr %8, i64 %.0817
  %18 = load i8, ptr %17, align 1, !tbaa !12
  %19 = icmp eq i8 %16, %18
  %20 = add nuw i64 %.0817, 1
  %21 = icmp ne i64 %20, %10
  %or.cond23.not = select i1 %19, i1 %21, i1 false
  br i1 %or.cond23.not, label %.lr.ph, label %.thread, !llvm.loop !13

.thread:                                          ; preds = %.lr.ph, %11, %.preheader, %.critedge2
  %.1 = phi i1 [ false, %.critedge2 ], [ true, %.preheader ], [ true, %11 ], [ %19, %.lr.ph ]
  ret i1 %.1
}

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 = !{!8, !8, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}


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