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

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

declare void @mln_alloc_free(ptr noundef) #1

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

declare ptr @mln_alloc_m(ptr noundef, i64 noundef) #1

; Function Attrs: nounwind uwtable
declare hidden i32 @mln_asn1_encode_add_content(ptr noundef, ptr noundef, i64 noundef) #2

; Function Attrs: nounwind uwtable
define dso_local i32 @mln_asn1_encode_boolean(ptr noundef nonnull %0, i8 noundef zeroext %1) #2 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca i8, align 1
  %6 = alloca i64, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i8 %1, ptr %5, align 1, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  store i64 0, ptr %6, align 8, !tbaa !10
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  store i64 2, ptr %6, align 8, !tbaa !10
  %11 = load i64, ptr %6, align 8, !tbaa !10
  %12 = add i64 %11, 1
  store i64 %12, ptr %6, align 8, !tbaa !10
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.mln_asn1_enresult_t, ptr %13, i32 0, i32 0
  %15 = load ptr, ptr %14, align 8, !tbaa !12
  store ptr %15, ptr %7, align 8, !tbaa !5
  %16 = load ptr, ptr %7, align 8, !tbaa !5
  %17 = load i64, ptr %6, align 8, !tbaa !10
  %18 = call ptr @mln_alloc_m(ptr noundef %16, i64 noundef %17)
  store ptr %18, ptr %8, align 8, !tbaa !5
  %19 = icmp eq ptr %18, null
  br i1 %19, label %20, label %21

20:                                               ; preds = %2
  store i32 2, ptr %3, align 4
  store i32 1, ptr %10, align 4
  br label %73

21:                                               ; preds = %2
  %22 = load ptr, ptr %8, align 8, !tbaa !5
  %23 = getelementptr inbounds i8, ptr %22, i64 1
  store ptr %23, ptr %9, align 8, !tbaa !5
  %24 = load ptr, ptr %4, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.mln_asn1_enresult_t, ptr %24, i32 0, i32 5
  %26 = load i32, ptr %25, align 8
  %27 = and i32 %26, 3
  %28 = shl i32 %27, 6
  %29 = load ptr, ptr %4, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.mln_asn1_enresult_t, ptr %29, i32 0, i32 5
  %31 = load i32, ptr %30, align 8
  %32 = lshr i32 %31, 2
  %33 = and i32 %32, 1
  %34 = icmp ne i32 %33, 0
  %35 = zext i1 %34 to i64
  %36 = select i1 %34, i32 32, i32 0
  %37 = or i32 %28, %36
  %38 = load ptr, ptr %4, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.mln_asn1_enresult_t, ptr %38, i32 0, i32 5
  %40 = load i32, ptr %39, align 8
  %41 = lshr i32 %40, 3
  %42 = icmp ne i32 %41, 268435455
  br i1 %42, label %43, label %49

43:                                               ; preds = %21
  %44 = load ptr, ptr %4, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.mln_asn1_enresult_t, ptr %44, i32 0, i32 5
  %46 = load i32, ptr %45, align 8
  %47 = lshr i32 %46, 3
  %48 = and i32 %47, 31
  br label %50

49:                                               ; preds = %21
  br label %50

50:                                               ; preds = %49, %43
  %51 = phi i32 [ %48, %43 ], [ 1, %49 ]
  %52 = or i32 %37, %51
  %53 = trunc i32 %52 to i8
  %54 = load ptr, ptr %8, align 8, !tbaa !5
  %55 = getelementptr inbounds i8, ptr %54, i64 0
  store i8 %53, ptr %55, align 1, !tbaa !9
  %56 = load ptr, ptr %9, align 8, !tbaa !5
  %57 = getelementptr inbounds i8, ptr %56, i32 1
  store ptr %57, ptr %9, align 8, !tbaa !5
  store i8 1, ptr %56, align 1, !tbaa !9
  %58 = load i8, ptr %5, align 1, !tbaa !9
  %59 = load ptr, ptr %9, align 8, !tbaa !5
  store i8 %58, ptr %59, align 1, !tbaa !9
  %60 = load ptr, ptr %4, align 8, !tbaa !5
  %61 = load ptr, ptr %8, align 8, !tbaa !5
  %62 = load i64, ptr %6, align 8, !tbaa !10
  %63 = call i32 @mln_asn1_encode_add_content(ptr noundef %60, ptr noundef %61, i64 noundef %62)
  %64 = icmp slt i32 %63, 0
  br i1 %64, label %65, label %67

65:                                               ; preds = %50
  %66 = load ptr, ptr %8, align 8, !tbaa !5
  call void @mln_alloc_free(ptr noundef %66)
  store i32 2, ptr %3, align 4
  store i32 1, ptr %10, align 4
  br label %73

67:                                               ; preds = %50
  %68 = load i64, ptr %6, align 8, !tbaa !10
  %69 = load ptr, ptr %4, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.mln_asn1_enresult_t, ptr %69, i32 0, i32 1
  %71 = load i64, ptr %70, align 8, !tbaa !15
  %72 = add i64 %71, %68
  store i64 %72, ptr %70, align 8, !tbaa !15
  store i32 0, ptr %3, align 4
  store i32 1, ptr %10, align 4
  br label %73

73:                                               ; preds = %67, %65, %20
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  %74 = load i32, ptr %3, align 4
  ret i32 %74
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 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 }

!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 = !{!7, !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"long", !7, i64 0}
!12 = !{!13, !6, i64 0}
!13 = !{!"", !6, i64 0, !11, i64 8, !6, i64 16, !14, i64 24, !14, i64 28, !14, i64 32, !14, i64 32, !14, i64 32}
!14 = !{!"int", !7, i64 0}
!15 = !{!13, !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"

declare void @mln_alloc_free(ptr noundef) local_unnamed_addr #0

declare ptr @mln_alloc_m(ptr noundef, i64 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare hidden i32 @mln_asn1_encode_add_content(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 3) i32 @mln_asn1_encode_boolean(ptr noundef nonnull %0, i8 noundef zeroext %1) local_unnamed_addr #1 {
  %3 = load ptr, ptr %0, align 8, !tbaa !5
  %4 = tail call ptr @mln_alloc_m(ptr noundef %3, i64 noundef 3) #2
  %5 = icmp eq ptr %4, null
  br i1 %5, label %26, label %6

6:                                                ; preds = %2
  %7 = getelementptr inbounds i8, ptr %4, i64 1
  %8 = getelementptr inbounds i8, ptr %0, i64 32
  %9 = load i32, ptr %8, align 8
  %10 = shl i32 %9, 6
  %11 = shl i32 %9, 3
  %12 = and i32 %11, 32
  %13 = or disjoint i32 %12, %10
  %14 = lshr i32 %9, 3
  %.not = icmp eq i32 %14, 268435455
  %15 = and i32 %14, 31
  %spec.select = select i1 %.not, i32 1, i32 %15
  %16 = or disjoint i32 %13, %spec.select
  %17 = trunc i32 %16 to i8
  store i8 %17, ptr %4, align 1, !tbaa !12
  %18 = getelementptr inbounds i8, ptr %4, i64 2
  store i8 1, ptr %7, align 1, !tbaa !12
  store i8 %1, ptr %18, align 1, !tbaa !12
  %19 = tail call i32 @mln_asn1_encode_add_content(ptr noundef nonnull %0, ptr noundef nonnull %4, i64 noundef 3)
  %20 = icmp slt i32 %19, 0
  br i1 %20, label %21, label %22

21:                                               ; preds = %6
  tail call void @mln_alloc_free(ptr noundef nonnull %4) #2
  br label %26

22:                                               ; preds = %6
  %23 = getelementptr inbounds i8, ptr %0, i64 8
  %24 = load i64, ptr %23, align 8, !tbaa !13
  %25 = add i64 %24, 3
  store i64 %25, ptr %23, align 8, !tbaa !13
  br label %26

26:                                               ; preds = %2, %22, %21
  %.0 = phi i32 [ 2, %21 ], [ 0, %22 ], [ 2, %2 ]
  ret i32 %.0
}

attributes #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 = { 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 = { 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 = !{!8, !8, i64 0}
!13 = !{!6, !10, i64 8}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass