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

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

@g_NumCodecs = external dso_local global i32, align 4
@g_Codecs = external dso_local global [64 x ptr], align 16

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

14:                                               ; preds = %57, %4
  %15 = load i32, ptr %10, align 4, !tbaa !11
  %16 = load i32, ptr @g_NumCodecs, align 4, !tbaa !11
  %17 = icmp ult i32 %15, %16
  br i1 %17, label %18, label %60

18:                                               ; preds = %14
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  %19 = load i32, ptr %10, align 4, !tbaa !11
  %20 = zext i32 %19 to i64
  %21 = getelementptr inbounds [64 x ptr], ptr @g_Codecs, i64 0, i64 %20
  %22 = load ptr, ptr %21, align 8, !tbaa !5
  store ptr %22, ptr %11, align 8, !tbaa !5
  %23 = load i8, ptr %7, align 1, !tbaa !9, !range !13, !noundef !14
  %24 = trunc i8 %23 to i1
  br i1 %24, label %25, label %29

25:                                               ; preds = %18
  %26 = load ptr, ptr %11, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.CCodecInfo, ptr %26, i32 0, i32 1
  %28 = load ptr, ptr %27, align 8, !tbaa !15
  br label %33

29:                                               ; preds = %18
  %30 = load ptr, ptr %11, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.CCodecInfo, ptr %30, i32 0, i32 0
  %32 = load ptr, ptr %31, align 8, !tbaa !18
  br label %33

33:                                               ; preds = %29, %25
  %34 = phi ptr [ %28, %25 ], [ %32, %29 ]
  %35 = icmp ne ptr %34, null
  br i1 %35, label %36, label %53

36:                                               ; preds = %33
  %37 = load ptr, ptr %6, align 8, !tbaa !5
  %38 = call noundef ptr @_ZNK7AStringcvPKcEv(ptr noundef nonnull align 8 dereferenceable(16) %37)
  %39 = load ptr, ptr %11, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.CCodecInfo, ptr %39, i32 0, i32 3
  %41 = load ptr, ptr %40, align 8, !tbaa !19
  %42 = call noundef zeroext i1 @_Z27StringsAreEqualNoCase_AsciiPKcS0_(ptr noundef %38, ptr noundef %41) #4
  br i1 %42, label %43, label %53

43:                                               ; preds = %36
  %44 = load ptr, ptr %11, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.CCodecInfo, ptr %44, i32 0, i32 2
  %46 = load i64, ptr %45, align 8, !tbaa !20
  %47 = load ptr, ptr %8, align 8, !tbaa !5
  store i64 %46, ptr %47, align 8, !tbaa !21
  %48 = load ptr, ptr %11, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.CCodecInfo, ptr %48, i32 0, i32 4
  %50 = load i32, ptr %49, align 8, !tbaa !22
  %51 = load ptr, ptr %9, align 8, !tbaa !5
  store i32 %50, ptr %51, align 4, !tbaa !11
  %52 = load i32, ptr %10, align 4, !tbaa !11
  store i32 %52, ptr %5, align 4
  store i32 1, ptr %12, align 4
  br label %54

53:                                               ; preds = %36, %33
  store i32 0, ptr %12, align 4
  br label %54

54:                                               ; preds = %53, %43
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  %55 = load i32, ptr %12, align 4
  switch i32 %55, label %61 [
    i32 0, label %56
  ]

56:                                               ; preds = %54
  br label %57

57:                                               ; preds = %56
  %58 = load i32, ptr %10, align 4, !tbaa !11
  %59 = add i32 %58, 1
  store i32 %59, ptr %10, align 4, !tbaa !11
  br label %14, !llvm.loop !23

60:                                               ; preds = %14
  store i32 -1, ptr %5, align 4
  store i32 1, ptr %12, align 4
  br label %61

61:                                               ; preds = %60, %54
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  %62 = load i32, ptr %5, align 4
  ret i32 %62
}

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

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

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

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

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #3 = { 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 #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 = !{!"bool", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{i8 0, i8 2}
!14 = !{}
!15 = !{!16, !6, i64 8}
!16 = !{!"_ZTS10CCodecInfo", !6, i64 0, !6, i64 8, !17, i64 16, !6, i64 24, !12, i64 32, !10, i64 36}
!17 = !{!"long long", !7, i64 0}
!18 = !{!16, !6, i64 0}
!19 = !{!16, !6, i64 24}
!20 = !{!16, !17, i64 16}
!21 = !{!17, !17, i64 0}
!22 = !{!16, !12, i64 32}
!23 = distinct !{!23, !24}
!24 = !{!"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_NumCodecs = external dso_local local_unnamed_addr global i32, align 4
@g_Codecs = external dso_local local_unnamed_addr global [64 x ptr], align 16

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

.lr.ph:                                           ; preds = %4
  %.in.idx = select i1 %1, i64 8, i64 0
  br label %6

6:                                                ; preds = %.lr.ph, %22
  %7 = phi i32 [ %5, %.lr.ph ], [ %23, %22 ]
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %22 ]
  %8 = getelementptr inbounds [64 x ptr], ptr @g_Codecs, i64 0, i64 %indvars.iv
  %9 = load ptr, ptr %8, align 8, !tbaa !9
  %.in = getelementptr inbounds i8, ptr %9, i64 %.in.idx
  %10 = load ptr, ptr %.in, align 8, !tbaa !9
  %.not = icmp eq ptr %10, null
  br i1 %.not, label %22, label %11

11:                                               ; preds = %6
  %12 = tail call noundef ptr @_ZNK7AStringcvPKcEv(ptr noundef nonnull align 8 dereferenceable(16) %0)
  %13 = getelementptr inbounds i8, ptr %9, i64 24
  %14 = load ptr, ptr %13, align 8, !tbaa !11
  %15 = tail call noundef zeroext i1 @_Z27StringsAreEqualNoCase_AsciiPKcS0_(ptr noundef %12, ptr noundef %14) #2
  br i1 %15, label %16, label %._crit_edge

._crit_edge:                                      ; preds = %11
  %.pre = load i32, ptr @g_NumCodecs, align 4, !tbaa !5
  br label %22

16:                                               ; preds = %11
  %17 = trunc nuw i64 %indvars.iv to i32
  %18 = getelementptr inbounds i8, ptr %9, i64 16
  %19 = load i64, ptr %18, align 8, !tbaa !15
  store i64 %19, ptr %2, align 8, !tbaa !16
  %20 = getelementptr inbounds i8, ptr %9, i64 32
  %21 = load i32, ptr %20, align 8, !tbaa !17
  store i32 %21, ptr %3, align 4, !tbaa !5
  br label %.loopexit

22:                                               ; preds = %._crit_edge, %6
  %23 = phi i32 [ %.pre, %._crit_edge ], [ %7, %6 ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %24 = zext i32 %23 to i64
  %25 = icmp ult i64 %indvars.iv.next, %24
  br i1 %25, label %6, label %.loopexit, !llvm.loop !18

.loopexit:                                        ; preds = %22, %4, %16
  %.2 = phi i32 [ %17, %16 ], [ -1, %4 ], [ -1, %22 ]
  ret i32 %.2
}

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

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

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 "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 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !10, i64 24}
!12 = !{!"_ZTS10CCodecInfo", !10, i64 0, !10, i64 8, !13, i64 16, !10, i64 24, !6, i64 32, !14, i64 36}
!13 = !{!"long long", !7, i64 0}
!14 = !{!"bool", !7, i64 0}
!15 = !{!12, !13, i64 16}
!16 = !{!13, !13, i64 0}
!17 = !{!12, !6, i64 32}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}


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