; LLVM IR from intel/QAT_Engine :: kpt/apps (kpt_swk)

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

; Function Attrs: nounwind uwtable
define dso_local i32 @wrap_key_with_gcm256(ptr noundef %0, i32 noundef %1, ptr noundef %2, ptr noundef %3, ptr noundef %4, ptr noundef %5, i32 noundef %6, ptr noundef %7, i32 noundef %8) #0 {
  %10 = alloca i32, align 4
  %11 = alloca ptr, align 8
  %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 ptr, align 8
  %19 = alloca i32, align 4
  %20 = alloca [4096 x i8], align 16
  %21 = alloca i32, align 4
  %22 = alloca i32, align 4
  %23 = alloca ptr, align 8
  store ptr %0, ptr %11, align 8, !tbaa !5
  store i32 %1, ptr %12, align 4, !tbaa !9
  store ptr %2, ptr %13, align 8, !tbaa !5
  store ptr %3, ptr %14, align 8, !tbaa !5
  store ptr %4, ptr %15, align 8, !tbaa !5
  store ptr %5, ptr %16, align 8, !tbaa !5
  store i32 %6, ptr %17, align 4, !tbaa !9
  store ptr %7, ptr %18, align 8, !tbaa !5
  store i32 %8, ptr %19, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4096, ptr %20) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %21) #4
  store i32 0, ptr %21, align 4, !tbaa !9
  %24 = load ptr, ptr %11, align 8, !tbaa !5
  %25 = icmp ne ptr %24, null
  br i1 %25, label %26, label %35

26:                                               ; preds = %9
  %27 = load ptr, ptr %13, align 8, !tbaa !5
  %28 = icmp ne ptr %27, null
  br i1 %28, label %29, label %35

29:                                               ; preds = %26
  %30 = load ptr, ptr %15, align 8, !tbaa !5
  %31 = icmp ne ptr %30, null
  br i1 %31, label %32, label %35

32:                                               ; preds = %29
  %33 = load ptr, ptr %16, align 8, !tbaa !5
  %34 = icmp ne ptr %33, null
  br i1 %34, label %36, label %35

35:                                               ; preds = %32, %29, %26, %9
  store i32 -1, ptr %10, align 4
  store i32 1, ptr %22, align 4
  br label %90

36:                                               ; preds = %32
  %37 = load i32, ptr %17, align 4, !tbaa !9
  %38 = icmp ne i32 12, %37
  br i1 %38, label %39, label %40

39:                                               ; preds = %36
  store i32 -1, ptr %10, align 4
  store i32 1, ptr %22, align 4
  br label %90

40:                                               ; preds = %36
  call void @llvm.lifetime.start.p0(i64 8, ptr %23) #4
  %41 = call ptr @EVP_CIPHER_CTX_new()
  store ptr %41, ptr %23, align 8, !tbaa !5
  %42 = load ptr, ptr %23, align 8, !tbaa !5
  %43 = call ptr @EVP_aes_256_gcm()
  %44 = call i32 @EVP_EncryptInit_ex(ptr noundef %42, ptr noundef %43, ptr noundef null, ptr noundef null, ptr noundef null)
  %45 = load ptr, ptr %23, align 8, !tbaa !5
  %46 = load i32, ptr %17, align 4, !tbaa !9
  %47 = call i32 @EVP_CIPHER_CTX_ctrl(ptr noundef %45, i32 noundef 9, i32 noundef %46, ptr noundef null)
  %48 = load ptr, ptr %23, align 8, !tbaa !5
  %49 = load ptr, ptr %15, align 8, !tbaa !5
  %50 = load ptr, ptr %16, align 8, !tbaa !5
  %51 = call i32 @EVP_EncryptInit_ex(ptr noundef %48, ptr noundef null, ptr noundef null, ptr noundef %49, ptr noundef %50)
  %52 = load ptr, ptr %18, align 8, !tbaa !5
  %53 = icmp ne ptr %52, null
  br i1 %53, label %54, label %62

54:                                               ; preds = %40
  %55 = load i32, ptr %19, align 4, !tbaa !9
  %56 = icmp sgt i32 %55, 0
  br i1 %56, label %57, label %62

57:                                               ; preds = %54
  %58 = load ptr, ptr %23, align 8, !tbaa !5
  %59 = load ptr, ptr %18, align 8, !tbaa !5
  %60 = load i32, ptr %19, align 4, !tbaa !9
  %61 = call i32 @EVP_EncryptUpdate(ptr noundef %58, ptr noundef null, ptr noundef %21, ptr noundef %59, i32 noundef %60)
  br label %62

62:                                               ; preds = %57, %54, %40
  %63 = load ptr, ptr %23, align 8, !tbaa !5
  %64 = getelementptr inbounds [4096 x i8], ptr %20, i64 0, i64 0
  %65 = load ptr, ptr %11, align 8, !tbaa !5
  %66 = load i32, ptr %12, align 4, !tbaa !9
  %67 = call i32 @EVP_EncryptUpdate(ptr noundef %63, ptr noundef %64, ptr noundef %21, ptr noundef %65, i32 noundef %66)
  %68 = load ptr, ptr %13, align 8, !tbaa !5
  %69 = getelementptr inbounds [4096 x i8], ptr %20, i64 0, i64 0
  %70 = load i32, ptr %21, align 4, !tbaa !9
  %71 = sext i32 %70 to i64
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %68, ptr align 16 %69, i64 %71, i1 false)
  %72 = load i32, ptr %21, align 4, !tbaa !9
  %73 = load ptr, ptr %14, align 8, !tbaa !5
  store i32 %72, ptr %73, align 4, !tbaa !9
  %74 = load ptr, ptr %23, align 8, !tbaa !5
  %75 = getelementptr inbounds [4096 x i8], ptr %20, i64 0, i64 0
  %76 = call i32 @EVP_EncryptFinal_ex(ptr noundef %74, ptr noundef %75, ptr noundef %21)
  %77 = load ptr, ptr %23, align 8, !tbaa !5
  %78 = getelementptr inbounds [4096 x i8], ptr %20, i64 0, i64 0
  %79 = call i32 @EVP_CIPHER_CTX_ctrl(ptr noundef %77, i32 noundef 16, i32 noundef 16, ptr noundef %78)
  %80 = load ptr, ptr %13, align 8, !tbaa !5
  %81 = load ptr, ptr %14, align 8, !tbaa !5
  %82 = load i32, ptr %81, align 4, !tbaa !9
  %83 = sext i32 %82 to i64
  %84 = getelementptr inbounds i8, ptr %80, i64 %83
  %85 = getelementptr inbounds [4096 x i8], ptr %20, i64 0, i64 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %84, ptr align 16 %85, i64 16, i1 false)
  %86 = load ptr, ptr %14, align 8, !tbaa !5
  %87 = load i32, ptr %86, align 4, !tbaa !9
  %88 = add nsw i32 %87, 16
  store i32 %88, ptr %86, align 4, !tbaa !9
  %89 = load ptr, ptr %23, align 8, !tbaa !5
  call void @EVP_CIPHER_CTX_free(ptr noundef %89)
  store i32 0, ptr %10, align 4
  store i32 1, ptr %22, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %23) #4
  br label %90

90:                                               ; preds = %62, %39, %35
  call void @llvm.lifetime.end.p0(i64 4, ptr %21) #4
  call void @llvm.lifetime.end.p0(i64 4096, ptr %20) #4
  %91 = load i32, ptr %10, align 4
  ret i32 %91
}

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

declare ptr @EVP_CIPHER_CTX_new() #2

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

declare ptr @EVP_aes_256_gcm() #2

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

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #3

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

declare void @EVP_CIPHER_CTX_free(ptr 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 = { 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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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}


; 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 range(i32 -1, 1) i32 @wrap_key_with_gcm256(ptr noundef %0, i32 noundef %1, ptr noundef writeonly %2, ptr nocapture noundef %3, ptr noundef %4, ptr noundef %5, i32 noundef %6, ptr noundef %7, i32 noundef %8) local_unnamed_addr #0 {
  %10 = alloca [4096 x i8], align 16
  %11 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4096, ptr nonnull %10) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %11) #4
  store i32 0, ptr %11, align 4, !tbaa !5
  %12 = insertelement <4 x ptr> poison, ptr %0, i64 0
  %13 = insertelement <4 x ptr> %12, ptr %2, i64 1
  %14 = insertelement <4 x ptr> %13, ptr %4, i64 2
  %15 = insertelement <4 x ptr> %14, ptr %5, i64 3
  %.not = icmp eq i32 %6, 12
  %16 = icmp eq <4 x ptr> %15, zeroinitializer
  %17 = bitcast <4 x i1> %16 to i4
  %18 = icmp eq i4 %17, 0
  %op.rdx = and i1 %18, %.not
  br i1 %op.rdx, label %19, label %40

19:                                               ; preds = %9
  %20 = tail call ptr @EVP_CIPHER_CTX_new() #4
  %21 = tail call ptr @EVP_aes_256_gcm() #4
  %22 = tail call i32 @EVP_EncryptInit_ex(ptr noundef %20, ptr noundef %21, ptr noundef null, ptr noundef null, ptr noundef null) #4
  %23 = tail call i32 @EVP_CIPHER_CTX_ctrl(ptr noundef %20, i32 noundef 9, i32 noundef 12, ptr noundef null) #4
  %24 = tail call i32 @EVP_EncryptInit_ex(ptr noundef %20, ptr noundef null, ptr noundef null, ptr noundef nonnull %4, ptr noundef nonnull %5) #4
  %25 = icmp ne ptr %7, null
  %26 = icmp sgt i32 %8, 0
  %or.cond7 = and i1 %25, %26
  br i1 %or.cond7, label %27, label %29

27:                                               ; preds = %19
  %28 = call i32 @EVP_EncryptUpdate(ptr noundef %20, ptr noundef null, ptr noundef nonnull %11, ptr noundef nonnull %7, i32 noundef %8) #4
  br label %29

29:                                               ; preds = %27, %19
  %30 = call i32 @EVP_EncryptUpdate(ptr noundef %20, ptr noundef nonnull %10, ptr noundef nonnull %11, ptr noundef nonnull %0, i32 noundef %1) #4
  %31 = load i32, ptr %11, align 4, !tbaa !5
  %32 = sext i32 %31 to i64
  call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 1 %2, ptr nonnull align 16 %10, i64 %32, i1 false)
  store i32 %31, ptr %3, align 4, !tbaa !5
  %33 = call i32 @EVP_EncryptFinal_ex(ptr noundef %20, ptr noundef nonnull %10, ptr noundef nonnull %11) #4
  %34 = call i32 @EVP_CIPHER_CTX_ctrl(ptr noundef %20, i32 noundef 16, i32 noundef 16, ptr noundef nonnull %10) #4
  %35 = load i32, ptr %3, align 4, !tbaa !5
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds i8, ptr %2, i64 %36
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 1 dereferenceable(16) %37, ptr noundef nonnull align 16 dereferenceable(16) %10, i64 16, i1 false)
  %38 = load i32, ptr %3, align 4, !tbaa !5
  %39 = add nsw i32 %38, 16
  store i32 %39, ptr %3, align 4, !tbaa !5
  call void @EVP_CIPHER_CTX_free(ptr noundef %20) #4
  br label %40

40:                                               ; preds = %9, %29
  %.0 = phi i32 [ 0, %29 ], [ -1, %9 ]
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %11) #4
  call void @llvm.lifetime.end.p0(i64 4096, ptr nonnull %10) #4
  ret i32 %.0
}

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

declare ptr @EVP_CIPHER_CTX_new() local_unnamed_addr #2

declare i32 @EVP_EncryptInit_ex(ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

declare ptr @EVP_aes_256_gcm() local_unnamed_addr #2

declare i32 @EVP_CIPHER_CTX_ctrl(ptr noundef, i32 noundef, i32 noundef, ptr noundef) local_unnamed_addr #2

declare i32 @EVP_EncryptUpdate(ptr noundef, ptr noundef, ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #3

declare i32 @EVP_EncryptFinal_ex(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

declare void @EVP_CIPHER_CTX_free(ptr noundef) local_unnamed_addr #2

; Function Attrs: mustprogress 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 = { mustprogress 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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}


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