; LLVM IR from SSBMTonberry/pocketlzma :: ref_spec/lzma1900/CPP/7zip/Crypto/MyAes.ll (ZN7NCrypto12CAesCbcCoder12SetFunctionsEj)

; 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"

%"class.NCrypto::CAesCbcCoder" = type { %struct.ICompressFilter, %struct.ICryptoProperties, %struct.ICompressSetCoderProperties, %class.CMyUnknownImp, ptr, i32, i32, i8, i8, [71 x i32], [16 x i8] }
%struct.ICompressFilter = type { %struct.IUnknown }
%struct.IUnknown = type { ptr }
%struct.ICryptoProperties = type { %struct.IUnknown }
%struct.ICompressSetCoderProperties = type { %struct.IUnknown }
%class.CMyUnknownImp = type { i32 }

@g_AesCbc_Encode = external global ptr, align 8
@g_AesCbc_Decode = external global ptr, align 8

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef zeroext i1 @_ZN7NCrypto12CAesCbcCoder12SetFunctionsEj(ptr noundef nonnull align 8 dereferenceable(352) %0, i32 noundef %1) #0 align 2 {
  %3 = alloca i1, align 1
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  %6 = load ptr, ptr %4, align 8
  %7 = getelementptr inbounds %"class.NCrypto::CAesCbcCoder", ptr %6, i32 0, i32 8
  %8 = load i8, ptr %7, align 1, !tbaa !11, !range !19, !noundef !20
  %9 = trunc i8 %8 to i1
  br i1 %9, label %10, label %12

10:                                               ; preds = %2
  %11 = load ptr, ptr @g_AesCbc_Encode, align 8, !tbaa !5
  br label %14

12:                                               ; preds = %2
  %13 = load ptr, ptr @g_AesCbc_Decode, align 8, !tbaa !5
  br label %14

14:                                               ; preds = %12, %10
  %15 = phi ptr [ %11, %10 ], [ %13, %12 ]
  %16 = getelementptr inbounds %"class.NCrypto::CAesCbcCoder", ptr %6, i32 0, i32 4
  store ptr %15, ptr %16, align 8, !tbaa !21
  %17 = load i32, ptr %5, align 4, !tbaa !9
  %18 = icmp eq i32 %17, 1
  br i1 %18, label %19, label %28

19:                                               ; preds = %14
  %20 = getelementptr inbounds %"class.NCrypto::CAesCbcCoder", ptr %6, i32 0, i32 8
  %21 = load i8, ptr %20, align 1, !tbaa !11, !range !19, !noundef !20
  %22 = trunc i8 %21 to i1
  br i1 %22, label %23, label %24

23:                                               ; preds = %19
  br label %25

24:                                               ; preds = %19
  br label %25

25:                                               ; preds = %24, %23
  %26 = phi ptr [ @AesCbc_Encode, %23 ], [ @AesCbc_Decode, %24 ]
  %27 = getelementptr inbounds %"class.NCrypto::CAesCbcCoder", ptr %6, i32 0, i32 4
  store ptr %26, ptr %27, align 8, !tbaa !21
  br label %28

28:                                               ; preds = %25, %14
  %29 = load i32, ptr %5, align 4, !tbaa !9
  %30 = icmp eq i32 %29, 2
  br i1 %30, label %31, label %36

31:                                               ; preds = %28
  %32 = load ptr, ptr @g_AesCbc_Encode, align 8, !tbaa !5
  %33 = icmp ne ptr %32, @AesCbc_Encode_Intel
  br i1 %33, label %34, label %35

34:                                               ; preds = %31
  store i1 false, ptr %3, align 1
  br label %37

35:                                               ; preds = %31
  br label %36

36:                                               ; preds = %35, %28
  store i1 true, ptr %3, align 1
  br label %37

37:                                               ; preds = %36, %34
  %38 = load i1, ptr %3, align 1
  ret i1 %38
}

declare void @AesCbc_Encode(ptr noundef, ptr noundef, i64 noundef) #1

declare void @AesCbc_Decode(ptr noundef, ptr noundef, i64 noundef) #1

