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

@.str = external hidden unnamed_addr constant [83 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 ptr @CRYPTO_zalloc(i64 noundef, ptr noundef, i32 noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local void @ossl_slh_dsa_hash_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) #0

; Function Attrs: nounwind uwtable
define dso_local ptr @ossl_slh_dsa_hash_ctx_dup(ptr noundef %0) #2 {
  %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 70)
  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 %82

10:                                               ; preds = %1
  %11 = load ptr, ptr %3, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.slh_dsa_hash_ctx_st, ptr %11, i32 0, i32 4
  %13 = load i32, ptr %12, align 8, !tbaa !9
  %14 = load ptr, ptr %4, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.slh_dsa_hash_ctx_st, ptr %14, i32 0, i32 4
  store i32 %13, ptr %15, align 8, !tbaa !9
  %16 = load ptr, ptr %3, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.slh_dsa_hash_ctx_st, ptr %16, i32 0, i32 0
  %18 = load ptr, ptr %17, align 8, !tbaa !12
  %19 = load ptr, ptr %4, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.slh_dsa_hash_ctx_st, ptr %19, i32 0, i32 0
  store ptr %18, ptr %20, align 8, !tbaa !12
  %21 = load ptr, ptr %3, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.slh_dsa_hash_ctx_st, ptr %21, i32 0, i32 1
  %23 = load ptr, ptr %22, align 8, !tbaa !13
  %24 = icmp ne ptr %23, null
  br i1 %24, label %25, label %34

25:                                               ; preds = %10
  %26 = load ptr, ptr %3, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.slh_dsa_hash_ctx_st, ptr %26, i32 0, i32 1
  %28 = load ptr, ptr %27, align 8, !tbaa !13
  %29 = call ptr @EVP_MD_CTX_dup(ptr noundef %28)
  %30 = load ptr, ptr %4, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.slh_dsa_hash_ctx_st, ptr %30, i32 0, i32 1
  store ptr %29, ptr %31, align 8, !tbaa !13
  %32 = icmp eq ptr %29, null
  br i1 %32, label %33, label %34

33:                                               ; preds = %25
  br label %80

34:                                               ; preds = %25, %10
  %35 = load ptr, ptr %3, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.slh_dsa_hash_ctx_st, ptr %35, i32 0, i32 2
  %37 = load ptr, ptr %36, align 8, !tbaa !14
  %38 = icmp ne ptr %37, null
  br i1 %38, label %39, label %64

39:                                               ; preds = %34
  %40 = load ptr, ptr %3, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.slh_dsa_hash_ctx_st, ptr %40, i32 0, i32 2
  %42 = load ptr, ptr %41, align 8, !tbaa !14
  %43 = load ptr, ptr %3, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.slh_dsa_hash_ctx_st, ptr %43, i32 0, i32 1
  %45 = load ptr, ptr %44, align 8, !tbaa !13
  %46 = icmp ne ptr %42, %45
  br i1 %46, label %47, label %57

47:                                               ; preds = %39
  %48 = load ptr, ptr %3, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.slh_dsa_hash_ctx_st, ptr %48, i32 0, i32 2
  %50 = load ptr, ptr %49, align 8, !tbaa !14
  %51 = call ptr @EVP_MD_CTX_dup(ptr noundef %50)
  %52 = load ptr, ptr %4, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.slh_dsa_hash_ctx_st, ptr %52, i32 0, i32 2
  store ptr %51, ptr %53, align 8, !tbaa !14
  %54 = icmp eq ptr %51, null
  br i1 %54, label %55, label %56

55:                                               ; preds = %47
  br label %80

56:                                               ; preds = %47
  br label %63

57:                                               ; preds = %39
  %58 = load ptr, ptr %4, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.slh_dsa_hash_ctx_st, ptr %58, i32 0, i32 1
  %60 = load ptr, ptr %59, align 8, !tbaa !13
  %61 = load ptr, ptr %4, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.slh_dsa_hash_ctx_st, ptr %61, i32 0, i32 2
  store ptr %60, ptr %62, align 8, !tbaa !14
  br label %63

63:                                               ; preds = %57, %56
  br label %64

64:                                               ; preds = %63, %34
  %65 = load ptr, ptr %3, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.slh_dsa_hash_ctx_st, ptr %65, i32 0, i32 3
  %67 = load ptr, ptr %66, align 8, !tbaa !15
  %68 = icmp ne ptr %67, null
  br i1 %68, label %69, label %78

