; 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
@__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 %109

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 %6, 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, -2
  %22 = or i8 %21, 0
  store i8 %22, ptr %19, align 8
  %23 = load ptr, ptr %4, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.ecx_key_st, ptr %23, i32 0, i32 5
  %25 = load i64, ptr %24, align 8, !tbaa !15
  %26 = load ptr, ptr %6, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.ecx_key_st, ptr %26, i32 0, i32 5
  store i64 %25, ptr %27, align 8, !tbaa !15
  %28 = load ptr, ptr %4, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.ecx_key_st, ptr %28, i32 0, i32 6
  %30 = load i32, ptr %29, align 8, !tbaa !16
  %31 = load ptr, ptr %6, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.ecx_key_st, ptr %31, i32 0, i32 6
  store i32 %30, ptr %32, align 8, !tbaa !16
  %33 = load ptr, ptr %6, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.ecx_key_st, ptr %33, i32 0, i32 7
  %35 = call i32 @CRYPTO_NEW_REF(ptr noundef %34, i32 noundef 1)
  %36 = icmp ne i32 %35, 0
  br i1 %36, label %38, label %37

37:                                               ; preds = %12
  br label %105

38:                                               ; preds = %12
  %39 = load ptr, ptr %4, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.ecx_key_st, ptr %39, i32 0, i32 1
  %41 = load ptr, ptr %40, align 8, !tbaa !17
  %42 = icmp ne ptr %41, null
  br i1 %42, label %43, label %56

43:                                               ; preds = %38
  %44 = load ptr, ptr %4, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.ecx_key_st, ptr %44, i32 0, i32 1
  %46 = load ptr, ptr %45, align 8, !tbaa !17
  %47 = call ptr @CRYPTO_strdup(ptr noundef %46, ptr noundef @.str, i32 noundef 125)
  %48 = load ptr, ptr %6, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.ecx_key_st, ptr %48, i32 0, i32 1
  store ptr %47, ptr %49, align 8, !tbaa !17
  %50 = load ptr, ptr %6, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.ecx_key_st, ptr %50, i32 0, i32 1
  %52 = load ptr, ptr %51, align 8, !tbaa !17
  %53 = icmp eq ptr %52, null
  br i1 %53, label %54, label %55

54:                                               ; preds = %43
  br label %105

55:                                               ; preds = %43
  br label %56

56:                                               ; preds = %55, %38
  %57 = load i32, ptr %5, align 4, !tbaa !9
  %58 = and i32 %57, 2
  %59 = icmp ne i32 %58, 0
  br i1 %59, label %60, label %79

60:                                               ; preds = %56
  %61 = load ptr, ptr %4, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.ecx_key_st, ptr %61, i32 0, i32 2
  %63 = load i8, ptr %62, align 8
  %64 = and i8 %63, 1
  %65 = zext i8 %64 to i32
  %66 = icmp eq i32 %65, 1
  br i1 %66, label %67, label %79

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

79:                                               ; preds = %67, %60, %56
  %80 = load i32, ptr %5, align 4, !tbaa !9
  %81 = and i32 %80, 1
  %82 = icmp ne i32 %81, 0
  br i1 %82, label %83, label %103

83:                                               ; preds = %79
  %84 = load ptr, ptr %4, align 8, !tbaa !5
  %85 = getelementptr inbounds %struct.ecx_key_st, ptr %84, i32 0, i32 4
  %86 = load ptr, ptr %85, align 8, !tbaa !18
  %87 = icmp ne ptr %86, null
  br i1 %87, label %88, label %103

88:                                               ; preds = %83
  %89 = load ptr, ptr %6, align 8, !tbaa !5
  %90 = call ptr @ossl_ecx_key_allocate_privkey(ptr noundef %89)
  %91 = icmp eq ptr %90, null
  br i1 %91, label %92, label %93

92:                                               ; preds = %88
  call void @ERR_new()
  call void @ERR_set_debug(ptr noundef @.str, i32 noundef 139, 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 %105

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

103:                                              ; preds = %93, %83, %79
  %104 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %104, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %109

105:                                              ; preds = %92, %54, %37
  %106 = load ptr, ptr %6, align 8, !tbaa !5
  %107 = getelementptr inbounds %struct.ecx_key_st, ptr %106, i32 0, i32 7
  call void @CRYPTO_FREE_REF(ptr noundef %107)
  %108 = load ptr, ptr %6, align 8, !tbaa !5
  call void @ossl_ecx_key_free(ptr noundef %108)
  store ptr null, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %109

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

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 [73 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 %51, 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 %3, i64 16
  %8 = load i8, ptr %7, align 8
  %9 = and i8 %8, -2
  store i8 %9, ptr %7, align 8
  %10 = getelementptr inbounds i8, ptr %0, i64 88
  %11 = load i64, ptr %10, align 8, !tbaa !13
  %12 = getelementptr inbounds i8, ptr %3, i64 88
  store i64 %11, ptr %12, align 8, !tbaa !13
  %13 = getelementptr inbounds i8, ptr %0, i64 96
  %14 = load i32, ptr %13, align 8, !tbaa !14
  %15 = getelementptr inbounds i8, ptr %3, i64 96
  store i32 %14, ptr %15, align 8, !tbaa !14
  %16 = getelementptr inbounds i8, ptr %3, i64 100
  %17 = tail call i32 @CRYPTO_NEW_REF(ptr noundef nonnull %16, i32 noundef 1)
  %.not = icmp eq i32 %17, 0
  br i1 %.not, label %50, label %18

18:                                               ; preds = %5
  %19 = getelementptr inbounds i8, ptr %0, i64 8
  %20 = load ptr, ptr %19, align 8, !tbaa !15
  %.not29 = icmp eq ptr %20, null
  br i1 %.not29, label %25, label %21

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

25:                                               ; preds = %21, %18
  %26 = and i32 %1, 2
  %.not30 = icmp eq i32 %26, 0
  br i1 %.not30, label %36, label %27

27:                                               ; preds = %25
  %28 = getelementptr inbounds i8, ptr %0, i64 16
  %29 = load i8, ptr %28, align 8
  %30 = and i8 %29, 1
  %.not31 = icmp eq i8 %30, 0
  br i1 %.not31, label %36, label %31

31:                                               ; preds = %27
  %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)
  %34 = load i8, ptr %7, align 8
  %35 = or i8 %34, 1
  store i8 %35, ptr %7, align 8
  br label %36

36:                                               ; preds = %31, %27, %25
  %37 = and i32 %1, 1
  %.not32 = icmp eq i32 %37, 0
  br i1 %.not32, label %51, label %38

38:                                               ; preds = %36
  %39 = getelementptr inbounds i8, ptr %0, i64 80
  %40 = load ptr, ptr %39, align 8, !tbaa !16
  %.not33 = icmp eq ptr %40, null
  br i1 %.not33, label %51, label %41

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

44:                                               ; preds = %41
  tail call void @ERR_new() #4
  tail call void @ERR_set_debug(ptr noundef nonnull @.str, i32 noundef 139, 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 %50

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

50:                                               ; preds = %21, %5, %44
  tail call void @CRYPTO_FREE_REF(ptr noundef nonnull %16)
  tail call void @ossl_ecx_key_free(ptr noundef nonnull %3) #4
  br label %51

51:                                               ; preds = %36, %38, %45, %2, %50
  %.0 = phi ptr [ null, %50 ], [ null, %2 ], [ %3, %45 ], [ %3, %38 ], [ %3, %36 ]
  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