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

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

; Function Attrs: nounwind uwtable
define dso_local void @NativeInteger_encode_der(ptr dead_on_unwind noalias writable sret(%struct.asn_enc_rval_s) align 8 %0, ptr noundef %1, ptr noundef %2, i32 noundef %3, i32 noundef %4, ptr noundef %5, ptr noundef %6) #0 {
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca ptr, align 8
  %13 = alloca ptr, align 8
  %14 = alloca i64, align 8
  %15 = alloca %struct.ASN__PRIMITIVE_TYPE_s, align 8
  %16 = alloca [8 x i8], align 1
  %17 = alloca ptr, align 8
  %18 = alloca %struct.asn_enc_rval_s, align 8
  store ptr %1, ptr %8, align 8, !tbaa !5
  store ptr %2, ptr %9, align 8, !tbaa !5
  store i32 %3, ptr %10, align 4, !tbaa !9
  store i32 %4, ptr %11, align 4, !tbaa !9
  store ptr %5, ptr %12, align 8, !tbaa !5
  store ptr %6, ptr %13, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #4
  %19 = load ptr, ptr %9, align 8, !tbaa !5
  %20 = load i64, ptr %19, align 8, !tbaa !11
  store i64 %20, ptr %14, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 16, ptr %15) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %17) #4
  %21 = getelementptr inbounds [8 x i8], ptr %16, i64 0, i64 0
  %22 = getelementptr inbounds i8, ptr %21, i64 8
  %23 = getelementptr inbounds i8, ptr %22, i64 -1
  store ptr %23, ptr %17, align 8, !tbaa !5
  br label %24

24:                                               ; preds = %32, %7
  %25 = load ptr, ptr %17, align 8, !tbaa !5
  %26 = getelementptr inbounds [8 x i8], ptr %16, i64 0, i64 0
  %27 = icmp uge ptr %25, %26
  br i1 %27, label %28, label %37

28:                                               ; preds = %24
  %29 = load i64, ptr %14, align 8, !tbaa !11
  %30 = trunc i64 %29 to i8
  %31 = load ptr, ptr %17, align 8, !tbaa !5
  store i8 %30, ptr %31, align 1, !tbaa !13
  br label %32

32:                                               ; preds = %28
  %33 = load ptr, ptr %17, align 8, !tbaa !5
  %34 = getelementptr inbounds i8, ptr %33, i32 -1
  store ptr %34, ptr %17, align 8, !tbaa !5
  %35 = load i64, ptr %14, align 8, !tbaa !11
  %36 = lshr i64 %35, 8
  store i64 %36, ptr %14, align 8, !tbaa !11
  br label %24, !llvm.loop !14

37:                                               ; preds = %24
  %38 = getelementptr inbounds [8 x i8], ptr %16, i64 0, i64 0
  %39 = getelementptr inbounds %struct.ASN__PRIMITIVE_TYPE_s, ptr %15, i32 0, i32 0
  store ptr %38, ptr %39, align 8, !tbaa !16
  %40 = getelementptr inbounds %struct.ASN__PRIMITIVE_TYPE_s, ptr %15, i32 0, i32 1
  store i32 8, ptr %40, align 8, !tbaa !18
  call void @llvm.lifetime.start.p0(i64 24, ptr %18) #4
  %41 = load ptr, ptr %8, align 8, !tbaa !5
  %42 = load i32, ptr %10, align 4, !tbaa !9
  %43 = load i32, ptr %11, align 4, !tbaa !9
  %44 = load ptr, ptr %12, align 8, !tbaa !5
  %45 = load ptr, ptr %13, align 8, !tbaa !5
  call void @INTEGER_encode_der(ptr dead_on_unwind writable sret(%struct.asn_enc_rval_s) align 8 %18, ptr noundef %41, ptr noundef %15, i32 noundef %42, i32 noundef %43, ptr noundef %44, ptr noundef %45)
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %0, ptr align 8 %18, i64 24, i1 false), !tbaa.struct !19
  call void @llvm.lifetime.end.p0(i64 24, ptr %18) #4
  %46 = getelementptr inbounds %struct.asn_enc_rval_s, ptr %0, i32 0, i32 0
  %47 = load i64, ptr %46, align 8, !tbaa !20
  %48 = icmp eq i64 %47, -1
  br i1 %48, label %49, label %52

49:                                               ; preds = %37
  %50 = load ptr, ptr %9, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.asn_enc_rval_s, ptr %0, i32 0, i32 2
  store ptr %50, ptr %51, align 8, !tbaa !22
  br label %52

52:                                               ; preds = %49, %37
  call void @llvm.lifetime.end.p0(i64 8, ptr %17) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #4
  call void @llvm.lifetime.end.p0(i64 16, ptr %15) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #4
  ret void
}

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #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) #2

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

declare void @INTEGER_encode_der(ptr dead_on_unwind writable sret(%struct.asn_enc_rval_s) align 8, ptr noundef, ptr noundef, i32 noundef, i32 noundef, ptr noundef, ptr noundef) #3

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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { "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 = { 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, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!7, !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = !{!17, !6, i64 0}
!17 = !{!"ASN__PRIMITIVE_TYPE_s", !6, i64 0, !10, i64 8}
!18 = !{!17, !10, i64 8}
!19 = !{i64 0, i64 8, !11, i64 8, i64 8, !5, i64 16, i64 8, !5}
!20 = !{!21, !12, i64 0}
!21 = !{!"asn_enc_rval_s", !12, i64 0, !6, i64 8, !6, i64 16}
!22 = !{!21, !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.asn_enc_rval_s = type { i64, ptr, ptr }
%struct.ASN__PRIMITIVE_TYPE_s = type { ptr, i32 }

; Function Attrs: nounwind uwtable
define dso_local void @NativeInteger_encode_der(ptr dead_on_unwind noalias nocapture writable sret(%struct.asn_enc_rval_s) align 8 %0, ptr noundef %1, ptr noundef %2, i32 noundef %3, i32 noundef %4, ptr noundef %5, ptr noundef %6) local_unnamed_addr #0 {
  %8 = alloca %struct.ASN__PRIMITIVE_TYPE_s, align 8
  %9 = alloca [8 x i8], align 1
  %10 = load i64, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %8) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %9) #3
  %11 = getelementptr inbounds i8, ptr %9, i64 7
  br label %12

12:                                               ; preds = %7, %12
  %.014 = phi ptr [ %11, %7 ], [ %14, %12 ]
  %.01113 = phi i64 [ %10, %7 ], [ %15, %12 ]
  %13 = trunc i64 %.01113 to i8
  store i8 %13, ptr %.014, align 1, !tbaa !9
  %14 = getelementptr inbounds i8, ptr %.014, i64 -1
  %15 = lshr i64 %.01113, 8
  %.not = icmp ult ptr %14, %9
  br i1 %.not, label %16, label %12, !llvm.loop !10

16:                                               ; preds = %12
  store ptr %9, ptr %8, align 8, !tbaa !12
  %17 = getelementptr inbounds i8, ptr %8, i64 8
  store i32 8, ptr %17, align 8, !tbaa !16
  call void @INTEGER_encode_der(ptr dead_on_unwind nonnull writable sret(%struct.asn_enc_rval_s) align 8 %0, ptr noundef %1, ptr noundef nonnull %8, i32 noundef %3, i32 noundef %4, ptr noundef %5, ptr noundef %6) #3
  %18 = load i64, ptr %0, align 8, !tbaa !17
  %19 = icmp eq i64 %18, -1
  br i1 %19, label %20, label %22

20:                                               ; preds = %16
  %21 = getelementptr inbounds i8, ptr %0, i64 16
  store ptr %2, ptr %21, align 8, !tbaa !19
  br label %22

22:                                               ; preds = %20, %16
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %9) #3
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %8) #3
  ret void
}

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

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

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

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 = { 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 = !{!7, !7, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}
!12 = !{!13, !14, i64 0}
!13 = !{!"ASN__PRIMITIVE_TYPE_s", !14, i64 0, !15, i64 8}
!14 = !{!"any pointer", !7, i64 0}
!15 = !{!"int", !7, i64 0}
!16 = !{!13, !15, i64 8}
!17 = !{!18, !6, i64 0}
!18 = !{!"asn_enc_rval_s", !6, i64 0, !14, i64 8, !14, i64 16}
!19 = !{!18, !14, i64 16}


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