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

; 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.OCTET_STRING = 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 [24 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local void @BMPString_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 %struct.asn_enc_rval_s, align 8
  %16 = 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) #4
  %17 = load ptr, ptr %9, align 8, !tbaa !5
  store ptr %17, ptr %14, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 24, ptr %15) #4
  %18 = load i32, ptr %10, align 4, !tbaa !9
  %19 = load i32, ptr %11, align 4, !tbaa !9
  %20 = load ptr, ptr %14, align 8, !tbaa !5
  %21 = icmp ne ptr %20, null
  br i1 %21, label %22, label %27

22:                                               ; preds = %7
  %23 = load ptr, ptr %14, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.OCTET_STRING, ptr %23, i32 0, i32 0
  %25 = load ptr, ptr %24, align 8, !tbaa !11
  %26 = icmp ne ptr %25, null
  br i1 %26, label %36, label %27

27:                                               ; preds = %22, %7
  br label %28

28:                                               ; preds = %27
  %29 = getelementptr inbounds %struct.asn_enc_rval_s, ptr %0, i32 0, i32 0
  store i64 -1, ptr %29, align 8, !tbaa !16
  %30 = load ptr, ptr %8, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.asn_enc_rval_s, ptr %0, i32 0, i32 1
  store ptr %30, ptr %31, align 8, !tbaa !18
  %32 = load ptr, ptr %9, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.asn_enc_rval_s, ptr %0, i32 0, i32 2
  store ptr %32, ptr %33, align 8, !tbaa !19
  call void @stacktrace_create(ptr noundef @.str.1, i64 noundef 204, i32 noundef 101, ptr noundef null)
  store i32 1, ptr %16, align 4
  br label %60

34:                                               ; No predecessors!
  br label %35

35:                                               ; preds = %34
  br label %36

36:                                               ; preds = %35, %22
  %37 = load ptr, ptr %14, align 8, !tbaa !5
  %38 = load ptr, ptr %12, align 8, !tbaa !5
  %39 = load ptr, ptr %13, align 8, !tbaa !5
  %40 = call i64 @BMPString__dump(ptr noundef %37, ptr noundef %38, ptr noundef %39)
  %41 = getelementptr inbounds %struct.asn_enc_rval_s, ptr %15, i32 0, i32 0
  store i64 %40, ptr %41, align 8, !tbaa !16
  %42 = getelementptr inbounds %struct.asn_enc_rval_s, ptr %15, i32 0, i32 0
  %43 = load i64, ptr %42, align 8, !tbaa !16
  %44 = icmp slt i64 %43, 0
  br i1 %44, label %45, label %54

45:                                               ; preds = %36
  br label %46

46:                                               ; preds = %45
  %47 = getelementptr inbounds %struct.asn_enc_rval_s, ptr %0, i32 0, i32 0
  store i64 -1, ptr %47, align 8, !tbaa !16
  %48 = load ptr, ptr %8, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.asn_enc_rval_s, ptr %0, i32 0, i32 1
  store ptr %48, ptr %49, align 8, !tbaa !18
  %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 !19
  call void @stacktrace_create(ptr noundef @.str.1, i64 noundef 209, i32 noundef 101, ptr noundef null)
  store i32 1, ptr %16, align 4
  br label %60

52:                                               ; No predecessors!
  br label %53

53:                                               ; preds = %52
  br label %54

54:                                               ; preds = %53, %36
  br label %55

55:                                               ; preds = %54
  %56 = getelementptr inbounds %struct.asn_enc_rval_s, ptr %15, i32 0, i32 2
  store ptr null, ptr %56, align 8, !tbaa !19
  %57 = getelementptr inbounds %struct.asn_enc_rval_s, ptr %15, i32 0, i32 1
  store ptr null, ptr %57, align 8, !tbaa !18
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %0, ptr align 8 %15, i64 24, i1 false), !tbaa.struct !20
  store i32 1, ptr %16, align 4
  br label %60

58:                                               ; No predecessors!
  br label %59

59:                                               ; preds = %58
  store i32 0, ptr %16, align 4
  br label %60

60:                                               ; preds = %59, %55, %46, %28
  call void @llvm.lifetime.end.p0(i64 24, ptr %15) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #4
  %61 = load i32, ptr %16, align 4
  switch i32 %61, label %63 [
    i32 0, label %62
    i32 1, label %62
  ]

62:                                               ; preds = %60, %60
  ret void

63:                                               ; preds = %60
  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 uwtable
declare hidden i64 @BMPString__dump(ptr noundef, ptr noundef, ptr noundef) #0

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, !6, i64 0}
!12 = !{!"OCTET_STRING", !6, i64 0, !10, i64 8, !13, i64 16}
!13 = !{!"asn_struct_ctx_s", !14, i64 0, !14, i64 2, !10, i64 4, !6, i64 8, !15, i64 16}
!14 = !{!"short", !7, i64 0}
!15 = !{!"long", !7, i64 0}
!16 = !{!17, !15, i64 0}
!17 = !{!"asn_enc_rval_s", !15, i64 0, !6, i64 8, !6, i64 16}
!18 = !{!17, !6, i64 8}
!19 = !{!17, !6, i64 16}
!20 = !{i64 0, i64 8, !21, i64 8, i64 8, !5, i64 16, i64 8, !5}
!21 = !{!15, !15, 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.asn_enc_rval_s = type { i64, ptr, ptr }

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

; Function Attrs: nounwind uwtable
define dso_local void @BMPString_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 noundef %5, ptr noundef %6) local_unnamed_addr #0 {
  %.not = icmp eq ptr %2, null
  br i1 %.not, label %10, label %8

8:                                                ; preds = %7
  %9 = load ptr, ptr %2, align 8, !tbaa !5
  %.not12 = icmp eq ptr %9, null
  br i1 %.not12, label %10, label %13

10:                                               ; preds = %7, %8
  store i64 -1, ptr %0, align 8, !tbaa !14
  %11 = getelementptr inbounds i8, ptr %0, i64 8
  store ptr %1, ptr %11, align 8, !tbaa !16
  %12 = getelementptr inbounds i8, ptr %0, i64 16
  store ptr %2, ptr %12, align 8, !tbaa !17
  tail call void @stacktrace_create(ptr noundef nonnull @.str.1, i64 noundef 204, i32 noundef 101, ptr noundef null) #3
  br label %20

13:                                               ; preds = %8
  %14 = tail call i64 @BMPString__dump(ptr noundef nonnull %2, ptr noundef %5, ptr noundef %6)
  %15 = icmp slt i64 %14, 0
  %16 = getelementptr inbounds i8, ptr %0, i64 8
  br i1 %15, label %17, label %19

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

19:                                               ; preds = %13
  store i64 %14, ptr %0, align 8, !tbaa !18
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %16, i8 0, i64 16, i1 false)
  br label %20

20:                                               ; preds = %19, %17, %10
  ret void
}

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

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #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 = { "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 nounwind willreturn memory(argmem: write) }
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, !7, i64 0}
!6 = !{!"OCTET_STRING", !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 = !{!15, !13, i64 0}
!15 = !{!"asn_enc_rval_s", !13, i64 0, !7, i64 8, !7, i64 16}
!16 = !{!15, !7, i64 8}
!17 = !{!15, !7, i64 16}
!18 = !{!13, !13, i64 0}


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