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

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

; Function Attrs: nounwind uwtable
define dso_local { i32, i64 } @UniversalString_decode_xer(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3, ptr noundef %4, i64 noundef %5) #0 {
  %7 = alloca %struct.asn_dec_rval_s, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca i64, align 8
  %14 = alloca %struct.asn_dec_rval_s, align 8
  %15 = alloca ptr, align 8
  %16 = alloca i64, align 8
  %17 = alloca ptr, align 8
  %18 = alloca i32, align 4
  %19 = alloca i32, align 4
  %20 = alloca ptr, align 8
  %21 = alloca ptr, align 8
  %22 = alloca i32, align 4
  store ptr %0, ptr %8, align 8, !tbaa !5
  store ptr %1, ptr %9, align 8, !tbaa !5
  store ptr %2, ptr %10, align 8, !tbaa !5
  store ptr %3, ptr %11, align 8, !tbaa !5
  store ptr %4, ptr %12, align 8, !tbaa !5
  store i64 %5, ptr %13, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 16, ptr %14) #6
  %23 = load ptr, ptr %8, align 8, !tbaa !5
  %24 = load ptr, ptr %9, align 8, !tbaa !5
  %25 = load ptr, ptr %10, align 8, !tbaa !5
  %26 = load ptr, ptr %11, align 8, !tbaa !5
  %27 = load ptr, ptr %12, align 8, !tbaa !5
  %28 = load i64, ptr %13, align 8, !tbaa !9
  %29 = call { i32, i64 } @OCTET_STRING_decode_xer_utf8(ptr noundef %23, ptr noundef %24, ptr noundef %25, ptr noundef %26, ptr noundef %27, i64 noundef %28)
  %30 = getelementptr inbounds { i32, i64 }, ptr %14, i32 0, i32 0
  %31 = extractvalue { i32, i64 } %29, 0
  store i32 %31, ptr %30, align 8
  %32 = getelementptr inbounds { i32, i64 }, ptr %14, i32 0, i32 1
  %33 = extractvalue { i32, i64 } %29, 1
  store i64 %33, ptr %32, align 8
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %7, ptr align 8 %14, i64 16, i1 false), !tbaa.struct !11
  call void @llvm.lifetime.end.p0(i64 16, ptr %14) #6
  %34 = getelementptr inbounds %struct.asn_dec_rval_s, ptr %7, i32 0, i32 0
  %35 = load i32, ptr %34, align 8, !tbaa !14
  %36 = icmp eq i32 %35, 0
  br i1 %36, label %37, label %117

37:                                               ; preds = %6
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #6
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #6
  call void @llvm.lifetime.start.p0(i64 8, ptr %17) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr %18) #6
  store i32 1, ptr %18, align 4, !tbaa !12
  %38 = load ptr, ptr %10, align 8, !tbaa !5
  %39 = load ptr, ptr %38, align 8, !tbaa !5
  store ptr %39, ptr %17, align 8, !tbaa !5
  %40 = load ptr, ptr %17, align 8, !tbaa !5
  %41 = call i64 @UTF8String_to_wcs(ptr noundef %40, ptr noundef null, i64 noundef 0)
  store i64 %41, ptr %16, align 8, !tbaa !9
  %42 = load i64, ptr %16, align 8, !tbaa !9
  %43 = add i64 %42, 1
  %44 = mul i64 4, %43
  %45 = call noalias ptr @malloc(i64 noundef %44) #7
  store ptr %45, ptr %15, align 8, !tbaa !5
  %46 = load ptr, ptr %15, align 8, !tbaa !5
  %47 = icmp eq ptr %46, null
  br i1 %47, label %55, label %48

48:                                               ; preds = %37
  %49 = load ptr, ptr %17, align 8, !tbaa !5
  %50 = load ptr, ptr %15, align 8, !tbaa !5
  %51 = load i64, ptr %16, align 8, !tbaa !9
  %52 = call i64 @UTF8String_to_wcs(ptr noundef %49, ptr noundef %50, i64 noundef %51)
  %53 = load i64, ptr %16, align 8, !tbaa !9
  %54 = icmp ne i64 %52, %53
  br i1 %54, label %55, label %58

