; LLVM IR from openanolis/openssl :: demos/cipher (aeskeywrap)

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

@libctx = external dso_local global ptr, align 8
@propq = external dso_local global ptr, align 8
@stdout = external global ptr, align 8
@wrap_pt = external hidden constant [32 x i8], align 16
@wrap_key = external hidden constant [32 x i8], align 16
@wrap_iv = external hidden constant [16 x i8], align 16
@wrap_ct = external hidden constant [40 x i8], align 16
@stderr = external global ptr, align 8
@.str.6 = external hidden unnamed_addr constant [19 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [13 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [13 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [24 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [44 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [49 x i8], align 1

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

declare i32 @printf(ptr noundef, ...) #1

declare i32 @BIO_dump_fp(ptr noundef, ptr noundef, i32 noundef) #1

declare ptr @EVP_CIPHER_CTX_new() #1

declare void @EVP_CIPHER_CTX_set_flags(ptr noundef, i32 noundef) #1

declare ptr @EVP_CIPHER_fetch(ptr noundef, ptr noundef, ptr noundef) #1

declare i32 @CRYPTO_memcmp(ptr noundef, ptr noundef, i64 noundef) #1

declare void @ERR_print_errors_fp(ptr noundef) #1

declare void @EVP_CIPHER_free(ptr noundef) #1

declare void @EVP_CIPHER_CTX_free(ptr noundef) #1

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

; Function Attrs: nounwind uwtable
define dso_local i32 @aes_wrap_decrypt() #2 {
  %1 = alloca i32, align 4
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca [1024 x i8], align 16
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #3
  store i32 0, ptr %1, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  store ptr null, ptr %3, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  call void @llvm.lifetime.start.p0(i64 1024, ptr %6) #3
  %7 = call i32 (ptr, ...) @printf(ptr noundef @.str.6)
  %8 = call i32 (ptr, ...) @printf(ptr noundef @.str.7)
  %9 = load ptr, ptr @stdout, align 8, !tbaa !9
  %10 = call i32 @BIO_dump_fp(ptr noundef %9, ptr noundef @wrap_ct, i32 noundef 40)
  %11 = call ptr @EVP_CIPHER_CTX_new()
  store ptr %11, ptr %2, align 8, !tbaa !9
  %12 = icmp eq ptr %11, null
  br i1 %12, label %13, label %14

13:                                               ; preds = %0
  br label %66

14:                                               ; preds = %0
  %15 = load ptr, ptr %2, align 8, !tbaa !9
  call void @EVP_CIPHER_CTX_set_flags(ptr noundef %15, i32 noundef 1)
  %16 = load ptr, ptr @libctx, align 8, !tbaa !9
  %17 = load ptr, ptr @propq, align 8, !tbaa !9
  %18 = call ptr @EVP_CIPHER_fetch(ptr noundef %16, ptr noundef @.str.8, ptr noundef %17)
  store ptr %18, ptr %3, align 8, !tbaa !9
  %19 = icmp eq ptr %18, null
  br i1 %19, label %20, label %21

20:                                               ; preds = %14
  br label %66

21:                                               ; preds = %14
  %22 = load ptr, ptr %2, align 8, !tbaa !9
  %23 = load ptr, ptr %3, align 8, !tbaa !9
  %24 = call i32 @EVP_DecryptInit_ex2(ptr noundef %22, ptr noundef %23, ptr noundef @wrap_key, ptr noundef @wrap_iv, ptr noundef null)
  %25 = icmp ne i32 %24, 0
  br i1 %25, label %27, label %26

26:                                               ; preds = %21
  br label %66

27:                                               ; preds = %21
  %28 = load ptr, ptr %2, align 8, !tbaa !9
  %29 = getelementptr inbounds [1024 x i8], ptr %6, i64 0, i64 0
  %30 = call i32 @EVP_DecryptUpdate(ptr noundef %28, ptr noundef %29, ptr noundef %4, ptr noundef @wrap_ct, i32 noundef 40)
  %31 = icmp ne i32 %30, 0
  br i1 %31, label %33, label %32

32:                                               ; preds = %27
  br label %66

33:                                               ; preds = %27
  %34 = load ptr, ptr %2, align 8, !tbaa !9
  %35 = getelementptr inbounds [1024 x i8], ptr %6, i64 0, i64 0
  %36 = load i32, ptr %4, align 4, !tbaa !5
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds i8, ptr %35, i64 %37
  %39 = call i32 @EVP_DecryptFinal_ex(ptr noundef %34, ptr noundef %38, ptr noundef %5)
  %40 = icmp ne i32 %39, 0
  br i1 %40, label %42, label %41

41:                                               ; preds = %33
  br label %66

42:                                               ; preds = %33
  %43 = load i32, ptr %5, align 4, !tbaa !5
  %44 = load i32, ptr %4, align 4, !tbaa !5
  %45 = add nsw i32 %44, %43
  store i32 %45, ptr %4, align 4, !tbaa !5
  %46 = load i32, ptr %4, align 4, !tbaa !5
  %47 = call i32 (ptr, ...) @printf(ptr noundef @.str.9, i32 noundef %46)
  %48 = load ptr, ptr @stdout, align 8, !tbaa !9
  %49 = getelementptr inbounds [1024 x i8], ptr %6, i64 0, i64 0
  %50 = load i32, ptr %4, align 4, !tbaa !5
  %51 = call i32 @BIO_dump_fp(ptr noundef %48, ptr noundef %49, i32 noundef %50)
  %52 = load i32, ptr %4, align 4, !tbaa !5
  %53 = sext i32 %52 to i64
  %54 = icmp eq i64 32, %53
  br i1 %54, label %55, label %63

55:                                               ; preds = %42
  %56 = getelementptr inbounds [1024 x i8], ptr %6, i64 0, i64 0
  %57 = load i32, ptr %4, align 4, !tbaa !5
  %58 = sext i32 %57 to i64
  %59 = call i32 @CRYPTO_memcmp(ptr noundef %56, ptr noundef @wrap_pt, i64 noundef %58)
  %60 = icmp ne i32 %59, 0
  br i1 %60, label %63, label %61

61:                                               ; preds = %55
  %62 = call i32 (ptr, ...) @printf(ptr noundef @.str.10)
  br label %65

63:                                               ; preds = %55, %42
  %64 = call i32 (ptr, ...) @printf(ptr noundef @.str.11)
  br label %65

65:                                               ; preds = %63, %61
  store i32 1, ptr %1, align 4, !tbaa !5
  br label %66

66:                                               ; preds = %65, %41, %32, %26, %20, %13
  %67 = load i32, ptr %1, align 4, !tbaa !5
  %68 = icmp ne i32 %67, 0
  br i1 %68, label %71, label %69

69:                                               ; preds = %66
  %70 = load ptr, ptr @stderr, align 8, !tbaa !9
  call void @ERR_print_errors_fp(ptr noundef %70)
  br label %71

71:                                               ; preds = %69, %66
  %72 = load ptr, ptr %3, align 8, !tbaa !9
  call void @EVP_CIPHER_free(ptr noundef %72)
  %73 = load ptr, ptr %2, align 8, !tbaa !9
  call void @EVP_CIPHER_CTX_free(ptr noundef %73)
  %74 = load i32, ptr %1, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 1024, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #3
  ret i32 %74
}

declare i32 @EVP_DecryptInit_ex2(ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef) #1

declare i32 @EVP_DecryptUpdate(ptr noundef, ptr noundef, ptr noundef, ptr noundef, i32 noundef) #1

declare i32 @EVP_DecryptFinal_ex(ptr noundef, ptr noundef, ptr noundef) #1

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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, !6, i64 0}
!6 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !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"

@libctx = external dso_local local_unnamed_addr global ptr, align 8
@propq = external dso_local local_unnamed_addr global ptr, align 8
@stdout = external local_unnamed_addr global ptr, align 8
@wrap_pt = external hidden constant [32 x i8], align 16
@wrap_key = external hidden constant [32 x i8], align 16
@wrap_iv = external hidden constant [16 x i8], align 16
@wrap_ct = external hidden constant [40 x i8], align 16
@stderr = external local_unnamed_addr global ptr, align 8
@.str.6 = external hidden unnamed_addr constant [19 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [13 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [13 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [24 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [44 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [49 x i8], align 1

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

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #1

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

declare ptr @EVP_CIPHER_CTX_new() local_unnamed_addr #2

declare void @EVP_CIPHER_CTX_set_flags(ptr noundef, i32 noundef) local_unnamed_addr #2

declare ptr @EVP_CIPHER_fetch(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

declare i32 @CRYPTO_memcmp(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #2

declare void @ERR_print_errors_fp(ptr noundef) local_unnamed_addr #2

declare void @EVP_CIPHER_free(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) #0

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 2) i32 @aes_wrap_decrypt() local_unnamed_addr #3 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca [1024 x i8], align 16
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2) #4
  call void @llvm.lifetime.start.p0(i64 1024, ptr nonnull %3) #4
  %4 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.6)
  %5 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.7)
  %6 = load ptr, ptr @stdout, align 8, !tbaa !5
  %7 = tail call i32 @BIO_dump_fp(ptr noundef %6, ptr noundef nonnull @wrap_ct, i32 noundef 40) #4
  %8 = tail call ptr @EVP_CIPHER_CTX_new() #4
  %9 = icmp eq ptr %8, null
  br i1 %9, label %40, label %10

10:                                               ; preds = %0
  tail call void @EVP_CIPHER_CTX_set_flags(ptr noundef nonnull %8, i32 noundef 1) #4
  %11 = load ptr, ptr @libctx, align 8, !tbaa !5
  %12 = load ptr, ptr @propq, align 8, !tbaa !5
  %13 = tail call ptr @EVP_CIPHER_fetch(ptr noundef %11, ptr noundef nonnull @.str.8, ptr noundef %12) #4
  %14 = icmp eq ptr %13, null
  br i1 %14, label %40, label %15

15:                                               ; preds = %10
  %16 = tail call i32 @EVP_DecryptInit_ex2(ptr noundef nonnull %8, ptr noundef nonnull %13, ptr noundef nonnull @wrap_key, ptr noundef nonnull @wrap_iv, ptr noundef null) #4
  %.not = icmp eq i32 %16, 0
  br i1 %.not, label %40, label %17

17:                                               ; preds = %15
  %18 = call i32 @EVP_DecryptUpdate(ptr noundef nonnull %8, ptr noundef nonnull %3, ptr noundef nonnull %1, ptr noundef nonnull @wrap_ct, i32 noundef 40) #4
  %.not12 = icmp eq i32 %18, 0
  br i1 %.not12, label %40, label %19

19:                                               ; preds = %17
  %20 = load i32, ptr %1, align 4, !tbaa !9
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds i8, ptr %3, i64 %21
  %23 = call i32 @EVP_DecryptFinal_ex(ptr noundef nonnull %8, ptr noundef nonnull %22, ptr noundef nonnull %2) #4
  %.not13 = icmp eq i32 %23, 0
  br i1 %.not13, label %40, label %24

24:                                               ; preds = %19
  %25 = load i32, ptr %2, align 4, !tbaa !9
  %26 = load i32, ptr %1, align 4, !tbaa !9
  %27 = add nsw i32 %26, %25
  store i32 %27, ptr %1, align 4, !tbaa !9
  %28 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.9, i32 noundef %27)
  %29 = load ptr, ptr @stdout, align 8, !tbaa !5
  %30 = load i32, ptr %1, align 4, !tbaa !9
  %31 = call i32 @BIO_dump_fp(ptr noundef %29, ptr noundef nonnull %3, i32 noundef %30) #4
  %32 = load i32, ptr %1, align 4, !tbaa !9
  %33 = icmp eq i32 %32, 32
  br i1 %33, label %34, label %38

34:                                               ; preds = %24
  %35 = call i32 @CRYPTO_memcmp(ptr noundef nonnull %3, ptr noundef nonnull @wrap_pt, i64 noundef 32) #4
  %.not14 = icmp eq i32 %35, 0
  br i1 %.not14, label %36, label %38

36:                                               ; preds = %34
  %37 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.10)
  br label %42

38:                                               ; preds = %34, %24
  %39 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.11)
  br label %42

40:                                               ; preds = %0, %10, %19, %17, %15
  %.0.ph = phi ptr [ %13, %15 ], [ %13, %17 ], [ %13, %19 ], [ null, %10 ], [ null, %0 ]
  %41 = load ptr, ptr @stderr, align 8, !tbaa !5
  call void @ERR_print_errors_fp(ptr noundef %41) #4
  br label %42

42:                                               ; preds = %38, %36, %40
  %.021 = phi ptr [ %.0.ph, %40 ], [ %13, %38 ], [ %13, %36 ]
  %.0819 = phi i32 [ 0, %40 ], [ 1, %38 ], [ 1, %36 ]
  call void @EVP_CIPHER_free(ptr noundef %.021) #4
  call void @EVP_CIPHER_CTX_free(ptr noundef %8) #4
  call void @llvm.lifetime.end.p0(i64 1024, ptr nonnull %3) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #4
  ret i32 %.0819
}

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

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

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

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nofree nounwind "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 = { "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 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}


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