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

; 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__endsWith__(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 i32, align 4
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  %12 = alloca ptr, align 8
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  %15 = getelementptr inbounds { ptr, i32 }, ptr %6, i32 0, i32 0
  store ptr %0, ptr %15, align 8
  %16 = getelementptr inbounds { ptr, i32 }, ptr %6, i32 0, i32 1
  store i32 %1, ptr %16, align 8
  %17 = getelementptr inbounds { ptr, i32 }, ptr %7, i32 0, i32 0
  store ptr %2, ptr %17, align 8
  %18 = getelementptr inbounds { ptr, i32 }, ptr %7, i32 0, i32 1
  store i32 %3, ptr %18, align 8
  %19 = getelementptr inbounds %struct.string__, ptr %6, i32 0, i32 1
  %20 = load i32, ptr %19, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.string__, ptr %7, i32 0, i32 1
  %22 = load i32, ptr %21, align 8, !tbaa !5
  %23 = icmp slt i32 %20, %22
  br i1 %23, label %24, label %25

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

25:                                               ; preds = %4
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  %26 = getelementptr inbounds %struct.string__, ptr %6, i32 0, i32 1
  %27 = load i32, ptr %26, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.string__, ptr %7, i32 0, i32 1
  %29 = load i32, ptr %28, align 8, !tbaa !5
  %30 = sub nsw i32 %27, %29
  store i32 %30, ptr %8, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  store i32 0, ptr %9, align 4, !tbaa !11
  br label %31

31:                                               ; preds = %82, %25
  %32 = load i32, ptr %9, align 4, !tbaa !11
  %33 = getelementptr inbounds %struct.string__, ptr %7, i32 0, i32 1
  %34 = load i32, ptr %33, align 8, !tbaa !5
  %35 = icmp slt i32 %32, %34
  br i1 %35, label %36, label %83

36:                                               ; preds = %31
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  store ptr %6, ptr %10, align 8, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  %37 = load i32, ptr %8, align 4, !tbaa !11
  %38 = load i32, ptr %9, align 4, !tbaa !11
  %39 = add nsw i32 %37, %38
  store i32 %39, ptr %11, align 4, !tbaa !11
  %40 = load i32, ptr %11, align 4, !tbaa !11
  %41 = load ptr, ptr %10, align 8, !tbaa !12
  %42 = getelementptr inbounds %struct.string__, ptr %41, i32 0, i32 1
  %43 = load i32, ptr %42, align 8, !tbaa !5
  %44 = icmp ult i32 %40, %43
  br i1 %44, label %48, label %45

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

48:                                               ; preds = %45, %36
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  store ptr %7, ptr %12, align 8, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #3
  %49 = load i32, ptr %9, align 4, !tbaa !11
  store i32 %49, ptr %13, align 4, !tbaa !11
  %50 = load i32, ptr %13, align 4, !tbaa !11
  %51 = load ptr, ptr %12, align 8, !tbaa !12
  %52 = getelementptr inbounds %struct.string__, ptr %51, i32 0, i32 1
  %53 = load i32, ptr %52, align 8, !tbaa !5
  %54 = icmp ult i32 %50, %53
  br i1 %54, label %58, label %55

55:                                               ; preds = %48
  %56 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @top_____abandonFn__)
  %57 = load ptr, ptr %56, align 8, !tbaa !12
  call void %57(i32 noundef -3)
  br label %58

58:                                               ; preds = %55, %48
  %59 = load ptr, ptr %10, 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 %11, 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 = load ptr, ptr %12, align 8, !tbaa !12
  %68 = getelementptr inbounds %struct.string__, ptr %67, i32 0, i32 0
  %69 = load ptr, ptr %68, align 8, !tbaa !13
  %70 = load i32, ptr %13, align 4, !tbaa !11
  %71 = zext i32 %70 to i64
  %72 = getelementptr inbounds i8, ptr %69, i64 %71
  %73 = load i8, ptr %72, align 1, !tbaa !14
  %74 = sext i8 %73 to i32
  %75 = icmp ne i32 %66, %74
  br i1 %75, label %76, label %77

76:                                               ; preds = %58
  store i8 0, ptr %5, align 1
  store i32 1, ptr %14, align 4
  br label %80

77:                                               ; preds = %58
  %78 = load i32, ptr %9, align 4, !tbaa !11
  %79 = add nsw i32 %78, 1
  store i32 %79, ptr %9, align 4, !tbaa !11
  store i32 0, ptr %14, align 4
  br label %80

80:                                               ; preds = %77, %76
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  %81 = load i32, ptr %14, align 4
  switch i32 %81, label %84 [
    i32 0, label %82
  ]

82:                                               ; preds = %80
  br label %31, !llvm.loop !15

83:                                               ; preds = %31
  store i32 0, ptr %14, align 4
  br label %84

84:                                               ; preds = %83, %80
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  %85 = load i32, ptr %14, align 4
  switch i32 %85, label %87 [
    i32 0, label %86
  ]

86:                                               ; preds = %84
  store i8 1, ptr %5, align 1
  store i32 1, ptr %14, align 4
  br label %87

87:                                               ; preds = %86, %84
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  br label %88

88:                                               ; preds = %87, %24
  %89 = load i8, ptr %5, align 1
  ret i8 %89
}

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__endsWith__(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 %24, label %6

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

10:                                               ; preds = %17, %6
  %indvars.iv = phi i64 [ %indvars.iv.next, %17 ], [ 0, %6 ]
  %exitcond = icmp eq i64 %indvars.iv, %wide.trip.count
  br i1 %exitcond, label %23, label %11

11:                                               ; preds = %10
  %12 = trunc nuw nsw i64 %indvars.iv to i32
  %13 = add nsw i32 %7, %12
  %14 = icmp ult i32 %13, %1
  br i1 %14, label %17, label %15

15:                                               ; preds = %11
  %16 = load ptr, ptr %8, align 8, !tbaa !5
  tail call void %16(i32 noundef -3) #3
  br label %17

17:                                               ; preds = %15, %11
  %18 = zext i32 %13 to i64
  %19 = getelementptr inbounds i8, ptr %0, i64 %18
  %20 = load i8, ptr %19, align 1, !tbaa !9
  %21 = getelementptr inbounds i8, ptr %2, i64 %indvars.iv
  %22 = load i8, ptr %21, align 1, !tbaa !9
  %.not = icmp eq i8 %20, %22
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  br i1 %.not, label %10, label %23, !llvm.loop !10

23:                                               ; preds = %10, %17
  %.not29.le = icmp sge i64 %indvars.iv, %9
  %spec.select = zext i1 %.not29.le to i8
  br label %24

24:                                               ; preds = %4, %23
  %.4 = phi i8 [ %spec.select, %23 ], [ 0, %4 ]
  ret i8 %.4
}

; 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,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LICMPass,LoopSimplifyCFGPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass