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

; 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 @INTEGER_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 ptr, align 8
  %15 = alloca ptr, align 8
  %16 = alloca ptr, align 8
  %17 = alloca i32, align 4
  %18 = alloca ptr, align 8
  %19 = alloca ptr, 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) #3
  %20 = load ptr, ptr %9, align 8, !tbaa !5
  store ptr %20, ptr %14, align 8, !tbaa !5
  %21 = load ptr, ptr %14, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.ASN__PRIMITIVE_TYPE_s, ptr %21, i32 0, i32 0
  %23 = load ptr, ptr %22, align 8, !tbaa !11
  %24 = icmp ne ptr %23, null
  br i1 %24, label %25, label %107

25:                                               ; preds = %7
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #3
  %26 = load ptr, ptr %14, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.ASN__PRIMITIVE_TYPE_s, ptr %26, i32 0, i32 0
  %28 = load ptr, ptr %27, align 8, !tbaa !11
  store ptr %28, ptr %15, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #3
  %29 = load ptr, ptr %15, align 8, !tbaa !5
  %30 = load ptr, ptr %14, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.ASN__PRIMITIVE_TYPE_s, ptr %30, i32 0, i32 1
  %32 = load i32, ptr %31, align 8, !tbaa !13
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds i8, ptr %29, i64 %33
  %35 = getelementptr inbounds i8, ptr %34, i64 -1
  store ptr %35, ptr %16, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %17) #3
  br label %36

36:                                               ; preds = %63, %25
  %37 = load ptr, ptr %15, align 8, !tbaa !5
  %38 = load ptr, ptr %16, align 8, !tbaa !5
  %39 = icmp ult ptr %37, %38
  br i1 %39, label %40, label %66

40:                                               ; preds = %36
  %41 = load ptr, ptr %15, align 8, !tbaa !5
  %42 = load i8, ptr %41, align 1, !tbaa !14
  %43 = zext i8 %42 to i32
  switch i32 %43, label %62 [
    i32 0, label %44
    i32 255, label %53
  ]

44:                                               ; preds = %40
  %45 = load ptr, ptr %15, align 8, !tbaa !5
  %46 = getelementptr inbounds i8, ptr %45, i64 1
  %47 = load i8, ptr %46, align 1, !tbaa !14
  %48 = zext i8 %47 to i32
  %49 = and i32 %48, 128
  %50 = icmp eq i32 %49, 0
  br i1 %50, label %51, label %52

51:                                               ; preds = %44
  br label %63

52:                                               ; preds = %44
  br label %62

53:                                               ; preds = %40
  %54 = load ptr, ptr %15, align 8, !tbaa !5
  %55 = getelementptr inbounds i8, ptr %54, i64 1
  %56 = load i8, ptr %55, align 1, !tbaa !14
  %57 = zext i8 %56 to i32
  %58 = and i32 %57, 128
  %59 = icmp ne i32 %58, 0
  br i1 %59, label %60, label %61

60:                                               ; preds = %53
  br label %63

61:                                               ; preds = %53
  br label %62

62:                                               ; preds = %61, %52, %40
  br label %66

63:                                               ; preds = %60, %51
  %64 = load ptr, ptr %15, align 8, !tbaa !5
  %65 = getelementptr inbounds i8, ptr %64, i32 1
  store ptr %65, ptr %15, align 8, !tbaa !5
  br label %36, !llvm.loop !15

66:                                               ; preds = %62, %36
  %67 = load ptr, ptr %15, align 8, !tbaa !5
  %68 = load ptr, ptr %14, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.ASN__PRIMITIVE_TYPE_s, ptr %68, i32 0, i32 0
  %70 = load ptr, ptr %69, align 8, !tbaa !11
  %71 = ptrtoint ptr %67 to i64
  %72 = ptrtoint ptr %70 to i64
  %73 = sub i64 %71, %72
  %74 = trunc i64 %73 to i32
  store i32 %74, ptr %17, align 4, !tbaa !9
  %75 = load i32, ptr %17, align 4, !tbaa !9
  %76 = icmp ne i32 %75, 0
  br i1 %76, label %77, label %106

77:                                               ; preds = %66
  call void @llvm.lifetime.start.p0(i64 8, ptr %18) #3
  %78 = load ptr, ptr %14, align 8, !tbaa !5
  %79 = getelementptr inbounds %struct.ASN__PRIMITIVE_TYPE_s, ptr %78, i32 0, i32 0
  %80 = load ptr, ptr %79, align 8, !tbaa !11
  store ptr %80, ptr %18, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %19) #3
  %81 = load i32, ptr %17, align 4, !tbaa !9
  %82 = load ptr, ptr %14, align 8, !tbaa !5
  %83 = getelementptr inbounds %struct.ASN__PRIMITIVE_TYPE_s, ptr %82, i32 0, i32 1
  %84 = load i32, ptr %83, align 8, !tbaa !13
  %85 = sub nsw i32 %84, %81
  store i32 %85, ptr %83, align 8, !tbaa !13
  %86 = load ptr, ptr %18, align 8, !tbaa !5
  %87 = load ptr, ptr %14, align 8, !tbaa !5
  %88 = getelementptr inbounds %struct.ASN__PRIMITIVE_TYPE_s, ptr %87, i32 0, i32 1
  %89 = load i32, ptr %88, align 8, !tbaa !13
  %90 = sext i32 %89 to i64
  %91 = getelementptr inbounds i8, ptr %86, i64 %90
  store ptr %91, ptr %19, align 8, !tbaa !5
  br label %92

92:                                               ; preds = %100, %77
  %93 = load ptr, ptr %18, align 8, !tbaa !5
  %94 = load ptr, ptr %19, align 8, !tbaa !5
  %95 = icmp ult ptr %93, %94
  br i1 %95, label %96, label %105

96:                                               ; preds = %92
  %97 = load ptr, ptr %15, align 8, !tbaa !5
  %98 = load i8, ptr %97, align 1, !tbaa !14
  %99 = load ptr, ptr %18, align 8, !tbaa !5
  store i8 %98, ptr %99, align 1, !tbaa !14
  br label %100

100:                                              ; preds = %96
  %101 = load ptr, ptr %18, align 8, !tbaa !5
  %102 = getelementptr inbounds i8, ptr %101, i32 1
  store ptr %102, ptr %18, align 8, !tbaa !5
  %103 = load ptr, ptr %15, align 8, !tbaa !5
  %104 = getelementptr inbounds i8, ptr %103, i32 1
  store ptr %104, ptr %15, align 8, !tbaa !5
  br label %92, !llvm.loop !17

105:                                              ; preds = %92
  call void @llvm.lifetime.end.p0(i64 8, ptr %19) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %18) #3
  br label %106

106:                                              ; preds = %105, %66
  call void @llvm.lifetime.end.p0(i64 4, ptr %17) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #3
  br label %107

107:                                              ; preds = %106, %7
  %108 = load ptr, ptr %8, align 8, !tbaa !5
  %109 = load ptr, ptr %9, align 8, !tbaa !5
  %110 = load i32, ptr %10, align 4, !tbaa !9
  %111 = load i32, ptr %11, align 4, !tbaa !9
  %112 = load ptr, ptr %12, align 8, !tbaa !5
  %113 = load ptr, ptr %13, align 8, !tbaa !5
  call void @der_encode_primitive(ptr dead_on_unwind writable sret(%struct.asn_enc_rval_s) align 8 %0, ptr noundef %108, ptr noundef %109, i32 noundef %110, i32 noundef %111, ptr noundef %112, ptr noundef %113)
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #3
  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 nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

declare void @der_encode_primitive(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) #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 = { 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 = !{!"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 = !{!"ASN__PRIMITIVE_TYPE_s", !6, i64 0, !10, i64 8}
!13 = !{!12, !10, i64 8}
!14 = !{!7, !7, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = distinct !{!17, !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 }

; Function Attrs: nounwind uwtable
define dso_local void @INTEGER_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) local_unnamed_addr #0 {
  %8 = load ptr, ptr %2, align 8, !tbaa !5
  %.not = icmp eq ptr %8, null
  br i1 %.not, label %.loopexit, label %9

9:                                                ; preds = %7
  %10 = getelementptr inbounds i8, ptr %2, i64 8
  %11 = load i32, ptr %10, align 8, !tbaa !11
  %12 = sext i32 %11 to i64
  %13 = getelementptr inbounds i8, ptr %8, i64 %12
  %14 = getelementptr inbounds i8, ptr %13, i64 -1
  %15 = icmp ult ptr %8, %14
  br i1 %15, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %9
  %.pre = load i8, ptr %8, align 1, !tbaa !12
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %24
  %16 = phi i8 [ %25, %24 ], [ %.pre, %.lr.ph.preheader ]
  %.035 = phi ptr [ %26, %24 ], [ %8, %.lr.ph.preheader ]
  switch i8 %16, label %._crit_edge [
    i8 0, label %17
    i8 -1, label %21
  ]

17:                                               ; preds = %.lr.ph
  %18 = getelementptr inbounds i8, ptr %.035, i64 1
  %19 = load i8, ptr %18, align 1, !tbaa !12
  %20 = icmp sgt i8 %19, -1
  br i1 %20, label %24, label %._crit_edge

21:                                               ; preds = %.lr.ph
  %22 = getelementptr inbounds i8, ptr %.035, i64 1
  %23 = load i8, ptr %22, align 1, !tbaa !12
  %.not33 = icmp sgt i8 %23, -1
  br i1 %.not33, label %._crit_edge, label %24

24:                                               ; preds = %21, %17
  %25 = phi i8 [ %23, %21 ], [ %19, %17 ]
  %26 = getelementptr inbounds i8, ptr %.035, i64 1
  %exitcond.not = icmp eq ptr %26, %14
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !13

._crit_edge:                                      ; preds = %24, %21, %17, %.lr.ph, %9
  %.0.lcssa = phi ptr [ %8, %9 ], [ %.035, %.lr.ph ], [ %.035, %17 ], [ %.035, %21 ], [ %14, %24 ]
  %27 = ptrtoint ptr %.0.lcssa to i64
  %28 = ptrtoint ptr %8 to i64
  %29 = sub i64 %27, %28
  %30 = trunc i64 %29 to i32
  %.not34 = icmp eq i32 %30, 0
  br i1 %.not34, label %.loopexit, label %31

31:                                               ; preds = %._crit_edge
  %32 = sub nsw i32 %11, %30
  store i32 %32, ptr %10, align 8, !tbaa !11
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds i8, ptr %8, i64 %33
  %35 = icmp sgt i32 %32, 0
  br i1 %35, label %iter.check, label %.loopexit

iter.check:                                       ; preds = %31
  %36 = add i64 %28, %12
  %sext = shl i64 %29, 32
  %37 = ashr exact i64 %sext, 32
  %38 = sub i64 %36, %37
  %39 = add i64 %28, 1
  %umax = tail call i64 @llvm.umax.i64(i64 %38, i64 %39)
  %40 = sub i64 %umax, %28
  %min.iters.check = icmp ult i64 %40, 8
  %41 = sub i64 %28, %27
  %diff.check = icmp ult i64 %41, 32
  %or.cond = or i1 %min.iters.check, %diff.check
  br i1 %or.cond, label %.lr.ph45.preheader, label %vector.main.loop.iter.check

vector.main.loop.iter.check:                      ; preds = %iter.check
  %min.iters.check46 = icmp ult i64 %40, 32
  br i1 %min.iters.check46, label %vec.epilog.ph, label %vector.ph

vector.ph:                                        ; preds = %vector.main.loop.iter.check
  %n.vec = and i64 %40, -32
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %next.gep = getelementptr i8, ptr %.0.lcssa, i64 %index
  %next.gep48 = getelementptr i8, ptr %8, i64 %index
  %42 = getelementptr i8, ptr %next.gep, i64 16
  %wide.load = load <16 x i8>, ptr %next.gep, align 1, !tbaa !12
  %wide.load50 = load <16 x i8>, ptr %42, align 1, !tbaa !12
  %43 = getelementptr i8, ptr %next.gep48, i64 16
  store <16 x i8> %wide.load, ptr %next.gep48, align 1, !tbaa !12
  store <16 x i8> %wide.load50, ptr %43, align 1, !tbaa !12
  %index.next = add nuw i64 %index, 32
  %44 = icmp eq i64 %index.next, %n.vec
  br i1 %44, label %middle.block, label %vector.body, !llvm.loop !15

middle.block:                                     ; preds = %vector.body
  %cmp.n = icmp eq i64 %40, %n.vec
  br i1 %cmp.n, label %.loopexit, label %vec.epilog.iter.check

vec.epilog.iter.check:                            ; preds = %middle.block
  %ind.end55 = getelementptr i8, ptr %8, i64 %n.vec
  %ind.end53 = getelementptr i8, ptr %.0.lcssa, i64 %n.vec
  %n.vec.remaining = and i64 %40, 24
  %min.epilog.iters.check = icmp eq i64 %n.vec.remaining, 0
  br i1 %min.epilog.iters.check, label %.lr.ph45.preheader, label %vec.epilog.ph

vec.epilog.ph:                                    ; preds = %vector.main.loop.iter.check, %vec.epilog.iter.check
  %vec.epilog.resume.val = phi i64 [ %n.vec, %vec.epilog.iter.check ], [ 0, %vector.main.loop.iter.check ]
  %n.vec52 = and i64 %40, -8
  %ind.end = getelementptr i8, ptr %.0.lcssa, i64 %n.vec52
  %ind.end54 = getelementptr i8, ptr %8, i64 %n.vec52
  br label %vec.epilog.vector.body

vec.epilog.vector.body:                           ; preds = %vec.epilog.vector.body, %vec.epilog.ph
  %index57 = phi i64 [ %vec.epilog.resume.val, %vec.epilog.ph ], [ %index.next61, %vec.epilog.vector.body ]
  %next.gep58 = getelementptr i8, ptr %.0.lcssa, i64 %index57
  %next.gep59 = getelementptr i8, ptr %8, i64 %index57
  %wide.load60 = load <8 x i8>, ptr %next.gep58, align 1, !tbaa !12
  store <8 x i8> %wide.load60, ptr %next.gep59, align 1, !tbaa !12
  %index.next61 = add nuw i64 %index57, 8
  %45 = icmp eq i64 %index.next61, %n.vec52
  br i1 %45, label %vec.epilog.middle.block, label %vec.epilog.vector.body, !llvm.loop !18

vec.epilog.middle.block:                          ; preds = %vec.epilog.vector.body
  %cmp.n62 = icmp eq i64 %40, %n.vec52
  br i1 %cmp.n62, label %.loopexit, label %.lr.ph45.preheader

.lr.ph45.preheader:                               ; preds = %vec.epilog.middle.block, %iter.check, %vec.epilog.iter.check
  %.143.ph = phi ptr [ %.0.lcssa, %iter.check ], [ %ind.end53, %vec.epilog.iter.check ], [ %ind.end, %vec.epilog.middle.block ]
  %.03042.ph = phi ptr [ %8, %iter.check ], [ %ind.end55, %vec.epilog.iter.check ], [ %ind.end54, %vec.epilog.middle.block ]
  br label %.lr.ph45

.lr.ph45:                                         ; preds = %.lr.ph45.preheader, %.lr.ph45
  %.143 = phi ptr [ %48, %.lr.ph45 ], [ %.143.ph, %.lr.ph45.preheader ]
  %.03042 = phi ptr [ %47, %.lr.ph45 ], [ %.03042.ph, %.lr.ph45.preheader ]
  %46 = load i8, ptr %.143, align 1, !tbaa !12
  store i8 %46, ptr %.03042, align 1, !tbaa !12
  %47 = getelementptr inbounds i8, ptr %.03042, i64 1
  %48 = getelementptr inbounds i8, ptr %.143, i64 1
  %49 = icmp ult ptr %47, %34
  br i1 %49, label %.lr.ph45, label %.loopexit, !llvm.loop !19

.loopexit:                                        ; preds = %.lr.ph45, %middle.block, %vec.epilog.middle.block, %31, %._crit_edge, %7
  tail call void @der_encode_primitive(ptr dead_on_unwind writable sret(%struct.asn_enc_rval_s) align 8 %0, ptr noundef %1, ptr noundef nonnull %2, i32 noundef %3, i32 noundef %4, ptr noundef %5, ptr noundef %6) #3
  ret void
}

declare void @der_encode_primitive(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 #1

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.umax.i64(i64, i64) #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 nosync nounwind speculatable willreturn memory(none) }
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 = !{!"ASN__PRIMITIVE_TYPE_s", !7, i64 0, !10, i64 8}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!6, !10, i64 8}
!12 = !{!8, !8, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14, !16, !17}
!16 = !{!"llvm.loop.isvectorized", i32 1}
!17 = !{!"llvm.loop.unroll.runtime.disable"}
!18 = distinct !{!18, !14, !16, !17}
!19 = distinct !{!19, !14, !16}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LCSSAPass,LoopLoadEliminationPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,LoopVectorizePass,SROAPass,SimplifyCFGPass,TailCallElimPass