69:                                               ; preds = %64
  %70 = load ptr, ptr %3, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct.slh_dsa_hash_ctx_st, ptr %70, i32 0, i32 3
  %72 = load ptr, ptr %71, align 8, !tbaa !15
  %73 = call ptr @EVP_MAC_CTX_dup(ptr noundef %72)
  %74 = load ptr, ptr %4, align 8, !tbaa !5
  %75 = getelementptr inbounds %struct.slh_dsa_hash_ctx_st, ptr %74, i32 0, i32 3
  store ptr %73, ptr %75, align 8, !tbaa !15
  %76 = icmp eq ptr %73, null
  br i1 %76, label %77, label %78

77:                                               ; preds = %69
  br label %80

78:                                               ; preds = %69, %64
  %79 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %79, ptr %2, align 8
  store i32 1, ptr %5, align 4
  br label %82

80:                                               ; preds = %77, %55, %33
  %81 = load ptr, ptr %4, align 8, !tbaa !5
  call void @ossl_slh_dsa_hash_ctx_free(ptr noundef %81)
  store ptr null, ptr %2, align 8
  store i32 1, ptr %5, align 4
  br label %82

82:                                               ; preds = %80, %78, %9
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  %83 = load ptr, ptr %2, align 8
  ret ptr %83
}

declare ptr @EVP_MD_CTX_dup(ptr noundef) #1

declare ptr @EVP_MAC_CTX_dup(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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !11, i64 32}
!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 0}
!13 = !{!10, !6, i64 8}
!14 = !{!10, !6, i64 16}
!15 = !{!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

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

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

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

4:                                                ; preds = %1
  %5 = getelementptr inbounds i8, ptr %0, i64 32
  %6 = load i32, ptr %5, align 8, !tbaa !5
  %7 = getelementptr inbounds i8, ptr %2, i64 32
  store i32 %6, ptr %7, align 8, !tbaa !5
  %8 = load ptr, ptr %0, align 8, !tbaa !11
  store ptr %8, ptr %2, align 8, !tbaa !11
  %9 = getelementptr inbounds i8, ptr %0, i64 8
  %10 = load ptr, ptr %9, align 8, !tbaa !12
  %.not = icmp eq ptr %10, null
  br i1 %.not, label %15, label %11

11:                                               ; preds = %4
  %12 = tail call ptr @EVP_MD_CTX_dup(ptr noundef nonnull %10) #2
  %13 = getelementptr inbounds i8, ptr %2, i64 8
  store ptr %12, ptr %13, align 8, !tbaa !12
  %14 = icmp eq ptr %12, null
  br i1 %14, label %35, label %15

15:                                               ; preds = %11, %4
  %16 = getelementptr inbounds i8, ptr %0, i64 16
  %17 = load ptr, ptr %16, align 8, !tbaa !13
  %.not25 = icmp eq ptr %17, null
  br i1 %.not25, label %28, label %18

18:                                               ; preds = %15
  %19 = load ptr, ptr %9, align 8, !tbaa !12
  %.not26 = icmp eq ptr %17, %19
  br i1 %.not26, label %24, label %20

20:                                               ; preds = %18
  %21 = tail call ptr @EVP_MD_CTX_dup(ptr noundef nonnull %17) #2
  %22 = getelementptr inbounds i8, ptr %2, i64 16
  store ptr %21, ptr %22, align 8, !tbaa !13
  %23 = icmp eq ptr %21, null
  br i1 %23, label %35, label %28

24:                                               ; preds = %18
  %25 = getelementptr inbounds i8, ptr %2, i64 8
  %26 = load ptr, ptr %25, align 8, !tbaa !12
  %27 = getelementptr inbounds i8, ptr %2, i64 16
  store ptr %26, ptr %27, align 8, !tbaa !13
  br label %28

28:                                               ; preds = %24, %20, %15
  %29 = getelementptr inbounds i8, ptr %0, i64 24
  %30 = load ptr, ptr %29, align 8, !tbaa !14
  %.not27 = icmp eq ptr %30, null
  br i1 %.not27, label %36, label %31

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

35:                                               ; preds = %31, %20, %11
  tail call void @ossl_slh_dsa_hash_ctx_free(ptr noundef nonnull %2)
  br label %36

36:                                               ; preds = %28, %31, %1, %35
  %.0 = phi ptr [ null, %35 ], [ null, %1 ], [ %2, %31 ], [ %2, %28 ]
  ret ptr %.0
}

declare ptr @EVP_MD_CTX_dup(ptr noundef) local_unnamed_addr #0

declare ptr @EVP_MAC_CTX_dup(ptr noundef) local_unnamed_addr #0

attributes #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 = { 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 #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, !10, i64 32}
!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 0}
!12 = !{!6, !7, i64 8}
!13 = !{!6, !7, i64 16}
!14 = !{!6, !7, i64 24}


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