; 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.wpacket_st = type { ptr, ptr, i64, i64, i64, ptr, i8 }
%struct.ECDSA_SIG_st = type { ptr, ptr }
%struct.buf_mem_st = type { i64, ptr, i64, i64 }

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

; 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 i32 @i2d_ECDSA_SIG(ptr noundef %0, ptr noundef %1) #1 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  %8 = alloca %struct.wpacket_st, align 8
  %9 = 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 ptr null, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.start.p0(i64 56, ptr %8) #3
  %10 = load ptr, ptr %5, align 8, !tbaa !5
  %11 = icmp eq ptr %10, null
  br i1 %11, label %12, label %17

12:                                               ; preds = %2
  %13 = call i32 @WPACKET_init_null(ptr noundef %8, i64 noundef 0)
  %14 = icmp ne i32 %13, 0
  br i1 %14, label %16, label %15

15:                                               ; preds = %12
  store i32 -1, ptr %3, align 4
  store i32 1, ptr %9, align 4
  br label %80

16:                                               ; preds = %12
  br label %39

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

21:                                               ; preds = %17
  %22 = call ptr @BUF_MEM_new()
  store ptr %22, ptr %6, align 8, !tbaa !5
  %23 = icmp eq ptr %22, null
  br i1 %23, label %28, label %24

24:                                               ; preds = %21
  %25 = load ptr, ptr %6, align 8, !tbaa !5
  %26 = call i32 @WPACKET_init_len(ptr noundef %8, ptr noundef %25, i64 noundef 0)
  %27 = icmp ne i32 %26, 0
  br i1 %27, label %30, label %28

28:                                               ; preds = %24, %21
  %29 = load ptr, ptr %6, align 8, !tbaa !5
  call void @BUF_MEM_free(ptr noundef %29)
  store i32 -1, ptr %3, align 4
  store i32 1, ptr %9, align 4
  br label %80

30:                                               ; preds = %24
  br label %38

31:                                               ; preds = %17
  %32 = load ptr, ptr %5, align 8, !tbaa !5
  %33 = load ptr, ptr %32, align 8, !tbaa !5
  %34 = call i32 @WPACKET_init_static_len(ptr noundef %8, ptr noundef %33, i64 noundef -1, i64 noundef 0)
  %35 = icmp ne i32 %34, 0
  br i1 %35, label %37, label %36

36:                                               ; preds = %31
  store i32 -1, ptr %3, align 4
  store i32 1, ptr %9, align 4
  br label %80

37:                                               ; preds = %31
  br label %38

38:                                               ; preds = %37, %30
  br label %39

39:                                               ; preds = %38, %16
  %40 = load ptr, ptr %4, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.ECDSA_SIG_st, ptr %40, i32 0, i32 0
  %42 = load ptr, ptr %41, align 8, !tbaa !9
  %43 = load ptr, ptr %4, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.ECDSA_SIG_st, ptr %43, i32 0, i32 1
  %45 = load ptr, ptr %44, align 8, !tbaa !11
  %46 = call i32 @ossl_encode_der_dsa_sig(ptr noundef %8, ptr noundef %42, ptr noundef %45)
  %47 = icmp ne i32 %46, 0
  br i1 %47, label %48, label %54

48:                                               ; preds = %39
  %49 = call i32 @WPACKET_get_total_written(ptr noundef %8, ptr noundef %7)
  %50 = icmp ne i32 %49, 0
  br i1 %50, label %51, label %54

51:                                               ; preds = %48
  %52 = call i32 @WPACKET_finish(ptr noundef %8)
  %53 = icmp ne i32 %52, 0
  br i1 %53, label %56, label %54

54:                                               ; preds = %51, %48, %39
  %55 = load ptr, ptr %6, align 8, !tbaa !5
  call void @BUF_MEM_free(ptr noundef %55)
  call void @WPACKET_cleanup(ptr noundef %8)
  store i32 -1, ptr %3, align 4
  store i32 1, ptr %9, align 4
  br label %80

56:                                               ; preds = %51
  %57 = load ptr, ptr %5, align 8, !tbaa !5
  %58 = icmp ne ptr %57, null
  br i1 %58, label %59, label %77

59:                                               ; preds = %56
  %60 = load ptr, ptr %5, align 8, !tbaa !5
  %61 = load ptr, ptr %60, align 8, !tbaa !5
  %62 = icmp eq ptr %61, null
  br i1 %62, label %63, label %71

63:                                               ; preds = %59
  %64 = load ptr, ptr %6, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.buf_mem_st, ptr %64, i32 0, i32 1
  %66 = load ptr, ptr %65, align 8, !tbaa !12
  %67 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %66, ptr %67, align 8, !tbaa !5
  %68 = load ptr, ptr %6, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.buf_mem_st, ptr %68, i32 0, i32 1
  store ptr null, ptr %69, align 8, !tbaa !12
  %70 = load ptr, ptr %6, align 8, !tbaa !5
  call void @BUF_MEM_free(ptr noundef %70)
  br label %76

71:                                               ; preds = %59
  %72 = load i64, ptr %7, align 8, !tbaa !15
  %73 = load ptr, ptr %5, align 8, !tbaa !5
  %74 = load ptr, ptr %73, align 8, !tbaa !5
  %75 = getelementptr inbounds i8, ptr %74, i64 %72
  store ptr %75, ptr %73, align 8, !tbaa !5
  br label %76

76:                                               ; preds = %71, %63
  br label %77

77:                                               ; preds = %76, %56
  %78 = load i64, ptr %7, align 8, !tbaa !15
  %79 = trunc i64 %78 to i32
  store i32 %79, ptr %3, align 4
  store i32 1, ptr %9, align 4
  br label %80

80:                                               ; preds = %77, %54, %36, %28, %15
  call void @llvm.lifetime.end.p0(i64 56, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  %81 = load i32, ptr %3, align 4
  ret i32 %81
}

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

declare ptr @BUF_MEM_new() #2

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

declare void @BUF_MEM_free(ptr noundef) #2

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

declare i32 @ossl_encode_der_dsa_sig(ptr noundef, ptr noundef, ptr noundef) #2

declare i32 @WPACKET_get_total_written(ptr noundef, ptr noundef) #2

declare i32 @WPACKET_finish(ptr noundef) #2

declare void @WPACKET_cleanup(ptr noundef) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { "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, !6, i64 0}
!10 = !{!"ECDSA_SIG_st", !6, i64 0, !6, i64 8}
!11 = !{!10, !6, i64 8}
!12 = !{!13, !6, i64 8}
!13 = !{!"buf_mem_st", !14, i64 0, !6, i64 8, !14, i64 16, !14, i64 24}
!14 = !{!"long", !7, i64 0}
!15 = !{!14, !14, 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"

%struct.wpacket_st = type { ptr, ptr, i64, i64, i64, ptr, i8 }

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

; Function Attrs: mustprogress 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 i32 @i2d_ECDSA_SIG(ptr nocapture noundef readonly %0, ptr noundef %1) local_unnamed_addr #1 {
  %3 = alloca i64, align 8
  %4 = alloca %struct.wpacket_st, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #3
  call void @llvm.lifetime.start.p0(i64 56, ptr nonnull %4) #3
  %5 = icmp eq ptr %1, null
  br i1 %5, label %6, label %8

6:                                                ; preds = %2
  %7 = call i32 @WPACKET_init_null(ptr noundef nonnull %4, i64 noundef 0) #3
  %.not21 = icmp eq i32 %7, 0
  br i1 %.not21, label %42, label %19

8:                                                ; preds = %2
  %9 = load ptr, ptr %1, align 8, !tbaa !5
  %10 = icmp eq ptr %9, null
  br i1 %10, label %11, label %17

11:                                               ; preds = %8
  %12 = tail call ptr @BUF_MEM_new() #3
  %13 = icmp eq ptr %12, null
  br i1 %13, label %16, label %14

14:                                               ; preds = %11
  %15 = call i32 @WPACKET_init_len(ptr noundef nonnull %4, ptr noundef nonnull %12, i64 noundef 0) #3
  %.not20 = icmp eq i32 %15, 0
  br i1 %.not20, label %16, label %19

16:                                               ; preds = %14, %11
  call void @BUF_MEM_free(ptr noundef %12) #3
  br label %42

17:                                               ; preds = %8
  %18 = call i32 @WPACKET_init_static_len(ptr noundef nonnull %4, ptr noundef nonnull %9, i64 noundef -1, i64 noundef 0) #3
  %.not = icmp eq i32 %18, 0
  br i1 %.not, label %42, label %19

19:                                               ; preds = %14, %17, %6
  %.0 = phi ptr [ null, %6 ], [ %12, %14 ], [ null, %17 ]
  %20 = load ptr, ptr %0, align 8, !tbaa !9
  %21 = getelementptr inbounds i8, ptr %0, i64 8
  %22 = load ptr, ptr %21, align 8, !tbaa !11
  %23 = call i32 @ossl_encode_der_dsa_sig(ptr noundef nonnull %4, ptr noundef %20, ptr noundef %22) #3
  %.not22 = icmp eq i32 %23, 0
  br i1 %.not22, label %28, label %24

24:                                               ; preds = %19
  %25 = call i32 @WPACKET_get_total_written(ptr noundef nonnull %4, ptr noundef nonnull %3) #3
  %.not23 = icmp eq i32 %25, 0
  br i1 %.not23, label %28, label %26

26:                                               ; preds = %24
  %27 = call i32 @WPACKET_finish(ptr noundef nonnull %4) #3
  %.not24 = icmp eq i32 %27, 0
  br i1 %.not24, label %28, label %29

28:                                               ; preds = %26, %24, %19
  call void @BUF_MEM_free(ptr noundef %.0) #3
  call void @WPACKET_cleanup(ptr noundef nonnull %4) #3
  br label %42

29:                                               ; preds = %26
  br i1 %5, label %39, label %30

30:                                               ; preds = %29
  %31 = load ptr, ptr %1, align 8, !tbaa !5
  %32 = icmp eq ptr %31, null
  br i1 %32, label %33, label %36

33:                                               ; preds = %30
  %34 = getelementptr inbounds i8, ptr %.0, i64 8
  %35 = load ptr, ptr %34, align 8, !tbaa !12
  store ptr %35, ptr %1, align 8, !tbaa !5
  store ptr null, ptr %34, align 8, !tbaa !12
  call void @BUF_MEM_free(ptr noundef %.0) #3
  br label %39

36:                                               ; preds = %30
  %37 = load i64, ptr %3, align 8, !tbaa !15
  %38 = getelementptr inbounds i8, ptr %31, i64 %37
  store ptr %38, ptr %1, align 8, !tbaa !5
  br label %39

39:                                               ; preds = %33, %36, %29
  %40 = load i64, ptr %3, align 8, !tbaa !15
  %41 = trunc i64 %40 to i32
  br label %42

42:                                               ; preds = %17, %6, %39, %28, %16
  %.015 = phi i32 [ %41, %39 ], [ -1, %28 ], [ -1, %16 ], [ -1, %6 ], [ -1, %17 ]
  call void @llvm.lifetime.end.p0(i64 56, ptr nonnull %4) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #3
  ret i32 %.015
}

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

declare ptr @BUF_MEM_new() local_unnamed_addr #2

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

declare void @BUF_MEM_free(ptr noundef) local_unnamed_addr #2

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

declare i32 @ossl_encode_der_dsa_sig(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

declare i32 @WPACKET_get_total_written(ptr noundef, ptr noundef) local_unnamed_addr #2

declare i32 @WPACKET_finish(ptr noundef) local_unnamed_addr #2

declare void @WPACKET_cleanup(ptr noundef) local_unnamed_addr #2

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { "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, !6, i64 0}
!10 = !{!"ECDSA_SIG_st", !6, i64 0, !6, i64 8}
!11 = !{!10, !6, i64 8}
!12 = !{!13, !6, i64 8}
!13 = !{!"buf_mem_st", !14, i64 0, !6, i64 8, !14, i64 16, !14, i64 24}
!14 = !{!"long", !7, i64 0}
!15 = !{!14, !14, i64 0}


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