; 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__.i2o_ECPublicKey = external hidden unnamed_addr constant [16 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

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

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

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

11:                                               ; preds = %2
  %12 = load ptr, ptr %4, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.ec_key_st, ptr %12, i32 0, i32 4
  %14 = load ptr, ptr %13, align 8, !tbaa !13
  %15 = icmp eq ptr %14, null
  br i1 %15, label %16, label %17

16:                                               ; preds = %11, %2
  call void @ERR_new()
  call void @ERR_set_debug(ptr noundef @.str.2, i32 noundef 1160, ptr noundef @__func__.i2o_ECPublicKey)
  call void (i32, i32, ptr, ...) @ERR_set_error(i32 noundef 16, i32 noundef 786690, ptr noundef null)
  store i32 0, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %81

17:                                               ; preds = %11
  %18 = load ptr, ptr %4, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.ec_key_st, ptr %18, i32 0, i32 3
  %20 = load ptr, ptr %19, align 8, !tbaa !17
  %21 = load ptr, ptr %4, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.ec_key_st, ptr %21, i32 0, i32 4
  %23 = load ptr, ptr %22, align 8, !tbaa !13
  %24 = load ptr, ptr %4, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.ec_key_st, ptr %24, i32 0, i32 7
  %26 = load i32, ptr %25, align 4, !tbaa !18
  %27 = call i64 @EC_POINT_point2oct(ptr noundef %20, ptr noundef %23, i32 noundef %26, ptr noundef null, i64 noundef 0, ptr noundef null)
  store i64 %27, ptr %6, align 8, !tbaa !9
  %28 = load ptr, ptr %5, align 8, !tbaa !5
  %29 = icmp eq ptr %28, null
  br i1 %29, label %33, label %30

30:                                               ; preds = %17
  %31 = load i64, ptr %6, align 8, !tbaa !9
  %32 = icmp eq i64 %31, 0
  br i1 %32, label %33, label %36

33:                                               ; preds = %30, %17
  %34 = load i64, ptr %6, align 8, !tbaa !9
  %35 = trunc i64 %34 to i32
  store i32 %35, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %81

36:                                               ; preds = %30
  %37 = load ptr, ptr %5, align 8, !tbaa !5
  %38 = load ptr, ptr %37, align 8, !tbaa !5
  %39 = icmp eq ptr %38, null
  br i1 %39, label %40, label %47

40:                                               ; preds = %36
  %41 = load i64, ptr %6, align 8, !tbaa !9
  %42 = call ptr @CRYPTO_malloc(i64 noundef %41, ptr noundef @.str.2, i32 noundef 1172)
  %43 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %42, ptr %43, align 8, !tbaa !5
  %44 = icmp eq ptr %42, null
  br i1 %44, label %45, label %46

45:                                               ; preds = %40
  store i32 0, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %81

46:                                               ; preds = %40
  store i32 1, ptr %7, align 4, !tbaa !11
  br label %47

47:                                               ; preds = %46, %36
  %48 = load ptr, ptr %4, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.ec_key_st, ptr %48, i32 0, i32 3
  %50 = load ptr, ptr %49, align 8, !tbaa !17
  %51 = load ptr, ptr %4, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.ec_key_st, ptr %51, i32 0, i32 4
  %53 = load ptr, ptr %52, align 8, !tbaa !13
  %54 = load ptr, ptr %4, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.ec_key_st, ptr %54, i32 0, i32 7
  %56 = load i32, ptr %55, align 4, !tbaa !18
  %57 = load ptr, ptr %5, align 8, !tbaa !5
  %58 = load ptr, ptr %57, align 8, !tbaa !5
  %59 = load i64, ptr %6, align 8, !tbaa !9
  %60 = call i64 @EC_POINT_point2oct(ptr noundef %50, ptr noundef %53, i32 noundef %56, ptr noundef %58, i64 noundef %59, ptr noundef null)
  %61 = icmp ne i64 %60, 0
  br i1 %61, label %70, label %62

62:                                               ; preds = %47
  call void @ERR_new()
  call void @ERR_set_debug(ptr noundef @.str.2, i32 noundef 1178, ptr noundef @__func__.i2o_ECPublicKey)
  call void (i32, i32, ptr, ...) @ERR_set_error(i32 noundef 16, i32 noundef 524304, ptr noundef null)
  %63 = load i32, ptr %7, align 4, !tbaa !11
  %64 = icmp ne i32 %63, 0
  br i1 %64, label %65, label %69

65:                                               ; preds = %62
  %66 = load ptr, ptr %5, align 8, !tbaa !5
  %67 = load ptr, ptr %66, align 8, !tbaa !5
  call void @CRYPTO_free(ptr noundef %67, ptr noundef @.str.2, i32 noundef 1180)
  %68 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr null, ptr %68, align 8, !tbaa !5
  br label %69

69:                                               ; preds = %65, %62
  store i32 0, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %81

70:                                               ; preds = %47
  %71 = load i32, ptr %7, align 4, !tbaa !11
  %72 = icmp ne i32 %71, 0
  br i1 %72, label %78, label %73

73:                                               ; preds = %70
  %74 = load i64, ptr %6, align 8, !tbaa !9
  %75 = load ptr, ptr %5, align 8, !tbaa !5
  %76 = load ptr, ptr %75, align 8, !tbaa !5
  %77 = getelementptr inbounds i8, ptr %76, i64 %74
  store ptr %77, ptr %75, align 8, !tbaa !5
  br label %78

78:                                               ; preds = %73, %70
  %79 = load i64, ptr %6, align 8, !tbaa !9
  %80 = trunc i64 %79 to i32
  store i32 %80, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %81

81:                                               ; preds = %78, %69, %45, %33, %16
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  %82 = load i32, ptr %3, align 4
  ret i32 %82
}

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


; 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__.i2o_ECPublicKey = external hidden unnamed_addr constant [16 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 void @CRYPTO_free(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #0

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

; Function Attrs: nounwind uwtable
define dso_local i32 @i2o_ECPublicKey(ptr noundef readonly %0, ptr noundef %1) local_unnamed_addr #1 {
  %3 = icmp eq ptr %0, null
  br i1 %3, label %8, label %4

4:                                                ; preds = %2
  %5 = getelementptr inbounds i8, ptr %0, i64 32
  %6 = load ptr, ptr %5, align 8, !tbaa !5
  %7 = icmp eq ptr %6, null
  br i1 %7, label %8, label %9

8:                                                ; preds = %4, %2
  tail call void @ERR_new() #2
  tail call void @ERR_set_debug(ptr noundef nonnull @.str.2, i32 noundef 1160, ptr noundef nonnull @__func__.i2o_ECPublicKey) #2
  tail call void (i32, i32, ptr, ...) @ERR_set_error(i32 noundef 16, i32 noundef 786690, ptr noundef null) #2
  br label %39

9:                                                ; preds = %4
  %10 = getelementptr inbounds i8, ptr %0, i64 24
  %11 = load ptr, ptr %10, align 8, !tbaa !14
  %12 = getelementptr inbounds i8, ptr %0, i64 52
  %13 = load i32, ptr %12, align 4, !tbaa !15
  %14 = tail call i64 @EC_POINT_point2oct(ptr noundef %11, ptr noundef nonnull %6, i32 noundef %13, ptr noundef null, i64 noundef 0, ptr noundef null) #2
  %15 = icmp eq ptr %1, null
  %16 = icmp eq i64 %14, 0
  %or.cond = select i1 %15, i1 true, i1 %16
  br i1 %or.cond, label %17, label %19

17:                                               ; preds = %9
  %18 = trunc i64 %14 to i32
  br label %39

19:                                               ; preds = %9
  %20 = load ptr, ptr %1, align 8, !tbaa !16
  %.not30.not = icmp eq ptr %20, null
  br i1 %.not30.not, label %21, label %24

21:                                               ; preds = %19
  %22 = tail call ptr @CRYPTO_malloc(i64 noundef %14, ptr noundef nonnull @.str.2, i32 noundef 1172) #2
  store ptr %22, ptr %1, align 8, !tbaa !16
  %23 = icmp eq ptr %22, null
  br i1 %23, label %39, label %24

24:                                               ; preds = %21, %19
  %25 = phi ptr [ %22, %21 ], [ %20, %19 ]
  %26 = load ptr, ptr %10, align 8, !tbaa !14
  %27 = load ptr, ptr %5, align 8, !tbaa !5
  %28 = load i32, ptr %12, align 4, !tbaa !15
  %29 = tail call i64 @EC_POINT_point2oct(ptr noundef %26, ptr noundef %27, i32 noundef %28, ptr noundef nonnull %25, i64 noundef %14, ptr noundef null) #2
  %.not = icmp eq i64 %29, 0
  br i1 %.not, label %30, label %33

30:                                               ; preds = %24
  tail call void @ERR_new() #2
  tail call void @ERR_set_debug(ptr noundef nonnull @.str.2, i32 noundef 1178, ptr noundef nonnull @__func__.i2o_ECPublicKey) #2
  tail call void (i32, i32, ptr, ...) @ERR_set_error(i32 noundef 16, i32 noundef 524304, ptr noundef null) #2
  br i1 %.not30.not, label %31, label %39

31:                                               ; preds = %30
  %32 = load ptr, ptr %1, align 8, !tbaa !16
  tail call void @CRYPTO_free(ptr noundef %32, ptr noundef nonnull @.str.2, i32 noundef 1180) #2
  store ptr null, ptr %1, align 8, !tbaa !16
  br label %39

33:                                               ; preds = %24
  br i1 %.not30.not, label %37, label %34

34:                                               ; preds = %33
  %35 = load ptr, ptr %1, align 8, !tbaa !16
  %36 = getelementptr inbounds i8, ptr %35, i64 %14
  store ptr %36, ptr %1, align 8, !tbaa !16
  br label %37

37:                                               ; preds = %34, %33
  %38 = trunc i64 %14 to i32
  br label %39

39:                                               ; preds = %30, %31, %21, %37, %17, %8
  %.024 = phi i32 [ 0, %8 ], [ %18, %17 ], [ %38, %37 ], [ 0, %21 ], [ 0, %31 ], [ 0, %30 ]
  ret i32 %.024
}

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


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