; LLVM IR from nickmqb/muon :: bootstrap/mu.ll_string (startsWith__)

; 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.string__ = type { ptr, i32 }

@top_____abandonFn__ = external dso_local thread_local global ptr, align 8

; 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 speculatable willreturn memory(none)
declare nonnull ptr @llvm.threadlocal.address.p0(ptr nonnull) #1

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

; Function Attrs: nounwind uwtable
define dso_local zeroext i8 @string__startsWith__(ptr %0, i32 %1, ptr %2, i32 %3) #2 {
  %5 = alloca i8, align 1
  %6 = alloca %struct.string__, align 8
  %7 = alloca %struct.string__, align 8
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  %11 = alloca ptr, align 8
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = getelementptr inbounds { ptr, i32 }, ptr %6, i32 0, i32 0
  store ptr %0, ptr %14, align 8
  %15 = getelementptr inbounds { ptr, i32 }, ptr %6, i32 0, i32 1
  store i32 %1, ptr %15, align 8
  %16 = getelementptr inbounds { ptr, i32 }, ptr %7, i32 0, i32 0
  store ptr %2, ptr %16, align 8
  %17 = getelementptr inbounds { ptr, i32 }, ptr %7, i32 0, i32 1
  store i32 %3, ptr %17, align 8
  %18 = getelementptr inbounds %struct.string__, ptr %6, i32 0, i32 1
  %19 = load i32, ptr %18, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.string__, ptr %7, i32 0, i32 1
  %21 = load i32, ptr %20, align 8, !tbaa !5
  %22 = icmp slt i32 %19, %21
  br i1 %22, label %23, label %24

23:                                               ; preds = %4
  store i8 0, ptr %5, align 1
  br label %79

24:                                               ; preds = %4
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  store i32 0, ptr %8, align 4, !tbaa !11
  br label %25

25:                                               ; preds = %74, %24
  %26 = load i32, ptr %8, align 4, !tbaa !11
  %27 = getelementptr inbounds %struct.string__, ptr %7, i32 0, i32 1
  %28 = load i32, ptr %27, align 8, !tbaa !5
  %29 = icmp slt i32 %26, %28
  br i1 %29, label %30, label %75

30:                                               ; preds = %25
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  store ptr %6, ptr %9, align 8, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  %31 = load i32, ptr %8, align 4, !tbaa !11
  store i32 %31, ptr %10, align 4, !tbaa !11
  %32 = load i32, ptr %10, align 4, !tbaa !11
  %33 = load ptr, ptr %9, align 8, !tbaa !12
  %34 = getelementptr inbounds %struct.string__, ptr %33, i32 0, i32 1
  %35 = load i32, ptr %34, align 8, !tbaa !5
  %36 = icmp ult i32 %32, %35
  br i1 %36, label %40, label %37

37:                                               ; preds = %30
  %38 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @top_____abandonFn__)
  %39 = load ptr, ptr %38, align 8, !tbaa !12
  call void %39(i32 noundef -3)
  br label %40

40:                                               ; preds = %37, %30
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  store ptr %7, ptr %11, align 8, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #3
  %41 = load i32, ptr %8, align 4, !tbaa !11
  store i32 %41, ptr %12, align 4, !tbaa !11
  %42 = load i32, ptr %12, align 4, !tbaa !11
  %43 = load ptr, ptr %11, align 8, !tbaa !12
  %44 = getelementptr inbounds %struct.string__, ptr %43, i32 0, i32 1
  %45 = load i32, ptr %44, align 8, !tbaa !5
  %46 = icmp ult i32 %42, %45
  br i1 %46, label %50, label %47

47:                                               ; preds = %40
  %48 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @top_____abandonFn__)
  %49 = load ptr, ptr %48, align 8, !tbaa !12
  call void %49(i32 noundef -3)
  br label %50

50:                                               ; preds = %47, %40
  %51 = load ptr, ptr %9, align 8, !tbaa !12
  %52 = getelementptr inbounds %struct.string__, ptr %51, i32 0, i32 0
  %53 = load ptr, ptr %52, align 8, !tbaa !13
  %54 = load i32, ptr %10, align 4, !tbaa !11
  %55 = zext i32 %54 to i64
  %56 = getelementptr inbounds i8, ptr %53, i64 %55
  %57 = load i8, ptr %56, align 1, !tbaa !14
  %58 = sext i8 %57 to i32
  %59 = load ptr, ptr %11, align 8, !tbaa !12
  %60 = getelementptr inbounds %struct.string__, ptr %59, i32 0, i32 0
  %61 = load ptr, ptr %60, align 8, !tbaa !13
  %62 = load i32, ptr %12, align 4, !tbaa !11
  %63 = zext i32 %62 to i64
  %64 = getelementptr inbounds i8, ptr %61, i64 %63
  %65 = load i8, ptr %64, align 1, !tbaa !14
  %66 = sext i8 %65 to i32
  %67 = icmp ne i32 %58, %66
  br i1 %67, label %68, label %69

