; 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_TYPE_descriptor_s = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, i32, ptr, i32, ptr, ptr, i32, ptr }
%struct.asn_INTEGER_specifics_s = type { ptr, ptr, i32, i32, i32, i32, i32 }

@.str.1 = external hidden unnamed_addr constant [28 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local void @NativeInteger_encode_xer(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 ptr, align 8
  %15 = alloca [32 x i8], align 16
  %16 = alloca %struct.asn_enc_rval_s, align 8
  %17 = alloca ptr, align 8
  %18 = alloca ptr, align 8
  %19 = alloca i32, align 4
  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) #5
  %20 = load ptr, ptr %8, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.asn_TYPE_descriptor_s, ptr %20, i32 0, i32 19
  %22 = load ptr, ptr %21, align 8, !tbaa !11
  store ptr %22, ptr %14, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 32, ptr %15) #5
  call void @llvm.lifetime.start.p0(i64 24, ptr %16) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %17) #5
  %23 = load ptr, ptr %9, align 8, !tbaa !5
  store ptr %23, ptr %17, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %18) #5
  %24 = load ptr, ptr %14, align 8, !tbaa !5
  %25 = icmp ne ptr %24, null
  br i1 %25, label %26, label %31

26:                                               ; preds = %7
  %27 = load ptr, ptr %14, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.asn_INTEGER_specifics_s, ptr %27, i32 0, i32 6
  %29 = load i32, ptr %28, align 8, !tbaa !13
  %30 = icmp ne i32 %29, 0
  br label %31

31:                                               ; preds = %26, %7
  %32 = phi i1 [ false, %7 ], [ %30, %26 ]
  %33 = zext i1 %32 to i64
  %34 = select i1 %32, ptr @.str.2, ptr @.str.3
  store ptr %34, ptr %18, align 8, !tbaa !5
  %35 = load i32, ptr %10, align 4, !tbaa !9
  %36 = load i32, ptr %11, align 4, !tbaa !9
  %37 = load ptr, ptr %17, align 8, !tbaa !5
  %38 = icmp ne ptr %37, null
  br i1 %38, label %48, label %39

39:                                               ; preds = %31
  br label %40

40:                                               ; preds = %39
  %41 = getelementptr inbounds %struct.asn_enc_rval_s, ptr %0, i32 0, i32 0
  store i64 -1, ptr %41, align 8, !tbaa !15
  %42 = load ptr, ptr %8, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.asn_enc_rval_s, ptr %0, i32 0, i32 1
  store ptr %42, ptr %43, align 8, !tbaa !18
  %44 = load ptr, ptr %9, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.asn_enc_rval_s, ptr %0, i32 0, i32 2
  store ptr %44, ptr %45, align 8, !tbaa !19
  call void @stacktrace_create(ptr noundef @.str.1, i64 noundef 264, i32 noundef 101, ptr noundef null)
  store i32 1, ptr %19, align 4
  br label %86

46:                                               ; No predecessors!
  br label %47

47:                                               ; preds = %46
  br label %48

48:                                               ; preds = %47, %31
  %49 = getelementptr inbounds [32 x i8], ptr %15, i64 0, i64 0
  %50 = load ptr, ptr %18, align 8, !tbaa !5
  %51 = load ptr, ptr %17, align 8, !tbaa !5
  %52 = load i64, ptr %51, align 8, !tbaa !20
  %53 = call i32 (ptr, i64, ptr, ...) @snprintf(ptr noundef %49, i64 noundef 32, ptr noundef %50, i64 noundef %52) #5
  %54 = sext i32 %53 to i64
  %55 = getelementptr inbounds %struct.asn_enc_rval_s, ptr %16, i32 0, i32 0
  store i64 %54, ptr %55, align 8, !tbaa !15
  %56 = getelementptr inbounds %struct.asn_enc_rval_s, ptr %16, i32 0, i32 0
  %57 = load i64, ptr %56, align 8, !tbaa !15
  %58 = icmp sle i64 %57, 0
  br i1 %58, label %71, label %59

59:                                               ; preds = %48
  %60 = getelementptr inbounds %struct.asn_enc_rval_s, ptr %16, i32 0, i32 0
  %61 = load i64, ptr %60, align 8, !tbaa !15
  %62 = icmp uge i64 %61, 32
  br i1 %62, label %71, label %63

