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

; 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 i32 @string__indexOf__(ptr %0, i32 %1, ptr %2, i32 %3) #2 {
  %5 = alloca i32, align 4
  %6 = alloca %struct.string__, align 8
  %7 = alloca %struct.string__, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca ptr, align 8
  %13 = alloca i32, align 4
  %14 = alloca ptr, align 8
  %15 = alloca i32, align 4
  %16 = alloca i32, align 4
  %17 = getelementptr inbounds { ptr, i32 }, ptr %6, i32 0, i32 0
  store ptr %0, ptr %17, align 8
  %18 = getelementptr inbounds { ptr, i32 }, ptr %6, i32 0, i32 1
  store i32 %1, ptr %18, align 8
  %19 = getelementptr inbounds { ptr, i32 }, ptr %7, i32 0, i32 0
  store ptr %2, ptr %19, align 8
  %20 = getelementptr inbounds { ptr, i32 }, ptr %7, i32 0, i32 1
  store i32 %3, ptr %20, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  %21 = getelementptr inbounds %struct.string__, ptr %6, i32 0, i32 1
  %22 = load i32, ptr %21, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.string__, ptr %7, i32 0, i32 1
  %24 = load i32, ptr %23, align 8, !tbaa !5
  %25 = sub nsw i32 %22, %24
  store i32 %25, 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 %26

26:                                               ; preds = %100, %4
  %27 = load i32, ptr %9, align 4, !tbaa !11
  %28 = load i32, ptr %8, align 4, !tbaa !11
  %29 = icmp sle i32 %27, %28
  br i1 %29, label %30, label %101

30:                                               ; preds = %26
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  %31 = load i32, ptr %9, align 4, !tbaa !11
  store i32 %31, ptr %10, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  store i32 0, ptr %11, align 4, !tbaa !11
  br label %32

32:                                               ; preds = %86, %30
  br label %33

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

38:                                               ; preds = %33
  br label %87

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

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

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

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

59:                                               ; preds = %56, %49
  %60 = load ptr, ptr %12, align 8, !tbaa !12
  %61 = getelementptr inbounds %struct.string__, ptr %60, i32 0, i32 0
  %62 = load ptr, ptr %61, align 8, !tbaa !13
  %63 = load i32, ptr %13, align 4, !tbaa !11
  %64 = zext i32 %63 to i64
  %65 = getelementptr inbounds i8, ptr %62, i64 %64
  %66 = load i8, ptr %65, align 1, !tbaa !14
  %67 = sext i8 %66 to i32
  %68 = load ptr, ptr %14, align 8, !tbaa !12
  %69 = getelementptr inbounds %struct.string__, ptr %68, i32 0, i32 0
  %70 = load ptr, ptr %69, align 8, !tbaa !13
  %71 = load i32, ptr %15, align 4, !tbaa !11
  %72 = zext i32 %71 to i64
  %73 = getelementptr inbounds i8, ptr %70, i64 %72
  %74 = load i8, ptr %73, align 1, !tbaa !14
  %75 = sext i8 %74 to i32
  %76 = icmp eq i32 %67, %75
  br i1 %76, label %77, label %82

77:                                               ; preds = %59
  %78 = load i32, ptr %10, align 4, !tbaa !11
  %79 = add nsw i32 %78, 1
  store i32 %79, ptr %10, align 4, !tbaa !11
  %80 = load i32, ptr %11, align 4, !tbaa !11
  %81 = add nsw i32 %80, 1
  store i32 %81, ptr %11, align 4, !tbaa !11
  br label %83

82:                                               ; preds = %59
  store i32 6, ptr %16, align 4
  br label %84

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

84:                                               ; preds = %83, %82
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  %85 = load i32, ptr %16, align 4
  switch i32 %85, label %98 [
    i32 0, label %86
    i32 6, label %88
  ]

86:                                               ; preds = %84
  br label %32

87:                                               ; preds = %38
  br label %88

88:                                               ; preds = %87, %84
  %89 = load i32, ptr %11, align 4, !tbaa !11
  %90 = getelementptr inbounds %struct.string__, ptr %7, i32 0, i32 1
  %91 = load i32, ptr %90, align 8, !tbaa !5
  %92 = icmp eq i32 %89, %91
  br i1 %92, label %93, label %95

