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

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

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN7NCrypto12CAesCbcCoder6SetKeyEPKhj(ptr noundef nonnull align 8 dereferenceable(352) %0, ptr noundef %1, i32 noundef %2) unnamed_addr #0 align 2 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store i32 %2, ptr %7, align 4, !tbaa !9
  %9 = load ptr, ptr %5, align 8
  %10 = load i32, ptr %7, align 4, !tbaa !9
  %11 = and i32 %10, 7
  %12 = icmp ne i32 %11, 0
  br i1 %12, label %19, label %13

13:                                               ; preds = %3
  %14 = load i32, ptr %7, align 4, !tbaa !9
  %15 = icmp ult i32 %14, 16
  br i1 %15, label %19, label %16

16:                                               ; preds = %13
  %17 = load i32, ptr %7, align 4, !tbaa !9
  %18 = icmp ugt i32 %17, 32
  br i1 %18, label %19, label %20

19:                                               ; preds = %16, %13, %3
  store i32 -2147024809, ptr %4, align 4
  br label %49

20:                                               ; preds = %16
  %21 = getelementptr inbounds %"class.NCrypto::CAesCbcCoder", ptr %9, i32 0, i32 6
  %22 = load i32, ptr %21, align 4, !tbaa !11
  %23 = icmp ne i32 %22, 0
  br i1 %23, label %24, label %30

24:                                               ; preds = %20
  %25 = load i32, ptr %7, align 4, !tbaa !9
  %26 = getelementptr inbounds %"class.NCrypto::CAesCbcCoder", ptr %9, i32 0, i32 6
  %27 = load i32, ptr %26, align 4, !tbaa !11
  %28 = icmp ne i32 %25, %27
  br i1 %28, label %29, label %30

29:                                               ; preds = %24
  store i32 -2147024809, ptr %4, align 4
  br label %49

30:                                               ; preds = %24, %20
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %31 = getelementptr inbounds %"class.NCrypto::CAesCbcCoder", ptr %9, i32 0, i32 8
  %32 = load i8, ptr %31, align 1, !tbaa !19, !range !20, !noundef !21
  %33 = trunc i8 %32 to i1
  br i1 %33, label %34, label %35

34:                                               ; preds = %30
  br label %36

35:                                               ; preds = %30
  br label %36

36:                                               ; preds = %35, %34
  %37 = phi ptr [ @Aes_SetKey_Enc, %34 ], [ @Aes_SetKey_Dec, %35 ]
  store ptr %37, ptr %8, align 8, !tbaa !5
  %38 = load ptr, ptr %8, align 8, !tbaa !5
  %39 = getelementptr inbounds %"class.NCrypto::CAesCbcCoder", ptr %9, i32 0, i32 9
  %40 = getelementptr inbounds [71 x i32], ptr %39, i64 0, i64 0
  %41 = getelementptr inbounds %"class.NCrypto::CAesCbcCoder", ptr %9, i32 0, i32 5
  %42 = load i32, ptr %41, align 8, !tbaa !22
  %43 = zext i32 %42 to i64
  %44 = getelementptr inbounds i32, ptr %40, i64 %43
  %45 = getelementptr inbounds i32, ptr %44, i64 4
  %46 = load ptr, ptr %6, align 8, !tbaa !5
  %47 = load i32, ptr %7, align 4, !tbaa !9
  call void %38(ptr noundef %45, ptr noundef %46, i32 noundef %47)
  %48 = getelementptr inbounds %"class.NCrypto::CAesCbcCoder", ptr %9, i32 0, i32 7
  store i8 1, ptr %48, align 8, !tbaa !23
  store i32 0, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  br label %49

49:                                               ; preds = %36, %29, %19
  %50 = load i32, ptr %4, align 4
  ret i32 %50
}

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

declare void @Aes_SetKey_Enc(ptr noundef, ptr noundef, i32 noundef) #2

declare void @Aes_SetKey_Dec(ptr noundef, ptr noundef, i32 noundef) #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 = { "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 = { 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 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 44}
!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 = !{!12, !18, i64 49}
!20 = !{i8 0, i8 2}
!21 = !{}
!22 = !{!12, !10, i64 40}
!23 = !{!12, !18, i64 48}


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

; Function Attrs: mustprogress uwtable
define dso_local noundef range(i32 -2147024809, 1) i32 @_ZN7NCrypto12CAesCbcCoder6SetKeyEPKhj(ptr noundef nonnull align 8 dereferenceable(352) %0, ptr noundef %1, i32 noundef %2) unnamed_addr #0 align 2 {
  %4 = and i32 %2, 7
  %5 = icmp ne i32 %4, 0
  %6 = add i32 %2, -33
  %7 = icmp ult i32 %6, -17
  %or.cond3 = or i1 %5, %7
  br i1 %or.cond3, label %22, label %8

8:                                                ; preds = %3
  %9 = getelementptr inbounds i8, ptr %0, i64 44
  %10 = load i32, ptr %9, align 4, !tbaa !5
  %.not = icmp eq i32 %10, 0
  %.not13 = icmp eq i32 %10, %2
  %or.cond = or i1 %.not, %.not13
  br i1 %or.cond, label %11, label %22

11:                                               ; preds = %8
  %12 = getelementptr inbounds i8, ptr %0, i64 49
  %13 = load i8, ptr %12, align 1, !tbaa !17, !range !18, !noundef !19
  %14 = trunc nuw i8 %13 to i1
  %Aes_SetKey_Enc.Aes_SetKey_Dec = select i1 %14, ptr @Aes_SetKey_Enc, ptr @Aes_SetKey_Dec
  %15 = getelementptr inbounds i8, ptr %0, i64 52
  %16 = getelementptr inbounds i8, ptr %0, i64 40
  %17 = load i32, ptr %16, align 8, !tbaa !20
  %18 = zext i32 %17 to i64
  %19 = getelementptr inbounds i32, ptr %15, i64 %18
  %20 = getelementptr inbounds i8, ptr %19, i64 16
  tail call void %Aes_SetKey_Enc.Aes_SetKey_Dec(ptr noundef nonnull %20, ptr noundef %1, i32 noundef %2), !callees !21
  %21 = getelementptr inbounds i8, ptr %0, i64 48
  store i8 1, ptr %21, align 8, !tbaa !22
  br label %22

22:                                               ; preds = %8, %3, %11
  %.0 = phi i32 [ 0, %11 ], [ -2147024809, %3 ], [ -2147024809, %8 ]
  ret i32 %.0
}

declare void @Aes_SetKey_Enc(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #1

declare void @Aes_SetKey_Dec(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #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 = { "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 44}
!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 = !{!6, !16, i64 49}
!18 = !{i8 0, i8 2}
!19 = !{}
!20 = !{!6, !12, i64 40}
!21 = !{ptr @Aes_SetKey_Dec, ptr @Aes_SetKey_Enc}
!22 = !{!6, !16, i64 48}


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