; LLVM IR from Water-Melon/Melon :: src (mln_asn1)

; 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.mln_asn1_enresult_t = type { ptr, i64, ptr, i32, i32, i32 }
%struct.mln_string_t = type { ptr, i64, i32 }
%struct.mln_chain_s = type { ptr, ptr }
%struct.mln_buf_s = type { ptr, ptr, ptr, ptr, ptr, ptr, i64, i64, i64, ptr, i8 }

; 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 uwtable
define dso_local i32 @mln_asn1_encode_trans_chain_once(ptr noundef nonnull %0, ptr noundef nonnull %1, ptr noundef nonnull %2) #1 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %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 ptr, align 8
  %13 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  %14 = load ptr, ptr %5, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.mln_asn1_enresult_t, ptr %14, i32 0, i32 0
  %16 = load ptr, ptr %15, align 8, !tbaa !9
  store ptr %16, ptr %12, align 8, !tbaa !5
  %17 = load ptr, ptr %5, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.mln_asn1_enresult_t, ptr %17, i32 0, i32 2
  %19 = load ptr, ptr %18, align 8, !tbaa !13
  %20 = load ptr, ptr %5, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.mln_asn1_enresult_t, ptr %20, i32 0, i32 4
  %22 = load i32, ptr %21, align 4, !tbaa !14
  %23 = zext i32 %22 to i64
  %24 = getelementptr inbounds %struct.mln_string_t, ptr %19, i64 %23
  store ptr %24, ptr %11, align 8, !tbaa !5
  %25 = load ptr, ptr %5, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.mln_asn1_enresult_t, ptr %25, i32 0, i32 2
  %27 = load ptr, ptr %26, align 8, !tbaa !13
  store ptr %27, ptr %10, align 8, !tbaa !5
  br label %28

28:                                               ; preds = %91, %3
  %29 = load ptr, ptr %10, align 8, !tbaa !5
  %30 = load ptr, ptr %11, align 8, !tbaa !5
  %31 = icmp ult ptr %29, %30
  br i1 %31, label %32, label %94

32:                                               ; preds = %28
  %33 = load ptr, ptr %12, align 8, !tbaa !5
  %34 = call ptr @mln_chain_new(ptr noundef %33)
  store ptr %34, ptr %8, align 8, !tbaa !5
  %35 = icmp eq ptr %34, null
  br i1 %35, label %36, label %37

36:                                               ; preds = %32
  store i32 2, ptr %4, align 4
  store i32 1, ptr %13, align 4
  br label %99

37:                                               ; preds = %32
  %38 = load ptr, ptr %12, align 8, !tbaa !5
  %39 = call ptr @mln_buf_new(ptr noundef %38)
  %40 = load ptr, ptr %8, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.mln_chain_s, ptr %40, i32 0, i32 0
  store ptr %39, ptr %41, align 8, !tbaa !15
  store ptr %39, ptr %9, align 8, !tbaa !5
  %42 = icmp eq ptr %39, null
  br i1 %42, label %43, label %45

43:                                               ; preds = %37
  %44 = load ptr, ptr %8, align 8, !tbaa !5
  call void @mln_chain_pool_release(ptr noundef %44)
  store i32 2, ptr %4, align 4
  store i32 1, ptr %13, align 4
  br label %99

45:                                               ; preds = %37
  %46 = load ptr, ptr %10, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.mln_string_t, ptr %46, i32 0, i32 0
  %48 = load ptr, ptr %47, align 8, !tbaa !17
  %49 = load ptr, ptr %9, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.mln_buf_s, ptr %49, i32 0, i32 3
  store ptr %48, ptr %50, align 8, !tbaa !19
  %51 = load ptr, ptr %9, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.mln_buf_s, ptr %51, i32 0, i32 1
  store ptr %48, ptr %52, align 8, !tbaa !21
  %53 = load ptr, ptr %9, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.mln_buf_s, ptr %53, i32 0, i32 0
  store ptr %48, ptr %54, align 8, !tbaa !22
  %55 = load ptr, ptr %10, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.mln_string_t, ptr %55, i32 0, i32 0
  %57 = load ptr, ptr %56, align 8, !tbaa !17
  %58 = load ptr, ptr %10, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.mln_string_t, ptr %58, i32 0, i32 1
  %60 = load i64, ptr %59, align 8, !tbaa !23
  %61 = getelementptr inbounds i8, ptr %57, i64 %60
  %62 = load ptr, ptr %9, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.mln_buf_s, ptr %62, i32 0, i32 2
  store ptr %61, ptr %63, align 8, !tbaa !24
  %64 = load ptr, ptr %9, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.mln_buf_s, ptr %64, i32 0, i32 4
  store ptr %61, ptr %65, align 8, !tbaa !25
  %66 = load ptr, ptr %9, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.mln_buf_s, ptr %66, i32 0, i32 10
  %68 = load i8, ptr %67, align 8
  %69 = and i8 %68, -5
  %70 = or i8 %69, 4
  store i8 %70, ptr %67, align 8
  %71 = load ptr, ptr %9, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.mln_buf_s, ptr %71, i32 0, i32 10
  %73 = load i8, ptr %72, align 8
  %74 = and i8 %73, -65
  %75 = or i8 %74, 64
  store i8 %75, ptr %72, align 8
  %76 = load ptr, ptr %6, align 8, !tbaa !5
  %77 = load ptr, ptr %76, align 8, !tbaa !5
  %78 = icmp eq ptr %77, null
  br i1 %78, label %79, label %83

