; LLVM IR from PaddlePaddle/FastDeploy :: fastdeploy/encryption/util/src/crypto (aes_gcm)

; 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: mustprogress uwtable
declare dso_local noundef i32 @_ZN10fastdeploy4util6crypto6AesGcm11aes_gcm_keyEPKhS4_P17evp_cipher_ctx_stS6_(ptr noundef, ptr noundef, ptr noundef, ptr noundef) #0 align 2

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

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

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

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN10fastdeploy4util6crypto6AesGcm15encrypt_aes_gcmEPKhRKiS4_S4_PhRi(ptr noundef %0, ptr noundef nonnull align 4 dereferenceable(4) %1, ptr noundef %2, ptr noundef %3, ptr noundef %4, ptr noundef nonnull align 4 dereferenceable(4) %5) #0 align 2 {
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca ptr, align 8
  %14 = alloca ptr, align 8
  %15 = alloca i32, align 4
  %16 = alloca i32, align 4
  %17 = alloca i32, align 4
  %18 = alloca [16 x i8], align 16
  %19 = alloca i32, align 4
  %20 = alloca i32, align 4
  store ptr %0, ptr %8, align 8, !tbaa !5
  store ptr %1, ptr %9, align 8, !tbaa !5
  store ptr %2, ptr %10, align 8, !tbaa !5
  store ptr %3, ptr %11, align 8, !tbaa !5
  store ptr %4, ptr %12, align 8, !tbaa !5
  store ptr %5, ptr %13, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #3
  store ptr null, ptr %14, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #3
  store i32 0, ptr %15, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %16) #3
  store i32 0, ptr %16, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %17) #3
  store i32 0, ptr %17, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 16, ptr %18) #3
  %21 = call ptr @EVP_CIPHER_CTX_new()
  store ptr %21, ptr %14, align 8, !tbaa !5
  %22 = icmp ne ptr %21, null
  br i1 %22, label %24, label %23

23:                                               ; preds = %6
  store i32 -1, ptr %7, align 4
  store i32 1, ptr %19, align 4
  br label %91

24:                                               ; preds = %6
  %25 = load ptr, ptr %10, align 8, !tbaa !5
  %26 = load ptr, ptr %11, align 8, !tbaa !5
  %27 = load ptr, ptr %14, align 8, !tbaa !5
  %28 = call noundef i32 @_ZN10fastdeploy4util6crypto6AesGcm11aes_gcm_keyEPKhS4_P17evp_cipher_ctx_stS6_(ptr noundef %25, ptr noundef %26, ptr noundef %27, ptr noundef null)
  store i32 %28, ptr %15, align 4, !tbaa !9
  %29 = load i32, ptr %15, align 4, !tbaa !9
  %30 = icmp ne i32 %29, 0
  br i1 %30, label %31, label %33

31:                                               ; preds = %24
  %32 = load ptr, ptr %14, align 8, !tbaa !5
  call void @EVP_CIPHER_CTX_free(ptr noundef %32)
  store i32 -1, ptr %7, align 4
  store i32 1, ptr %19, align 4
  br label %91

33:                                               ; preds = %24
  %34 = load ptr, ptr %14, align 8, !tbaa !5
  %35 = load ptr, ptr %12, align 8, !tbaa !5
  %36 = load ptr, ptr %8, align 8, !tbaa !5
  %37 = load ptr, ptr %9, align 8, !tbaa !5
  %38 = load i32, ptr %37, align 4, !tbaa !9
  %39 = call i32 @EVP_EncryptUpdate(ptr noundef %34, ptr noundef %35, ptr noundef %16, ptr noundef %36, i32 noundef %38)
  store i32 %39, ptr %15, align 4, !tbaa !9
  %40 = load i32, ptr %15, align 4, !tbaa !9
  %41 = icmp ne i32 %40, 1
  br i1 %41, label %42, label %44

42:                                               ; preds = %33
  %43 = load ptr, ptr %14, align 8, !tbaa !5
  call void @EVP_CIPHER_CTX_free(ptr noundef %43)
  store i32 -2, ptr %7, align 4
  store i32 1, ptr %19, align 4
  br label %91

44:                                               ; preds = %33
  %45 = load i32, ptr %16, align 4, !tbaa !9
  store i32 %45, ptr %17, align 4, !tbaa !9
  %46 = load ptr, ptr %14, align 8, !tbaa !5
  %47 = load ptr, ptr %12, align 8, !tbaa !5
  %48 = load i32, ptr %17, align 4, !tbaa !9
  %49 = sext i32 %48 to i64
  %50 = getelementptr inbounds i8, ptr %47, i64 %49
  %51 = call i32 @EVP_EncryptFinal_ex(ptr noundef %46, ptr noundef %50, ptr noundef %16)
  store i32 %51, ptr %15, align 4, !tbaa !9
  %52 = load i32, ptr %15, align 4, !tbaa !9
  %53 = icmp ne i32 1, %52
  br i1 %53, label %54, label %56

54:                                               ; preds = %44
  %55 = load ptr, ptr %14, align 8, !tbaa !5
  call void @EVP_CIPHER_CTX_free(ptr noundef %55)
  store i32 -3, ptr %7, align 4
  store i32 1, ptr %19, align 4
  br label %91

56:                                               ; preds = %44
  %57 = load i32, ptr %16, align 4, !tbaa !9
  %58 = load i32, ptr %17, align 4, !tbaa !9
  %59 = add nsw i32 %58, %57
  store i32 %59, ptr %17, align 4, !tbaa !9
  %60 = load ptr, ptr %14, align 8, !tbaa !5
  %61 = getelementptr inbounds [16 x i8], ptr %18, i64 0, i64 0
  %62 = call i32 @EVP_CIPHER_CTX_ctrl(ptr noundef %60, i32 noundef 16, i32 noundef 16, ptr noundef %61)
  store i32 %62, ptr %15, align 4, !tbaa !9
  %63 = load i32, ptr %15, align 4, !tbaa !9
  %64 = icmp ne i32 1, %63
  br i1 %64, label %65, label %67

65:                                               ; preds = %56
  %66 = load ptr, ptr %14, align 8, !tbaa !5
  call void @EVP_CIPHER_CTX_free(ptr noundef %66)
  store i32 -4, ptr %7, align 4
  store i32 1, ptr %19, align 4
  br label %91

67:                                               ; preds = %56
  %68 = load ptr, ptr %14, align 8, !tbaa !5
  call void @EVP_CIPHER_CTX_free(ptr noundef %68)
  call void @llvm.lifetime.start.p0(i64 4, ptr %20) #3
  store i32 0, ptr %20, align 4, !tbaa !9
  br label %69

69:                                               ; preds = %84, %67
  %70 = load i32, ptr %20, align 4, !tbaa !9
  %71 = icmp slt i32 %70, 16
  br i1 %71, label %73, label %72

72:                                               ; preds = %69
  store i32 2, ptr %19, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %20) #3
  br label %87

73:                                               ; preds = %69
  %74 = load i32, ptr %20, align 4, !tbaa !9
  %75 = sext i32 %74 to i64
  %76 = getelementptr inbounds [16 x i8], ptr %18, i64 0, i64 %75
  %77 = load i8, ptr %76, align 1, !tbaa !11
  %78 = load ptr, ptr %12, align 8, !tbaa !5
  %79 = load i32, ptr %17, align 4, !tbaa !9
  %80 = load i32, ptr %20, align 4, !tbaa !9
  %81 = add nsw i32 %79, %80
  %82 = sext i32 %81 to i64
  %83 = getelementptr inbounds i8, ptr %78, i64 %82
  store i8 %77, ptr %83, align 1, !tbaa !11
  br label %84

84:                                               ; preds = %73
  %85 = load i32, ptr %20, align 4, !tbaa !9
  %86 = add nsw i32 %85, 1
  store i32 %86, ptr %20, align 4, !tbaa !9
  br label %69, !llvm.loop !12

87:                                               ; preds = %72
  %88 = load i32, ptr %17, align 4, !tbaa !9
  %89 = add nsw i32 %88, 16
  %90 = load ptr, ptr %13, align 8, !tbaa !5
  store i32 %89, ptr %90, align 4, !tbaa !9
  store i32 0, ptr %7, align 4
  store i32 1, ptr %19, align 4
  br label %91

91:                                               ; preds = %87, %65, %54, %42, %31, %23
  call void @llvm.lifetime.end.p0(i64 16, ptr %18) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %17) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #3
  %92 = load i32, ptr %7, align 4
  ret i32 %92
}

declare ptr @EVP_CIPHER_CTX_new() #2

declare void @EVP_CIPHER_CTX_free(ptr noundef) #2

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

declare i32 @EVP_EncryptFinal_ex(ptr noundef, ptr noundef, ptr noundef) #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" }
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 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}


; 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
declare dso_local noundef i32 @_ZN10fastdeploy4util6crypto6AesGcm11aes_gcm_keyEPKhS4_P17evp_cipher_ctx_stS6_(ptr noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #0 align 2

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

declare i32 @EVP_CIPHER_CTX_ctrl(ptr noundef, i32 noundef, i32 noundef, 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

; Function Attrs: mustprogress uwtable
define dso_local noundef range(i32 -4, 1) i32 @_ZN10fastdeploy4util6crypto6AesGcm15encrypt_aes_gcmEPKhRKiS4_S4_PhRi(ptr noundef %0, ptr nocapture noundef nonnull readonly align 4 dereferenceable(4) %1, ptr noundef %2, ptr noundef %3, ptr noundef %4, ptr nocapture noundef nonnull writeonly align 4 dereferenceable(4) %5) local_unnamed_addr #0 align 2 {
  %7 = alloca i32, align 4
  %8 = alloca [16 x i8], align 16
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %7) #3
  store i32 0, ptr %7, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %8) #3
  %9 = tail call ptr @EVP_CIPHER_CTX_new()
  %.not = icmp eq ptr %9, null
  br i1 %.not, label %33, label %10

10:                                               ; preds = %6
  %11 = tail call noundef i32 @_ZN10fastdeploy4util6crypto6AesGcm11aes_gcm_keyEPKhS4_P17evp_cipher_ctx_stS6_(ptr noundef %2, ptr noundef %3, ptr noundef nonnull %9, ptr noundef null)
  %.not31 = icmp eq i32 %11, 0
  br i1 %.not31, label %13, label %12

12:                                               ; preds = %10
  tail call void @EVP_CIPHER_CTX_free(ptr noundef nonnull %9)
  br label %33

13:                                               ; preds = %10
  %14 = load i32, ptr %1, align 4, !tbaa !5
  %15 = call i32 @EVP_EncryptUpdate(ptr noundef nonnull %9, ptr noundef %4, ptr noundef nonnull %7, ptr noundef %0, i32 noundef %14)
  %.not32 = icmp eq i32 %15, 1
  br i1 %.not32, label %17, label %16

16:                                               ; preds = %13
  call void @EVP_CIPHER_CTX_free(ptr noundef nonnull %9)
  br label %33

17:                                               ; preds = %13
  %18 = load i32, ptr %7, align 4, !tbaa !5
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds i8, ptr %4, i64 %19
  %21 = call i32 @EVP_EncryptFinal_ex(ptr noundef nonnull %9, ptr noundef %20, ptr noundef nonnull %7)
  %.not33 = icmp eq i32 %21, 1
  br i1 %.not33, label %23, label %22

22:                                               ; preds = %17
  call void @EVP_CIPHER_CTX_free(ptr noundef nonnull %9)
  br label %33

23:                                               ; preds = %17
  %24 = load i32, ptr %7, align 4, !tbaa !5
  %25 = call i32 @EVP_CIPHER_CTX_ctrl(ptr noundef nonnull %9, i32 noundef 16, i32 noundef 16, ptr noundef nonnull %8)
  %.not34 = icmp eq i32 %25, 1
  br i1 %.not34, label %27, label %26

26:                                               ; preds = %23
  call void @EVP_CIPHER_CTX_free(ptr noundef nonnull %9)
  br label %33

27:                                               ; preds = %23
  %28 = add nsw i32 %24, %18
  call void @EVP_CIPHER_CTX_free(ptr noundef nonnull %9)
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds i8, ptr %4, i64 %29
  %31 = load <16 x i8>, ptr %8, align 16, !tbaa !9
  store <16 x i8> %31, ptr %30, align 1, !tbaa !9
  %32 = add nsw i32 %28, 16
  store i32 %32, ptr %5, align 4, !tbaa !5
  br label %33

33:                                               ; preds = %6, %27, %26, %22, %16, %12
  %.029 = phi i32 [ -1, %12 ], [ -2, %16 ], [ -3, %22 ], [ -4, %26 ], [ 0, %27 ], [ -1, %6 ]
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %8) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %7) #3
  ret i32 %.029
}

declare ptr @EVP_CIPHER_CTX_new() local_unnamed_addr #2

declare void @EVP_CIPHER_CTX_free(ptr noundef) local_unnamed_addr #2

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

declare i32 @EVP_EncryptFinal_ex(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #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" }
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 = { 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 = !{!7, !7, i64 0}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,LoopRotatePass,PostOrderFunctionAttrsPass,ReassociatePass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,TailCallElimPass