; LLVM IR from openanolis/openssl :: crypto/ec (ecx_backend)

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

@.str = external hidden unnamed_addr constant [76 x i8], align 1
@__func__.ossl_ecx_key_dup = external hidden unnamed_addr constant [17 x i8], align 1

declare void @ERR_new() #0

declare void @ERR_set_debug(ptr noundef, i32 noundef, ptr noundef) #0

declare void @ERR_set_error(i32 noundef, i32 noundef, ptr noundef, ...) #0

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

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

; Function Attrs: nounwind uwtable
define dso_local ptr @ossl_ecx_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) #5
  %8 = call ptr @CRYPTO_zalloc(i64 noundef 104, ptr noundef @.str, i32 noundef 111)
  store ptr %8, ptr %6, align 8, !tbaa !5
  %9 = load ptr, ptr %6, align 8, !tbaa !5
  %10 = icmp eq ptr %9, null
  br i1 %10, label %11, label %12

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

12:                                               ; preds = %2
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.ecx_key_st, ptr %13, i32 0, i32 0
  %15 = load ptr, ptr %14, align 8, !tbaa !11
  %16 = load ptr, ptr %6, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.ecx_key_st, ptr %16, i32 0, i32 0
  store ptr %15, ptr %17, align 8, !tbaa !11
  %18 = load ptr, ptr %4, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.ecx_key_st, ptr %18, i32 0, i32 2
  %20 = load i8, ptr %19, align 8
  %21 = and i8 %20, 1
  %22 = zext i8 %21 to i32
  %23 = load ptr, ptr %6, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.ecx_key_st, ptr %23, i32 0, i32 2
  %25 = trunc i32 %22 to i8
  %26 = load i8, ptr %24, align 8
  %27 = and i8 %25, 1
  %28 = and i8 %26, -2
  %29 = or i8 %28, %27
  store i8 %29, ptr %24, align 8
  %30 = zext i8 %27 to i32
  %31 = load ptr, ptr %4, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.ecx_key_st, ptr %31, i32 0, i32 5
  %33 = load i64, ptr %32, align 8, !tbaa !15
  %34 = load ptr, ptr %6, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.ecx_key_st, ptr %34, i32 0, i32 5
  store i64 %33, ptr %35, align 8, !tbaa !15
  %36 = load ptr, ptr %4, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.ecx_key_st, ptr %36, i32 0, i32 6
  %38 = load i32, ptr %37, align 8, !tbaa !16
  %39 = load ptr, ptr %6, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.ecx_key_st, ptr %39, i32 0, i32 6
  store i32 %38, ptr %40, align 8, !tbaa !16
  %41 = load ptr, ptr %6, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.ecx_key_st, ptr %41, i32 0, i32 7
  %43 = call i32 @CRYPTO_NEW_REF(ptr noundef %42, i32 noundef 1)
  %44 = icmp ne i32 %43, 0
  br i1 %44, label %46, label %45

45:                                               ; preds = %12
  br label %101

46:                                               ; preds = %12
  %47 = load ptr, ptr %4, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.ecx_key_st, ptr %47, i32 0, i32 1
  %49 = load ptr, ptr %48, align 8, !tbaa !17
  %50 = icmp ne ptr %49, null
  br i1 %50, label %51, label %64

51:                                               ; preds = %46
  %52 = load ptr, ptr %4, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.ecx_key_st, ptr %52, i32 0, i32 1
  %54 = load ptr, ptr %53, align 8, !tbaa !17
  %55 = call ptr @CRYPTO_strdup(ptr noundef %54, ptr noundef @.str, i32 noundef 125)
  %56 = load ptr, ptr %6, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.ecx_key_st, ptr %56, i32 0, i32 1
  store ptr %55, ptr %57, align 8, !tbaa !17
  %58 = load ptr, ptr %6, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.ecx_key_st, ptr %58, i32 0, i32 1
  %60 = load ptr, ptr %59, align 8, !tbaa !17
  %61 = icmp eq ptr %60, null
  br i1 %61, label %62, label %63

62:                                               ; preds = %51
  br label %101

63:                                               ; preds = %51
  br label %64

64:                                               ; preds = %63, %46
  %65 = load i32, ptr %5, align 4, !tbaa !9
  %66 = and i32 %65, 2
  %67 = icmp ne i32 %66, 0
  br i1 %67, label %68, label %75

68:                                               ; preds = %64
  %69 = load ptr, ptr %6, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.ecx_key_st, ptr %69, i32 0, i32 3
  %71 = getelementptr inbounds [57 x i8], ptr %70, i64 0, i64 0
  %72 = load ptr, ptr %4, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct.ecx_key_st, ptr %72, i32 0, i32 3
  %74 = getelementptr inbounds [57 x i8], ptr %73, i64 0, i64 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %71, ptr align 1 %74, i64 57, i1 false)
  br label %75

75:                                               ; preds = %68, %64
  %76 = load i32, ptr %5, align 4, !tbaa !9
  %77 = and i32 %76, 1
  %78 = icmp ne i32 %77, 0
  br i1 %78, label %79, label %99

79:                                               ; preds = %75
  %80 = load ptr, ptr %4, align 8, !tbaa !5
  %81 = getelementptr inbounds %struct.ecx_key_st, ptr %80, i32 0, i32 4
  %82 = load ptr, ptr %81, align 8, !tbaa !18
  %83 = icmp ne ptr %82, null
  br i1 %83, label %84, label %99

84:                                               ; preds = %79
  %85 = load ptr, ptr %6, align 8, !tbaa !5
  %86 = call ptr @ossl_ecx_key_allocate_privkey(ptr noundef %85)
  %87 = icmp eq ptr %86, null
  br i1 %87, label %88, label %89

88:                                               ; preds = %84
  call void @ERR_new()
  call void @ERR_set_debug(ptr noundef @.str, i32 noundef 136, ptr noundef @__func__.ossl_ecx_key_dup)
  call void (i32, i32, ptr, ...) @ERR_set_error(i32 noundef 16, i32 noundef 524304, ptr noundef null)
  br label %101

89:                                               ; preds = %84
  %90 = load ptr, ptr %6, align 8, !tbaa !5
  %91 = getelementptr inbounds %struct.ecx_key_st, ptr %90, i32 0, i32 4
  %92 = load ptr, ptr %91, align 8, !tbaa !18
  %93 = load ptr, ptr %4, align 8, !tbaa !5
  %94 = getelementptr inbounds %struct.ecx_key_st, ptr %93, i32 0, i32 4
  %95 = load ptr, ptr %94, align 8, !tbaa !18
  %96 = load ptr, ptr %6, align 8, !tbaa !5
  %97 = getelementptr inbounds %struct.ecx_key_st, ptr %96, i32 0, i32 5
  %98 = load i64, ptr %97, align 8, !tbaa !15
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %92, ptr align 1 %95, i64 %98, i1 false)
  br label %99

99:                                               ; preds = %89, %79, %75
  %100 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %100, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %105

101:                                              ; preds = %88, %62, %45
  %102 = load ptr, ptr %6, align 8, !tbaa !5
  %103 = getelementptr inbounds %struct.ecx_key_st, ptr %102, i32 0, i32 7
  call void @CRYPTO_FREE_REF(ptr noundef %103)
  %104 = load ptr, ptr %6, align 8, !tbaa !5
  call void @ossl_ecx_key_free(ptr noundef %104)
  store ptr null, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %105

105:                                              ; preds = %101, %99, %11
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #5
  %106 = load ptr, ptr %3, align 8
  ret ptr %106
}

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @CRYPTO_NEW_REF(ptr noundef, i32 noundef) #3

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

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

declare ptr @ossl_ecx_key_allocate_privkey(ptr noundef) #0

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @CRYPTO_FREE_REF(ptr noundef) #3

declare void @ossl_ecx_key_free(ptr noundef) #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { inlinehint 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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #5 = { 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 = !{!12, !6, i64 0}
!12 = !{!"ecx_key_st", !6, i64 0, !6, i64 8, !10, i64 16, !7, i64 17, !6, i64 80, !13, i64 88, !10, i64 96, !14, i64 100}
!13 = !{!"long", !7, i64 0}
!14 = !{!"", !7, i64 0}
!15 = !{!12, !13, i64 88}
!16 = !{!12, !10, i64 96}
!17 = !{!12, !6, i64 8}
!18 = !{!12, !6, i64 80}


; 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 [76 x i8], align 1
@__func__.ossl_ecx_key_dup = external hidden unnamed_addr constant [17 x i8], align 1

declare void @ERR_new() local_unnamed_addr #0

declare void @ERR_set_debug(ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #0

declare void @ERR_set_error(i32 noundef, i32 noundef, ptr noundef, ...) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local ptr @ossl_ecx_key_dup(ptr nocapture noundef readonly %0, i32 noundef %1) local_unnamed_addr #1 {
  %3 = tail call ptr @CRYPTO_zalloc(i64 noundef 104, ptr noundef nonnull @.str, i32 noundef 111) #4
  %4 = icmp eq ptr %3, null
  br i1 %4, label %49, label %5

5:                                                ; preds = %2
  %6 = load ptr, ptr %0, align 8, !tbaa !5
  store ptr %6, ptr %3, align 8, !tbaa !5
  %7 = getelementptr inbounds i8, ptr %0, i64 16
  %8 = load i8, ptr %7, align 8
  %9 = and i8 %8, 1
  %10 = getelementptr inbounds i8, ptr %3, i64 16
  %11 = load i8, ptr %10, align 8
  %12 = and i8 %11, -2
  %13 = or disjoint i8 %12, %9
  store i8 %13, ptr %10, align 8
  %14 = getelementptr inbounds i8, ptr %0, i64 88
  %15 = load i64, ptr %14, align 8, !tbaa !13
  %16 = getelementptr inbounds i8, ptr %3, i64 88
  store i64 %15, ptr %16, align 8, !tbaa !13
  %17 = getelementptr inbounds i8, ptr %0, i64 96
  %18 = load i32, ptr %17, align 8, !tbaa !14
  %19 = getelementptr inbounds i8, ptr %3, i64 96
  store i32 %18, ptr %19, align 8, !tbaa !14
  %20 = getelementptr inbounds i8, ptr %3, i64 100
  %21 = tail call i32 @CRYPTO_NEW_REF(ptr noundef nonnull %20, i32 noundef 1)
  %.not = icmp eq i32 %21, 0
  br i1 %.not, label %48, label %22

22:                                               ; preds = %5
  %23 = getelementptr inbounds i8, ptr %0, i64 8
  %24 = load ptr, ptr %23, align 8, !tbaa !15
  %.not28 = icmp eq ptr %24, null
  br i1 %.not28, label %29, label %25

25:                                               ; preds = %22
  %26 = tail call ptr @CRYPTO_strdup(ptr noundef nonnull %24, ptr noundef nonnull @.str, i32 noundef 125) #4
  %27 = getelementptr inbounds i8, ptr %3, i64 8
  store ptr %26, ptr %27, align 8, !tbaa !15
  %28 = icmp eq ptr %26, null
  br i1 %28, label %48, label %29

29:                                               ; preds = %25, %22
  %30 = and i32 %1, 2
  %.not29 = icmp eq i32 %30, 0
  br i1 %.not29, label %34, label %31

31:                                               ; preds = %29
  %32 = getelementptr inbounds i8, ptr %3, i64 17
  %33 = getelementptr inbounds i8, ptr %0, i64 17
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 1 dereferenceable(57) %32, ptr noundef nonnull align 1 dereferenceable(57) %33, i64 57, i1 false)
  br label %34

34:                                               ; preds = %31, %29
  %35 = and i32 %1, 1
  %.not30 = icmp eq i32 %35, 0
  br i1 %.not30, label %49, label %36

36:                                               ; preds = %34
  %37 = getelementptr inbounds i8, ptr %0, i64 80
  %38 = load ptr, ptr %37, align 8, !tbaa !16
  %.not31 = icmp eq ptr %38, null
  br i1 %.not31, label %49, label %39

39:                                               ; preds = %36
  %40 = tail call ptr @ossl_ecx_key_allocate_privkey(ptr noundef nonnull %3) #4
  %41 = icmp eq ptr %40, null
  br i1 %41, label %42, label %43

42:                                               ; preds = %39
  tail call void @ERR_new() #4
  tail call void @ERR_set_debug(ptr noundef nonnull @.str, i32 noundef 136, ptr noundef nonnull @__func__.ossl_ecx_key_dup) #4
  tail call void (i32, i32, ptr, ...) @ERR_set_error(i32 noundef 16, i32 noundef 524304, ptr noundef null) #4
  br label %48

43:                                               ; preds = %39
  %44 = getelementptr inbounds i8, ptr %3, i64 80
  %45 = load ptr, ptr %44, align 8, !tbaa !16
  %46 = load ptr, ptr %37, align 8, !tbaa !16
  %47 = load i64, ptr %16, align 8, !tbaa !13
  tail call void @llvm.memcpy.p0.p0.i64(ptr align 1 %45, ptr align 1 %46, i64 %47, i1 false)
  br label %49

48:                                               ; preds = %25, %5, %42
  tail call void @CRYPTO_FREE_REF(ptr noundef nonnull %20)
  tail call void @ossl_ecx_key_free(ptr noundef nonnull %3) #4
  br label %49

49:                                               ; preds = %34, %36, %43, %2, %48
  %.0 = phi ptr [ null, %48 ], [ null, %2 ], [ %3, %43 ], [ %3, %36 ], [ %3, %34 ]
  ret ptr %.0
}

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @CRYPTO_NEW_REF(ptr noundef, i32 noundef) local_unnamed_addr #2

declare ptr @CRYPTO_strdup(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #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) #3

declare ptr @ossl_ecx_key_allocate_privkey(ptr noundef) local_unnamed_addr #0

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @CRYPTO_FREE_REF(ptr noundef) local_unnamed_addr #2

declare void @ossl_ecx_key_free(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 = { inlinehint 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 = { mustprogress 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, !7, i64 0}
!6 = !{!"ecx_key_st", !7, i64 0, !7, i64 8, !10, i64 16, !8, i64 17, !7, i64 80, !11, i64 88, !10, i64 96, !12, i64 100}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"long", !8, i64 0}
!12 = !{!"", !8, i64 0}
!13 = !{!6, !11, i64 88}
!14 = !{!6, !10, i64 96}
!15 = !{!6, !7, i64 8}
!16 = !{!6, !7, i64 80}


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