; LLVM IR from openssl/openssl :: crypto/ec (ec_deprecated)

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

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

; 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 @EC_POINT_bn2point(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3) #2 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i64, align 8
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store ptr %2, ptr %8, align 8, !tbaa !5
  store ptr %3, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  store i64 0, ptr %10, align 8, !tbaa !9
  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 %7, align 8, !tbaa !5
  %15 = call i32 @BN_num_bits(ptr noundef %14)
  %16 = add nsw i32 %15, 7
  %17 = sdiv i32 %16, 8
  %18 = sext i32 %17 to i64
  store i64 %18, ptr %10, align 8, !tbaa !9
  %19 = icmp eq i64 %18, 0
  br i1 %19, label %20, label %21

20:                                               ; preds = %4
  store i64 1, ptr %10, align 8, !tbaa !9
  br label %21

21:                                               ; preds = %20, %4
  %22 = load i64, ptr %10, align 8, !tbaa !9
  %23 = call ptr @CRYPTO_malloc(i64 noundef %22, ptr noundef @.str, i32 noundef 50)
  store ptr %23, ptr %11, align 8, !tbaa !5
  %24 = icmp eq ptr %23, null
  br i1 %24, label %25, label %26

25:                                               ; preds = %21
  store ptr null, ptr %5, align 8
  store i32 1, ptr %13, align 4
  br label %66

26:                                               ; preds = %21
  %27 = load ptr, ptr %7, align 8, !tbaa !5
  %28 = load ptr, ptr %11, align 8, !tbaa !5
  %29 = load i64, ptr %10, align 8, !tbaa !9
  %30 = trunc i64 %29 to i32
  %31 = call i32 @BN_bn2binpad(ptr noundef %27, ptr noundef %28, i32 noundef %30)
  %32 = icmp slt i32 %31, 0
  br i1 %32, label %33, label %35

33:                                               ; preds = %26
  %34 = load ptr, ptr %11, align 8, !tbaa !5
  call void @CRYPTO_free(ptr noundef %34, ptr noundef @.str, i32 noundef 54)
  store ptr null, ptr %5, align 8
  store i32 1, ptr %13, align 4
  br label %66

35:                                               ; preds = %26
  %36 = load ptr, ptr %8, align 8, !tbaa !5
  %37 = icmp eq ptr %36, null
  br i1 %37, label %38, label %45

38:                                               ; preds = %35
  %39 = load ptr, ptr %6, align 8, !tbaa !5
  %40 = call ptr @EC_POINT_new(ptr noundef %39)
  store ptr %40, ptr %12, align 8, !tbaa !5
  %41 = icmp eq ptr %40, null
  br i1 %41, label %42, label %44

42:                                               ; preds = %38
  %43 = load ptr, ptr %11, align 8, !tbaa !5
  call void @CRYPTO_free(ptr noundef %43, ptr noundef @.str, i32 noundef 60)
  store ptr null, ptr %5, align 8
  store i32 1, ptr %13, align 4
  br label %66

44:                                               ; preds = %38
  br label %47

45:                                               ; preds = %35
  %46 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr %46, ptr %12, align 8, !tbaa !5
  br label %47

47:                                               ; preds = %45, %44
  %48 = load ptr, ptr %6, align 8, !tbaa !5
  %49 = load ptr, ptr %12, align 8, !tbaa !5
  %50 = load ptr, ptr %11, align 8, !tbaa !5
  %51 = load i64, ptr %10, align 8, !tbaa !9
  %52 = load ptr, ptr %9, align 8, !tbaa !5
  %53 = call i32 @EC_POINT_oct2point(ptr noundef %48, ptr noundef %49, ptr noundef %50, i64 noundef %51, ptr noundef %52)
  %54 = icmp ne i32 %53, 0
  br i1 %54, label %63, label %55

55:                                               ; preds = %47
  %56 = load ptr, ptr %12, align 8, !tbaa !5
  %57 = load ptr, ptr %8, align 8, !tbaa !5
  %58 = icmp ne ptr %56, %57
  br i1 %58, label %59, label %61

59:                                               ; preds = %55
  %60 = load ptr, ptr %12, align 8, !tbaa !5
  call void @EC_POINT_clear_free(ptr noundef %60)
  br label %61

61:                                               ; preds = %59, %55
  %62 = load ptr, ptr %11, align 8, !tbaa !5
  call void @CRYPTO_free(ptr noundef %62, ptr noundef @.str, i32 noundef 69)
  store ptr null, ptr %5, align 8
  store i32 1, ptr %13, align 4
  br label %66

63:                                               ; preds = %47
  %64 = load ptr, ptr %11, align 8, !tbaa !5
  call void @CRYPTO_free(ptr noundef %64, ptr noundef @.str, i32 noundef 73)
  %65 = load ptr, ptr %12, align 8, !tbaa !5
  store ptr %65, ptr %5, align 8
  store i32 1, ptr %13, align 4
  br label %66

66:                                               ; preds = %63, %61, %42, %33, %25
  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
  %67 = load ptr, ptr %5, align 8
  ret ptr %67
}

declare i32 @BN_num_bits(ptr noundef) #1

declare ptr @CRYPTO_malloc(i64 noundef, ptr noundef, i32 noundef) #1

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

declare ptr @EC_POINT_new(ptr noundef) #1

declare i32 @EC_POINT_oct2point(ptr noundef, ptr noundef, ptr noundef, i64 noundef, ptr noundef) #1

declare void @EC_POINT_clear_free(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, !10, i64 0}
!10 = !{!"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 [75 x i8], align 1

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

; Function Attrs: nounwind uwtable
define dso_local noundef ptr @EC_POINT_bn2point(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3) local_unnamed_addr #1 {
  %5 = tail call i32 @BN_num_bits(ptr noundef %1) #2
  %6 = add nsw i32 %5, 7
  %7 = sdiv i32 %6, 8
  %.off = add i32 %5, 14
  %8 = icmp ult i32 %.off, 15
  %narrow = select i1 %8, i32 1, i32 %7
  %spec.store.select = sext i32 %narrow to i64
  %9 = tail call ptr @CRYPTO_malloc(i64 noundef %spec.store.select, ptr noundef nonnull @.str, i32 noundef 50) #2
  %10 = icmp eq ptr %9, null
  br i1 %10, label %23, label %11

11:                                               ; preds = %4
  %12 = tail call i32 @BN_bn2binpad(ptr noundef %1, ptr noundef nonnull %9, i32 noundef %narrow) #2
  %13 = icmp slt i32 %12, 0
  br i1 %13, label %.sink.split, label %14

14:                                               ; preds = %11
  %15 = icmp eq ptr %2, null
  br i1 %15, label %16, label %19

16:                                               ; preds = %14
  %17 = tail call ptr @EC_POINT_new(ptr noundef %0) #2
  %18 = icmp eq ptr %17, null
  br i1 %18, label %.sink.split, label %19

19:                                               ; preds = %14, %16
  %.0 = phi ptr [ %17, %16 ], [ %2, %14 ]
  %20 = tail call i32 @EC_POINT_oct2point(ptr noundef %0, ptr noundef nonnull %.0, ptr noundef nonnull %9, i64 noundef %spec.store.select, ptr noundef %3) #2
  %.not = icmp eq i32 %20, 0
  br i1 %.not, label %21, label %.sink.split

21:                                               ; preds = %19
  %.not25 = icmp eq ptr %.0, %2
  br i1 %.not25, label %.sink.split, label %22

22:                                               ; preds = %21
  tail call void @EC_POINT_clear_free(ptr noundef nonnull %.0) #2
  br label %.sink.split

.sink.split:                                      ; preds = %19, %21, %22, %16, %11
  %.sink = phi i32 [ 54, %11 ], [ 60, %16 ], [ 69, %22 ], [ 69, %21 ], [ 73, %19 ]
  %.021.ph = phi ptr [ null, %11 ], [ null, %16 ], [ null, %22 ], [ null, %21 ], [ %.0, %19 ]
  tail call void @CRYPTO_free(ptr noundef nonnull %9, ptr noundef nonnull @.str, i32 noundef %.sink) #2
  br label %23

23:                                               ; preds = %.sink.split, %4
  %.021 = phi ptr [ null, %4 ], [ %.021.ph, %.sink.split ]
  ret ptr %.021
}

declare i32 @BN_num_bits(ptr noundef) local_unnamed_addr #0

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

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

declare ptr @EC_POINT_new(ptr noundef) local_unnamed_addr #0

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

declare void @EC_POINT_clear_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 = { 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)"}


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