68:                                               ; preds = %50
  store i8 0, ptr %5, align 1
  store i32 1, ptr %13, align 4
  br label %72

69:                                               ; preds = %50
  %70 = load i32, ptr %8, align 4, !tbaa !11
  %71 = add nsw i32 %70, 1
  store i32 %71, ptr %8, align 4, !tbaa !11
  store i32 0, ptr %13, align 4
  br label %72

72:                                               ; preds = %69, %68
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  %73 = load i32, ptr %13, align 4
  switch i32 %73, label %76 [
    i32 0, label %74
  ]

74:                                               ; preds = %72
  br label %25, !llvm.loop !15

75:                                               ; preds = %25
  store i32 0, ptr %13, align 4
  br label %76

76:                                               ; preds = %75, %72
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  %77 = load i32, ptr %13, align 4
  switch i32 %77, label %81 [
    i32 0, label %78
    i32 1, label %79
  ]

78:                                               ; preds = %76
  store i8 1, ptr %5, align 1
  br label %79

79:                                               ; preds = %78, %76, %23
  %80 = load i8, ptr %5, align 1
  ret i8 %80

81:                                               ; preds = %76
  unreachable
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #2 = { 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 = { 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, !10, i64 8}
!6 = !{!"", !7, i64 0, !10, i64 8}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!10, !10, i64 0}
!12 = !{!7, !7, i64 0}
!13 = !{!6, !7, i64 0}
!14 = !{!8, !8, 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"

@top_____abandonFn__ = external dso_local thread_local local_unnamed_addr global ptr, align 8

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare nonnull ptr @llvm.threadlocal.address.p0(ptr nonnull) #0

; Function Attrs: nounwind uwtable
define dso_local zeroext i8 @string__startsWith__(ptr nocapture readonly %0, i32 %1, ptr nocapture readonly %2, i32 %3) local_unnamed_addr #1 {
  %5 = icmp slt i32 %1, %3
  br i1 %5, label %20, label %.preheader

.preheader:                                       ; preds = %4
  %6 = tail call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @top_____abandonFn__)
  %7 = sext i32 %3 to i64
  %8 = zext i32 %1 to i64
  %smax = tail call i32 @llvm.smax.i32(i32 %3, i32 0)
  %wide.trip.count = zext nneg i32 %smax to i64
  br label %9

9:                                                ; preds = %.preheader, %14
  %indvars.iv = phi i64 [ 0, %.preheader ], [ %indvars.iv.next, %14 ]
  %exitcond = icmp eq i64 %indvars.iv, %wide.trip.count
  br i1 %exitcond, label %19, label %10

10:                                               ; preds = %9
  %11 = icmp ult i64 %indvars.iv, %8
  br i1 %11, label %14, label %12

12:                                               ; preds = %10
  %13 = load ptr, ptr %6, align 8, !tbaa !5
  tail call void %13(i32 noundef -3) #3
  br label %14

14:                                               ; preds = %12, %10
  %15 = getelementptr inbounds i8, ptr %0, i64 %indvars.iv
  %16 = load i8, ptr %15, align 1, !tbaa !9
  %17 = getelementptr inbounds i8, ptr %2, i64 %indvars.iv
  %18 = load i8, ptr %17, align 1, !tbaa !9
  %.not = icmp eq i8 %16, %18
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  br i1 %.not, label %9, label %19, !llvm.loop !10

19:                                               ; preds = %9, %14
  %.not25.le = icmp sge i64 %indvars.iv, %7
  %spec.select = zext i1 %.not25.le to i8
  br label %20

20:                                               ; preds = %19, %4
  %.3 = phi i8 [ 0, %4 ], [ %spec.select, %19 ]
  ret i8 %.3
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.smax.i32(i32, i32) #2

attributes #0 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #1 = { 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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!7, !7, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: ConstraintEliminationPass,CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LICMPass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass