; LLVM IR from openssl/openssl :: crypto/slh_dsa (slh_dsa_hash_ctx)

; 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.slh_dsa_hash_ctx_st = type { ptr, ptr, ptr, ptr, i32 }
%struct.slh_dsa_key_st = type { [128 x i8], ptr, ptr, ptr, i32, ptr, ptr, ptr, ptr, ptr, ptr }

@.str = external hidden unnamed_addr constant [83 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local ptr @ossl_slh_dsa_hash_ctx_new(ptr noundef %0) #0 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  %6 = call ptr @CRYPTO_zalloc(i64 noundef 40, ptr noundef @.str, i32 noundef 28)
  store ptr %6, ptr %4, align 8, !tbaa !5
  %7 = load ptr, ptr %4, align 8, !tbaa !5
  %8 = icmp eq ptr %7, null
  br i1 %8, label %9, label %10

9:                                                ; preds = %1
  store ptr null, ptr %2, align 8
  store i32 1, ptr %5, align 4
  br label %94

10:                                               ; preds = %1
  %11 = load ptr, ptr %3, align 8, !tbaa !5
  %12 = load ptr, ptr %4, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.slh_dsa_hash_ctx_st, ptr %12, i32 0, i32 0
  store ptr %11, ptr %13, align 8, !tbaa !9
  %14 = call ptr @EVP_MD_CTX_new()
  %15 = load ptr, ptr %4, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.slh_dsa_hash_ctx_st, ptr %15, i32 0, i32 1
  store ptr %14, ptr %16, align 8, !tbaa !12
  %17 = load ptr, ptr %4, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.slh_dsa_hash_ctx_st, ptr %17, i32 0, i32 1
  %19 = load ptr, ptr %18, align 8, !tbaa !12
  %20 = icmp eq ptr %19, null
  br i1 %20, label %21, label %22

21:                                               ; preds = %10
  br label %92

22:                                               ; preds = %10
  %23 = load ptr, ptr %4, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.slh_dsa_hash_ctx_st, ptr %23, i32 0, i32 1
  %25 = load ptr, ptr %24, align 8, !tbaa !12
  %26 = load ptr, ptr %3, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.slh_dsa_key_st, ptr %26, i32 0, i32 8
  %28 = load ptr, ptr %27, align 8, !tbaa !13
  %29 = call i32 @EVP_DigestInit_ex2(ptr noundef %25, ptr noundef %28, ptr noundef null)
  %30 = icmp ne i32 %29, 1
  br i1 %30, label %31, label %32

31:                                               ; preds = %22
  br label %92

32:                                               ; preds = %22
  %33 = load ptr, ptr %3, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.slh_dsa_key_st, ptr %33, i32 0, i32 9
  %35 = load ptr, ptr %34, align 8, !tbaa !15
  %36 = icmp ne ptr %35, null
  br i1 %36, label %37, label %90

37:                                               ; preds = %32
  %38 = load ptr, ptr %3, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.slh_dsa_key_st, ptr %38, i32 0, i32 9
  %40 = load ptr, ptr %39, align 8, !tbaa !15
  %41 = load ptr, ptr %3, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.slh_dsa_key_st, ptr %41, i32 0, i32 8
  %43 = load ptr, ptr %42, align 8, !tbaa !13
  %44 = icmp eq ptr %40, %43
  br i1 %44, label %45, label %51

45:                                               ; preds = %37
  %46 = load ptr, ptr %4, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.slh_dsa_hash_ctx_st, ptr %46, i32 0, i32 1
  %48 = load ptr, ptr %47, align 8, !tbaa !12
  %49 = load ptr, ptr %4, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.slh_dsa_hash_ctx_st, ptr %49, i32 0, i32 2
  store ptr %48, ptr %50, align 8, !tbaa !16
  br label %71

51:                                               ; preds = %37
  %52 = call ptr @EVP_MD_CTX_new()
  %53 = load ptr, ptr %4, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.slh_dsa_hash_ctx_st, ptr %53, i32 0, i32 2
  store ptr %52, ptr %54, align 8, !tbaa !16
  %55 = load ptr, ptr %4, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.slh_dsa_hash_ctx_st, ptr %55, i32 0, i32 2
  %57 = load ptr, ptr %56, align 8, !tbaa !16
  %58 = icmp eq ptr %57, null
  br i1 %58, label %59, label %60

59:                                               ; preds = %51
  br label %92

60:                                               ; preds = %51
  %61 = load ptr, ptr %4, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.slh_dsa_hash_ctx_st, ptr %61, i32 0, i32 2
  %63 = load ptr, ptr %62, align 8, !tbaa !16
  %64 = load ptr, ptr %3, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.slh_dsa_key_st, ptr %64, i32 0, i32 9
  %66 = load ptr, ptr %65, align 8, !tbaa !15
  %67 = call i32 @EVP_DigestInit_ex2(ptr noundef %63, ptr noundef %66, ptr noundef null)
  %68 = icmp ne i32 %67, 1
  br i1 %68, label %69, label %70

69:                                               ; preds = %60
  br label %92

70:                                               ; preds = %60
  br label %71

71:                                               ; preds = %70, %45
  %72 = load ptr, ptr %3, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct.slh_dsa_key_st, ptr %72, i32 0, i32 10
  %74 = load ptr, ptr %73, align 8, !tbaa !17
  %75 = icmp ne ptr %74, null
  br i1 %75, label %76, label %89

76:                                               ; preds = %71
  %77 = load ptr, ptr %3, align 8, !tbaa !5
  %78 = getelementptr inbounds %struct.slh_dsa_key_st, ptr %77, i32 0, i32 10
  %79 = load ptr, ptr %78, align 8, !tbaa !17
  %80 = call ptr @EVP_MAC_CTX_new(ptr noundef %79)
  %81 = load ptr, ptr %4, align 8, !tbaa !5
  %82 = getelementptr inbounds %struct.slh_dsa_hash_ctx_st, ptr %81, i32 0, i32 3
  store ptr %80, ptr %82, align 8, !tbaa !18
  %83 = load ptr, ptr %4, align 8, !tbaa !5
  %84 = getelementptr inbounds %struct.slh_dsa_hash_ctx_st, ptr %83, i32 0, i32 3
  %85 = load ptr, ptr %84, align 8, !tbaa !18
  %86 = icmp eq ptr %85, null
  br i1 %86, label %87, label %88

87:                                               ; preds = %76
  br label %92

88:                                               ; preds = %76
  br label %89

89:                                               ; preds = %88, %71
  br label %90

90:                                               ; preds = %89, %32
  %91 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %91, ptr %2, align 8
  store i32 1, ptr %5, align 4
  br label %94

92:                                               ; preds = %87, %69, %59, %31, %21
  %93 = load ptr, ptr %4, align 8, !tbaa !5
  call void @ossl_slh_dsa_hash_ctx_free(ptr noundef %93)
  store ptr null, ptr %2, align 8
  store i32 1, ptr %5, align 4
  br label %94

94:                                               ; preds = %92, %90, %9
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  %95 = load ptr, ptr %2, align 8
  ret ptr %95
}

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

declare ptr @CRYPTO_zalloc(i64 noundef, ptr noundef, i32 noundef) #2

declare ptr @EVP_MD_CTX_new() #2

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

declare ptr @EVP_MAC_CTX_new(ptr noundef) #2

; Function Attrs: nounwind uwtable
declare dso_local void @ossl_slh_dsa_hash_ctx_free(ptr noundef) #0

; 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 = { 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, !6, i64 0}
!10 = !{!"slh_dsa_hash_ctx_st", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !11, i64 32}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !6, i64 8}
!13 = !{!14, !6, i64 184}
!14 = !{!"slh_dsa_key_st", !7, i64 0, !6, i64 128, !6, i64 136, !6, i64 144, !11, i64 152, !6, i64 160, !6, i64 168, !6, i64 176, !6, i64 184, !6, i64 192, !6, i64 200}
!15 = !{!14, !6, i64 192}
!16 = !{!10, !6, i64 16}
!17 = !{!14, !6, i64 200}
!18 = !{!10, !6, i64 24}


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

@.str = external hidden unnamed_addr constant [83 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local ptr @ossl_slh_dsa_hash_ctx_new(ptr noundef %0) local_unnamed_addr #0 {
  %2 = tail call ptr @CRYPTO_zalloc(i64 noundef 40, ptr noundef nonnull @.str, i32 noundef 28) #2
  %3 = icmp eq ptr %2, null
  br i1 %3, label %35, label %4

4:                                                ; preds = %1
  store ptr %0, ptr %2, align 8, !tbaa !5
  %5 = tail call ptr @EVP_MD_CTX_new() #2
  %6 = getelementptr inbounds i8, ptr %2, i64 8
  store ptr %5, ptr %6, align 8, !tbaa !11
  %7 = icmp eq ptr %5, null
  br i1 %7, label %34, label %8

8:                                                ; preds = %4
  %9 = getelementptr inbounds i8, ptr %0, i64 184
  %10 = load ptr, ptr %9, align 8, !tbaa !12
  %11 = tail call i32 @EVP_DigestInit_ex2(ptr noundef nonnull %5, ptr noundef %10, ptr noundef null) #2
  %.not = icmp eq i32 %11, 1
  br i1 %.not, label %12, label %34

12:                                               ; preds = %8
  %13 = getelementptr inbounds i8, ptr %0, i64 192
  %14 = load ptr, ptr %13, align 8, !tbaa !14
  %.not28 = icmp eq ptr %14, null
  br i1 %.not28, label %35, label %15

15:                                               ; preds = %12
  %16 = load ptr, ptr %9, align 8, !tbaa !12
  %17 = icmp eq ptr %14, %16
  %18 = getelementptr inbounds i8, ptr %2, i64 16
  br i1 %17, label %19, label %21

19:                                               ; preds = %15
  %20 = load ptr, ptr %6, align 8, !tbaa !11
  store ptr %20, ptr %18, align 8, !tbaa !15
  br label %27

21:                                               ; preds = %15
  %22 = tail call ptr @EVP_MD_CTX_new() #2
  store ptr %22, ptr %18, align 8, !tbaa !15
  %23 = icmp eq ptr %22, null
  br i1 %23, label %34, label %24

24:                                               ; preds = %21
  %25 = load ptr, ptr %13, align 8, !tbaa !14
  %26 = tail call i32 @EVP_DigestInit_ex2(ptr noundef nonnull %22, ptr noundef %25, ptr noundef null) #2
  %.not29 = icmp eq i32 %26, 1
  br i1 %.not29, label %27, label %34

27:                                               ; preds = %24, %19
  %28 = getelementptr inbounds i8, ptr %0, i64 200
  %29 = load ptr, ptr %28, align 8, !tbaa !16
  %.not30 = icmp eq ptr %29, null
  br i1 %.not30, label %35, label %30

30:                                               ; preds = %27
  %31 = tail call ptr @EVP_MAC_CTX_new(ptr noundef nonnull %29) #2
  %32 = getelementptr inbounds i8, ptr %2, i64 24
  store ptr %31, ptr %32, align 8, !tbaa !17
  %33 = icmp eq ptr %31, null
  br i1 %33, label %34, label %35

34:                                               ; preds = %30, %24, %21, %8, %4
  tail call void @ossl_slh_dsa_hash_ctx_free(ptr noundef nonnull %2)
  br label %35

35:                                               ; preds = %12, %30, %27, %1, %34
  %.0 = phi ptr [ null, %34 ], [ null, %1 ], [ %2, %27 ], [ %2, %30 ], [ %2, %12 ]
  ret ptr %.0
}

declare ptr @CRYPTO_zalloc(i64 noundef, ptr noundef, i32 noundef) local_unnamed_addr #1

declare ptr @EVP_MD_CTX_new() local_unnamed_addr #1

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

declare ptr @EVP_MAC_CTX_new(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local void @ossl_slh_dsa_hash_ctx_free(ptr noundef) local_unnamed_addr #0

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 = { 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 = !{!"slh_dsa_hash_ctx_st", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !10, i64 32}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!6, !7, i64 8}
!12 = !{!13, !7, i64 184}
!13 = !{!"slh_dsa_key_st", !8, i64 0, !7, i64 128, !7, i64 136, !7, i64 144, !10, i64 152, !7, i64 160, !7, i64 168, !7, i64 176, !7, i64 184, !7, i64 192, !7, i64 200}
!14 = !{!13, !7, i64 192}
!15 = !{!6, !7, i64 16}
!16 = !{!13, !7, i64 200}
!17 = !{!6, !7, i64 24}


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