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

; 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.ec_key_st = type { ptr, ptr, i32, ptr, ptr, ptr, i32, i32, %struct.CRYPTO_REF_COUNT, i32, %struct.crypto_ex_data_st, ptr, ptr, i64 }
%struct.CRYPTO_REF_COUNT = type { i32 }
%struct.crypto_ex_data_st = type { ptr, ptr }

@.str.2 = external hidden unnamed_addr constant [69 x i8], align 1
@__func__.d2i_ECParameters = external hidden unnamed_addr constant [17 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 @ERR_new() #1

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

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

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

declare i32 @EC_GROUP_get_curve_name(ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local ptr @d2i_ECPKParameters(ptr noundef, ptr noundef, i64 noundef) #2

declare ptr @EC_KEY_new() #1

declare void @EC_KEY_set_flags(ptr noundef, i32 noundef) #1

declare void @EC_KEY_free(ptr noundef) #1

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

12:                                               ; preds = %3
  %13 = load ptr, ptr %6, align 8, !tbaa !5
  %14 = load ptr, ptr %13, align 8, !tbaa !5
  %15 = icmp eq ptr %14, null
  br i1 %15, label %16, label %17

16:                                               ; preds = %12, %3
  call void @ERR_new()
  call void @ERR_set_debug(ptr noundef @.str.2, i32 noundef 1102, ptr noundef @__func__.d2i_ECParameters)
  call void (i32, i32, ptr, ...) @ERR_set_error(i32 noundef 16, i32 noundef 786690, ptr noundef null)
  store ptr null, ptr %4, align 8
  store i32 1, ptr %9, align 4
  br label %75

17:                                               ; preds = %12
  %18 = load ptr, ptr %5, align 8, !tbaa !5
  %19 = icmp eq ptr %18, null
  br i1 %19, label %24, label %20

20:                                               ; preds = %17
  %21 = load ptr, ptr %5, align 8, !tbaa !5
  %22 = load ptr, ptr %21, align 8, !tbaa !5
  %23 = icmp eq ptr %22, null
  br i1 %23, label %24, label %29

24:                                               ; preds = %20, %17
  %25 = call ptr @EC_KEY_new()
  store ptr %25, ptr %8, align 8, !tbaa !5
  %26 = icmp eq ptr %25, null
  br i1 %26, label %27, label %28

27:                                               ; preds = %24
  call void @ERR_new()
  call void @ERR_set_debug(ptr noundef @.str.2, i32 noundef 1108, ptr noundef @__func__.d2i_ECParameters)
  call void (i32, i32, ptr, ...) @ERR_set_error(i32 noundef 16, i32 noundef 524304, ptr noundef null)
  store ptr null, ptr %4, align 8
  store i32 1, ptr %9, align 4
  br label %75

28:                                               ; preds = %24
  br label %32

29:                                               ; preds = %20
  %30 = load ptr, ptr %5, align 8, !tbaa !5
  %31 = load ptr, ptr %30, align 8, !tbaa !5
  store ptr %31, ptr %8, align 8, !tbaa !5
  br label %32

32:                                               ; preds = %29, %28
  %33 = load ptr, ptr %8, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.ec_key_st, ptr %33, i32 0, i32 3
  %35 = load ptr, ptr %6, align 8, !tbaa !5
  %36 = load i64, ptr %7, align 8, !tbaa !9
  %37 = call ptr @d2i_ECPKParameters(ptr noundef %34, ptr noundef %35, i64 noundef %36)
  %38 = icmp ne ptr %37, null
  br i1 %38, label %55, label %39

39:                                               ; preds = %32
  %40 = load ptr, ptr %5, align 8, !tbaa !5
  %41 = icmp eq ptr %40, null
  br i1 %41, label %47, label %42

42:                                               ; preds = %39
  %43 = load ptr, ptr %5, align 8, !tbaa !5
  %44 = load ptr, ptr %43, align 8, !tbaa !5
  %45 = load ptr, ptr %8, align 8, !tbaa !5
  %46 = icmp ne ptr %44, %45
  br i1 %46, label %47, label %49

47:                                               ; preds = %42, %39
  %48 = load ptr, ptr %8, align 8, !tbaa !5
  call void @EC_KEY_free(ptr noundef %48)
  br label %54

49:                                               ; preds = %42
  %50 = load ptr, ptr %8, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.ec_key_st, ptr %50, i32 0, i32 13
  %52 = load i64, ptr %51, align 8, !tbaa !11
  %53 = add i64 %52, 1
  store i64 %53, ptr %51, align 8, !tbaa !11
  br label %54

54:                                               ; preds = %49, %47
  store ptr null, ptr %4, align 8
  store i32 1, ptr %9, align 4
  br label %75

55:                                               ; preds = %32
  %56 = load ptr, ptr %8, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.ec_key_st, ptr %56, i32 0, i32 3
  %58 = load ptr, ptr %57, align 8, !tbaa !16
  %59 = call i32 @EC_GROUP_get_curve_name(ptr noundef %58)
  %60 = icmp eq i32 %59, 1172
  br i1 %60, label %61, label %63

61:                                               ; preds = %55
  %62 = load ptr, ptr %8, align 8, !tbaa !5
  call void @EC_KEY_set_flags(ptr noundef %62, i32 noundef 4)
  br label %63

63:                                               ; preds = %61, %55
  %64 = load ptr, ptr %8, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.ec_key_st, ptr %64, i32 0, i32 13
  %66 = load i64, ptr %65, align 8, !tbaa !11
  %67 = add i64 %66, 1
  store i64 %67, ptr %65, align 8, !tbaa !11
  %68 = load ptr, ptr %5, align 8, !tbaa !5
  %69 = icmp ne ptr %68, null
  br i1 %69, label %70, label %73

70:                                               ; preds = %63
  %71 = load ptr, ptr %8, align 8, !tbaa !5
  %72 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %71, ptr %72, align 8, !tbaa !5
  br label %73

73:                                               ; preds = %70, %63
  %74 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr %74, ptr %4, align 8
  store i32 1, ptr %9, align 4
  br label %75

75:                                               ; preds = %73, %54, %27, %16
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  %76 = load ptr, ptr %4, align 8
  ret ptr %76
}

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}
!11 = !{!12, !10, i64 96}
!12 = !{!"ec_key_st", !6, i64 0, !6, i64 8, !13, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !13, i64 48, !13, i64 52, !14, i64 56, !13, i64 60, !15, i64 64, !6, i64 80, !6, i64 88, !10, i64 96}
!13 = !{!"int", !7, i64 0}
!14 = !{!"", !7, i64 0}
!15 = !{!"crypto_ex_data_st", !6, i64 0, !6, i64 8}
!16 = !{!12, !6, i64 24}


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

declare i32 @EC_GROUP_get_curve_name(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local ptr @d2i_ECPKParameters(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #1

declare ptr @EC_KEY_new() local_unnamed_addr #0

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

declare void @EC_KEY_free(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local ptr @d2i_ECParameters(ptr noundef %0, ptr noundef %1, i64 noundef %2) local_unnamed_addr #1 {
  %4 = icmp eq ptr %1, null
  br i1 %4, label %8, label %5

5:                                                ; preds = %3
  %6 = load ptr, ptr %1, align 8, !tbaa !5
  %7 = icmp eq ptr %6, null
  br i1 %7, label %8, label %9

8:                                                ; preds = %5, %3
  tail call void @ERR_new() #2
  tail call void @ERR_set_debug(ptr noundef nonnull @.str.2, i32 noundef 1102, ptr noundef nonnull @__func__.d2i_ECParameters) #2
  tail call void (i32, i32, ptr, ...) @ERR_set_error(i32 noundef 16, i32 noundef 786690, ptr noundef null) #2
  br label %41

9:                                                ; preds = %5
  %10 = icmp eq ptr %0, null
  br i1 %10, label %14, label %11

11:                                               ; preds = %9
  %12 = load ptr, ptr %0, align 8, !tbaa !5
  %13 = icmp eq ptr %12, null
  br i1 %13, label %14, label %.thread

14:                                               ; preds = %11, %9
  %15 = tail call ptr @EC_KEY_new() #2
  %16 = icmp eq ptr %15, null
  br i1 %16, label %17, label %18

17:                                               ; preds = %14
  tail call void @ERR_new() #2
  tail call void @ERR_set_debug(ptr noundef nonnull @.str.2, i32 noundef 1108, ptr noundef nonnull @__func__.d2i_ECParameters) #2
  tail call void (i32, i32, ptr, ...) @ERR_set_error(i32 noundef 16, i32 noundef 524304, ptr noundef null) #2
  br label %41

18:                                               ; preds = %14
  %19 = getelementptr inbounds i8, ptr %15, i64 24
  %20 = tail call ptr @d2i_ECPKParameters(ptr noundef nonnull %19, ptr noundef nonnull %1, i64 noundef %2)
  %.not = icmp eq ptr %20, null
  br i1 %.not, label %23, label %30

.thread:                                          ; preds = %11
  %21 = getelementptr inbounds i8, ptr %12, i64 24
  %22 = tail call ptr @d2i_ECPKParameters(ptr noundef nonnull %21, ptr noundef nonnull %1, i64 noundef %2)
  %.not28 = icmp eq ptr %22, null
  br i1 %.not28, label %.thread31, label %30

23:                                               ; preds = %18
  br i1 %10, label %25, label %.thread31

.thread31:                                        ; preds = %.thread, %23
  %.03033 = phi ptr [ %15, %23 ], [ %12, %.thread ]
  %24 = load ptr, ptr %0, align 8, !tbaa !5
  %.not25 = icmp eq ptr %24, %.03033
  br i1 %.not25, label %26, label %25

25:                                               ; preds = %.thread31, %23
  %.03034 = phi ptr [ %.03033, %.thread31 ], [ %15, %23 ]
  tail call void @EC_KEY_free(ptr noundef nonnull %.03034) #2
  br label %41

26:                                               ; preds = %.thread31
  %27 = getelementptr inbounds i8, ptr %.03033, i64 96
  %28 = load i64, ptr %27, align 8, !tbaa !9
  %29 = add i64 %28, 1
  store i64 %29, ptr %27, align 8, !tbaa !9
  br label %41

30:                                               ; preds = %.thread, %18
  %31 = phi ptr [ %21, %.thread ], [ %19, %18 ]
  %.029 = phi ptr [ %12, %.thread ], [ %15, %18 ]
  %32 = load ptr, ptr %31, align 8, !tbaa !15
  %33 = tail call i32 @EC_GROUP_get_curve_name(ptr noundef %32) #2
  %34 = icmp eq i32 %33, 1172
  br i1 %34, label %35, label %36

35:                                               ; preds = %30
  tail call void @EC_KEY_set_flags(ptr noundef nonnull %.029, i32 noundef 4) #2
  br label %36

36:                                               ; preds = %35, %30
  %37 = getelementptr inbounds i8, ptr %.029, i64 96
  %38 = load i64, ptr %37, align 8, !tbaa !9
  %39 = add i64 %38, 1
  store i64 %39, ptr %37, align 8, !tbaa !9
  br i1 %10, label %41, label %40

40:                                               ; preds = %36
  store ptr %.029, ptr %0, align 8, !tbaa !5
  br label %41

41:                                               ; preds = %36, %40, %25, %26, %17, %8
  %.020 = phi ptr [ null, %8 ], [ null, %17 ], [ null, %26 ], [ null, %25 ], [ %.029, %40 ], [ %.029, %36 ]
  ret ptr %.020
}

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)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !14, i64 96}
!10 = !{!"ec_key_st", !6, i64 0, !6, i64 8, !11, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !11, i64 48, !11, i64 52, !12, i64 56, !11, i64 60, !13, i64 64, !6, i64 80, !6, i64 88, !14, i64 96}
!11 = !{!"int", !7, i64 0}
!12 = !{!"", !7, i64 0}
!13 = !{!"crypto_ex_data_st", !6, i64 0, !6, i64 8}
!14 = !{!"long", !7, i64 0}
!15 = !{!10, !6, i64 24}


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