79:                                               ; preds = %45
  %80 = load ptr, ptr %8, align 8, !tbaa !5
  %81 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %80, ptr %81, align 8, !tbaa !5
  %82 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %80, ptr %82, align 8, !tbaa !5
  br label %90

83:                                               ; preds = %45
  %84 = load ptr, ptr %8, align 8, !tbaa !5
  %85 = load ptr, ptr %7, align 8, !tbaa !5
  %86 = load ptr, ptr %85, align 8, !tbaa !5
  %87 = getelementptr inbounds %struct.mln_chain_s, ptr %86, i32 0, i32 1
  store ptr %84, ptr %87, align 8, !tbaa !26
  %88 = load ptr, ptr %8, align 8, !tbaa !5
  %89 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %88, ptr %89, align 8, !tbaa !5
  br label %90

90:                                               ; preds = %83, %79
  br label %91

91:                                               ; preds = %90
  %92 = load ptr, ptr %10, align 8, !tbaa !5
  %93 = getelementptr inbounds %struct.mln_string_t, ptr %92, i32 1
  store ptr %93, ptr %10, align 8, !tbaa !5
  br label %28, !llvm.loop !27

94:                                               ; preds = %28
  %95 = load ptr, ptr %5, align 8, !tbaa !5
  %96 = getelementptr inbounds %struct.mln_asn1_enresult_t, ptr %95, i32 0, i32 4
  store i32 0, ptr %96, align 4, !tbaa !14
  %97 = load ptr, ptr %5, align 8, !tbaa !5
  %98 = getelementptr inbounds %struct.mln_asn1_enresult_t, ptr %97, i32 0, i32 1
  store i64 0, ptr %98, align 8, !tbaa !29
  store i32 0, ptr %4, align 4
  store i32 1, ptr %13, align 4
  br label %99

99:                                               ; preds = %94, %43, %36
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  %100 = load i32, ptr %4, align 4
  ret i32 %100
}

declare ptr @mln_chain_new(ptr noundef) #2

declare ptr @mln_buf_new(ptr noundef) #2

declare void @mln_chain_pool_release(ptr noundef) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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, !6, i64 0}
!10 = !{!"", !6, i64 0, !11, i64 8, !6, i64 16, !12, i64 24, !12, i64 28, !12, i64 32, !12, i64 32, !12, i64 32}
!11 = !{!"long", !7, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!10, !6, i64 16}
!14 = !{!10, !12, i64 28}
!15 = !{!16, !6, i64 0}
!16 = !{!"mln_chain_s", !6, i64 0, !6, i64 8}
!17 = !{!18, !6, i64 0}
!18 = !{!"", !6, i64 0, !11, i64 8, !11, i64 16, !11, i64 16, !11, i64 16}
!19 = !{!20, !6, i64 24}
!20 = !{!"mln_buf_s", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !11, i64 48, !11, i64 56, !11, i64 64, !6, i64 72, !12, i64 80, !12, i64 80, !12, i64 80, !12, i64 80, !12, i64 80, !12, i64 80, !12, i64 80, !12, i64 80}
!21 = !{!20, !6, i64 8}
!22 = !{!20, !6, i64 0}
!23 = !{!18, !11, i64 8}
!24 = !{!20, !6, i64 16}
!25 = !{!20, !6, i64 32}
!26 = !{!16, !6, i64 8}
!27 = distinct !{!27, !28}
!28 = !{!"llvm.loop.mustprogress"}
!29 = !{!10, !11, 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"

%struct.mln_string_t = type { ptr, i64, i32 }

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 3) i32 @mln_asn1_encode_trans_chain_once(ptr nocapture noundef nonnull %0, ptr nocapture noundef nonnull %1, ptr nocapture noundef nonnull %2) local_unnamed_addr #0 {
  %4 = load ptr, ptr %0, align 8, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %0, i64 16
  %6 = load ptr, ptr %5, align 8, !tbaa !12
  %7 = getelementptr inbounds i8, ptr %0, i64 28
  %8 = load i32, ptr %7, align 4, !tbaa !13
  %9 = zext i32 %8 to i64
  %10 = getelementptr inbounds %struct.mln_string_t, ptr %6, i64 %9
  %.not = icmp eq i32 %8, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %3, %34
  %.03135 = phi ptr [ %35, %34 ], [ %6, %3 ]
  %11 = tail call ptr @mln_chain_new(ptr noundef %4) #2
  %12 = icmp eq ptr %11, null
  br i1 %12, label %.loopexit, label %13

13:                                               ; preds = %.lr.ph
  %14 = tail call ptr @mln_buf_new(ptr noundef %4) #2
  store ptr %14, ptr %11, align 8, !tbaa !14
  %15 = icmp eq ptr %14, null
  br i1 %15, label %16, label %17

16:                                               ; preds = %13
  tail call void @mln_chain_pool_release(ptr noundef nonnull %11) #2
  br label %.loopexit

17:                                               ; preds = %13
  %18 = load ptr, ptr %.03135, align 8, !tbaa !16
  %19 = getelementptr inbounds i8, ptr %14, i64 24
  store ptr %18, ptr %19, align 8, !tbaa !18
  %20 = getelementptr inbounds i8, ptr %14, i64 8
  store ptr %18, ptr %20, align 8, !tbaa !20
  store ptr %18, ptr %14, align 8, !tbaa !21
  %21 = getelementptr inbounds i8, ptr %.03135, i64 8
  %22 = load i64, ptr %21, align 8, !tbaa !22
  %23 = getelementptr inbounds i8, ptr %18, i64 %22
  %24 = getelementptr inbounds i8, ptr %14, i64 16
  store ptr %23, ptr %24, align 8, !tbaa !23
  %25 = getelementptr inbounds i8, ptr %14, i64 32
  store ptr %23, ptr %25, align 8, !tbaa !24
  %26 = getelementptr inbounds i8, ptr %14, i64 80
  %27 = load i8, ptr %26, align 8
  %28 = or i8 %27, 68
  store i8 %28, ptr %26, align 8
  %29 = load ptr, ptr %1, align 8, !tbaa !25
  %30 = icmp eq ptr %29, null
  br i1 %30, label %34, label %31

31:                                               ; preds = %17
  %32 = load ptr, ptr %2, align 8, !tbaa !25
  %33 = getelementptr inbounds i8, ptr %32, i64 8
  br label %34

34:                                               ; preds = %17, %31
  %.sink40 = phi ptr [ %33, %31 ], [ %2, %17 ]
  %.sink = phi ptr [ %2, %31 ], [ %1, %17 ]
  store ptr %11, ptr %.sink40, align 8, !tbaa !25
  store ptr %11, ptr %.sink, align 8, !tbaa !25
  %35 = getelementptr inbounds i8, ptr %.03135, i64 24
  %36 = icmp ult ptr %35, %10
  br i1 %36, label %.lr.ph, label %._crit_edge, !llvm.loop !26

._crit_edge:                                      ; preds = %34, %3
  store i32 0, ptr %7, align 4, !tbaa !13
  %37 = getelementptr inbounds i8, ptr %0, i64 8
  store i64 0, ptr %37, align 8, !tbaa !28
  br label %.loopexit

.loopexit:                                        ; preds = %.lr.ph, %._crit_edge, %16
  %.0 = phi i32 [ 2, %16 ], [ 0, %._crit_edge ], [ 2, %.lr.ph ]
  ret i32 %.0
}

declare ptr @mln_chain_new(ptr noundef) local_unnamed_addr #1

declare ptr @mln_buf_new(ptr noundef) local_unnamed_addr #1

declare void @mln_chain_pool_release(ptr noundef) local_unnamed_addr #1

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 = { 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 = !{!"", !7, i64 0, !10, i64 8, !7, i64 16, !11, i64 24, !11, i64 28, !11, i64 32, !11, i64 32, !11, i64 32}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!"int", !8, i64 0}
!12 = !{!6, !7, i64 16}
!13 = !{!6, !11, i64 28}
!14 = !{!15, !7, i64 0}
!15 = !{!"mln_chain_s", !7, i64 0, !7, i64 8}
!16 = !{!17, !7, i64 0}
!17 = !{!"", !7, i64 0, !10, i64 8, !10, i64 16, !10, i64 16, !10, i64 16}
!18 = !{!19, !7, i64 24}
!19 = !{!"mln_buf_s", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !7, i64 32, !7, i64 40, !10, i64 48, !10, i64 56, !10, i64 64, !7, i64 72, !11, i64 80, !11, i64 80, !11, i64 80, !11, i64 80, !11, i64 80, !11, i64 80, !11, i64 80, !11, i64 80}
!20 = !{!19, !7, i64 8}
!21 = !{!19, !7, i64 0}
!22 = !{!17, !10, i64 8}
!23 = !{!19, !7, i64 16}
!24 = !{!19, !7, i64 32}
!25 = !{!7, !7, i64 0}
!26 = distinct !{!26, !27}
!27 = !{!"llvm.loop.mustprogress"}
!28 = !{!6, !10, i64 8}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass