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

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

@.str = external hidden unnamed_addr constant [78 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

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

; Function Attrs: nounwind uwtable
declare dso_local void @ossl_slh_dsa_key_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_key_dup(ptr noundef %0, i32 noundef %1) #2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  store ptr null, ptr %6, align 8, !tbaa !5
  %8 = load ptr, ptr %4, align 8, !tbaa !5
  %9 = icmp eq ptr %8, null
  br i1 %9, label %10, label %11

10:                                               ; preds = %2
  store ptr null, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %82

11:                                               ; preds = %2
  %12 = call ptr @CRYPTO_zalloc(i64 noundef 208, ptr noundef @.str, i32 noundef 142)
  store ptr %12, ptr %6, align 8, !tbaa !5
  %13 = load ptr, ptr %6, align 8, !tbaa !5
  %14 = icmp ne ptr %13, null
  br i1 %14, label %15, label %78

15:                                               ; preds = %11
  %16 = load ptr, ptr %6, align 8, !tbaa !5
  %17 = load ptr, ptr %4, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %16, ptr align 8 %17, i64 208, i1 false), !tbaa.struct !11
  %18 = load ptr, ptr %6, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.slh_dsa_key_st, ptr %18, i32 0, i32 3
  store ptr null, ptr %19, align 8, !tbaa !13
  %20 = load ptr, ptr %6, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.slh_dsa_key_st, ptr %20, i32 0, i32 1
  store ptr null, ptr %21, align 8, !tbaa !15
  %22 = load ptr, ptr %6, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.slh_dsa_key_st, ptr %22, i32 0, i32 4
  store i32 0, ptr %23, align 8, !tbaa !16
  %24 = load ptr, ptr %6, align 8, !tbaa !5
  %25 = load ptr, ptr %4, align 8, !tbaa !5
  call void @slh_dsa_key_hash_dup(ptr noundef %24, ptr noundef %25)
  %26 = load ptr, ptr %4, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.slh_dsa_key_st, ptr %26, i32 0, i32 3
  %28 = load ptr, ptr %27, align 8, !tbaa !13
  %29 = icmp ne ptr %28, null
  br i1 %29, label %30, label %43

30:                                               ; preds = %15
  %31 = load ptr, ptr %4, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.slh_dsa_key_st, ptr %31, i32 0, i32 3
  %33 = load ptr, ptr %32, align 8, !tbaa !13
  %34 = call ptr @CRYPTO_strdup(ptr noundef %33, ptr noundef @.str, i32 noundef 150)
  %35 = load ptr, ptr %6, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.slh_dsa_key_st, ptr %35, i32 0, i32 3
  store ptr %34, ptr %36, align 8, !tbaa !13
  %37 = load ptr, ptr %6, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.slh_dsa_key_st, ptr %37, i32 0, i32 3
  %39 = load ptr, ptr %38, align 8, !tbaa !13
  %40 = icmp eq ptr %39, null
  br i1 %40, label %41, label %42

41:                                               ; preds = %30
  br label %80

42:                                               ; preds = %30
  br label %43

43:                                               ; preds = %42, %15
  %44 = load i32, ptr %5, align 4, !tbaa !9
  %45 = and i32 %44, 3
  %46 = icmp ne i32 %45, 0
  br i1 %46, label %47, label %77

47:                                               ; preds = %43
  %48 = load ptr, ptr %4, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.slh_dsa_key_st, ptr %48, i32 0, i32 1
  %50 = load ptr, ptr %49, align 8, !tbaa !15
  %51 = icmp ne ptr %50, null
  br i1 %51, label %52, label %66

52:                                               ; preds = %47
  %53 = load ptr, ptr %6, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.slh_dsa_key_st, ptr %53, i32 0, i32 0
  %55 = getelementptr inbounds [128 x i8], ptr %54, i64 0, i64 0
  %56 = load ptr, ptr %6, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.slh_dsa_key_st, ptr %56, i32 0, i32 5
  %58 = load ptr, ptr %57, align 8, !tbaa !17
  %59 = getelementptr inbounds %struct.slh_dsa_params_st, ptr %58, i32 0, i32 3
  %60 = load i32, ptr %59, align 8, !tbaa !18
  %61 = mul i32 %60, 2
  %62 = zext i32 %61 to i64
  %63 = getelementptr inbounds i8, ptr %55, i64 %62
  %64 = load ptr, ptr %6, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.slh_dsa_key_st, ptr %64, i32 0, i32 1
  store ptr %63, ptr %65, align 8, !tbaa !15
  br label %66

66:                                               ; preds = %52, %47
  %67 = load i32, ptr %5, align 4, !tbaa !9
  %68 = and i32 %67, 1
  %69 = icmp ne i32 %68, 0
  br i1 %69, label %70, label %76

70:                                               ; preds = %66
  %71 = load ptr, ptr %4, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.slh_dsa_key_st, ptr %71, i32 0, i32 4
  %73 = load i32, ptr %72, align 8, !tbaa !16
  %74 = load ptr, ptr %6, align 8, !tbaa !5
  %75 = getelementptr inbounds %struct.slh_dsa_key_st, ptr %74, i32 0, i32 4
  store i32 %73, ptr %75, align 8, !tbaa !16
  br label %76

76:                                               ; preds = %70, %66
  br label %77

77:                                               ; preds = %76, %43
  br label %78

78:                                               ; preds = %77, %11
  %79 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %79, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %82

80:                                               ; preds = %41
  %81 = load ptr, ptr %6, align 8, !tbaa !5
  call void @ossl_slh_dsa_key_free(ptr noundef %81)
  store ptr null, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %82

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

; 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

