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

; 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__(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 = %70, %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 %71

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
  store i8 %44, ptr %14, align 1, !tbaa !14
  call void @llvm.lifetime.start.p0(i64 1, ptr %15) #2
  %45 = load ptr, ptr %12, align 8, !tbaa !13
  %46 = load i8, ptr %45, align 1, !tbaa !14
  store i8 %46, ptr %15, align 1, !tbaa !14
  %47 = load i8, ptr %14, align 1, !tbaa !14
  %48 = sext i8 %47 to i32
  %49 = load i8, ptr %15, align 1, !tbaa !14
  %50 = sext i8 %49 to i32
  %51 = icmp eq i32 %48, %50
  br i1 %51, label %52, label %53

52:                                               ; preds = %42
  br label %61

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

59:                                               ; preds = %53
  store i32 -1, ptr %5, align 4
  store i32 1, ptr %16, align 4
  br label %68

60:                                               ; preds = %53
  store i32 1, ptr %5, align 4
  store i32 1, ptr %16, align 4
  br label %68

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

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

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

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

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

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

80:                                               ; preds = %74
  store i32 -1, ptr %5, align 4
  store i32 1, ptr %16, align 4
  br label %90

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

87:                                               ; preds = %81
  store i32 1, ptr %5, align 4
  store i32 1, ptr %16, align 4
  br label %90

88:                                               ; preds = %81
  br label %89

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

90:                                               ; preds = %89, %87, %80, %72
  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
  %91 = load i32, ptr %5, align 4
  ret i32 %91
}

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: nofree norecurse nosync nounwind memory(read, inaccessiblemem: none) uwtable
define dso_local i32 @string__compare__(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 = load i8, ptr %2, align 1, !tbaa !5
  %8 = icmp eq i8 %6, %7
  br i1 %8, label %.lr.ph62, label %.thread

.lr.ph:                                           ; preds = %.lr.ph62
  %9 = getelementptr inbounds i8, ptr %.0304361, i64 1
  %10 = getelementptr inbounds i8, ptr %.0264559, i64 1
  %11 = load i8, ptr %10, align 1, !tbaa !5
  %12 = load i8, ptr %9, align 1, !tbaa !5
  %13 = icmp eq i8 %11, %12
  br i1 %13, label %.lr.ph62, label %.thread.loopexit

.thread.loopexit:                                 ; preds = %.lr.ph
  %.not.le = icmp slt i32 %15, %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 [ %6, %.lr.ph.preheader ], [ %11, %.thread.loopexit ]
  %.lcssa = phi i8 [ %7, %.lr.ph.preheader ], [ %12, %.thread.loopexit ]
  %14 = icmp ult i8 %.lcssa56, %.lcssa
  %. = select i1 %14, i32 -1, i32 1
  br label %.loopexit

.lr.ph62:                                         ; preds = %.lr.ph.preheader, %.lr.ph
  %.0304361 = phi ptr [ %9, %.lr.ph ], [ %2, %.lr.ph.preheader ]
  %.0284460 = phi i32 [ %15, %.lr.ph ], [ 0, %.lr.ph.preheader ]
  %.0264559 = phi ptr [ %10, %.lr.ph ], [ %0, %.lr.ph.preheader ]
  %15 = add nuw nsw i32 %.0284460, 1
  %exitcond.not = icmp eq i32 %15, %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 ]
  %16 = icmp slt i32 %1, %3
  %brmerge = or i1 %16, %.not40
  %17 = icmp sgt i32 %1, %3
  %.34 = zext i1 %17 to i32
  %.3 = select i1 %brmerge, i32 %.2.mux, i32 %.34
  ret i32 %.3
}

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

attributes #0 = { nofree norecurse nosync nounwind memory(read, inaccessiblemem: none) 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