; LLVM IR from openssl/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 [73 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [5 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local i32 @ossl_ecx_public_from_private(ptr noundef) #0

; Function Attrs: nounwind uwtable
define dso_local i32 @ossl_ecx_key_fromdata(ptr noundef %0, ptr noundef %1, i32 noundef %2) #0 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i64, align 8
  %9 = alloca i64, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store i32 %2, ptr %7, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  store i64 0, ptr %8, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  store i64 0, ptr %9, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  store ptr null, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  %14 = load ptr, ptr %5, align 8, !tbaa !5
  %15 = icmp eq ptr %14, null
  br i1 %15, label %16, label %17

16:                                               ; preds = %3
  store i32 0, ptr %4, align 4
  store i32 1, ptr %13, align 4
  br label %94

17:                                               ; preds = %3
  %18 = load ptr, ptr %6, align 8, !tbaa !5
  %19 = call ptr @OSSL_PARAM_locate_const(ptr noundef %18, ptr noundef @.str.1)
  store ptr %19, ptr %11, align 8, !tbaa !5
  %20 = load i32, ptr %7, align 4, !tbaa !9
  %21 = icmp ne i32 %20, 0
  br i1 %21, label %22, label %25

22:                                               ; preds = %17
  %23 = load ptr, ptr %6, align 8, !tbaa !5
  %24 = call ptr @OSSL_PARAM_locate_const(ptr noundef %23, ptr noundef @.str.2)
  store ptr %24, ptr %10, align 8, !tbaa !5
  br label %25

25:                                               ; preds = %22, %17
  %26 = load ptr, ptr %11, align 8, !tbaa !5
  %27 = icmp eq ptr %26, null
  br i1 %27, label %28, label %32

28:                                               ; preds = %25
  %29 = load ptr, ptr %10, align 8, !tbaa !5
  %30 = icmp eq ptr %29, null
  br i1 %30, label %31, label %32

31:                                               ; preds = %28
  store i32 0, ptr %4, align 4
  store i32 1, ptr %13, align 4
  br label %94

32:                                               ; preds = %28, %25
  %33 = load ptr, ptr %10, align 8, !tbaa !5
  %34 = icmp ne ptr %33, null
  br i1 %34, label %35, label %59

35:                                               ; preds = %32
  %36 = load ptr, ptr %10, align 8, !tbaa !5
  %37 = load ptr, ptr %5, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.ecx_key_st, ptr %37, i32 0, i32 4
  %39 = load ptr, ptr %5, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.ecx_key_st, ptr %39, i32 0, i32 5
  %41 = load i64, ptr %40, align 8, !tbaa !13
  %42 = call i32 @OSSL_PARAM_get_octet_string(ptr noundef %36, ptr noundef %38, i64 noundef %41, ptr noundef %8)
  %43 = icmp ne i32 %42, 0
  br i1 %43, label %45, label %44

44:                                               ; preds = %35
  store i32 0, ptr %4, align 4
  store i32 1, ptr %13, align 4
  br label %94

45:                                               ; preds = %35
  %46 = load i64, ptr %8, align 8, !tbaa !11
  %47 = load ptr, ptr %5, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.ecx_key_st, ptr %47, i32 0, i32 5
  %49 = load i64, ptr %48, align 8, !tbaa !13
  %50 = icmp ne i64 %46, %49
  br i1 %50, label %51, label %58

51:                                               ; preds = %45
  %52 = load ptr, ptr %5, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.ecx_key_st, ptr %52, i32 0, i32 4
  %54 = load ptr, ptr %53, align 8, !tbaa !16
  %55 = load i64, ptr %8, align 8, !tbaa !11
  call void @CRYPTO_secure_clear_free(ptr noundef %54, i64 noundef %55, ptr noundef @.str, i32 noundef 84)
  %56 = load ptr, ptr %5, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.ecx_key_st, ptr %56, i32 0, i32 4
  store ptr null, ptr %57, align 8, !tbaa !16
  store i32 0, ptr %4, align 4
  store i32 1, ptr %13, align 4
  br label %94

58:                                               ; preds = %45
  br label %59

59:                                               ; preds = %58, %32
  %60 = load ptr, ptr %5, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.ecx_key_st, ptr %60, i32 0, i32 3
  %62 = getelementptr inbounds [57 x i8], ptr %61, i64 0, i64 0
  store ptr %62, ptr %12, align 8, !tbaa !5
  %63 = load ptr, ptr %11, align 8, !tbaa !5
  %64 = icmp ne ptr %63, null
  br i1 %64, label %65, label %70

65:                                               ; preds = %59
  %66 = load ptr, ptr %11, align 8, !tbaa !5
  %67 = call i32 @OSSL_PARAM_get_octet_string(ptr noundef %66, ptr noundef %12, i64 noundef 57, ptr noundef %9)
  %68 = icmp ne i32 %67, 0
  br i1 %68, label %70, label %69

69:                                               ; preds = %65
  store i32 0, ptr %4, align 4
  store i32 1, ptr %13, align 4
  br label %94

70:                                               ; preds = %65, %59
  %71 = load ptr, ptr %11, align 8, !tbaa !5
  %72 = icmp ne ptr %71, null
  br i1 %72, label %73, label %80

73:                                               ; preds = %70
  %74 = load i64, ptr %9, align 8, !tbaa !11
  %75 = load ptr, ptr %5, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct.ecx_key_st, ptr %75, i32 0, i32 5
  %77 = load i64, ptr %76, align 8, !tbaa !13
  %78 = icmp ne i64 %74, %77
  br i1 %78, label %79, label %80

79:                                               ; preds = %73
  store i32 0, ptr %4, align 4
  store i32 1, ptr %13, align 4
  br label %94

80:                                               ; preds = %73, %70
  %81 = load ptr, ptr %11, align 8, !tbaa !5
  %82 = icmp eq ptr %81, null
  br i1 %82, label %83, label %88

83:                                               ; preds = %80
  %84 = load ptr, ptr %5, align 8, !tbaa !5
  %85 = call i32 @ossl_ecx_public_from_private(ptr noundef %84)
  %86 = icmp ne i32 %85, 0
  br i1 %86, label %88, label %87

87:                                               ; preds = %83
  store i32 0, ptr %4, align 4
  store i32 1, ptr %13, align 4
  br label %94

88:                                               ; preds = %83, %80
  %89 = load ptr, ptr %5, align 8, !tbaa !5
  %90 = getelementptr inbounds %struct.ecx_key_st, ptr %89, i32 0, i32 2
  %91 = load i8, ptr %90, align 8
  %92 = and i8 %91, -2
  %93 = or i8 %92, 1
  store i8 %93, ptr %90, align 8
  store i32 1, ptr %4, align 4
  store i32 1, ptr %13, align 4
  br label %94

94:                                               ; preds = %88, %87, %79, %69, %51, %44, %31, %16
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  %95 = load i32, ptr %4, align 4
  ret i32 %95
}

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

declare ptr @OSSL_PARAM_locate_const(ptr noundef, ptr noundef) #2

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

declare void @CRYPTO_secure_clear_free(ptr noundef, i64 noundef, ptr noundef, i32 noundef) #2

; 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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!14, !12, i64 88}
!14 = !{!"ecx_key_st", !6, i64 0, !6, i64 8, !10, i64 16, !7, i64 17, !6, i64 80, !12, i64 88, !10, i64 96, !15, i64 100}
!15 = !{!"", !7, i64 0}
!16 = !{!14, !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 [73 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [5 x i8], align 1

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

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 2) i32 @ossl_ecx_key_fromdata(ptr noundef %0, ptr noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  %6 = alloca ptr, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #3
  store i64 0, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %5) #3
  store i64 0, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %6) #3
  %7 = icmp eq ptr %0, null
  br i1 %7, label %39, label %8

8:                                                ; preds = %3
  %9 = tail call ptr @OSSL_PARAM_locate_const(ptr noundef %1, ptr noundef nonnull @.str.1) #3
  %.not = icmp eq i32 %2, 0
  br i1 %.not, label %12, label %10

10:                                               ; preds = %8
  %11 = tail call ptr @OSSL_PARAM_locate_const(ptr noundef %1, ptr noundef nonnull @.str.2) #3
  br label %12

12:                                               ; preds = %10, %8
  %.022 = phi ptr [ %11, %10 ], [ null, %8 ]
  %13 = icmp eq ptr %9, null
  %14 = icmp eq ptr %.022, null
  %or.cond = select i1 %13, i1 %14, i1 false
  br i1 %or.cond, label %39, label %15

15:                                               ; preds = %12
  br i1 %14, label %26, label %16

16:                                               ; preds = %15
  %17 = getelementptr inbounds i8, ptr %0, i64 80
  %18 = getelementptr inbounds i8, ptr %0, i64 88
  %19 = load i64, ptr %18, align 8, !tbaa !9
  %20 = call i32 @OSSL_PARAM_get_octet_string(ptr noundef nonnull %.022, ptr noundef nonnull %17, i64 noundef %19, ptr noundef nonnull %4) #3
  %.not27 = icmp eq i32 %20, 0
  br i1 %.not27, label %39, label %21

