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

; 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_alloc_s = type { ptr, i64, i64, ptr, ptr, ptr, ptr, [35 x %struct.mln_alloc_mgr_s], ptr, ptr, ptr, ptr }
%struct.mln_alloc_mgr_s = type { i64, ptr, ptr, ptr, ptr, ptr, ptr }

; 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 ptr @mln_alloc_init(ptr noundef %0, i64 noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  %6 = alloca ptr, align 8
  %7 = 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
  %8 = load ptr, ptr %4, align 8, !tbaa !5
  %9 = icmp ne ptr %8, null
  br i1 %9, label %10, label %42

10:                                               ; preds = %2
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.mln_alloc_s, ptr %11, i32 0, i32 0
  %13 = load ptr, ptr %12, align 8, !tbaa !11
  %14 = icmp ne ptr %13, null
  br i1 %14, label %15, label %26

15:                                               ; preds = %10
  %16 = load ptr, ptr %4, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.mln_alloc_s, ptr %16, i32 0, i32 4
  %18 = load ptr, ptr %17, align 8, !tbaa !13
  %19 = load ptr, ptr %4, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.mln_alloc_s, ptr %19, i32 0, i32 3
  %21 = load ptr, ptr %20, align 8, !tbaa !14
  %22 = call i32 %18(ptr noundef %21)
  %23 = icmp ne i32 %22, 0
  br i1 %23, label %24, label %25

24:                                               ; preds = %15
  store ptr null, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %78

25:                                               ; preds = %15
  br label %26

26:                                               ; preds = %25, %10
  %27 = load ptr, ptr %4, align 8, !tbaa !5
  %28 = call ptr @mln_alloc_m(ptr noundef %27, i64 noundef 2048)
  store ptr %28, ptr %6, align 8, !tbaa !5
  %29 = load ptr, ptr %4, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.mln_alloc_s, ptr %29, i32 0, i32 0
  %31 = load ptr, ptr %30, align 8, !tbaa !11
  %32 = icmp ne ptr %31, null
  br i1 %32, label %33, label %41

33:                                               ; preds = %26
  %34 = load ptr, ptr %4, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.mln_alloc_s, ptr %34, i32 0, i32 5
  %36 = load ptr, ptr %35, align 8, !tbaa !15
  %37 = load ptr, ptr %4, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.mln_alloc_s, ptr %37, i32 0, i32 3
  %39 = load ptr, ptr %38, align 8, !tbaa !14
  %40 = call i32 %36(ptr noundef %39)
  br label %41

41:                                               ; preds = %33, %26
  br label %44

42:                                               ; preds = %2
  %43 = call noalias ptr @malloc(i64 noundef 2048) #5
  store ptr %43, ptr %6, align 8, !tbaa !5
  br label %44

44:                                               ; preds = %42, %41
  %45 = load ptr, ptr %6, align 8, !tbaa !5
  %46 = icmp eq ptr %45, null
  br i1 %46, label %47, label %49

47:                                               ; preds = %44
  %48 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %48, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %78

49:                                               ; preds = %44
  %50 = load ptr, ptr %6, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.mln_alloc_s, ptr %50, i32 0, i32 7
  %52 = getelementptr inbounds [35 x %struct.mln_alloc_mgr_s], ptr %51, i64 0, i64 0
  call void @mln_alloc_mgr_table_init(ptr noundef %52)
  %53 = load ptr, ptr %4, align 8, !tbaa !5
  %54 = load ptr, ptr %6, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.mln_alloc_s, ptr %54, i32 0, i32 6
  store ptr %53, ptr %55, align 8, !tbaa !16
  %56 = load ptr, ptr %6, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.mln_alloc_s, ptr %56, i32 0, i32 9
  store ptr null, ptr %57, align 8, !tbaa !17
  %58 = load ptr, ptr %6, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.mln_alloc_s, ptr %58, i32 0, i32 8
  store ptr null, ptr %59, align 8, !tbaa !18
  %60 = load ptr, ptr %6, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.mln_alloc_s, ptr %60, i32 0, i32 11
  store ptr null, ptr %61, align 8, !tbaa !19
  %62 = load ptr, ptr %6, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.mln_alloc_s, ptr %62, i32 0, i32 10
  store ptr null, ptr %63, align 8, !tbaa !20
  %64 = load ptr, ptr %6, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.mln_alloc_s, ptr %64, i32 0, i32 0
  store ptr null, ptr %65, align 8, !tbaa !11
  %66 = load i64, ptr %5, align 8, !tbaa !9
  %67 = load ptr, ptr %6, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.mln_alloc_s, ptr %67, i32 0, i32 1
  store i64 %66, ptr %68, align 8, !tbaa !21
  %69 = load ptr, ptr %6, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.mln_alloc_s, ptr %69, i32 0, i32 2
  store i64 0, ptr %70, align 8, !tbaa !22
  %71 = load ptr, ptr %6, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.mln_alloc_s, ptr %71, i32 0, i32 3
  store ptr null, ptr %72, align 8, !tbaa !14
  %73 = load ptr, ptr %6, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct.mln_alloc_s, ptr %73, i32 0, i32 4
  store ptr null, ptr %74, align 8, !tbaa !13
  %75 = load ptr, ptr %6, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct.mln_alloc_s, ptr %75, i32 0, i32 5
  store ptr null, ptr %76, align 8, !tbaa !15
  %77 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %77, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %78

78:                                               ; preds = %49, %47, %24
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  %79 = load ptr, ptr %3, align 8
  ret ptr %79
}

; Function Attrs: nounwind uwtable
declare dso_local ptr @mln_alloc_m(ptr noundef, i64 noundef) #1

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @mln_alloc_mgr_table_init(ptr noundef) #3

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 = { 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 = { inlinehint 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 = !{!12, !6, i64 0}
!12 = !{!"mln_alloc_s", !6, i64 0, !10, i64 8, !10, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !7, i64 56, !6, i64 2016, !6, i64 2024, !6, i64 2032, !6, i64 2040}
!13 = !{!12, !6, i64 32}
!14 = !{!12, !6, i64 24}
!15 = !{!12, !6, i64 40}
!16 = !{!12, !6, i64 48}
!17 = !{!12, !6, i64 2024}
!18 = !{!12, !6, i64 2016}
!19 = !{!12, !6, i64 2040}
!20 = !{!12, !6, i64 2032}
!21 = !{!12, !10, i64 8}
!22 = !{!12, !10, i64 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"

; Function Attrs: nounwind uwtable
define dso_local ptr @mln_alloc_init(ptr noundef %0, i64 noundef %1) local_unnamed_addr #0 {
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %20, label %3

3:                                                ; preds = %2
  %4 = load ptr, ptr %0, align 8, !tbaa !5
  %.not27 = icmp eq ptr %4, null
  br i1 %.not27, label %11, label %5

5:                                                ; preds = %3
  %6 = getelementptr inbounds i8, ptr %0, i64 32
  %7 = load ptr, ptr %6, align 8, !tbaa !11
  %8 = getelementptr inbounds i8, ptr %0, i64 24
  %9 = load ptr, ptr %8, align 8, !tbaa !12
  %10 = tail call i32 %7(ptr noundef %9) #4
  %.not28 = icmp eq i32 %10, 0
  br i1 %.not28, label %11, label %30

11:                                               ; preds = %5, %3
  %12 = tail call ptr @mln_alloc_m(ptr noundef nonnull %0, i64 noundef 2048)
  %13 = load ptr, ptr %0, align 8, !tbaa !5
  %.not29 = icmp eq ptr %13, null
  br i1 %.not29, label %22, label %14

14:                                               ; preds = %11
  %15 = getelementptr inbounds i8, ptr %0, i64 40
  %16 = load ptr, ptr %15, align 8, !tbaa !13
  %17 = getelementptr inbounds i8, ptr %0, i64 24
  %18 = load ptr, ptr %17, align 8, !tbaa !12
  %19 = tail call i32 %16(ptr noundef %18) #4
  br label %22

20:                                               ; preds = %2
  %21 = tail call noalias dereferenceable_or_null(2048) ptr @malloc(i64 noundef 2048) #5
  br label %22

22:                                               ; preds = %11, %14, %20
  %.0 = phi ptr [ %12, %14 ], [ %12, %11 ], [ %21, %20 ]
  %23 = icmp eq ptr %.0, null
  br i1 %23, label %30, label %24

24:                                               ; preds = %22
  %25 = getelementptr inbounds i8, ptr %.0, i64 56
  tail call void @mln_alloc_mgr_table_init(ptr noundef nonnull %25)
  %26 = getelementptr inbounds i8, ptr %.0, i64 48
  store ptr %0, ptr %26, align 8, !tbaa !14
  %27 = getelementptr inbounds i8, ptr %.0, i64 2016
  store ptr null, ptr %.0, align 8, !tbaa !5
  %28 = getelementptr inbounds i8, ptr %.0, i64 8
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(32) %27, i8 0, i64 32, i1 false)
  store i64 %1, ptr %28, align 8, !tbaa !15
  %29 = getelementptr inbounds i8, ptr %.0, i64 16
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(32) %29, i8 0, i64 32, i1 false)
  br label %30

30:                                               ; preds = %22, %5, %24
  %.025 = phi ptr [ %.0, %24 ], [ null, %5 ], [ null, %22 ]
  ret ptr %.025
}

; Function Attrs: nounwind uwtable
declare dso_local ptr @mln_alloc_m(ptr noundef, i64 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: inlinehint nounwind uwtable
declare hidden void @mln_alloc_mgr_table_init(ptr noundef) local_unnamed_addr #2

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #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 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 = { inlinehint 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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
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, !7, i64 0}
!6 = !{!"mln_alloc_s", !7, i64 0, !10, i64 8, !10, i64 16, !7, i64 24, !7, i64 32, !7, i64 40, !7, i64 48, !8, i64 56, !7, i64 2016, !7, i64 2024, !7, i64 2032, !7, i64 2040}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!6, !7, i64 32}
!12 = !{!6, !7, i64 24}
!13 = !{!6, !7, i64 40}
!14 = !{!6, !7, i64 48}
!15 = !{!6, !10, i64 8}


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