; 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.CCreatedCoder = type { %class.CMyComPtr, %class.CMyComPtr.0, i8, i8, i32 }
%class.CMyComPtr = type { ptr }
%class.CMyComPtr.0 = type { ptr }
%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 i32 @_Z17CreateCoder_IndexjbR9CMyComPtrI15ICompressFilterER13CCreatedCoder(i32 noundef %0, i1 noundef zeroext %1, ptr noundef nonnull align 8 dereferenceable(8) %2, ptr noundef nonnull align 8 dereferenceable(24) %3) #1 {
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i8, align 1
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca i32, align 4
  %13 = alloca ptr, align 8
  store i32 %0, ptr %6, align 4, !tbaa !5
  %14 = zext i1 %1 to i8
  store i8 %14, ptr %7, align 1, !tbaa !9
  store ptr %2, ptr %8, align 8, !tbaa !11
  store ptr %3, ptr %9, align 8, !tbaa !11
  %15 = load ptr, ptr %9, align 8, !tbaa !11
  %16 = getelementptr inbounds %struct.CCreatedCoder, ptr %15, i32 0, i32 2
  store i8 0, ptr %16, align 8, !tbaa !13
  %17 = load ptr, ptr %9, align 8, !tbaa !11
  %18 = getelementptr inbounds %struct.CCreatedCoder, ptr %17, i32 0, i32 3
  store i8 0, ptr %18, align 1, !tbaa !17
  %19 = load ptr, ptr %9, align 8, !tbaa !11
  %20 = getelementptr inbounds %struct.CCreatedCoder, ptr %19, i32 0, i32 4
  store i32 1, ptr %20, align 4, !tbaa !18
  %21 = load i32, ptr %6, align 4, !tbaa !5
  %22 = load i32, ptr @g_NumCodecs, align 4, !tbaa !5
  %23 = icmp ult i32 %21, %22
  br i1 %23, label %24, label %117

24:                                               ; preds = %4
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #2
  %25 = load i32, ptr %6, align 4, !tbaa !5
  %26 = zext i32 %25 to i64
  %27 = getelementptr inbounds [64 x ptr], ptr @g_Codecs, i64 0, i64 %26
  %28 = load ptr, ptr %27, align 8, !tbaa !11
  store ptr %28, ptr %10, align 8, !tbaa !11
  %29 = load i8, ptr %7, align 1, !tbaa !9, !range !19, !noundef !20
  %30 = trunc i8 %29 to i1
  br i1 %30, label %31, label %72

31:                                               ; preds = %24
  %32 = load ptr, ptr %10, align 8, !tbaa !11
  %33 = getelementptr inbounds %struct.CCodecInfo, ptr %32, i32 0, i32 1
  %34 = load ptr, ptr %33, align 8, !tbaa !21
  %35 = icmp ne ptr %34, null
  br i1 %35, label %36, label %71

36:                                               ; preds = %31
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #2
  %37 = load ptr, ptr %10, align 8, !tbaa !11
  %38 = getelementptr inbounds %struct.CCodecInfo, ptr %37, i32 0, i32 1
  %39 = load ptr, ptr %38, align 8, !tbaa !21
  %40 = call noundef ptr %39()
  store ptr %40, ptr %11, align 8, !tbaa !11
  %41 = load ptr, ptr %10, align 8, !tbaa !11
  %42 = getelementptr inbounds %struct.CCodecInfo, ptr %41, i32 0, i32 5
  %43 = load i8, ptr %42, align 4, !tbaa !24, !range !19, !noundef !20
  %44 = trunc i8 %43 to i1
  br i1 %44, label %45, label %49

45:                                               ; preds = %36
  %46 = load ptr, ptr %11, align 8, !tbaa !11
  %47 = load ptr, ptr %8, align 8, !tbaa !11
  %48 = call noundef ptr @_ZN9CMyComPtrI15ICompressFilterEaSEPS0_(ptr noundef nonnull align 8 dereferenceable(8) %47, ptr noundef %46)
  br label %70

49:                                               ; preds = %36
  %50 = load ptr, ptr %10, align 8, !tbaa !11
  %51 = getelementptr inbounds %struct.CCodecInfo, ptr %50, i32 0, i32 4
  %52 = load i32, ptr %51, align 8, !tbaa !25
  %53 = icmp eq i32 %52, 1
  br i1 %53, label %54, label %59

