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

; 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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

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

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

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

11:                                               ; preds = %41, %3
  %12 = load i32, ptr %7, align 4, !tbaa !11
  %13 = load i32, ptr @g_NumHashers, align 4, !tbaa !11
  %14 = icmp ult i32 %12, %13
  br i1 %14, label %15, label %44

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

25:                                               ; preds = %15
  %26 = load ptr, ptr %8, align 8, !tbaa !9
  %27 = getelementptr inbounds %struct.CHasherInfo, ptr %26, i32 0, i32 0
  %28 = load ptr, ptr %27, align 8, !tbaa !15
  %29 = call noundef ptr %28()
  %30 = load ptr, ptr %6, align 8, !tbaa !9
  %31 = call noundef ptr @_ZN9CMyComPtrI7IHasherEaSEPS0_(ptr noundef nonnull align 8 dereferenceable(8) %30, ptr noundef %29)
  %32 = load ptr, ptr %8, align 8, !tbaa !9
  %33 = getelementptr inbounds %struct.CHasherInfo, ptr %32, i32 0, i32 2
  %34 = load ptr, ptr %33, align 8, !tbaa !16
  %35 = load ptr, ptr %5, align 8, !tbaa !9
  %36 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZN7AStringaSEPKc(ptr noundef nonnull align 8 dereferenceable(16) %35, ptr noundef %34)
  store i32 2, ptr %9, align 4
  br label %38

37:                                               ; preds = %15
  store i32 0, ptr %9, align 4
  br label %38

38:                                               ; preds = %37, %25
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  %39 = load i32, ptr %9, align 4
  switch i32 %39, label %45 [
    i32 0, label %40
    i32 2, label %44
  ]

40:                                               ; preds = %38
  br label %41

41:                                               ; preds = %40
  %42 = load i32, ptr %7, align 4, !tbaa !11
  %43 = add i32 %42, 1
  store i32 %43, ptr %7, align 4, !tbaa !11
  br label %11, !llvm.loop !17

44:                                               ; preds = %38, %11
  store i32 1, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  ret i32 0

45:                                               ; preds = %38
  unreachable
}

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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" }
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 = !{!"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 8}
!14 = !{!"_ZTS11CHasherInfo", !10, i64 0, !6, i64 8, !10, i64 16, !12, i64 24}
!15 = !{!14, !10, i64 0}
!16 = !{!14, !10, i64 16}
!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_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: mustprogress nounwind uwtable
declare dso_local void @_ZN7AString5EmptyEv(ptr noundef nonnull align 8 dereferenceable(16)) local_unnamed_addr #0 align 2

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

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z12CreateHasheryR7AStringR9CMyComPtrI7IHasherE(i64 noundef %0, ptr noundef nonnull align 8 dereferenceable(16) %1, ptr noundef nonnull align 8 dereferenceable(8) %2) local_unnamed_addr #2 {
  tail call void @_ZN7AString5EmptyEv(ptr noundef nonnull align 8 dereferenceable(16) %1)
  %4 = load i32, ptr @g_NumHashers, align 4, !tbaa !5
  %.not = icmp eq i32 %4, 0
  br i1 %.not, label %.loopexit, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %3
  %wide.trip.count = zext i32 %4 to i64
  br label %.lr.ph

5:                                                ; preds = %.lr.ph
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %.loopexit, label %.lr.ph, !llvm.loop !9

.lr.ph:                                           ; preds = %.lr.ph.preheader, %5
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next, %5 ]
  %6 = getelementptr inbounds [16 x ptr], ptr @g_Hashers, i64 0, i64 %indvars.iv
  %7 = load ptr, ptr %6, align 8, !tbaa !11
  %8 = getelementptr inbounds i8, ptr %7, i64 8
  %9 = load i64, ptr %8, align 8, !tbaa !13
  %10 = icmp eq i64 %9, %0
  br i1 %10, label %11, label %5

11:                                               ; preds = %.lr.ph
  %12 = load ptr, ptr %7, align 8, !tbaa !16
  %13 = tail call noundef ptr %12()
  %14 = tail call noundef ptr @_ZN9CMyComPtrI7IHasherEaSEPS0_(ptr noundef nonnull align 8 dereferenceable(8) %2, ptr noundef %13)
  %15 = getelementptr inbounds i8, ptr %7, i64 16
  %16 = load ptr, ptr %15, align 8, !tbaa !17
  %17 = tail call noundef nonnull align 8 dereferenceable(16) ptr @_ZN7AStringaSEPKc(ptr noundef nonnull align 8 dereferenceable(16) %1, ptr noundef %16)
  br label %.loopexit

.loopexit:                                        ; preds = %5, %3, %11
  ret i32 0
}

; Function Attrs: mustprogress uwtable
declare dso_local noundef ptr @_ZN9CMyComPtrI7IHasherEaSEPS0_(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef) local_unnamed_addr #2 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 = { "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 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" }

!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, !15, i64 8}
!14 = !{!"_ZTS11CHasherInfo", !12, i64 0, !15, i64 8, !12, i64 16, !6, i64 24}
!15 = !{!"long long", !7, i64 0}
!16 = !{!14, !12, i64 0}
!17 = !{!14, !12, i64 16}


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