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

; 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 }
%struct.ANY = type { ptr, i32, %struct.asn_struct_ctx_s }
%struct.asn_struct_ctx_s = type { i16, i16, i32, ptr, i64 }

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

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

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

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

17:                                               ; preds = %14
  store i32 2, ptr %9, align 4, !tbaa !9
  %18 = load i32, ptr %9, align 4, !tbaa !9
  call void @stacktrace_create(ptr noundef @.str.1, i64 noundef 100, i32 noundef %18, ptr noundef null)
  br label %58

19:                                               ; preds = %14
  br label %20

20:                                               ; preds = %19
  br label %21

21:                                               ; preds = %20
  br label %22

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

25:                                               ; preds = %22
  store i32 2, ptr %9, align 4, !tbaa !9
  %26 = load i32, ptr %9, align 4, !tbaa !9
  call void @stacktrace_create(ptr noundef @.str.1, i64 noundef 101, i32 noundef %26, ptr noundef null)
  br label %58

27:                                               ; preds = %22
  br label %28

28:                                               ; preds = %27
  br label %29

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

32:                                               ; preds = %29
  %33 = load ptr, ptr %4, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.ANY, ptr %33, i32 0, i32 0
  %35 = load ptr, ptr %34, align 8, !tbaa !16
  %36 = icmp ne ptr %35, null
  br i1 %36, label %37, label %43

37:                                               ; preds = %32
  %38 = load ptr, ptr %4, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.ANY, ptr %38, i32 0, i32 0
  %40 = load ptr, ptr %39, align 8, !tbaa !16
  call void @free(ptr noundef %40) #5
  %41 = load ptr, ptr %4, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.ANY, ptr %41, i32 0, i32 0
  store ptr null, ptr %42, align 8, !tbaa !16
  br label %43

43:                                               ; preds = %37, %32
  %44 = load ptr, ptr %4, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.ANY, ptr %44, i32 0, i32 1
  store i32 0, ptr %45, align 8, !tbaa !20
  br label %58

46:                                               ; preds = %29
  call void @llvm.lifetime.start.p0(i64 24, ptr %10) #5
  %47 = load ptr, ptr %5, align 8, !tbaa !5
  %48 = 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 %10, ptr noundef %47, ptr noundef %48, ptr noundef @ANY__consume_bytes, ptr noundef %7)
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %8, ptr align 8 %10, i64 24, i1 false), !tbaa.struct !21
  call void @llvm.lifetime.end.p0(i64 24, ptr %10) #5
  %49 = getelementptr inbounds %struct.asn_enc_rval_s, ptr %8, i32 0, i32 0
  %50 = load i64, ptr %49, align 8, !tbaa !23
  %51 = icmp eq i64 %50, -1
  br i1 %51, label %52, label %57

52:                                               ; preds = %46
  br label %53

53:                                               ; preds = %52
  store i32 102, ptr %9, align 4, !tbaa !9
  %54 = load i32, ptr %9, align 4, !tbaa !9
  call void @stacktrace_create(ptr noundef @.str.1, i64 noundef 113, i32 noundef %54, ptr noundef null)
  br label %58

55:                                               ; No predecessors!
  br label %56

56:                                               ; preds = %55
  br label %57

57:                                               ; preds = %56, %46
  br label %58

58:                                               ; preds = %57, %53, %43, %25, %17
  %59 = load ptr, ptr %4, align 8, !tbaa !5
  %60 = icmp ne ptr %59, null
  br i1 %60, label %61, label %82

61:                                               ; preds = %58
  %62 = load ptr, ptr %4, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.ANY, ptr %62, i32 0, i32 0
  %64 = load ptr, ptr %63, align 8, !tbaa !16
  %65 = icmp ne ptr %64, null
  br i1 %65, label %66, label %72

66:                                               ; preds = %61
  %67 = load ptr, ptr %4, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.ANY, ptr %67, i32 0, i32 0
  %69 = load ptr, ptr %68, align 8, !tbaa !16
  call void @free(ptr noundef %69) #5
  %70 = load ptr, ptr %4, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct.ANY, ptr %70, i32 0, i32 0
  store ptr null, ptr %71, align 8, !tbaa !16
  br label %72

72:                                               ; preds = %66, %61
  %73 = getelementptr inbounds %struct._callback_arg, ptr %7, i32 0, i32 0
  %74 = load ptr, ptr %73, align 8, !tbaa !15
  %75 = load ptr, ptr %4, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct.ANY, ptr %75, i32 0, i32 0
  store ptr %74, ptr %76, align 8, !tbaa !16
  %77 = getelementptr inbounds %struct._callback_arg, ptr %7, i32 0, i32 1
  %78 = load i64, ptr %77, align 8, !tbaa !14
  %79 = trunc i64 %78 to i32
  %80 = load ptr, ptr %4, align 8, !tbaa !5
  %81 = getelementptr inbounds %struct.ANY, ptr %80, i32 0, i32 1
  store i32 %79, ptr %81, align 8, !tbaa !20
  br label %82

82:                                               ; preds = %72, %58
  %83 = load i32, ptr %9, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #5
  call void @llvm.lifetime.end.p0(i64 24, ptr %8) #5
  call void @llvm.lifetime.end.p0(i64 24, ptr %7) #5
  ret i32 %83
}

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

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

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) #0

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

; 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) #4

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

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 #4 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = !{!17, !6, i64 0}
!17 = !{!"ANY", !6, i64 0, !10, i64 8, !18, i64 16}
!18 = !{!"asn_struct_ctx_s", !19, i64 0, !19, i64 2, !10, i64 4, !6, i64 8, !13, i64 16}
!19 = !{!"short", !7, i64 0}
!20 = !{!17, !10, i64 8}
!21 = !{i64 0, i64 8, !22, i64 8, i64 8, !5, i64 16, i64 8, !5}
!22 = !{!13, !13, i64 0}
!23 = !{!24, !13, i64 0}
!24 = !{!"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.1 = external hidden unnamed_addr constant [18 x i8], align 1

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

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 103) i32 @ANY_fromType(ptr noundef %0, ptr noundef %1, ptr noundef %2) local_unnamed_addr #1 {
  %4 = alloca %struct._callback_arg, align 8
  %5 = alloca %struct.asn_enc_rval_s, align 8
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %4) #5
  %6 = getelementptr inbounds i8, ptr %4, i64 8
  %.not = icmp eq ptr %0, null
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(24) %4, i8 0, i64 24, i1 false)
  br i1 %.not, label %18, label %7

7:                                                ; preds = %3
  %.not23 = icmp eq ptr %1, null
  br i1 %.not23, label %8, label %9

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

9:                                                ; preds = %7
  %.not24 = icmp eq ptr %2, null
  br i1 %.not24, label %10, label %15

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

12:                                               ; preds = %10
  tail call void @free(ptr noundef nonnull %11) #5
  store ptr null, ptr %0, align 8, !tbaa !5
  br label %13

13:                                               ; preds = %12, %10
  %14 = getelementptr inbounds i8, ptr %0, i64 8
  store i32 0, ptr %14, align 8, !tbaa !14
  br label %19

15:                                               ; preds = %9
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %5) #5
  call void @der_encode(ptr dead_on_unwind nonnull writable sret(%struct.asn_enc_rval_s) align 8 %5, ptr noundef nonnull %1, ptr noundef nonnull %2, ptr noundef nonnull @ANY__consume_bytes, ptr noundef nonnull %4) #5
  %.sroa.0.0.copyload = load i64, ptr %5, align 8, !tbaa !15
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %5) #5
  %16 = icmp eq i64 %.sroa.0.0.copyload, -1
  br i1 %16, label %17, label %19

17:                                               ; preds = %15
  call void @stacktrace_create(ptr noundef nonnull @.str.1, i64 noundef 113, i32 noundef 102, ptr noundef null) #5
  br label %19

18:                                               ; preds = %3
  tail call void @stacktrace_create(ptr noundef nonnull @.str.1, i64 noundef 100, i32 noundef 2, ptr noundef null) #5
  br label %27

19:                                               ; preds = %15, %17, %13, %8
  %.0.ph = phi i32 [ 2, %8 ], [ 0, %13 ], [ 0, %15 ], [ 102, %17 ]
  %20 = load ptr, ptr %0, align 8, !tbaa !5
  %.not26 = icmp eq ptr %20, null
  br i1 %.not26, label %22, label %21

21:                                               ; preds = %19
  call void @free(ptr noundef nonnull %20) #5
  br label %22

22:                                               ; preds = %21, %19
  %23 = load ptr, ptr %4, align 8, !tbaa !16
  store ptr %23, ptr %0, align 8, !tbaa !5
  %24 = load i64, ptr %6, align 8, !tbaa !18
  %25 = trunc i64 %24 to i32
  %26 = getelementptr inbounds i8, ptr %0, i64 8
  store i32 %25, ptr %26, align 8, !tbaa !14
  br label %27

27:                                               ; preds = %18, %22
  %.029 = phi i32 [ %.0.ph, %22 ], [ 2, %18 ]
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %4) #5
  ret i32 %.029
}

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

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

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 #0

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

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

; 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 = { "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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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, !7, i64 0}
!6 = !{!"ANY", !7, i64 0, !10, i64 8, !11, i64 16}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"asn_struct_ctx_s", !12, i64 0, !12, i64 2, !10, i64 4, !7, i64 8, !13, i64 16}
!12 = !{!"short", !8, i64 0}
!13 = !{!"long", !8, i64 0}
!14 = !{!6, !10, i64 8}
!15 = !{!13, !13, i64 0}
!16 = !{!17, !7, i64 0}
!17 = !{!"_callback_arg", !7, i64 0, !13, i64 8, !13, i64 16}
!18 = !{!17, !13, i64 8}


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