54:                                               ; preds = %49
  %55 = load ptr, ptr %11, align 8, !tbaa !11
  %56 = load ptr, ptr %9, align 8, !tbaa !11
  %57 = getelementptr inbounds %struct.CCreatedCoder, ptr %56, i32 0, i32 0
  %58 = call noundef ptr @_ZN9CMyComPtrI14ICompressCoderEaSEPS0_(ptr noundef nonnull align 8 dereferenceable(8) %57, ptr noundef %55)
  br label %69

59:                                               ; preds = %49
  %60 = load ptr, ptr %11, align 8, !tbaa !11
  %61 = load ptr, ptr %9, align 8, !tbaa !11
  %62 = getelementptr inbounds %struct.CCreatedCoder, ptr %61, i32 0, i32 1
  %63 = call noundef ptr @_ZN9CMyComPtrI15ICompressCoder2EaSEPS0_(ptr noundef nonnull align 8 dereferenceable(8) %62, ptr noundef %60)
  %64 = load ptr, ptr %10, align 8, !tbaa !11
  %65 = getelementptr inbounds %struct.CCodecInfo, ptr %64, i32 0, i32 4
  %66 = load i32, ptr %65, align 8, !tbaa !25
  %67 = load ptr, ptr %9, align 8, !tbaa !11
  %68 = getelementptr inbounds %struct.CCreatedCoder, ptr %67, i32 0, i32 4
  store i32 %66, ptr %68, align 4, !tbaa !18
  br label %69

69:                                               ; preds = %59, %54
  br label %70

70:                                               ; preds = %69, %45
  store i32 0, ptr %5, align 4
  store i32 1, ptr %12, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #2
  br label %114

71:                                               ; preds = %31
  br label %113

72:                                               ; preds = %24
  %73 = load ptr, ptr %10, align 8, !tbaa !11
  %74 = getelementptr inbounds %struct.CCodecInfo, ptr %73, i32 0, i32 0
  %75 = load ptr, ptr %74, align 8, !tbaa !26
  %76 = icmp ne ptr %75, null
  br i1 %76, label %77, label %112

77:                                               ; preds = %72
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #2
  %78 = load ptr, ptr %10, align 8, !tbaa !11
  %79 = getelementptr inbounds %struct.CCodecInfo, ptr %78, i32 0, i32 0
  %80 = load ptr, ptr %79, align 8, !tbaa !26
  %81 = call noundef ptr %80()
  store ptr %81, ptr %13, align 8, !tbaa !11
  %82 = load ptr, ptr %10, align 8, !tbaa !11
  %83 = getelementptr inbounds %struct.CCodecInfo, ptr %82, i32 0, i32 5
  %84 = load i8, ptr %83, align 4, !tbaa !24, !range !19, !noundef !20
  %85 = trunc i8 %84 to i1
  br i1 %85, label %86, label %90

86:                                               ; preds = %77
  %87 = load ptr, ptr %13, align 8, !tbaa !11
  %88 = load ptr, ptr %8, align 8, !tbaa !11
  %89 = call noundef ptr @_ZN9CMyComPtrI15ICompressFilterEaSEPS0_(ptr noundef nonnull align 8 dereferenceable(8) %88, ptr noundef %87)
  br label %111

90:                                               ; preds = %77
  %91 = load ptr, ptr %10, align 8, !tbaa !11
  %92 = getelementptr inbounds %struct.CCodecInfo, ptr %91, i32 0, i32 4
  %93 = load i32, ptr %92, align 8, !tbaa !25
  %94 = icmp eq i32 %93, 1
  br i1 %94, label %95, label %100

95:                                               ; preds = %90
  %96 = load ptr, ptr %13, align 8, !tbaa !11
  %97 = load ptr, ptr %9, align 8, !tbaa !11
  %98 = getelementptr inbounds %struct.CCreatedCoder, ptr %97, i32 0, i32 0
  %99 = call noundef ptr @_ZN9CMyComPtrI14ICompressCoderEaSEPS0_(ptr noundef nonnull align 8 dereferenceable(8) %98, ptr noundef %96)
  br label %110