21:                                               ; preds = %16
  %22 = load i64, ptr %4, align 8, !tbaa !5
  %23 = load i64, ptr %18, align 8, !tbaa !9
  %.not28 = icmp eq i64 %22, %23
  br i1 %.not28, label %26, label %24

24:                                               ; preds = %21
  %25 = load ptr, ptr %17, align 8, !tbaa !14
  call void @CRYPTO_secure_clear_free(ptr noundef %25, i64 noundef %22, ptr noundef nonnull @.str, i32 noundef 84) #3
  store ptr null, ptr %17, align 8, !tbaa !14
  br label %39

26:                                               ; preds = %21, %15
  %27 = getelementptr inbounds i8, ptr %0, i64 17
  store ptr %27, ptr %6, align 8, !tbaa !15
  br i1 %13, label %34, label %28

28:                                               ; preds = %26
  %29 = call i32 @OSSL_PARAM_get_octet_string(ptr noundef nonnull %9, ptr noundef nonnull %6, i64 noundef 57, ptr noundef nonnull %5) #3
  %.not30 = icmp eq i32 %29, 0
  br i1 %.not30, label %39, label %30

30:                                               ; preds = %28
  %31 = load i64, ptr %5, align 8, !tbaa !5
  %32 = getelementptr inbounds i8, ptr %0, i64 88
  %33 = load i64, ptr %32, align 8, !tbaa !9
  %.not31 = icmp eq i64 %31, %33
  br i1 %.not31, label %.critedge, label %39

34:                                               ; preds = %26
  %35 = call i32 @ossl_ecx_public_from_private(ptr noundef nonnull %0)
  %.not32 = icmp eq i32 %35, 0
  br i1 %.not32, label %39, label %.critedge

.critedge:                                        ; preds = %30, %34
  %36 = getelementptr inbounds i8, ptr %0, i64 16
  %37 = load i8, ptr %36, align 8
  %38 = or i8 %37, 1
  store i8 %38, ptr %36, align 8
  br label %39

39:                                               ; preds = %34, %30, %28, %16, %12, %3, %.critedge, %24
  %.0 = phi i32 [ 0, %24 ], [ 1, %.critedge ], [ 0, %3 ], [ 0, %12 ], [ 0, %16 ], [ 0, %28 ], [ 0, %30 ], [ 0, %34 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %5) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #3
  ret i32 %.0
}

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

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

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

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


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