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

; 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 zeroext i8 @string__equals__(ptr %0, i32 %1, ptr %2, i32 %3) #1 {
  %5 = alloca i8, align 1
  %6 = alloca %struct.string__, align 8
  %7 = alloca %struct.string__, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  %11 = alloca i8, align 1
  %12 = alloca i8, align 1
  %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 ne i32 %19, %21
  br i1 %22, label %23, label %24

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

24:                                               ; preds = %4
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #2
  %25 = getelementptr inbounds %struct.string__, ptr %6, i32 0, i32 0
  %26 = load ptr, ptr %25, align 8, !tbaa !11
  store ptr %26, ptr %8, align 8, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #2
  %27 = getelementptr inbounds %struct.string__, ptr %7, i32 0, i32 0
  %28 = load ptr, ptr %27, align 8, !tbaa !11
  store ptr %28, ptr %9, align 8, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #2
  store i32 0, ptr %10, align 4, !tbaa !13
  br label %29

29:                                               ; preds = %54, %24
  %30 = load i32, ptr %10, align 4, !tbaa !13
  %31 = getelementptr inbounds %struct.string__, ptr %6, i32 0, i32 1
  %32 = load i32, ptr %31, align 8, !tbaa !5
  %33 = icmp slt i32 %30, %32
  br i1 %33, label %34, label %55

34:                                               ; preds = %29
  call void @llvm.lifetime.start.p0(i64 1, ptr %11) #2
  %35 = load ptr, ptr %8, align 8, !tbaa !12
  %36 = load i8, ptr %35, align 1, !tbaa !14
  store i8 %36, ptr %11, align 1, !tbaa !14
  call void @llvm.lifetime.start.p0(i64 1, ptr %12) #2
  %37 = load ptr, ptr %9, align 8, !tbaa !12
  %38 = load i8, ptr %37, align 1, !tbaa !14
  store i8 %38, ptr %12, align 1, !tbaa !14
  %39 = load i8, ptr %11, align 1, !tbaa !14
  %40 = sext i8 %39 to i32
  %41 = load i8, ptr %12, align 1, !tbaa !14
  %42 = sext i8 %41 to i32
  %43 = icmp ne i32 %40, %42
  br i1 %43, label %44, label %45

44:                                               ; preds = %34
  store i8 0, ptr %5, align 1
  store i32 1, ptr %13, align 4
  br label %52

45:                                               ; preds = %34
  %46 = load ptr, ptr %8, align 8, !tbaa !12
  %47 = getelementptr inbounds i8, ptr %46, i64 1
  store ptr %47, ptr %8, align 8, !tbaa !12
  %48 = load ptr, ptr %9, align 8, !tbaa !12
  %49 = getelementptr inbounds i8, ptr %48, i64 1
  store ptr %49, ptr %9, align 8, !tbaa !12
  %50 = load i32, ptr %10, align 4, !tbaa !13
  %51 = add nsw i32 %50, 1
  store i32 %51, ptr %10, align 4, !tbaa !13
  store i32 0, ptr %13, align 4
  br label %52

52:                                               ; preds = %45, %44
  call void @llvm.lifetime.end.p0(i64 1, ptr %12) #2
  call void @llvm.lifetime.end.p0(i64 1, ptr %11) #2
  %53 = load i32, ptr %13, align 4
  switch i32 %53, label %56 [
    i32 0, label %54
  ]

54:                                               ; preds = %52
  br label %29, !llvm.loop !15

55:                                               ; preds = %29
  store i32 0, ptr %13, align 4
  br label %56

56:                                               ; preds = %55, %52
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #2
  %57 = load i32, ptr %13, align 4
  switch i32 %57, label %59 [
    i32 0, label %58
  ]

58:                                               ; preds = %56
  store i8 1, ptr %5, align 1
  store i32 1, ptr %13, align 4
  br label %59

59:                                               ; preds = %58, %56
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #2
  br label %60

60:                                               ; preds = %59, %23
  %61 = load i8, ptr %5, align 1
  ret i8 %61
}

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 = !{!6, !7, i64 0}
!12 = !{!7, !7, i64 0}
!13 = !{!10, !10, 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 zeroext i8 @string__equals__(ptr nocapture readonly %0, i32 %1, ptr nocapture readonly %2, i32 %3) local_unnamed_addr #0 {
  %.not = icmp eq i32 %1, %3
  br i1 %.not, label %.preheader.preheader, label %12

.preheader.preheader:                             ; preds = %4
  %smax = tail call i32 @llvm.smax.i32(i32 %1, i32 0)
  br label %.preheader

.preheader:                                       ; preds = %.preheader.preheader, %5
  %.020 = phi ptr [ %9, %5 ], [ %2, %.preheader.preheader ]
  %.018 = phi i32 [ %10, %5 ], [ 0, %.preheader.preheader ]
  %.016 = phi ptr [ %8, %5 ], [ %0, %.preheader.preheader ]
  %exitcond = icmp eq i32 %.018, %smax
  br i1 %exitcond, label %11, label %5

5:                                                ; preds = %.preheader
  %6 = load i8, ptr %.016, align 1, !tbaa !5
  %7 = load i8, ptr %.020, align 1, !tbaa !5
  %.not23 = icmp eq i8 %6, %7
  %8 = getelementptr inbounds i8, ptr %.016, i64 1
  %9 = getelementptr inbounds i8, ptr %.020, i64 1
  %10 = add nuw i32 %.018, 1
  br i1 %.not23, label %.preheader, label %11, !llvm.loop !8

11:                                               ; preds = %.preheader, %5
  %.not24.le = icmp sge i32 %.018, %1
  %spec.select = zext i1 %.not24.le to i8
  br label %12

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.smax.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"}
!8 = distinct !{!8, !9}
!9 = !{!"llvm.loop.mustprogress"}


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