100:                                              ; preds = %90
  %101 = load ptr, ptr %13, align 8, !tbaa !11
  %102 = load ptr, ptr %9, align 8, !tbaa !11
  %103 = getelementptr inbounds %struct.CCreatedCoder, ptr %102, i32 0, i32 1
  %104 = call noundef ptr @_ZN9CMyComPtrI15ICompressCoder2EaSEPS0_(ptr noundef nonnull align 8 dereferenceable(8) %103, ptr noundef %101)
  %105 = load ptr, ptr %10, align 8, !tbaa !11
  %106 = getelementptr inbounds %struct.CCodecInfo, ptr %105, i32 0, i32 4
  %107 = load i32, ptr %106, align 8, !tbaa !25
  %108 = load ptr, ptr %9, align 8, !tbaa !11
  %109 = getelementptr inbounds %struct.CCreatedCoder, ptr %108, i32 0, i32 4
  store i32 %107, ptr %109, align 4, !tbaa !18
  br label %110

110:                                              ; preds = %100, %95
  br label %111

111:                                              ; preds = %110, %86
  store i32 0, ptr %5, align 4
  store i32 1, ptr %12, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #2
  br label %114

112:                                              ; preds = %72
  br label %113

113:                                              ; preds = %112, %71
  store i32 0, ptr %12, align 4
  br label %114

114:                                              ; preds = %113, %111, %70
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #2
  %115 = load i32, ptr %12, align 4
  switch i32 %115, label %120 [
    i32 0, label %116
    i32 1, label %118
  ]

116:                                              ; preds = %114
  br label %117

117:                                              ; preds = %116, %4
  store i32 0, ptr %5, align 4
  br label %118

118:                                              ; preds = %117, %114
  %119 = load i32, ptr %5, align 4
  ret i32 %119