63:                                               ; preds = %59
  %64 = load ptr, ptr %12, align 8, !tbaa !5
  %65 = getelementptr inbounds [32 x i8], ptr %15, i64 0, i64 0
  %66 = getelementptr inbounds %struct.asn_enc_rval_s, ptr %16, i32 0, i32 0
  %67 = load i64, ptr %66, align 8, !tbaa !15
  %68 = load ptr, ptr %13, align 8, !tbaa !5
  %69 = call i32 %64(ptr noundef %65, i64 noundef %67, ptr noundef %68)
  %70 = icmp slt i32 %69, 0
  br i1 %70, label %71, label %80

71:                                               ; preds = %63, %59, %48
  br label %72

72:                                               ; preds = %71
  %73 = getelementptr inbounds %struct.asn_enc_rval_s, ptr %0, i32 0, i32 0
  store i64 -1, ptr %73, align 8, !tbaa !15
  %74 = load ptr, ptr %8, align 8, !tbaa !5
  %75 = getelementptr inbounds %struct.asn_enc_rval_s, ptr %0, i32 0, i32 1
  store ptr %74, ptr %75, align 8, !tbaa !18
  %76 = load ptr, ptr %9, align 8, !tbaa !5
  %77 = getelementptr inbounds %struct.asn_enc_rval_s, ptr %0, i32 0, i32 2
  store ptr %76, ptr %77, align 8, !tbaa !19
  call void @stacktrace_create(ptr noundef @.str.1, i64 noundef 270, i32 noundef 101, ptr noundef null)
  store i32 1, ptr %19, align 4
  br label %86

78:                                               ; No predecessors!
  br label %79

79:                                               ; preds = %78
  br label %80

80:                                               ; preds = %79, %63
  br label %81

81:                                               ; preds = %80
  %82 = getelementptr inbounds %struct.asn_enc_rval_s, ptr %16, i32 0, i32 2
  store ptr null, ptr %82, align 8, !tbaa !19
  %83 = getelementptr inbounds %struct.asn_enc_rval_s, ptr %16, i32 0, i32 1
  store ptr null, ptr %83, align 8, !tbaa !18
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %0, ptr align 8 %16, i64 24, i1 false), !tbaa.struct !21
  store i32 1, ptr %19, align 4
  br label %86

84:                                               ; No predecessors!
  br label %85

85:                                               ; preds = %84
  store i32 0, ptr %19, align 4
  br label %86

86:                                               ; preds = %85, %81, %72, %40
  call void @llvm.lifetime.end.p0(i64 8, ptr %18) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %17) #5
  call void @llvm.lifetime.end.p0(i64 24, ptr %16) #5
  call void @llvm.lifetime.end.p0(i64 32, ptr %15) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #5
  %87 = load i32, ptr %19, align 4
  switch i32 %87, label %89 [
    i32 0, label %88
    i32 1, label %88
  ]

88:                                               ; preds = %86, %86
  ret void

89:                                               ; preds = %86
  unreachable
}

; 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 @stacktrace_create(ptr noundef, i64 noundef, i32 noundef, ptr noundef) #3

; Function Attrs: nounwind
declare i32 @snprintf(ptr noundef, i64 noundef, 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 = { 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 "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, !6, i64 152}
!12 = !{!"asn_TYPE_descriptor_s", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !6, i64 88, !6, i64 96, !10, i64 104, !6, i64 112, !10, i64 120, !6, i64 128, !6, i64 136, !10, i64 144, !6, i64 152}
!13 = !{!14, !10, i64 32}
!14 = !{!"asn_INTEGER_specifics_s", !6, i64 0, !6, i64 8, !10, i64 16, !10, i64 20, !10, i64 24, !10, i64 28, !10, i64 32}
!15 = !{!16, !17, i64 0}
!16 = !{!"asn_enc_rval_s", !17, i64 0, !6, i64 8, !6, i64 16}
!17 = !{!"long", !7, i64 0}
!18 = !{!16, !6, i64 8}
!19 = !{!16, !6, i64 16}
!20 = !{!17, !17, i64 0}
!21 = !{i64 0, i64 8, !20, i64 8, i64 8, !5, i64 16, i64 8, !5}


; 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 }

@.str.1 = external hidden unnamed_addr constant [28 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [4 x i8], align 1

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

11:                                               ; preds = %7
  %12 = getelementptr inbounds i8, ptr %10, i64 32
  %13 = load i32, ptr %12, align 8, !tbaa !11
  %.not20 = icmp eq i32 %13, 0
  %14 = select i1 %.not20, ptr @.str.3, ptr @.str.2
  br label %15

15:                                               ; preds = %11, %7
  %16 = phi ptr [ @.str.3, %7 ], [ %14, %11 ]
  %.not21 = icmp eq ptr %2, null
  br i1 %.not21, label %17, label %20

17:                                               ; preds = %15
  store i64 -1, ptr %0, align 8, !tbaa !13
  %18 = getelementptr inbounds i8, ptr %0, i64 8
  store ptr %1, ptr %18, align 8, !tbaa !16
  %19 = getelementptr inbounds i8, ptr %0, i64 16
  store ptr null, ptr %19, align 8, !tbaa !17
  tail call void @stacktrace_create(ptr noundef nonnull @.str.1, i64 noundef 264, i32 noundef 101, ptr noundef null) #5
  br label %32

20:                                               ; preds = %15
  %21 = load i64, ptr %2, align 8, !tbaa !18
  %22 = call i32 (ptr, i64, ptr, ...) @snprintf(ptr noundef nonnull dereferenceable(1) %8, i64 noundef 32, ptr noundef nonnull %16, i64 noundef %21) #5
  %23 = sext i32 %22 to i64
  %24 = add i32 %22, -32
  %or.cond = icmp ult i32 %24, -31
  br i1 %or.cond, label %28, label %25

25:                                               ; preds = %20
  %26 = call i32 %5(ptr noundef nonnull %8, i64 noundef %23, ptr noundef %6) #5
  %27 = icmp slt i32 %26, 0
  br i1 %27, label %28, label %31

28:                                               ; preds = %20, %25
  store i64 -1, ptr %0, align 8, !tbaa !13
  %29 = getelementptr inbounds i8, ptr %0, i64 8
  store ptr %1, ptr %29, align 8, !tbaa !16
  %30 = getelementptr inbounds i8, ptr %0, i64 16
  store ptr %2, ptr %30, align 8, !tbaa !17
  call void @stacktrace_create(ptr noundef nonnull @.str.1, i64 noundef 270, i32 noundef 101, ptr noundef null) #5
  br label %32

31:                                               ; preds = %25
  store i64 %23, ptr %0, align 8, !tbaa !18
  %.sroa.7.0..sroa_idx = getelementptr inbounds i8, ptr %0, i64 8
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %.sroa.7.0..sroa_idx, i8 0, i64 16, i1 false)
  br label %32

32:                                               ; preds = %31, %28, %17
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %8) #5
  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 @stacktrace_create(ptr noundef, i64 noundef, i32 noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: nofree nounwind
declare noundef i32 @snprintf(ptr noalias nocapture noundef writeonly, i64 noundef, ptr nocapture noundef readonly, ...) 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 = { nofree 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: 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 152}
!6 = !{!"asn_TYPE_descriptor_s", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !7, i64 32, !7, i64 40, !7, i64 48, !7, i64 56, !7, i64 64, !7, i64 72, !7, i64 80, !7, i64 88, !7, i64 96, !10, i64 104, !7, i64 112, !10, i64 120, !7, i64 128, !7, i64 136, !10, i64 144, !7, i64 152}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!12, !10, i64 32}
!12 = !{!"asn_INTEGER_specifics_s", !7, i64 0, !7, i64 8, !10, i64 16, !10, i64 20, !10, i64 24, !10, i64 28, !10, i64 32}
!13 = !{!14, !15, i64 0}
!14 = !{!"asn_enc_rval_s", !15, i64 0, !7, i64 8, !7, i64 16}
!15 = !{!"long", !8, i64 0}
!16 = !{!14, !7, i64 8}
!17 = !{!14, !7, i64 16}
!18 = !{!15, !15, i64 0}


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