; LLVM IR from intel/cryptography-primitives :: sources/ippcp (pcpaes_xtsinit)

; 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._cpAES_XTS = type { i32, i32, %struct._cpRijndael128, %struct._cpRijndael128 }
%struct._cpRijndael128 = type { i32, i32, i32, i32, ptr, ptr, ptr, ptr, ptr, ptr, i32, i32, [124 x i32] }

; Function Attrs: nounwind uwtable
define dso_local i32 @ippsAES_XTSInit(ptr noundef %0, i32 noundef %1, i32 noundef %2, ptr noundef %3, i32 noundef %4) #0 {
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca ptr, align 8
  %14 = alloca ptr, align 8
  %15 = alloca ptr, align 8
  %16 = alloca ptr, align 8
  %17 = alloca i32, align 4
  %18 = alloca i32, align 4
  store ptr %0, ptr %7, align 8, !tbaa !5
  store i32 %1, ptr %8, align 4, !tbaa !9
  store i32 %2, ptr %9, align 4, !tbaa !9
  store ptr %3, ptr %10, align 8, !tbaa !5
  store i32 %4, ptr %11, align 4, !tbaa !9
  %19 = load ptr, ptr %7, align 8, !tbaa !5
  %20 = icmp eq ptr null, %19
  br i1 %20, label %21, label %22

21:                                               ; preds = %5
  store i32 -8, ptr %6, align 4
  br label %83

22:                                               ; preds = %5
  %23 = load i32, ptr %8, align 4, !tbaa !9
  %24 = icmp ne i32 %23, 256
  br i1 %24, label %25, label %29

25:                                               ; preds = %22
  %26 = load i32, ptr %8, align 4, !tbaa !9
  %27 = icmp ne i32 %26, 512
  br i1 %27, label %28, label %29

28:                                               ; preds = %25
  store i32 -15, ptr %6, align 4
  br label %83

29:                                               ; preds = %25, %22
  %30 = load i32, ptr %9, align 4, !tbaa !9
  %31 = icmp slt i32 %30, 128
  br i1 %31, label %32, label %33

32:                                               ; preds = %29
  store i32 -15, ptr %6, align 4
  br label %83

33:                                               ; preds = %29
  %34 = load ptr, ptr %10, align 8, !tbaa !5
  %35 = icmp eq ptr null, %34
  br i1 %35, label %36, label %37

36:                                               ; preds = %33
  store i32 -8, ptr %6, align 4
  br label %83

37:                                               ; preds = %33
  %38 = load i32, ptr %11, align 4, !tbaa !9
  %39 = icmp sgt i32 1144, %38
  br i1 %39, label %40, label %41

40:                                               ; preds = %37
  store i32 -9, ptr %6, align 4
  br label %83

41:                                               ; preds = %37
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #4
  %42 = load i32, ptr %8, align 4, !tbaa !9
  %43 = sdiv i32 %42, 2
  %44 = sdiv i32 %43, 8
  store i32 %44, ptr %12, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #4
  %45 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %45, ptr %13, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #4
  %46 = load ptr, ptr %7, align 8, !tbaa !5
  %47 = load i32, ptr %12, align 4, !tbaa !9
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds i8, ptr %46, i64 %48
  store ptr %49, ptr %14, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #4
  %50 = load ptr, ptr %10, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct._cpAES_XTS, ptr %50, i32 0, i32 2
  store ptr %51, ptr %15, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #4
  %52 = load ptr, ptr %10, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct._cpAES_XTS, ptr %52, i32 0, i32 3
  store ptr %53, ptr %16, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %17) #4
  store i32 0, ptr %17, align 4, !tbaa !9
  %54 = load ptr, ptr %13, align 8, !tbaa !5
  %55 = load i32, ptr %12, align 4, !tbaa !9
  %56 = load ptr, ptr %15, align 8, !tbaa !5
  %57 = call i32 @ippsAESInit(ptr noundef %54, i32 noundef %55, ptr noundef %56, i32 noundef 568)
  store i32 %57, ptr %17, align 4, !tbaa !9
  %58 = load i32, ptr %17, align 4, !tbaa !9
  %59 = icmp ne i32 0, %58
  br i1 %59, label %60, label %62

60:                                               ; preds = %41
  %61 = load i32, ptr %17, align 4, !tbaa !9
  store i32 %61, ptr %6, align 4
  store i32 1, ptr %18, align 4
  br label %82

62:                                               ; preds = %41
  %63 = load ptr, ptr %14, align 8, !tbaa !5
  %64 = load i32, ptr %12, align 4, !tbaa !9
  %65 = load ptr, ptr %16, align 8, !tbaa !5
  %66 = call i32 @ippsAESInit(ptr noundef %63, i32 noundef %64, ptr noundef %65, i32 noundef 568)
  store i32 %66, ptr %17, align 4, !tbaa !9
  %67 = load i32, ptr %17, align 4, !tbaa !9
  %68 = icmp ne i32 0, %67
  br i1 %68, label %69, label %71

69:                                               ; preds = %62
  %70 = load i32, ptr %17, align 4, !tbaa !9
  store i32 %70, ptr %6, align 4
  store i32 1, ptr %18, align 4
  br label %82

71:                                               ; preds = %62
  %72 = load ptr, ptr %10, align 8, !tbaa !5
  %73 = call i64 @IPP_UINT_PTR(ptr noundef %72)
  %74 = trunc i64 %73 to i32
  %75 = xor i32 1129136467, %74
  %76 = load ptr, ptr %10, align 8, !tbaa !5
  %77 = getelementptr inbounds %struct._cpAES_XTS, ptr %76, i32 0, i32 0
  store i32 %75, ptr %77, align 8, !tbaa !11
  %78 = load i32, ptr %9, align 4, !tbaa !9
  %79 = load ptr, ptr %10, align 8, !tbaa !5
  %80 = getelementptr inbounds %struct._cpAES_XTS, ptr %79, i32 0, i32 1
  store i32 %78, ptr %80, align 4, !tbaa !14
  %81 = load i32, ptr %17, align 4, !tbaa !9
  store i32 %81, ptr %6, align 4
  store i32 1, ptr %18, align 4
  br label %82

82:                                               ; preds = %71, %69, %60
  call void @llvm.lifetime.end.p0(i64 4, ptr %17) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #4
  br label %83

83:                                               ; preds = %82, %40, %36, %32, %28, %21
  %84 = load i32, ptr %6, align 4
  ret i32 %84
}

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

declare i32 @ippsAESInit(ptr noundef, i32 noundef, ptr noundef, i32 noundef) #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden i64 @IPP_UINT_PTR(ptr noundef) #3

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

attributes #0 = { 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 = { 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 = { inlinehint 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 #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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 0}
!12 = !{!"_cpAES_XTS", !10, i64 0, !10, i64 4, !13, i64 8, !13, i64 576}
!13 = !{!"_cpRijndael128", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !10, i64 64, !10, i64 68, !7, i64 72}
!14 = !{!12, !10, i64 4}


; 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: nounwind uwtable
define dso_local i32 @ippsAES_XTSInit(ptr noundef %0, i32 noundef %1, i32 noundef %2, ptr noundef %3, i32 noundef %4) local_unnamed_addr #0 {
  %6 = icmp eq ptr %0, null
  br i1 %6, label %28, label %7

7:                                                ; preds = %5
  switch i32 %1, label %28 [
    i32 512, label %8
    i32 256, label %8
  ]

8:                                                ; preds = %7, %7
  %9 = icmp slt i32 %2, 128
  br i1 %9, label %28, label %10

10:                                               ; preds = %8
  %11 = icmp eq ptr %3, null
  br i1 %11, label %28, label %12

12:                                               ; preds = %10
  %13 = icmp slt i32 %4, 1144
  br i1 %13, label %28, label %14

14:                                               ; preds = %12
  %15 = lshr exact i32 %1, 4
  %16 = getelementptr inbounds i8, ptr %3, i64 8
  %17 = tail call i32 @ippsAESInit(ptr noundef nonnull %0, i32 noundef %15, ptr noundef nonnull %16, i32 noundef 568) #3
  %.not = icmp eq i32 %17, 0
  br i1 %.not, label %18, label %28

18:                                               ; preds = %14
  %19 = getelementptr inbounds i8, ptr %3, i64 576
  %20 = zext nneg i32 %15 to i64
  %21 = getelementptr inbounds i8, ptr %0, i64 %20
  %22 = tail call i32 @ippsAESInit(ptr noundef nonnull %21, i32 noundef %15, ptr noundef nonnull %19, i32 noundef 568) #3
  %.not34 = icmp eq i32 %22, 0
  br i1 %.not34, label %23, label %28

23:                                               ; preds = %18
  %24 = tail call i64 @IPP_UINT_PTR(ptr noundef nonnull %3)
  %25 = trunc i64 %24 to i32
  %26 = xor i32 %25, 1129136467
  store i32 %26, ptr %3, align 8, !tbaa !5
  %27 = getelementptr inbounds i8, ptr %3, i64 4
  store i32 %2, ptr %27, align 4, !tbaa !12
  br label %28

28:                                               ; preds = %23, %14, %18, %12, %10, %8, %7, %5
  %.1 = phi i32 [ -8, %5 ], [ -15, %7 ], [ -15, %8 ], [ -8, %10 ], [ -9, %12 ], [ 0, %23 ], [ %17, %14 ], [ %22, %18 ]
  ret i32 %.1
}

declare i32 @ippsAESInit(ptr noundef, i32 noundef, ptr noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: inlinehint nounwind uwtable
declare hidden i64 @IPP_UINT_PTR(ptr noundef) local_unnamed_addr #2

attributes #0 = { 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 = { inlinehint 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 = { 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, !7, i64 0}
!6 = !{!"_cpAES_XTS", !7, i64 0, !7, i64 4, !10, i64 8, !10, i64 576}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"_cpRijndael128", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12, !11, i64 16, !11, i64 24, !11, i64 32, !11, i64 40, !11, i64 48, !11, i64 56, !7, i64 64, !7, i64 68, !8, i64 72}
!11 = !{!"any pointer", !8, i64 0}
!12 = !{!6, !7, i64 4}


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