120:                                              ; preds = %114
  unreachable
}

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

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

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

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 = { 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 = !{!"bool", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"any pointer", !7, i64 0}
!13 = !{!14, !10, i64 16}
!14 = !{!"_ZTS13CCreatedCoder", !15, i64 0, !16, i64 8, !10, i64 16, !10, i64 17, !6, i64 20}
!15 = !{!"_ZTS9CMyComPtrI14ICompressCoderE", !12, i64 0}
!16 = !{!"_ZTS9CMyComPtrI15ICompressCoder2E", !12, i64 0}
!17 = !{!14, !10, i64 17}
!18 = !{!14, !6, i64 20}
!19 = !{i8 0, i8 2}
!20 = !{}
!21 = !{!22, !12, i64 8}
!22 = !{!"_ZTS10CCodecInfo", !12, i64 0, !12, i64 8, !23, i64 16, !12, i64 24, !6, i64 32, !10, i64 36}
!23 = !{!"long long", !7, i64 0}
!24 = !{!22, !10, i64 36}
!25 = !{!22, !6, i64 32}
!26 = !{!22, !12, i64 0}


; 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 i32 @_Z17CreateCoder_IndexjbR9CMyComPtrI15ICompressFilterER13CCreatedCoder(i32 noundef %0, i1 noundef zeroext %1, ptr noundef nonnull align 8 dereferenceable(8) %2, ptr noundef nonnull align 8 dereferenceable(24) %3) local_unnamed_addr #0 {
  %5 = getelementptr inbounds i8, ptr %3, i64 16
  store i8 0, ptr %5, align 8, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %3, i64 17
  store i8 0, ptr %6, align 1, !tbaa !14
  %7 = getelementptr inbounds i8, ptr %3, i64 20
  store i32 1, ptr %7, align 4, !tbaa !15
  %8 = load i32, ptr @g_NumCodecs, align 4, !tbaa !16
  %9 = icmp ugt i32 %8, %0
  br i1 %9, label %10, label %53

10:                                               ; preds = %4
  %11 = zext i32 %0 to i64
  %12 = getelementptr inbounds [64 x ptr], ptr @g_Codecs, i64 0, i64 %11
  %13 = load ptr, ptr %12, align 8, !tbaa !17
  br i1 %1, label %14, label %34

14:                                               ; preds = %10
  %15 = getelementptr inbounds i8, ptr %13, i64 8
  %16 = load ptr, ptr %15, align 8, !tbaa !18
  %.not34 = icmp eq ptr %16, null
  br i1 %.not34, label %53, label %17

17:                                               ; preds = %14
  %18 = tail call noundef ptr %16()
  %19 = getelementptr inbounds i8, ptr %13, i64 36
  %20 = load i8, ptr %19, align 4, !tbaa !21, !range !22, !noundef !23
  %21 = trunc nuw i8 %20 to i1
  br i1 %21, label %22, label %24

22:                                               ; preds = %17
  %23 = tail call noundef ptr @_ZN9CMyComPtrI15ICompressFilterEaSEPS0_(ptr noundef nonnull align 8 dereferenceable(8) %2, ptr noundef %18)
  br label %53

24:                                               ; preds = %17
  %25 = getelementptr inbounds i8, ptr %13, i64 32
  %26 = load i32, ptr %25, align 8, !tbaa !24
  %27 = icmp eq i32 %26, 1
  br i1 %27, label %28, label %30

28:                                               ; preds = %24
  %29 = tail call noundef ptr @_ZN9CMyComPtrI14ICompressCoderEaSEPS0_(ptr noundef nonnull align 8 dereferenceable(8) %3, ptr noundef %18)
  br label %53

30:                                               ; preds = %24
  %31 = getelementptr inbounds i8, ptr %3, i64 8
  %32 = tail call noundef ptr @_ZN9CMyComPtrI15ICompressCoder2EaSEPS0_(ptr noundef nonnull align 8 dereferenceable(8) %31, ptr noundef %18)
  %33 = load i32, ptr %25, align 8, !tbaa !24
  store i32 %33, ptr %7, align 4, !tbaa !15
  br label %53

34:                                               ; preds = %10
  %35 = load ptr, ptr %13, align 8, !tbaa !25
  %.not = icmp eq ptr %35, null
  br i1 %.not, label %53, label %36

36:                                               ; preds = %34
  %37 = tail call noundef ptr %35()
  %38 = getelementptr inbounds i8, ptr %13, i64 36
  %39 = load i8, ptr %38, align 4, !tbaa !21, !range !22, !noundef !23
  %40 = trunc nuw i8 %39 to i1
  br i1 %40, label %41, label %43

41:                                               ; preds = %36
  %42 = tail call noundef ptr @_ZN9CMyComPtrI15ICompressFilterEaSEPS0_(ptr noundef nonnull align 8 dereferenceable(8) %2, ptr noundef %37)
  br label %53

43:                                               ; preds = %36
  %44 = getelementptr inbounds i8, ptr %13, i64 32
  %45 = load i32, ptr %44, align 8, !tbaa !24
  %46 = icmp eq i32 %45, 1
  br i1 %46, label %47, label %49

47:                                               ; preds = %43
  %48 = tail call noundef ptr @_ZN9CMyComPtrI14ICompressCoderEaSEPS0_(ptr noundef nonnull align 8 dereferenceable(8) %3, ptr noundef %37)
  br label %53

49:                                               ; preds = %43
  %50 = getelementptr inbounds i8, ptr %3, i64 8
  %51 = tail call noundef ptr @_ZN9CMyComPtrI15ICompressCoder2EaSEPS0_(ptr noundef nonnull align 8 dereferenceable(8) %50, ptr noundef %37)
  %52 = load i32, ptr %44, align 8, !tbaa !24
  store i32 %52, ptr %7, align 4, !tbaa !15
  br label %53

53:                                               ; preds = %28, %30, %22, %47, %49, %41, %34, %14, %4
  ret i32 0
}

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

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

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

!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, !12, i64 16}
!6 = !{!"_ZTS13CCreatedCoder", !7, i64 0, !11, i64 8, !12, i64 16, !12, i64 17, !13, i64 20}
!7 = !{!"_ZTS9CMyComPtrI14ICompressCoderE", !8, i64 0}
!8 = !{!"any pointer", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}
!11 = !{!"_ZTS9CMyComPtrI15ICompressCoder2E", !8, i64 0}
!12 = !{!"bool", !9, i64 0}
!13 = !{!"int", !9, i64 0}
!14 = !{!6, !12, i64 17}
!15 = !{!6, !13, i64 20}
!16 = !{!13, !13, i64 0}
!17 = !{!8, !8, i64 0}
!18 = !{!19, !8, i64 8}
!19 = !{!"_ZTS10CCodecInfo", !8, i64 0, !8, i64 8, !20, i64 16, !8, i64 24, !13, i64 32, !12, i64 36}
!20 = !{!"long long", !9, i64 0}
!21 = !{!19, !12, i64 36}
!22 = !{i8 0, i8 2}
!23 = !{}
!24 = !{!19, !13, i64 32}
!25 = !{!19, !8, i64 0}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,SROAPass,SimplifyCFGPass,TailCallElimPass