; LLVM IR from gulrak/filesystem :: test/impl_test.ll (ZN3ghc10filesystem6detail26compare_simple_insensitiveEPKcmS3_m)

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_ZN3ghc10filesystem6detail26compare_simple_insensitiveEPKcmS3_m(ptr noundef %0, i64 noundef %1, ptr noundef %2, i64 noundef %3) #0 {
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i64, align 8
  store ptr %0, ptr %6, align 8, !tbaa !5
  store i64 %1, ptr %7, align 8, !tbaa !9
  store ptr %2, ptr %8, align 8, !tbaa !5
  store i64 %3, ptr %9, align 8, !tbaa !9
  br label %10

10:                                               ; preds = %28, %4
  %11 = load i64, ptr %7, align 8, !tbaa !9
  %12 = icmp ugt i64 %11, 0
  br i1 %12, label %13, label %26

13:                                               ; preds = %10
  %14 = load i64, ptr %9, align 8, !tbaa !9
  %15 = icmp ugt i64 %14, 0
  br i1 %15, label %16, label %26

16:                                               ; preds = %13
  %17 = load ptr, ptr %6, align 8, !tbaa !5
  %18 = load i8, ptr %17, align 1, !tbaa !11
  %19 = zext i8 %18 to i32
  %20 = call i32 @tolower(i32 noundef %19) #2
  %21 = load ptr, ptr %8, align 8, !tbaa !5
  %22 = load i8, ptr %21, align 1, !tbaa !11
  %23 = zext i8 %22 to i32
  %24 = call i32 @tolower(i32 noundef %23) #2
  %25 = icmp eq i32 %20, %24
  br label %26

26:                                               ; preds = %16, %13, %10
  %27 = phi i1 [ false, %13 ], [ false, %10 ], [ %25, %16 ]
  br i1 %27, label %28, label %37

28:                                               ; preds = %26
  %29 = load i64, ptr %7, align 8, !tbaa !9
  %30 = add i64 %29, -1
  store i64 %30, ptr %7, align 8, !tbaa !9
  %31 = load i64, ptr %9, align 8, !tbaa !9
  %32 = add i64 %31, -1
  store i64 %32, ptr %9, align 8, !tbaa !9
  %33 = load ptr, ptr %6, align 8, !tbaa !5
  %34 = getelementptr inbounds i8, ptr %33, i32 1
  store ptr %34, ptr %6, align 8, !tbaa !5
  %35 = load ptr, ptr %8, align 8, !tbaa !5
  %36 = getelementptr inbounds i8, ptr %35, i32 1
  store ptr %36, ptr %8, align 8, !tbaa !5
  br label %10, !llvm.loop !12

37:                                               ; preds = %26
  %38 = load i64, ptr %7, align 8, !tbaa !9
  %39 = icmp ne i64 %38, 0
  br i1 %39, label %40, label %53

40:                                               ; preds = %37
  %41 = load i64, ptr %9, align 8, !tbaa !9
  %42 = icmp ne i64 %41, 0
  br i1 %42, label %43, label %53

43:                                               ; preds = %40
  %44 = load ptr, ptr %6, align 8, !tbaa !5
  %45 = load i8, ptr %44, align 1, !tbaa !11
  %46 = sext i8 %45 to i32
  %47 = load ptr, ptr %8, align 8, !tbaa !5
  %48 = load i8, ptr %47, align 1, !tbaa !11
  %49 = sext i8 %48 to i32
  %50 = icmp slt i32 %46, %49
  %51 = zext i1 %50 to i64
  %52 = select i1 %50, i32 -1, i32 1
  store i32 %52, ptr %5, align 4
  br label %65

53:                                               ; preds = %40, %37
  %54 = load i64, ptr %7, align 8, !tbaa !9
  %55 = icmp eq i64 %54, 0
  br i1 %55, label %56, label %60

56:                                               ; preds = %53
  %57 = load i64, ptr %9, align 8, !tbaa !9
  %58 = icmp eq i64 %57, 0
  br i1 %58, label %59, label %60