declare void @AesCbc_Encode_Intel(ptr noundef, ptr noundef, i64 noundef) #1

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

!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, !18, i64 49}
!12 = !{!"_ZTSN7NCrypto12CAesCbcCoderE", !13, i64 0, !15, i64 8, !16, i64 16, !17, i64 24, !6, i64 32, !10, i64 40, !10, i64 44, !18, i64 48, !18, i64 49, !7, i64 52, !7, i64 336}
!13 = !{!"_ZTS15ICompressFilter", !14, i64 0}
!14 = !{!"_ZTS8IUnknown"}
!15 = !{!"_ZTS17ICryptoProperties", !14, i64 0}
!16 = !{!"_ZTS27ICompressSetCoderProperties", !14, i64 0}
!17 = !{!"_ZTS13CMyUnknownImp", !10, i64 0}
!18 = !{!"bool", !7, i64 0}
!19 = !{i8 0, i8 2}
!20 = !{}
!21 = !{!12, !6, i64 32}


; 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_AesCbc_Encode = external local_unnamed_addr global ptr, align 8
@g_AesCbc_Decode = external local_unnamed_addr global ptr, align 8

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(read, argmem: readwrite, inaccessiblemem: none) uwtable
define dso_local noundef zeroext i1 @_ZN7NCrypto12CAesCbcCoder12SetFunctionsEj(ptr nocapture noundef nonnull align 8 dereferenceable(352) %0, i32 noundef %1) local_unnamed_addr #0 align 2 {
  %3 = getelementptr inbounds i8, ptr %0, i64 49
  %4 = load i8, ptr %3, align 1, !tbaa !5, !range !17, !noundef !18
  %5 = trunc nuw i8 %4 to i1
  %6 = load ptr, ptr @g_AesCbc_Encode, align 8
  %7 = load ptr, ptr @g_AesCbc_Decode, align 8
  %8 = select i1 %5, ptr %6, ptr %7
  %9 = icmp eq i32 %1, 1
  %AesCbc_Encode.AesCbc_Decode = select i1 %5, ptr @AesCbc_Encode, ptr @AesCbc_Decode
  %spec.select = select i1 %9, ptr %AesCbc_Encode.AesCbc_Decode, ptr %8
  %10 = getelementptr inbounds i8, ptr %0, i64 32
  store ptr %spec.select, ptr %10, align 8, !tbaa !19
  %11 = icmp ne i32 %1, 2
  %12 = icmp eq ptr %6, @AesCbc_Encode_Intel
  %or.cond.not = select i1 %11, i1 true, i1 %12
  ret i1 %or.cond.not
}

declare void @AesCbc_Encode(ptr noundef, ptr noundef, i64 noundef) #1

declare void @AesCbc_Decode(ptr noundef, ptr noundef, i64 noundef) #1

declare void @AesCbc_Encode_Intel(ptr noundef, ptr noundef, i64 noundef) #1

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(read, argmem: readwrite, inaccessiblemem: none) 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" }

!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, !16, i64 49}
!6 = !{!"_ZTSN7NCrypto12CAesCbcCoderE", !7, i64 0, !9, i64 8, !10, i64 16, !11, i64 24, !15, i64 32, !12, i64 40, !12, i64 44, !16, i64 48, !16, i64 49, !13, i64 52, !13, i64 336}
!7 = !{!"_ZTS15ICompressFilter", !8, i64 0}
!8 = !{!"_ZTS8IUnknown"}
!9 = !{!"_ZTS17ICryptoProperties", !8, i64 0}
!10 = !{!"_ZTS27ICompressSetCoderProperties", !8, i64 0}
!11 = !{!"_ZTS13CMyUnknownImp", !12, i64 0}
!12 = !{!"int", !13, i64 0}
!13 = !{!"omnipotent char", !14, i64 0}
!14 = !{!"Simple C++ TBAA"}
!15 = !{!"any pointer", !13, i64 0}
!16 = !{!"bool", !13, i64 0}
!17 = !{i8 0, i8 2}
!18 = !{}
!19 = !{!6, !15, i64 32}


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