; 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__PRIMITIVE_TYPE_s = type { ptr, i32 }

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

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

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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @asn_ulong2INTEGER(ptr noundef %0, i64 noundef %1) #3 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i64 %1, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  %11 = load i64, ptr %5, align 8, !tbaa !9
  %12 = icmp ule i64 %11, 9223372036854775807
  br i1 %12, label %13, label %17

13:                                               ; preds = %2
  %14 = load ptr, ptr %4, align 8, !tbaa !5
  %15 = load i64, ptr %5, align 8, !tbaa !9
  %16 = call i32 @asn_long2INTEGER(ptr noundef %14, i64 noundef %15)
  store i32 %16, ptr %3, align 4
  store i32 1, ptr %10, align 4
  br label %62

17:                                               ; preds = %2
  %18 = call noalias ptr @malloc(i64 noundef 9) #5
  store ptr %18, ptr %6, align 8, !tbaa !5
  %19 = load ptr, ptr %6, align 8, !tbaa !5
  %20 = icmp ne ptr %19, null
  br i1 %20, label %22, label %21

21:                                               ; preds = %17
  store i32 -1, ptr %3, align 4
  store i32 1, ptr %10, align 4
  br label %62

22:                                               ; preds = %17
  %23 = load ptr, ptr %6, align 8, !tbaa !5
  %24 = getelementptr inbounds i8, ptr %23, i64 9
  store ptr %24, ptr %7, align 8, !tbaa !5
  %25 = load ptr, ptr %6, align 8, !tbaa !5
  %26 = getelementptr inbounds i8, ptr %25, i64 0
  store i8 0, ptr %26, align 1, !tbaa !11
  %27 = load ptr, ptr %6, align 8, !tbaa !5
  %28 = getelementptr inbounds i8, ptr %27, i64 1
  store ptr %28, ptr %8, align 8, !tbaa !5
  store i32 56, ptr %9, align 4, !tbaa !12
  br label %29

29:                                               ; preds = %40, %22
  %30 = load ptr, ptr %8, align 8, !tbaa !5
  %31 = load ptr, ptr %7, align 8, !tbaa !5
  %32 = icmp ult ptr %30, %31
  br i1 %32, label %33, label %45

33:                                               ; preds = %29
  %34 = load i64, ptr %5, align 8, !tbaa !9
  %35 = load i32, ptr %9, align 4, !tbaa !12
  %36 = zext i32 %35 to i64
  %37 = lshr i64 %34, %36
  %38 = trunc i64 %37 to i8
  %39 = load ptr, ptr %8, align 8, !tbaa !5
  store i8 %38, ptr %39, align 1, !tbaa !11
  br label %40

40:                                               ; preds = %33
  %41 = load i32, ptr %9, align 4, !tbaa !12
  %42 = sub nsw i32 %41, 8
  store i32 %42, ptr %9, align 4, !tbaa !12
  %43 = load ptr, ptr %8, align 8, !tbaa !5
  %44 = getelementptr inbounds i8, ptr %43, i32 1
  store ptr %44, ptr %8, align 8, !tbaa !5
  br label %29, !llvm.loop !14

45:                                               ; preds = %29
  %46 = load ptr, ptr %4, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.ASN__PRIMITIVE_TYPE_s, ptr %46, i32 0, i32 0
  %48 = load ptr, ptr %47, align 8, !tbaa !16
  %49 = icmp ne ptr %48, null
  br i1 %49, label %50, label %56

50:                                               ; preds = %45
  %51 = load ptr, ptr %4, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.ASN__PRIMITIVE_TYPE_s, ptr %51, i32 0, i32 0
  %53 = load ptr, ptr %52, align 8, !tbaa !16
  call void @free(ptr noundef %53) #4
  %54 = load ptr, ptr %4, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.ASN__PRIMITIVE_TYPE_s, ptr %54, i32 0, i32 0
  store ptr null, ptr %55, align 8, !tbaa !16
  br label %56

56:                                               ; preds = %50, %45
  %57 = load ptr, ptr %6, align 8, !tbaa !5
  %58 = load ptr, ptr %4, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.ASN__PRIMITIVE_TYPE_s, ptr %58, i32 0, i32 0
  store ptr %57, ptr %59, align 8, !tbaa !16
  %60 = load ptr, ptr %4, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.ASN__PRIMITIVE_TYPE_s, ptr %60, i32 0, i32 1
  store i32 9, ptr %61, align 8, !tbaa !18
  store i32 0, ptr %3, align 4
  store i32 1, ptr %10, align 4
  br label %62

62:                                               ; preds = %56, %21, %13
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  %63 = load i32, ptr %3, align 4
  ret i32 %63
}

; Function Attrs: nounwind uwtable
declare dso_local i32 @asn_long2INTEGER(ptr noundef, i64 noundef) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { 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 #3 = { 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 #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 = !{!"long", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"int", !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = !{!17, !6, i64 0}
!17 = !{!"ASN__PRIMITIVE_TYPE_s", !6, i64 0, !13, i64 8}
!18 = !{!17, !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: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #0

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

; Function Attrs: nounwind uwtable
define dso_local i32 @asn_ulong2INTEGER(ptr noundef %0, i64 noundef %1) local_unnamed_addr #2 {
  %3 = icmp sgt i64 %1, -1
  br i1 %3, label %4, label %6

4:                                                ; preds = %2
  %5 = tail call i32 @asn_long2INTEGER(ptr noundef %0, i64 noundef %1)
  br label %28

6:                                                ; preds = %2
  %7 = tail call noalias dereferenceable_or_null(9) ptr @malloc(i64 noundef 9) #3
  %.not = icmp eq ptr %7, null
  br i1 %.not, label %28, label %8

8:                                                ; preds = %6
  store i8 0, ptr %7, align 1, !tbaa !5
  %.020.ptr = getelementptr inbounds i8, ptr %7, i64 1
  %9 = lshr i64 %1, 56
  %10 = trunc nuw i64 %9 to i8
  store i8 %10, ptr %.020.ptr, align 1, !tbaa !5
  %.020.ptr.1 = getelementptr inbounds i8, ptr %7, i64 2
  %11 = lshr i64 %1, 48
  %12 = trunc i64 %11 to i8
  store i8 %12, ptr %.020.ptr.1, align 1, !tbaa !5
  %.020.ptr.2 = getelementptr inbounds i8, ptr %7, i64 3
  %13 = lshr i64 %1, 40
  %14 = trunc i64 %13 to i8
  store i8 %14, ptr %.020.ptr.2, align 1, !tbaa !5
  %.020.ptr.3 = getelementptr inbounds i8, ptr %7, i64 4
  %15 = lshr i64 %1, 32
  %16 = trunc i64 %15 to i8
  store i8 %16, ptr %.020.ptr.3, align 1, !tbaa !5
  %.020.ptr.4 = getelementptr inbounds i8, ptr %7, i64 5
  %17 = lshr i64 %1, 24
  %18 = trunc i64 %17 to i8
  store i8 %18, ptr %.020.ptr.4, align 1, !tbaa !5
  %.020.ptr.5 = getelementptr inbounds i8, ptr %7, i64 6
  %19 = lshr i64 %1, 16
  %20 = trunc i64 %19 to i8
  store i8 %20, ptr %.020.ptr.5, align 1, !tbaa !5
  %.020.ptr.6 = getelementptr inbounds i8, ptr %7, i64 7
  %21 = lshr i64 %1, 8
  %22 = trunc i64 %21 to i8
  store i8 %22, ptr %.020.ptr.6, align 1, !tbaa !5
  %.020.ptr.7 = getelementptr inbounds i8, ptr %7, i64 8
  %23 = trunc i64 %1 to i8
  store i8 %23, ptr %.020.ptr.7, align 1, !tbaa !5
  %24 = load ptr, ptr %0, align 8, !tbaa !8
  %.not26 = icmp eq ptr %24, null
  br i1 %.not26, label %26, label %25

25:                                               ; preds = %8
  tail call void @free(ptr noundef nonnull %24) #4
  br label %26

26:                                               ; preds = %25, %8
  store ptr %7, ptr %0, align 8, !tbaa !8
  %27 = getelementptr inbounds i8, ptr %0, i64 8
  store i32 9, ptr %27, align 8, !tbaa !12
  br label %28

28:                                               ; preds = %6, %26, %4
  %.021 = phi i32 [ %5, %4 ], [ 0, %26 ], [ -1, %6 ]
  ret i32 %.021
}

; Function Attrs: nounwind uwtable
declare dso_local i32 @asn_long2INTEGER(ptr noundef, i64 noundef) local_unnamed_addr #2

attributes #0 = { 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 #1 = { 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 #2 = { 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 #3 = { nounwind allocsize(0) }
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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = !{!9, !10, i64 0}
!9 = !{!"ASN__PRIMITIVE_TYPE_s", !10, i64 0, !11, i64 8}
!10 = !{!"any pointer", !6, i64 0}
!11 = !{!"int", !6, i64 0}
!12 = !{!9, !11, i64 8}


; Effective O3 passes: CorrelatedValuePropagationPass,DSEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LoopRotatePass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass