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

; 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: 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: mustprogress uwtable
define dso_local noundef zeroext i1 @_Z10FindMethodyR7AString(i64 noundef %0, ptr noundef nonnull align 8 dereferenceable(16) %1) #1 {
  %3 = alloca i1, align 1
  %4 = alloca i64, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  store i64 %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !9
  %9 = load ptr, ptr %5, align 8, !tbaa !9
  call void @_ZN7AString5EmptyEv(ptr noundef nonnull align 8 dereferenceable(16) %9)
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  store i32 0, ptr %6, align 4, !tbaa !11
  br label %10

10:                                               ; preds = %34, %2
  %11 = load i32, ptr %6, align 4, !tbaa !11
  %12 = load i32, ptr @g_NumCodecs, align 4, !tbaa !11
  %13 = icmp ult i32 %11, %12
  br i1 %13, label %14, label %37

14:                                               ; preds = %10
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %15 = load i32, ptr %6, align 4, !tbaa !11
  %16 = zext i32 %15 to i64
  %17 = getelementptr inbounds [64 x ptr], ptr @g_Codecs, i64 0, i64 %16
  %18 = load ptr, ptr %17, align 8, !tbaa !9
  store ptr %18, ptr %7, align 8, !tbaa !9
  %19 = load i64, ptr %4, align 8, !tbaa !5
  %20 = load ptr, ptr %7, align 8, !tbaa !9
  %21 = getelementptr inbounds %struct.CCodecInfo, ptr %20, i32 0, i32 2
  %22 = load i64, ptr %21, align 8, !tbaa !13
  %23 = icmp eq i64 %19, %22
  br i1 %23, label %24, label %30

24:                                               ; preds = %14
  %25 = load ptr, ptr %7, align 8, !tbaa !9
  %26 = getelementptr inbounds %struct.CCodecInfo, ptr %25, i32 0, i32 3
  %27 = load ptr, ptr %26, align 8, !tbaa !16
  %28 = load ptr, ptr %5, align 8, !tbaa !9
  %29 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZN7AStringaSEPKc(ptr noundef nonnull align 8 dereferenceable(16) %28, ptr noundef %27)
  store i1 true, ptr %3, align 1
  store i32 1, ptr %8, align 4
  br label %31

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

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

33:                                               ; preds = %31
  br label %34

34:                                               ; preds = %33
  %35 = load i32, ptr %6, align 4, !tbaa !11
  %36 = add i32 %35, 1
  store i32 %36, ptr %6, align 4, !tbaa !11
  br label %10, !llvm.loop !17

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

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

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

declare noundef nonnull align 8 dereferenceable(16) ptr @_ZN7AStringaSEPKc(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 = { "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 = !{!"long long", !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, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !6, i64 16}
!14 = !{!"_ZTS10CCodecInfo", !10, i64 0, !10, i64 8, !6, i64 16, !10, i64 24, !12, i64 32, !15, i64 36}
!15 = !{!"bool", !7, i64 0}
!16 = !{!14, !10, i64 24}
!17 = distinct !{!17, !18}
!18 = !{!"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 uwtable
define dso_local noundef zeroext i1 @_Z10FindMethodyR7AString(i64 noundef %0, ptr noundef nonnull align 8 dereferenceable(16) %1) local_unnamed_addr #0 {
  tail call void @_ZN7AString5EmptyEv(ptr noundef nonnull align 8 dereferenceable(16) %1)
  %3 = load i32, ptr @g_NumCodecs, align 4, !tbaa !5
  %.not18 = icmp eq i32 %3, 0
  br i1 %.not18, label %.loopexit, label %.critedge.preheader

.critedge.preheader:                              ; preds = %2
  %4 = zext i32 %3 to i64
  %5 = load ptr, ptr @g_Codecs, align 16, !tbaa !9
  %6 = getelementptr inbounds i8, ptr %5, i64 16
  %7 = load i64, ptr %6, align 8, !tbaa !11
  %.not27 = icmp eq i64 %7, %0
  br i1 %.not27, label %.critedge._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %.critedge.preheader, %.critedge
  %indvars.iv28 = phi i64 [ %indvars.iv.next, %.critedge ], [ 0, %.critedge.preheader ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv28, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %4
  br i1 %exitcond.not, label %.loopexit, label %.critedge, !llvm.loop !15

.critedge:                                        ; preds = %.lr.ph
  %8 = getelementptr inbounds [64 x ptr], ptr @g_Codecs, i64 0, i64 %indvars.iv.next
  %9 = load ptr, ptr %8, align 8, !tbaa !9
  %10 = getelementptr inbounds i8, ptr %9, i64 16
  %11 = load i64, ptr %10, align 8, !tbaa !11
  %.not = icmp eq i64 %11, %0
  br i1 %.not, label %.critedge._crit_edge.loopexit, label %.lr.ph, !llvm.loop !15

.critedge._crit_edge.loopexit:                    ; preds = %.critedge
  %12 = icmp ult i64 %indvars.iv.next, %4
  br label %.critedge._crit_edge

.critedge._crit_edge:                             ; preds = %.critedge._crit_edge.loopexit, %.critedge.preheader
  %.lcssa24 = phi i1 [ true, %.critedge.preheader ], [ %12, %.critedge._crit_edge.loopexit ]
  %.lcssa = phi ptr [ %5, %.critedge.preheader ], [ %9, %.critedge._crit_edge.loopexit ]
  %13 = getelementptr inbounds i8, ptr %.lcssa, i64 24
  %14 = load ptr, ptr %13, align 8, !tbaa !17
  %15 = tail call noundef nonnull align 8 dereferenceable(16) ptr @_ZN7AStringaSEPKc(ptr noundef nonnull align 8 dereferenceable(16) %1, ptr noundef %14)
  br label %.loopexit

.loopexit:                                        ; preds = %.lr.ph, %2, %.critedge._crit_edge
  %16 = phi i1 [ %.lcssa24, %.critedge._crit_edge ], [ false, %2 ], [ false, %.lr.ph ]
  ret i1 %16
}

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

declare noundef nonnull align 8 dereferenceable(16) ptr @_ZN7AStringaSEPKc(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef) local_unnamed_addr #2

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 = { 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 = { "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" }

!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, !13, i64 16}
!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 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = !{!12, !10, i64 24}


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