93:                                               ; preds = %88
  %94 = load i32, ptr %9, align 4, !tbaa !11
  store i32 %94, ptr %5, align 4
  store i32 1, ptr %16, align 4
  br label %98

95:                                               ; preds = %88
  %96 = load i32, ptr %9, align 4, !tbaa !11
  %97 = add nsw i32 %96, 1
  store i32 %97, ptr %9, align 4, !tbaa !11
  store i32 0, ptr %16, align 4
  br label %98

98:                                               ; preds = %95, %93, %84
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  %99 = load i32, ptr %16, align 4
  switch i32 %99, label %102 [
    i32 0, label %100
  ]

100:                                              ; preds = %98
  br label %26, !llvm.loop !15

101:                                              ; preds = %26
  store i32 0, ptr %16, align 4
  br label %102

102:                                              ; preds = %101, %98
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  %103 = load i32, ptr %16, align 4
  switch i32 %103, label %105 [
    i32 0, label %104
  ]

104:                                              ; preds = %102
  store i32 -1, ptr %5, align 4
  store i32 1, ptr %16, align 4
  br label %105

105:                                              ; preds = %104, %102
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  %106 = load i32, ptr %5, align 4
  ret i32 %106
}

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 i32 @string__indexOf__(ptr nocapture readonly %0, i32 %1, ptr nocapture readonly %2, i32 %3) local_unnamed_addr #1 {
  %5 = sub nsw i32 %1, %3
  %6 = tail call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @top_____abandonFn__)
  %7 = zext i32 %1 to i64
  %smax = tail call i32 @llvm.smax.i32(i32 %3, i32 0)
  %smax47 = tail call i32 @llvm.smax.i32(i32 %5, i32 -1)
  %8 = add i32 %smax47, 1
  %wide.trip.count48 = zext i32 %8 to i64
  %wide.trip.count = zext nneg i32 %smax to i64
  br label %9

9:                                                ; preds = %.split.loop.exit50, %4
  %indvars.iv40 = phi i64 [ %indvars.iv.next41, %.split.loop.exit50 ], [ 0, %4 ]
  %exitcond49 = icmp eq i64 %indvars.iv40, %wide.trip.count48
  br i1 %exitcond49, label %.split.loop.exit52, label %.preheader

.preheader:                                       ; preds = %9, %14
  %indvars.iv42 = phi i64 [ %indvars.iv.next43, %14 ], [ %indvars.iv40, %9 ]
  %indvars.iv = phi i64 [ %indvars.iv.next, %14 ], [ 0, %9 ]
  %exitcond.not = icmp eq i64 %indvars.iv, %wide.trip.count
  br i1 %exitcond.not, label %.split.loop.exit50, label %10

10:                                               ; preds = %.preheader
  %11 = icmp ult i64 %indvars.iv42, %7
  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.iv42
  %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
  %19 = icmp eq i8 %16, %18
  %indvars.iv.next43 = add nuw nsw i64 %indvars.iv42, 1
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  br i1 %19, label %.preheader, label %.split.loop.exit

.split.loop.exit:                                 ; preds = %14
  %20 = trunc nuw nsw i64 %indvars.iv to i32
  br label %.split.loop.exit50

.split.loop.exit50:                               ; preds = %.preheader, %.split.loop.exit
  %.030.lcssa = phi i32 [ %20, %.split.loop.exit ], [ %smax, %.preheader ]
  %.not = icmp eq i32 %.030.lcssa, %3
  %indvars.iv.next41 = add nuw nsw i64 %indvars.iv40, 1
  br i1 %.not, label %.split.loop.exit53, label %9, !llvm.loop !10

.split.loop.exit53:                               ; preds = %.split.loop.exit50
  %indvars.le = trunc i64 %indvars.iv40 to i32
  br label %.split.loop.exit52

.split.loop.exit52:                               ; preds = %9, %.split.loop.exit53
  %spec.select = phi i32 [ %indvars.le, %.split.loop.exit53 ], [ -1, %9 ]
  ret i32 %spec.select
}

; 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: ADCEPass,ConstraintEliminationPass,CorrelatedValuePropagationPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LICMPass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass