; LLVM IR from specinfo-ua/UAPKI :: library/uapkif/src/asn1 (asn1-utils)

; 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._callback_arg = type { ptr, i64, i64 }
%struct.asn_enc_rval_s = type { i64, ptr, ptr }

@.str = external hidden unnamed_addr constant [25 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i32 @asn_encode(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3) #0 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca %struct._callback_arg, align 8
  %10 = alloca %struct.asn_enc_rval_s, align 8
  %11 = alloca i32, align 4
  %12 = alloca %struct.asn_enc_rval_s, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !5
  store ptr %3, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 24, ptr %9) #5
  call void @llvm.lifetime.start.p0(i64 24, ptr %10) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #5
  store i32 0, ptr %11, align 4, !tbaa !9
  br label %13

13:                                               ; preds = %4
  %14 = load ptr, ptr %5, align 8, !tbaa !5
  %15 = icmp ne ptr %14, null
  br i1 %15, label %18, label %16

16:                                               ; preds = %13
  store i32 2, ptr %11, align 4, !tbaa !9
  %17 = load i32, ptr %11, align 4, !tbaa !9
  call void @stacktrace_create(ptr noundef @.str, i64 noundef 86, i32 noundef %17, ptr noundef null)
  br label %67

18:                                               ; preds = %13
  br label %19

19:                                               ; preds = %18
  br label %20

20:                                               ; preds = %19
  br label %21

21:                                               ; preds = %20
  %22 = load ptr, ptr %6, align 8, !tbaa !5
  %23 = icmp ne ptr %22, null
  br i1 %23, label %26, label %24

24:                                               ; preds = %21
  store i32 2, ptr %11, align 4, !tbaa !9
  %25 = load i32, ptr %11, align 4, !tbaa !9
  call void @stacktrace_create(ptr noundef @.str, i64 noundef 87, i32 noundef %25, ptr noundef null)
  br label %67

26:                                               ; preds = %21
  br label %27

27:                                               ; preds = %26
  br label %28

28:                                               ; preds = %27
  br label %29

29:                                               ; preds = %28
  %30 = load ptr, ptr %7, align 8, !tbaa !5
  %31 = icmp ne ptr %30, null
  br i1 %31, label %34, label %32

32:                                               ; preds = %29
  store i32 2, ptr %11, align 4, !tbaa !9
  %33 = load i32, ptr %11, align 4, !tbaa !9
  call void @stacktrace_create(ptr noundef @.str, i64 noundef 88, i32 noundef %33, ptr noundef null)
  br label %67

34:                                               ; preds = %29
  br label %35

35:                                               ; preds = %34
  br label %36

36:                                               ; preds = %35
  br label %37

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

40:                                               ; preds = %37
  store i32 2, ptr %11, align 4, !tbaa !9
  %41 = load i32, ptr %11, align 4, !tbaa !9
  call void @stacktrace_create(ptr noundef @.str, i64 noundef 89, i32 noundef %41, ptr noundef null)
  br label %67

42:                                               ; preds = %37
  br label %43

43:                                               ; preds = %42
  br label %44

44:                                               ; preds = %43
  %45 = getelementptr inbounds %struct._callback_arg, ptr %9, i32 0, i32 2
  store i64 0, ptr %45, align 8, !tbaa !11
  %46 = getelementptr inbounds %struct._callback_arg, ptr %9, i32 0, i32 1
  store i64 0, ptr %46, align 8, !tbaa !14
  %47 = getelementptr inbounds %struct._callback_arg, ptr %9, i32 0, i32 0
  store ptr null, ptr %47, align 8, !tbaa !15
  call void @llvm.lifetime.start.p0(i64 24, ptr %12) #5
  %48 = load ptr, ptr %5, align 8, !tbaa !5
  %49 = load ptr, ptr %6, align 8, !tbaa !5
  call void @der_encode(ptr dead_on_unwind writable sret(%struct.asn_enc_rval_s) align 8 %12, ptr noundef %48, ptr noundef %49, ptr noundef @der_encode_consume_bytes, ptr noundef %9)
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %10, ptr align 8 %12, i64 24, i1 false), !tbaa.struct !16
  call void @llvm.lifetime.end.p0(i64 24, ptr %12) #5
  %50 = getelementptr inbounds %struct.asn_enc_rval_s, ptr %10, i32 0, i32 0
  %51 = load i64, ptr %50, align 8, !tbaa !18
  %52 = icmp eq i64 %51, -1
  br i1 %52, label %53, label %60

53:                                               ; preds = %44
  %54 = getelementptr inbounds %struct._callback_arg, ptr %9, i32 0, i32 0
  %55 = load ptr, ptr %54, align 8, !tbaa !15
  call void @free(ptr noundef %55) #5
  br label %56

56:                                               ; preds = %53
  store i32 100, ptr %11, align 4, !tbaa !9
  %57 = load i32, ptr %11, align 4, !tbaa !9
  call void @stacktrace_create(ptr noundef @.str, i64 noundef 98, i32 noundef %57, ptr noundef null)
  br label %67

58:                                               ; No predecessors!
  br label %59

59:                                               ; preds = %58
  br label %60

60:                                               ; preds = %59, %44
  %61 = getelementptr inbounds %struct._callback_arg, ptr %9, i32 0, i32 0
  %62 = load ptr, ptr %61, align 8, !tbaa !15
  %63 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %62, ptr %63, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.asn_enc_rval_s, ptr %10, i32 0, i32 0
  %65 = load i64, ptr %64, align 8, !tbaa !18
  %66 = load ptr, ptr %8, align 8, !tbaa !5
  store i64 %65, ptr %66, align 8, !tbaa !17
  br label %67

67:                                               ; preds = %60, %56, %40, %32, %24, %16
  %68 = load i32, ptr %11, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #5
  call void @llvm.lifetime.end.p0(i64 24, ptr %10) #5
  call void @llvm.lifetime.end.p0(i64 24, ptr %9) #5
  ret i32 %68
}

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

declare void @stacktrace_create(ptr noundef, i64 noundef, i32 noundef, ptr noundef) #2

declare void @der_encode(ptr dead_on_unwind writable sret(%struct.asn_enc_rval_s) align 8, ptr noundef, ptr noundef, ptr noundef, ptr noundef) #2

; Function Attrs: nounwind uwtable
declare hidden i32 @der_encode_consume_bytes(ptr noundef, i64 noundef, ptr 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) #3

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

; Function Attrs: nounwind
declare void @free(ptr noundef) #4

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { nounwind "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 #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, !13, i64 16}
!12 = !{!"_callback_arg", !6, i64 0, !13, i64 8, !13, i64 16}
!13 = !{!"long", !7, i64 0}
!14 = !{!12, !13, i64 8}
!15 = !{!12, !6, i64 0}
!16 = !{i64 0, i64 8, !17, i64 8, i64 8, !5, i64 16, i64 8, !5}
!17 = !{!13, !13, i64 0}
!18 = !{!19, !13, i64 0}
!19 = !{!"asn_enc_rval_s", !13, i64 0, !6, i64 8, !6, i64 16}


; 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._callback_arg = type { ptr, i64, i64 }
%struct.asn_enc_rval_s = type { i64, ptr, ptr }

@.str = external hidden unnamed_addr constant [25 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 101) i32 @asn_encode(ptr noundef %0, ptr noundef %1, ptr noundef writeonly %2, ptr noundef writeonly %3) local_unnamed_addr #0 {
  %5 = alloca %struct._callback_arg, align 8
  %6 = alloca %struct.asn_enc_rval_s, align 8
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %5) #5
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %7, label %8

7:                                                ; preds = %4
  tail call void @stacktrace_create(ptr noundef nonnull @.str, i64 noundef 86, i32 noundef 2, ptr noundef null) #5
  br label %19

8:                                                ; preds = %4
  %.not18 = icmp eq ptr %1, null
  br i1 %.not18, label %9, label %10

9:                                                ; preds = %8
  tail call void @stacktrace_create(ptr noundef nonnull @.str, i64 noundef 87, i32 noundef 2, ptr noundef null) #5
  br label %19

10:                                               ; preds = %8
  %.not19 = icmp eq ptr %2, null
  br i1 %.not19, label %11, label %12

11:                                               ; preds = %10
  tail call void @stacktrace_create(ptr noundef nonnull @.str, i64 noundef 88, i32 noundef 2, ptr noundef null) #5
  br label %19

12:                                               ; preds = %10
  %.not20 = icmp eq ptr %3, null
  br i1 %.not20, label %13, label %14

13:                                               ; preds = %12
  tail call void @stacktrace_create(ptr noundef nonnull @.str, i64 noundef 89, i32 noundef 2, ptr noundef null) #5
  br label %19

14:                                               ; preds = %12
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(24) %5, i8 0, i64 24, i1 false)
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %6) #5
  call void @der_encode(ptr dead_on_unwind nonnull writable sret(%struct.asn_enc_rval_s) align 8 %6, ptr noundef nonnull %0, ptr noundef nonnull %1, ptr noundef nonnull @der_encode_consume_bytes, ptr noundef nonnull %5) #5
  %.sroa.0.0.copyload = load i64, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %6) #5
  %15 = icmp eq i64 %.sroa.0.0.copyload, -1
  %16 = load ptr, ptr %5, align 8, !tbaa !9
  br i1 %15, label %17, label %18

17:                                               ; preds = %14
  call void @free(ptr noundef %16) #5
  call void @stacktrace_create(ptr noundef nonnull @.str, i64 noundef 98, i32 noundef 100, ptr noundef null) #5
  br label %19

18:                                               ; preds = %14
  store ptr %16, ptr %2, align 8, !tbaa !12
  store i64 %.sroa.0.0.copyload, ptr %3, align 8, !tbaa !5
  br label %19

19:                                               ; preds = %18, %17, %13, %11, %9, %7
  %.0 = phi i32 [ 100, %17 ], [ 0, %18 ], [ 2, %13 ], [ 2, %11 ], [ 2, %9 ], [ 2, %7 ]
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %5) #5
  ret i32 %.0
}

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

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

declare void @der_encode(ptr dead_on_unwind writable sret(%struct.asn_enc_rval_s) align 8, ptr noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
declare hidden i32 @der_encode_consume_bytes(ptr noundef, i64 noundef, ptr noundef) #0

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

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #3

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #4

attributes #0 = { 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 #1 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" "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: write) }
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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !11, i64 0}
!10 = !{!"_callback_arg", !11, i64 0, !6, i64 8, !6, i64 16}
!11 = !{!"any pointer", !7, i64 0}
!12 = !{!11, !11, i64 0}


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