; LLVM IR from SSBMTonberry/pocketlzma :: ref_spec/lzma1900/CPP/7zip/Common/CreateCoder.ll (Z14FindHashMethodRK7AStringRy)

; 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.CHasherInfo = type { ptr, i64, ptr, i32 }

@g_NumHashers = external dso_local global i32, align 4
@g_Hashers = external dso_local global [16 x ptr], align 16

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nounwind
declare noundef zeroext i1 @_Z27StringsAreEqualNoCase_AsciiPKcS0_(ptr noundef, ptr noundef) #1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZNK7AStringcvPKcEv(ptr noundef nonnull align 8 dereferenceable(16)) #2 align 2

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_Z14FindHashMethodRK7AStringRy(ptr noundef nonnull align 8 dereferenceable(16) %0, ptr noundef nonnull align 8 dereferenceable(8) %1) #3 {
  %3 = alloca i1, align 1
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  store i32 0, ptr %6, align 4, !tbaa !9
  br label %9

9:                                                ; preds = %33, %2
  %10 = load i32, ptr %6, align 4, !tbaa !9
  %11 = load i32, ptr @g_NumHashers, align 4, !tbaa !9
  %12 = icmp ult i32 %10, %11
  br i1 %12, label %13, label %36

13:                                               ; preds = %9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %14 = load i32, ptr %6, align 4, !tbaa !9
  %15 = zext i32 %14 to i64
  %16 = getelementptr inbounds [16 x ptr], ptr @g_Hashers, i64 0, i64 %15
  %17 = load ptr, ptr %16, align 8, !tbaa !5
  store ptr %17, ptr %7, align 8, !tbaa !5
  %18 = load ptr, ptr %4, align 8, !tbaa !5
  %19 = call noundef ptr @_ZNK7AStringcvPKcEv(ptr noundef nonnull align 8 dereferenceable(16) %18)
  %20 = load ptr, ptr %7, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.CHasherInfo, ptr %20, i32 0, i32 2
  %22 = load ptr, ptr %21, align 8, !tbaa !11
  %23 = call noundef zeroext i1 @_Z27StringsAreEqualNoCase_AsciiPKcS0_(ptr noundef %19, ptr noundef %22) #4
  br i1 %23, label %24, label %29

24:                                               ; preds = %13
  %25 = load ptr, ptr %7, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.CHasherInfo, ptr %25, i32 0, i32 1
  %27 = load i64, ptr %26, align 8, !tbaa !14
  %28 = load ptr, ptr %5, align 8, !tbaa !5
  store i64 %27, ptr %28, align 8, !tbaa !15
  store i1 true, ptr %3, align 1
  store i32 1, ptr %8, align 4
  br label %30

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

30:                                               ; preds = %29, %24
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  %31 = load i32, ptr %8, align 4
  switch i32 %31, label %37 [
    i32 0, label %32
  ]

32:                                               ; preds = %30
  br label %33

33:                                               ; preds = %32
  %34 = load i32, ptr %6, align 4, !tbaa !9
  %35 = add i32 %34, 1
  store i32 %35, ptr %6, align 4, !tbaa !9
  br label %9, !llvm.loop !16

36:                                               ; preds = %9
  store i1 false, ptr %3, align 1
  store i32 1, ptr %8, align 4
  br label %37

37:                                               ; preds = %36, %30
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  %38 = load i1, ptr %3, align 1
  ret i1 %38
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nounwind "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 = { 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 #3 = { mustprogress 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 #4 = { 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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !6, i64 16}
!12 = !{!"_ZTS11CHasherInfo", !6, i64 0, !13, i64 8, !6, i64 16, !10, i64 24}
!13 = !{!"long long", !7, i64 0}
!14 = !{!12, !13, i64 8}
!15 = !{!13, !13, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"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"

@g_NumHashers = external dso_local local_unnamed_addr global i32, align 4
@g_Hashers = external dso_local local_unnamed_addr global [16 x ptr], align 16

; Function Attrs: nounwind
declare noundef zeroext i1 @_Z27StringsAreEqualNoCase_AsciiPKcS0_(ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZNK7AStringcvPKcEv(ptr noundef nonnull align 8 dereferenceable(16)) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef zeroext i1 @_Z14FindHashMethodRK7AStringRy(ptr noundef nonnull align 8 dereferenceable(16) %0, ptr nocapture noundef nonnull writeonly align 8 dereferenceable(8) %1) local_unnamed_addr #1 {
  %3 = load i32, ptr @g_NumHashers, align 4, !tbaa !5
  %.not = icmp eq i32 %3, 0
  br i1 %.not, label %.loopexit, label %.critedge

4:                                                ; preds = %.critedge
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %5 = load i32, ptr @g_NumHashers, align 4, !tbaa !5
  %6 = zext i32 %5 to i64
  %7 = icmp ult i64 %indvars.iv.next, %6
  br i1 %7, label %.critedge, label %.loopexit, !llvm.loop !9

.critedge:                                        ; preds = %2, %4
  %indvars.iv = phi i64 [ %indvars.iv.next, %4 ], [ 0, %2 ]
  %8 = getelementptr inbounds [16 x ptr], ptr @g_Hashers, i64 0, i64 %indvars.iv
  %9 = load ptr, ptr %8, align 8, !tbaa !11
  %10 = tail call noundef ptr @_ZNK7AStringcvPKcEv(ptr noundef nonnull align 8 dereferenceable(16) %0)
  %11 = getelementptr inbounds i8, ptr %9, i64 16
  %12 = load ptr, ptr %11, align 8, !tbaa !13
  %13 = tail call noundef zeroext i1 @_Z27StringsAreEqualNoCase_AsciiPKcS0_(ptr noundef %10, ptr noundef %12) #2
  br i1 %13, label %14, label %4

14:                                               ; preds = %.critedge
  %15 = getelementptr inbounds i8, ptr %9, i64 8
  %16 = load i64, ptr %15, align 8, !tbaa !16
  store i64 %16, ptr %1, align 8, !tbaa !17
  br label %.loopexit

.loopexit:                                        ; preds = %4, %2, %14
  %17 = phi i1 [ true, %14 ], [ false, %2 ], [ false, %4 ]
  ret i1 %17
}

attributes #0 = { nounwind "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 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, !6, i64 0}
!6 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!12, !12, i64 0}
!12 = !{!"any pointer", !7, i64 0}
!13 = !{!14, !12, i64 16}
!14 = !{!"_ZTS11CHasherInfo", !12, i64 0, !15, i64 8, !12, i64 16, !6, i64 24}
!15 = !{!"long long", !7, i64 0}
!16 = !{!14, !15, i64 8}
!17 = !{!15, !15, i64 0}


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