55:                                               ; preds = %48, %37
  %56 = getelementptr inbounds %struct.asn_dec_rval_s, ptr %7, i32 0, i32 0
  store i32 2, ptr %56, align 8, !tbaa !14
  %57 = getelementptr inbounds %struct.asn_dec_rval_s, ptr %7, i32 0, i32 1
  store i64 0, ptr %57, align 8, !tbaa !16
  store i32 1, ptr %19, align 4
  br label %114

58:                                               ; preds = %48
  %59 = load ptr, ptr %15, align 8, !tbaa !5
  %60 = load i64, ptr %16, align 8, !tbaa !9
  %61 = getelementptr inbounds i32, ptr %59, i64 %60
  store i32 0, ptr %61, align 4, !tbaa !12
  br label %62

62:                                               ; preds = %58
  %63 = load i8, ptr %18, align 4, !tbaa !17
  %64 = icmp ne i8 %63, 0
  br i1 %64, label %65, label %100

65:                                               ; preds = %62
  call void @llvm.lifetime.start.p0(i64 8, ptr %20) #6
  %66 = load ptr, ptr %15, align 8, !tbaa !5
  store ptr %66, ptr %20, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %21) #6
  %67 = load ptr, ptr %15, align 8, !tbaa !5
  %68 = load i64, ptr %16, align 8, !tbaa !9
  %69 = getelementptr inbounds i32, ptr %67, i64 %68
  store ptr %69, ptr %21, align 8, !tbaa !5
  br label %70

70:                                               ; preds = %96, %65
  %71 = load ptr, ptr %20, align 8, !tbaa !5
  %72 = load ptr, ptr %21, align 8, !tbaa !5
  %73 = icmp ult ptr %71, %72
  br i1 %73, label %74, label %99

74:                                               ; preds = %70
  call void @llvm.lifetime.start.p0(i64 4, ptr %22) #6
  %75 = load ptr, ptr %20, align 8, !tbaa !5
  %76 = load i32, ptr %75, align 4, !tbaa !12
  store i32 %76, ptr %22, align 4, !tbaa !12
  %77 = load i32, ptr %22, align 4, !tbaa !12
  %78 = lshr i32 %77, 24
  %79 = trunc i32 %78 to i8
  %80 = load ptr, ptr %20, align 8, !tbaa !5
  %81 = getelementptr inbounds i8, ptr %80, i64 0
  store i8 %79, ptr %81, align 1, !tbaa !17
  %82 = load i32, ptr %22, align 4, !tbaa !12
  %83 = lshr i32 %82, 16
  %84 = trunc i32 %83 to i8
  %85 = load ptr, ptr %20, align 8, !tbaa !5
  %86 = getelementptr inbounds i8, ptr %85, i64 1
  store i8 %84, ptr %86, align 1, !tbaa !17
  %87 = load i32, ptr %22, align 4, !tbaa !12
  %88 = lshr i32 %87, 8
  %89 = trunc i32 %88 to i8
  %90 = load ptr, ptr %20, align 8, !tbaa !5
  %91 = getelementptr inbounds i8, ptr %90, i64 2
  store i8 %89, ptr %91, align 1, !tbaa !17
  %92 = load i32, ptr %22, align 4, !tbaa !12
  %93 = trunc i32 %92 to i8
  %94 = load ptr, ptr %20, align 8, !tbaa !5
  %95 = getelementptr inbounds i8, ptr %94, i64 3
  store i8 %93, ptr %95, align 1, !tbaa !17
  call void @llvm.lifetime.end.p0(i64 4, ptr %22) #6
  br label %96

96:                                               ; preds = %74
  %97 = load ptr, ptr %20, align 8, !tbaa !5
  %98 = getelementptr inbounds i32, ptr %97, i32 1
  store ptr %98, ptr %20, align 8, !tbaa !5
  br label %70, !llvm.loop !18

99:                                               ; preds = %70
  call void @llvm.lifetime.end.p0(i64 8, ptr %21) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %20) #6
  br label %100

100:                                              ; preds = %99, %62
  %101 = load ptr, ptr %17, align 8, !tbaa !5
  %102 = getelementptr inbounds %struct.OCTET_STRING, ptr %101, i32 0, i32 0
  %103 = load ptr, ptr %102, align 8, !tbaa !20
  call void @free(ptr noundef %103) #6
  %104 = load ptr, ptr %17, align 8, !tbaa !5
  %105 = getelementptr inbounds %struct.OCTET_STRING, ptr %104, i32 0, i32 0
  store ptr null, ptr %105, align 8, !tbaa !20
  %106 = load ptr, ptr %15, align 8, !tbaa !5
  %107 = load ptr, ptr %17, align 8, !tbaa !5
  %108 = getelementptr inbounds %struct.OCTET_STRING, ptr %107, i32 0, i32 0
  store ptr %106, ptr %108, align 8, !tbaa !20
  %109 = load i64, ptr %16, align 8, !tbaa !9
  %110 = mul i64 4, %109
  %111 = trunc i64 %110 to i32
  %112 = load ptr, ptr %17, align 8, !tbaa !5
  %113 = getelementptr inbounds %struct.OCTET_STRING, ptr %112, i32 0, i32 1
  store i32 %111, ptr %113, align 8, !tbaa !24
  store i32 0, ptr %19, align 4
  br label %114

114:                                              ; preds = %100, %55
  call void @llvm.lifetime.end.p0(i64 4, ptr %18) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %17) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #6
  %115 = load i32, ptr %19, align 4
  switch i32 %115, label %120 [
    i32 0, label %116
    i32 1, label %118
  ]

116:                                              ; preds = %114
  br label %117

117:                                              ; preds = %116, %6
  br label %118

118:                                              ; preds = %117, %114
  %119 = load { i32, i64 }, ptr %7, align 8
  ret { i32, i64 } %119

120:                                              ; preds = %114
  unreachable
}

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

declare { i32, i64 } @OCTET_STRING_decode_xer_utf8(ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef, i64 noundef) #2

; 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

declare i64 @UTF8String_to_wcs(ptr noundef, ptr noundef, i64 noundef) #2

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #4

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

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 allocsize(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 #5 = { 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 #6 = { nounwind }
attributes #7 = { nounwind allocsize(0) }

!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 = !{!"long", !7, i64 0}
!11 = !{i64 0, i64 4, !12, i64 8, i64 8, !9}
!12 = !{!13, !13, i64 0}
!13 = !{!"int", !7, i64 0}
!14 = !{!15, !13, i64 0}
!15 = !{!"asn_dec_rval_s", !13, i64 0, !10, i64 8}
!16 = !{!15, !10, i64 8}
!17 = !{!7, !7, i64 0}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}
!20 = !{!21, !6, i64 0}
!21 = !{!"OCTET_STRING", !6, i64 0, !13, i64 8, !22, i64 16}
!22 = !{!"asn_struct_ctx_s", !23, i64 0, !23, i64 2, !13, i64 4, !6, i64 8, !10, i64 16}
!23 = !{!"short", !7, i64 0}
!24 = !{!21, !13, i64 8}


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

; Function Attrs: nounwind uwtable
define dso_local { i32, i64 } @UniversalString_decode_xer(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3, ptr noundef %4, i64 noundef %5) local_unnamed_addr #0 {
  %7 = tail call { i32, i64 } @OCTET_STRING_decode_xer_utf8(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3, ptr noundef %4, i64 noundef %5) #4
  %8 = extractvalue { i32, i64 } %7, 0
  %9 = extractvalue { i32, i64 } %7, 1
  %10 = icmp eq i32 %8, 0
  br i1 %10, label %11, label %39

11:                                               ; preds = %6
  %12 = load ptr, ptr %2, align 8, !tbaa !5
  %13 = tail call i64 @UTF8String_to_wcs(ptr noundef %12, ptr noundef null, i64 noundef 0) #4
  %14 = shl i64 %13, 2
  %15 = add i64 %14, 4
  %16 = tail call noalias ptr @malloc(i64 noundef %15) #5
  %17 = icmp eq ptr %16, null
  br i1 %17, label %39, label %18

18:                                               ; preds = %11
  %19 = tail call i64 @UTF8String_to_wcs(ptr noundef %12, ptr noundef nonnull %16, i64 noundef %13) #4
  %.not = icmp eq i64 %19, %13
  br i1 %.not, label %20, label %39

20:                                               ; preds = %18
  %21 = getelementptr inbounds i32, ptr %16, i64 %13
  store i32 0, ptr %21, align 4, !tbaa !9
  %22 = icmp sgt i64 %13, 0
  br i1 %22, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %20, %.lr.ph
  %.044 = phi ptr [ %34, %.lr.ph ], [ %16, %20 ]
  %23 = load i32, ptr %.044, align 4, !tbaa !9
  %24 = lshr i32 %23, 24
  %25 = trunc nuw i32 %24 to i8
  store i8 %25, ptr %.044, align 1, !tbaa !11
  %26 = lshr i32 %23, 16
  %27 = trunc i32 %26 to i8
  %28 = getelementptr inbounds i8, ptr %.044, i64 1
  store i8 %27, ptr %28, align 1, !tbaa !11
  %29 = lshr i32 %23, 8
  %30 = trunc i32 %29 to i8
  %31 = getelementptr inbounds i8, ptr %.044, i64 2
  store i8 %30, ptr %31, align 1, !tbaa !11
  %32 = trunc i32 %23 to i8
  %33 = getelementptr inbounds i8, ptr %.044, i64 3
  store i8 %32, ptr %33, align 1, !tbaa !11
  %34 = getelementptr inbounds i8, ptr %.044, i64 4
  %35 = icmp ult ptr %34, %21
  br i1 %35, label %.lr.ph, label %._crit_edge, !llvm.loop !12

._crit_edge:                                      ; preds = %.lr.ph, %20
  %36 = load ptr, ptr %12, align 8, !tbaa !14
  tail call void @free(ptr noundef %36) #4
  store ptr %16, ptr %12, align 8, !tbaa !14
  %.tr = trunc i64 %13 to i32
  %37 = shl i32 %.tr, 2
  %38 = getelementptr inbounds i8, ptr %12, i64 8
  store i32 %37, ptr %38, align 8, !tbaa !19
  br label %39

39:                                               ; preds = %._crit_edge, %18, %11, %6
  %.sroa.038.1 = phi i32 [ %8, %6 ], [ 0, %._crit_edge ], [ 2, %18 ], [ 2, %11 ]
  %.sroa.5.1 = phi i64 [ %9, %6 ], [ %9, %._crit_edge ], [ 0, %18 ], [ 0, %11 ]
  %.fca.0.insert = insertvalue { i32, i64 } poison, i32 %.sroa.038.1, 0
  %.fca.1.insert = insertvalue { i32, i64 } %.fca.0.insert, i64 %.sroa.5.1, 1
  ret { i32, i64 } %.fca.1.insert
}

declare { i32, i64 } @OCTET_STRING_decode_xer_utf8(ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #1

declare i64 @UTF8String_to_wcs(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #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 = { "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 nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(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 #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 = { nounwind }
attributes #5 = { nounwind allocsize(0) }

!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 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = !{!15, !6, i64 0}
!15 = !{!"OCTET_STRING", !6, i64 0, !10, i64 8, !16, i64 16}
!16 = !{!"asn_struct_ctx_s", !17, i64 0, !17, i64 2, !10, i64 4, !6, i64 8, !18, i64 16}
!17 = !{!"short", !7, i64 0}
!18 = !{!"long", !7, i64 0}
!19 = !{!15, !10, i64 8}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass