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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @uper_open_type_put(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3) #0 {
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca i64, align 8
  %13 = alloca i64, align 8
  %14 = alloca i32, align 4
  %15 = alloca i64, align 8
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store ptr %2, ptr %8, align 8, !tbaa !5
  store ptr %3, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #4
  %16 = load ptr, ptr %6, align 8, !tbaa !5
  %17 = load ptr, ptr %7, align 8, !tbaa !5
  %18 = load ptr, ptr %8, align 8, !tbaa !5
  %19 = call i64 @uper_encode_to_new_buffer(ptr noundef %16, ptr noundef %17, ptr noundef %18, ptr noundef %10)
  store i64 %19, ptr %12, align 8, !tbaa !9
  %20 = load i64, ptr %12, align 8, !tbaa !9
  %21 = icmp sle i64 %20, 0
  br i1 %21, label %22, label %23

22:                                               ; preds = %4
  store i32 -1, ptr %5, align 4
  store i32 1, ptr %14, align 4
  br label %61

23:                                               ; preds = %4
  %24 = load ptr, ptr %10, align 8, !tbaa !5
  store ptr %24, ptr %11, align 8, !tbaa !5
  %25 = load i64, ptr %12, align 8, !tbaa !9
  store i64 %25, ptr %13, align 8, !tbaa !9
  br label %26

26:                                               ; preds = %54, %23
  %27 = load i64, ptr %13, align 8, !tbaa !9
  %28 = icmp ne i64 %27, 0
  br i1 %28, label %29, label %55

29:                                               ; preds = %26
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #4
  %30 = load ptr, ptr %9, align 8, !tbaa !5
  %31 = load i64, ptr %13, align 8, !tbaa !9
  %32 = call i64 @uper_put_length(ptr noundef %30, i64 noundef %31)
  store i64 %32, ptr %15, align 8, !tbaa !9
  %33 = load i64, ptr %15, align 8, !tbaa !9
  %34 = icmp slt i64 %33, 0
  br i1 %34, label %35, label %36

35:                                               ; preds = %29
  store i32 2, ptr %14, align 4
  br label %52

36:                                               ; preds = %29
  %37 = load ptr, ptr %9, align 8, !tbaa !5
  %38 = load ptr, ptr %11, align 8, !tbaa !5
  %39 = load i64, ptr %15, align 8, !tbaa !9
  %40 = mul nsw i64 %39, 8
  %41 = trunc i64 %40 to i32
  %42 = call i32 @per_put_many_bits(ptr noundef %37, ptr noundef %38, i32 noundef %41)
  %43 = icmp ne i32 %42, 0
  br i1 %43, label %44, label %45

44:                                               ; preds = %36
  store i32 2, ptr %14, align 4
  br label %52

45:                                               ; preds = %36
  %46 = load ptr, ptr %11, align 8, !tbaa !5
  %47 = load i64, ptr %15, align 8, !tbaa !9
  %48 = getelementptr inbounds i8, ptr %46, i64 %47
  store ptr %48, ptr %11, align 8, !tbaa !5
  %49 = load i64, ptr %15, align 8, !tbaa !9
  %50 = load i64, ptr %13, align 8, !tbaa !9
  %51 = sub i64 %50, %49
  store i64 %51, ptr %13, align 8, !tbaa !9
  store i32 0, ptr %14, align 4
  br label %52

52:                                               ; preds = %45, %44, %35
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #4
  %53 = load i32, ptr %14, align 4
  switch i32 %53, label %63 [
    i32 0, label %54
    i32 2, label %55
  ]

54:                                               ; preds = %52
  br label %26, !llvm.loop !11

55:                                               ; preds = %52, %26
  %56 = load ptr, ptr %10, align 8, !tbaa !5
  call void @free(ptr noundef %56) #4
  store ptr null, ptr %10, align 8, !tbaa !5
  %57 = load i64, ptr %13, align 8, !tbaa !9
  %58 = icmp ne i64 %57, 0
  br i1 %58, label %59, label %60

59:                                               ; preds = %55
  store i32 -1, ptr %5, align 4
  store i32 1, ptr %14, align 4
  br label %61

60:                                               ; preds = %55
  store i32 0, ptr %5, align 4
  store i32 1, ptr %14, align 4
  br label %61

61:                                               ; preds = %60, %59, %22
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  %62 = load i32, ptr %5, align 4
  ret i32 %62

63:                                               ; preds = %52
  unreachable
}

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

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

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

declare i32 @per_put_many_bits(ptr noundef, ptr noundef, i32 noundef) #2

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

; Function Attrs: nounwind
declare void @free(ptr noundef) #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 = { 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 "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 = !{!"long", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


; 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 range(i32 -1, 1) i32 @uper_open_type_put(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3) local_unnamed_addr #0 {
  %5 = alloca ptr, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %5) #4
  %6 = call i64 @uper_encode_to_new_buffer(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef nonnull %5) #4
  %.019.fr30 = freeze i64 %6
  %7 = icmp slt i64 %.019.fr30, 1
  br i1 %7, label %20, label %8

8:                                                ; preds = %4
  %9 = load ptr, ptr %5, align 8, !tbaa !5
  br label %10

10:                                               ; preds = %8, %16
  %.019.fr32 = phi i64 [ %.019.fr30, %8 ], [ %18, %16 ]
  %.02031 = phi ptr [ %9, %8 ], [ %17, %16 ]
  %11 = call i64 @uper_put_length(ptr noundef %3, i64 noundef %.019.fr32) #4
  %.fr = freeze i64 %11
  %12 = icmp slt i64 %.fr, 0
  br i1 %12, label %.thread, label %13

13:                                               ; preds = %10
  %.tr = trunc i64 %.fr to i32
  %14 = shl i32 %.tr, 3
  %15 = call i32 @per_put_many_bits(ptr noundef %3, ptr noundef %.02031, i32 noundef %14) #4
  %.not24 = icmp eq i32 %15, 0
  br i1 %.not24, label %16, label %.thread

16:                                               ; preds = %13
  %17 = getelementptr inbounds i8, ptr %.02031, i64 %.fr
  %18 = sub i64 %.019.fr32, %.fr
  %.not = icmp eq i64 %18, 0
  br i1 %.not, label %.thread, label %10

.thread:                                          ; preds = %13, %10, %16
  %.019.fr.lcssa = phi i32 [ -1, %13 ], [ -1, %10 ], [ 0, %16 ]
  %19 = load ptr, ptr %5, align 8, !tbaa !5
  call void @free(ptr noundef %19) #4
  br label %20

20:                                               ; preds = %.thread, %4
  %.0 = phi i32 [ -1, %4 ], [ %.019.fr.lcssa, %.thread ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %5) #4
  ret i32 %.0
}

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

declare i64 @uper_encode_to_new_buffer(ptr noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

declare i64 @uper_put_length(ptr noundef, i64 noundef) local_unnamed_addr #2

declare i32 @per_put_many_bits(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #2

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

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

!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"}


; Effective O3 passes: CorrelatedValuePropagationPass,DSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LCSSAPass,LoopRotatePass,SROAPass,SimplifyCFGPass