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

; 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 }

; 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 willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nounwind uwtable
define dso_local i32 @string__compare_ignoreCase__(ptr %0, i32 %1, ptr %2, i32 %3) #1 {
  %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 ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca i32, align 4
  %14 = alloca i8, align 1
  %15 = alloca i8, align 1
  %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) #2
  %21 = getelementptr inbounds %struct.string__, ptr %6, i32 0, i32 1
  %22 = load i32, ptr %21, align 8, !tbaa !5
  store i32 %22, ptr %8, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #2
  %23 = getelementptr inbounds %struct.string__, ptr %7, i32 0, i32 1
  %24 = load i32, ptr %23, align 8, !tbaa !5
  store i32 %24, ptr %9, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #2
  %25 = load i32, ptr %8, align 4, !tbaa !11
  %26 = load i32, ptr %9, align 4, !tbaa !11
  %27 = icmp slt i32 %25, %26
  br i1 %27, label %28, label %30

28:                                               ; preds = %4
  %29 = load i32, ptr %8, align 4, !tbaa !11
  br label %32

30:                                               ; preds = %4
  %31 = load i32, ptr %9, align 4, !tbaa !11
  br label %32

32:                                               ; preds = %30, %28
  %33 = phi i32 [ %29, %28 ], [ %31, %30 ]
  store i32 %33, ptr %10, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #2
  %34 = getelementptr inbounds %struct.string__, ptr %6, i32 0, i32 0
  %35 = load ptr, ptr %34, align 8, !tbaa !12
  store ptr %35, ptr %11, align 8, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #2
  %36 = getelementptr inbounds %struct.string__, ptr %7, i32 0, i32 0
  %37 = load ptr, ptr %36, align 8, !tbaa !12
  store ptr %37, ptr %12, align 8, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #2
  store i32 0, ptr %13, align 4, !tbaa !11
  br label %38

38:                                               ; preds = %72, %32
  %39 = load i32, ptr %13, align 4, !tbaa !11
  %40 = load i32, ptr %10, align 4, !tbaa !11
  %41 = icmp slt i32 %39, %40
  br i1 %41, label %42, label %73

42:                                               ; preds = %38
  call void @llvm.lifetime.start.p0(i64 1, ptr %14) #2
  %43 = load ptr, ptr %11, align 8, !tbaa !13
  %44 = load i8, ptr %43, align 1, !tbaa !14
  %45 = call signext i8 @string__toLower___(i8 noundef signext %44)
  store i8 %45, ptr %14, align 1, !tbaa !14
  call void @llvm.lifetime.start.p0(i64 1, ptr %15) #2
  %46 = load ptr, ptr %12, align 8, !tbaa !13
  %47 = load i8, ptr %46, align 1, !tbaa !14
  %48 = call signext i8 @string__toLower___(i8 noundef signext %47)
  store i8 %48, ptr %15, align 1, !tbaa !14
  %49 = load i8, ptr %14, align 1, !tbaa !14
  %50 = sext i8 %49 to i32
  %51 = load i8, ptr %15, align 1, !tbaa !14
  %52 = sext i8 %51 to i32
  %53 = icmp eq i32 %50, %52
  br i1 %53, label %54, label %55

54:                                               ; preds = %42
  br label %63

55:                                               ; preds = %42
  %56 = load i8, ptr %14, align 1, !tbaa !14
  %57 = zext i8 %56 to i32
  %58 = load i8, ptr %15, align 1, !tbaa !14
  %59 = zext i8 %58 to i32
  %60 = icmp slt i32 %57, %59
  br i1 %60, label %61, label %62

61:                                               ; preds = %55
  store i32 -1, ptr %5, align 4
  store i32 1, ptr %16, align 4
  br label %70

62:                                               ; preds = %55
  store i32 1, ptr %5, align 4
  store i32 1, ptr %16, align 4
  br label %70

63:                                               ; preds = %54
  %64 = load ptr, ptr %11, align 8, !tbaa !13
  %65 = getelementptr inbounds i8, ptr %64, i64 1
  store ptr %65, ptr %11, align 8, !tbaa !13
  %66 = load ptr, ptr %12, align 8, !tbaa !13
  %67 = getelementptr inbounds i8, ptr %66, i64 1
  store ptr %67, ptr %12, align 8, !tbaa !13
  %68 = load i32, ptr %13, align 4, !tbaa !11
  %69 = add nsw i32 %68, 1
  store i32 %69, ptr %13, align 4, !tbaa !11
  store i32 0, ptr %16, align 4
  br label %70

70:                                               ; preds = %63, %62, %61
  call void @llvm.lifetime.end.p0(i64 1, ptr %15) #2
  call void @llvm.lifetime.end.p0(i64 1, ptr %14) #2
  %71 = load i32, ptr %16, align 4
  switch i32 %71, label %74 [
    i32 0, label %72
  ]

72:                                               ; preds = %70
  br label %38, !llvm.loop !15

73:                                               ; preds = %38
  store i32 0, ptr %16, align 4
  br label %74

74:                                               ; preds = %73, %70
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #2
  %75 = load i32, ptr %16, align 4
  switch i32 %75, label %92 [
    i32 0, label %76
  ]

76:                                               ; preds = %74
  %77 = getelementptr inbounds %struct.string__, ptr %6, i32 0, i32 1
  %78 = load i32, ptr %77, align 8, !tbaa !5
  %79 = getelementptr inbounds %struct.string__, ptr %7, i32 0, i32 1
  %80 = load i32, ptr %79, align 8, !tbaa !5
  %81 = icmp slt i32 %78, %80
  br i1 %81, label %82, label %83

82:                                               ; preds = %76
  store i32 -1, ptr %5, align 4
  store i32 1, ptr %16, align 4
  br label %92

83:                                               ; preds = %76
  %84 = getelementptr inbounds %struct.string__, ptr %6, i32 0, i32 1
  %85 = load i32, ptr %84, align 8, !tbaa !5
  %86 = getelementptr inbounds %struct.string__, ptr %7, i32 0, i32 1
  %87 = load i32, ptr %86, align 8, !tbaa !5
  %88 = icmp sgt i32 %85, %87
  br i1 %88, label %89, label %90

89:                                               ; preds = %83
  store i32 1, ptr %5, align 4
  store i32 1, ptr %16, align 4
  br label %92

90:                                               ; preds = %83
  br label %91

91:                                               ; preds = %90
  store i32 0, ptr %5, align 4
  store i32 1, ptr %16, align 4
  br label %92

92:                                               ; preds = %91, %89, %82, %74
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  %93 = load i32, ptr %5, align 4
  ret i32 %93
}

; Function Attrs: nounwind uwtable
declare dso_local signext i8 @string__toLower___(i8 noundef signext) #1

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 = !{!6, !7, i64 0}
!13 = !{!7, !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"

; Function Attrs: nounwind uwtable
define dso_local i32 @string__compare_ignoreCase__(ptr nocapture readonly %0, i32 %1, ptr nocapture readonly %2, i32 %3) local_unnamed_addr #0 {
  %5 = tail call i32 @llvm.smin.i32(i32 %1, i32 %3)
  %.not42 = icmp sgt i32 %5, 0
  br i1 %.not42, label %.lr.ph.preheader, label %.loopexit

.lr.ph.preheader:                                 ; preds = %4
  %6 = load i8, ptr %0, align 1, !tbaa !5
  %7 = tail call signext i8 @string__toLower___(i8 noundef signext %6)
  %8 = load i8, ptr %2, align 1, !tbaa !5
  %9 = tail call signext i8 @string__toLower___(i8 noundef signext %8)
  %10 = icmp eq i8 %7, %9
  br i1 %10, label %.lr.ph62, label %.thread

.lr.ph:                                           ; preds = %.lr.ph62
  %11 = getelementptr inbounds i8, ptr %.0304361, i64 1
  %12 = getelementptr inbounds i8, ptr %.0264559, i64 1
  %13 = load i8, ptr %12, align 1, !tbaa !5
  %14 = tail call signext i8 @string__toLower___(i8 noundef signext %13)
  %15 = load i8, ptr %11, align 1, !tbaa !5
  %16 = tail call signext i8 @string__toLower___(i8 noundef signext %15)
  %17 = icmp eq i8 %14, %16
  br i1 %17, label %.lr.ph62, label %.thread.loopexit

.thread.loopexit:                                 ; preds = %.lr.ph
  %.not.le = icmp slt i32 %19, %5
  br label %.thread

.thread:                                          ; preds = %.thread.loopexit, %.lr.ph.preheader
  %.not46.lcssa = phi i1 [ true, %.lr.ph.preheader ], [ %.not.le, %.thread.loopexit ]
  %.lcssa56 = phi i8 [ %7, %.lr.ph.preheader ], [ %14, %.thread.loopexit ]
  %.lcssa = phi i8 [ %9, %.lr.ph.preheader ], [ %16, %.thread.loopexit ]
  %18 = icmp ult i8 %.lcssa56, %.lcssa
  %. = select i1 %18, i32 -1, i32 1
  br label %.loopexit

.lr.ph62:                                         ; preds = %.lr.ph.preheader, %.lr.ph
  %.0304361 = phi ptr [ %11, %.lr.ph ], [ %2, %.lr.ph.preheader ]
  %.0284460 = phi i32 [ %19, %.lr.ph ], [ 0, %.lr.ph.preheader ]
  %.0264559 = phi ptr [ %12, %.lr.ph ], [ %0, %.lr.ph.preheader ]
  %19 = add nuw nsw i32 %.0284460, 1
  %exitcond.not = icmp eq i32 %19, %5
  br i1 %exitcond.not, label %.loopexit, label %.lr.ph

.loopexit:                                        ; preds = %.lr.ph62, %4, %.thread
  %.not40 = phi i1 [ %.not46.lcssa, %.thread ], [ false, %4 ], [ false, %.lr.ph62 ]
  %.2.mux = phi i32 [ %., %.thread ], [ -1, %4 ], [ -1, %.lr.ph62 ]
  %20 = icmp slt i32 %1, %3
  %brmerge = or i1 %20, %.not40
  %21 = icmp sgt i32 %1, %3
  %.34 = zext i1 %21 to i32
  %.3 = select i1 %brmerge, i32 %.2.mux, i32 %.34
  ret i32 %.3
}

; Function Attrs: nounwind uwtable
declare dso_local signext i8 @string__toLower___(i8 noundef signext) local_unnamed_addr #0

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

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }

!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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}


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