59:                                               ; preds = %56
  store i32 0, ptr %5, align 4
  br label %65

60:                                               ; preds = %56, %53
  %61 = load i64, ptr %7, align 8, !tbaa !9
  %62 = icmp eq i64 %61, 0
  %63 = zext i1 %62 to i64
  %64 = select i1 %62, i32 -1, i32 1
  store i32 %64, ptr %5, align 4
  br label %65

65:                                               ; preds = %60, %59, %43
  %66 = load i32, ptr %5, align 4
  ret i32 %66
}

; Function Attrs: nounwind willreturn memory(read)
declare i32 @tolower(i32 noundef) #1

attributes #0 = { mustprogress 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 = { nounwind willreturn memory(read) "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 willreturn memory(read) }

!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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"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: mustprogress nofree nounwind willreturn memory(read) uwtable
define dso_local noundef range(i32 -1, 2) i32 @_ZN3ghc10filesystem6detail26compare_simple_insensitiveEPKcmS3_m(ptr nocapture noundef readonly %0, i64 noundef %1, ptr nocapture noundef readonly %2, i64 noundef %3) local_unnamed_addr #0 {
  %5 = icmp ne i64 %1, 0
  %6 = icmp ne i64 %3, 0
  %or.cond28 = and i1 %5, %6
  br i1 %or.cond28, label %.lr.ph, label %.critedge

.lr.ph:                                           ; preds = %4, %14
  %.032 = phi i64 [ %16, %14 ], [ %3, %4 ]
  %.02031 = phi ptr [ %18, %14 ], [ %2, %4 ]
  %.02130 = phi i64 [ %15, %14 ], [ %1, %4 ]
  %.02229 = phi ptr [ %17, %14 ], [ %0, %4 ]
  %7 = load i8, ptr %.02229, align 1, !tbaa !5
  %8 = zext i8 %7 to i32
  %9 = tail call i32 @tolower(i32 noundef %8) #2
  %10 = load i8, ptr %.02031, align 1, !tbaa !5
  %11 = zext i8 %10 to i32
  %12 = tail call i32 @tolower(i32 noundef %11) #2
  %13 = icmp eq i32 %9, %12
  br i1 %13, label %14, label %21

14:                                               ; preds = %.lr.ph
  %15 = add i64 %.02130, -1
  %16 = add i64 %.032, -1
  %17 = getelementptr inbounds i8, ptr %.02229, i64 1
  %18 = getelementptr inbounds i8, ptr %.02031, i64 1
  %19 = icmp ne i64 %15, 0
  %20 = icmp ne i64 %16, 0
  %or.cond = select i1 %19, i1 %20, i1 false
  br i1 %or.cond, label %.lr.ph, label %.critedge, !llvm.loop !8

21:                                               ; preds = %.lr.ph
  %22 = icmp slt i8 %7, %10
  %23 = select i1 %22, i32 -1, i32 1
  br label %27

.critedge:                                        ; preds = %14, %4
  %.021.lcssa = phi i64 [ %1, %4 ], [ %15, %14 ]
  %.0.lcssa = phi i64 [ %3, %4 ], [ %16, %14 ]
  %24 = icmp eq i64 %.021.lcssa, 0
  %25 = icmp ne i64 %.0.lcssa, 0
  %26 = sext i1 %25 to i32
  %spec.select = select i1 %24, i32 %26, i32 1
  br label %27

27:                                               ; preds = %.critedge, %21
  %.023 = phi i32 [ %23, %21 ], [ %spec.select, %.critedge ]
  ret i32 %.023
}

; Function Attrs: mustprogress nofree nounwind willreturn memory(read)
declare i32 @tolower(i32 noundef) local_unnamed_addr #1

attributes #0 = { mustprogress nofree nounwind willreturn memory(read) 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 = { mustprogress nofree nounwind willreturn memory(read) "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 willreturn memory(read) }

!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++ TBAA"}
!8 = distinct !{!8, !9}
!9 = !{!"llvm.loop.mustprogress"}


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