; Function Attrs: nounwind uwtable
declare hidden void @slh_dsa_key_hash_dup(ptr noundef, ptr noundef) #2

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 = { 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}
!11 = !{i64 0, i64 128, !12, i64 128, i64 8, !5, i64 136, i64 8, !5, i64 144, i64 8, !5, i64 152, i64 4, !9, i64 160, i64 8, !5, i64 168, i64 8, !5, i64 176, i64 8, !5, i64 184, i64 8, !5, i64 192, i64 8, !5, i64 200, i64 8, !5}
!12 = !{!7, !7, i64 0}
!13 = !{!14, !6, i64 144}
!14 = !{!"slh_dsa_key_st", !7, i64 0, !6, i64 128, !6, i64 136, !6, i64 144, !10, i64 152, !6, i64 160, !6, i64 168, !6, i64 176, !6, i64 184, !6, i64 192, !6, i64 200}
!15 = !{!14, !6, i64 128}
!16 = !{!14, !10, i64 152}
!17 = !{!14, !6, i64 160}
!18 = !{!19, !10, i64 16}
!19 = !{!"slh_dsa_params_st", !6, i64 0, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20, !10, i64 24, !10, i64 28, !10, i64 32, !10, i64 36, !10, i64 40, !10, i64 44, !10, i64 48, !10, i64 52, !20, i64 56}
!20 = !{!"long", !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"

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

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

declare ptr @CRYPTO_strdup(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #0

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

; Function Attrs: nounwind uwtable
define dso_local ptr @ossl_slh_dsa_key_dup(ptr noundef %0, i32 noundef %1) local_unnamed_addr #1 {
  %3 = icmp eq ptr %0, null
  br i1 %3, label %34, label %4

4:                                                ; preds = %2
  %5 = tail call ptr @CRYPTO_zalloc(i64 noundef 208, ptr noundef nonnull @.str, i32 noundef 142) #3
  %.not = icmp eq ptr %5, null
  br i1 %.not, label %34, label %6

6:                                                ; preds = %4
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(208) %5, ptr noundef nonnull align 8 dereferenceable(208) %0, i64 208, i1 false), !tbaa.struct !5
  %7 = getelementptr inbounds i8, ptr %5, i64 144
  store ptr null, ptr %7, align 8, !tbaa !13
  %8 = getelementptr inbounds i8, ptr %5, i64 128
  store ptr null, ptr %8, align 8, !tbaa !15
  %9 = getelementptr inbounds i8, ptr %5, i64 152
  store i32 0, ptr %9, align 8, !tbaa !16
  tail call void @slh_dsa_key_hash_dup(ptr noundef nonnull %5, ptr noundef nonnull %0)
  %10 = getelementptr inbounds i8, ptr %0, i64 144
  %11 = load ptr, ptr %10, align 8, !tbaa !13
  %.not26 = icmp eq ptr %11, null
  br i1 %.not26, label %15, label %12

12:                                               ; preds = %6
  %13 = tail call ptr @CRYPTO_strdup(ptr noundef nonnull %11, ptr noundef nonnull @.str, i32 noundef 150) #3
  store ptr %13, ptr %7, align 8, !tbaa !13
  %14 = icmp eq ptr %13, null
  br i1 %14, label %33, label %15

15:                                               ; preds = %12, %6
  %16 = and i32 %1, 3
  %.not27 = icmp eq i32 %16, 0
  br i1 %.not27, label %34, label %17

17:                                               ; preds = %15
  %18 = getelementptr inbounds i8, ptr %0, i64 128
  %19 = load ptr, ptr %18, align 8, !tbaa !15
  %.not28 = icmp eq ptr %19, null
  br i1 %.not28, label %28, label %20

20:                                               ; preds = %17
  %21 = getelementptr inbounds i8, ptr %5, i64 160
  %22 = load ptr, ptr %21, align 8, !tbaa !17
  %23 = getelementptr inbounds i8, ptr %22, i64 16
  %24 = load i32, ptr %23, align 8, !tbaa !18
  %25 = shl i32 %24, 1
  %26 = zext i32 %25 to i64
  %27 = getelementptr inbounds i8, ptr %5, i64 %26
  store ptr %27, ptr %8, align 8, !tbaa !15
  br label %28

28:                                               ; preds = %20, %17
  %29 = and i32 %1, 1
  %.not29 = icmp eq i32 %29, 0
  br i1 %.not29, label %34, label %30

30:                                               ; preds = %28
  %31 = getelementptr inbounds i8, ptr %0, i64 152
  %32 = load i32, ptr %31, align 8, !tbaa !16
  store i32 %32, ptr %9, align 8, !tbaa !16
  br label %34

33:                                               ; preds = %12
  tail call void @ossl_slh_dsa_key_free(ptr noundef nonnull %5)
  br label %34

34:                                               ; preds = %4, %28, %30, %15, %2, %33
  %.0 = phi ptr [ null, %33 ], [ null, %2 ], [ %5, %15 ], [ %5, %30 ], [ %5, %28 ], [ null, %4 ]
  ret ptr %.0
}

; 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) #2

; Function Attrs: nounwind uwtable
declare hidden void @slh_dsa_key_hash_dup(ptr noundef, ptr noundef) local_unnamed_addr #1

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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = !{i64 0, i64 128, !6, i64 128, i64 8, !9, i64 136, i64 8, !9, i64 144, i64 8, !9, i64 152, i64 4, !11, i64 160, i64 8, !9, i64 168, i64 8, !9, i64 176, i64 8, !9, i64 184, i64 8, !9, i64 192, i64 8, !9, i64 200, i64 8, !9}
!6 = !{!7, !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}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !10, i64 144}
!14 = !{!"slh_dsa_key_st", !7, i64 0, !10, i64 128, !10, i64 136, !10, i64 144, !12, i64 152, !10, i64 160, !10, i64 168, !10, i64 176, !10, i64 184, !10, i64 192, !10, i64 200}
!15 = !{!14, !10, i64 128}
!16 = !{!14, !12, i64 152}
!17 = !{!14, !10, i64 160}
!18 = !{!19, !12, i64 16}
!19 = !{!"slh_dsa_params_st", !10, i64 0, !12, i64 8, !12, i64 12, !12, i64 16, !12, i64 20, !12, i64 24, !12, i64 28, !12, i64 32, !12, i64 36, !12, i64 40, !12, i64 44, !12, i64 48, !12, i64 52, !20, i64 56}
!20 = !{!"long", !7, i64 0}


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