; LLVM IR from masyagin1998/GCI :: src/garbage-collector (allocator)

; 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.ALLOCATOR = type { ptr, i64, %struct.ALLOCATOR_LIST, %struct.ALLOCATOR_LIST }
%struct.ALLOCATOR_LIST = type { ptr, ptr, i64, i64 }

; 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 @allocator_malloc_block(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
  %8 = alloca i64, align 8
  %9 = alloca ptr, align 8
  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) #2
  %10 = load ptr, ptr %4, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.ALLOCATOR, ptr %10, i32 0, i32 2
  %12 = getelementptr inbounds %struct.ALLOCATOR_LIST, ptr %11, i32 0, i32 1
  %13 = load ptr, ptr %12, align 8, !tbaa !11
  %14 = getelementptr inbounds i8, ptr %13, i64 1
  %15 = load i64, ptr %14, align 8, !tbaa !9
  %16 = add i64 %15, 34
  %17 = load i64, ptr %5, align 8, !tbaa !9
  %18 = icmp ult i64 %16, %17
  br i1 %18, label %19, label %20

19:                                               ; preds = %2
  store ptr null, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %151

20:                                               ; preds = %2
  %21 = load ptr, ptr %4, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.ALLOCATOR, ptr %21, i32 0, i32 2
  %23 = load i64, ptr %5, align 8, !tbaa !9
  %24 = call ptr @allocator_list_search_by_sizemem(ptr noundef %22, i64 noundef %23)
  store ptr %24, ptr %6, align 8, !tbaa !5
  %25 = load ptr, ptr %4, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.ALLOCATOR, ptr %25, i32 0, i32 2
  %27 = load ptr, ptr %6, align 8, !tbaa !5
  call void @allocator_list_remove_elem(ptr noundef %26, ptr noundef %27)
  %28 = load ptr, ptr %6, align 8, !tbaa !5
  %29 = getelementptr inbounds i8, ptr %28, i64 1
  %30 = load i64, ptr %29, align 8, !tbaa !9
  %31 = load i64, ptr %5, align 8, !tbaa !9
  %32 = add i64 %31, 35
  %33 = icmp ult i64 %30, %32
  br i1 %33, label %34, label %55

34:                                               ; preds = %20
  %35 = load ptr, ptr %6, align 8, !tbaa !5
  store i8 1, ptr %35, align 1, !tbaa !14
  %36 = load ptr, ptr %6, align 8, !tbaa !5
  %37 = getelementptr inbounds i8, ptr %36, i64 1
  %38 = getelementptr inbounds i8, ptr %37, i64 8
  %39 = getelementptr inbounds i8, ptr %38, i64 8
  %40 = getelementptr inbounds i8, ptr %39, i64 8
  %41 = load ptr, ptr %6, align 8, !tbaa !5
  %42 = getelementptr inbounds i8, ptr %41, i64 1
  %43 = load i64, ptr %42, align 8, !tbaa !9
  %44 = mul i64 %43, 1
  %45 = getelementptr inbounds i8, ptr %40, i64 %44
  %46 = getelementptr inbounds i8, ptr %45, i64 8
  store i8 1, ptr %46, align 1, !tbaa !14
  %47 = load ptr, ptr %4, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.ALLOCATOR, ptr %47, i32 0, i32 3
  %49 = load ptr, ptr %6, align 8, !tbaa !5
  call void @allocator_list_push_back(ptr noundef %48, ptr noundef %49)
  %50 = load ptr, ptr %6, align 8, !tbaa !5
  %51 = getelementptr inbounds i8, ptr %50, i64 1
  %52 = getelementptr inbounds i8, ptr %51, i64 8
  %53 = getelementptr inbounds i8, ptr %52, i64 8
  %54 = getelementptr inbounds i8, ptr %53, i64 8
  store ptr %54, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %151

55:                                               ; preds = %20
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #2
  %56 = load ptr, ptr %6, align 8, !tbaa !5
  %57 = getelementptr inbounds i8, ptr %56, i64 1
  %58 = load i64, ptr %57, align 8, !tbaa !9
  %59 = load i64, ptr %5, align 8, !tbaa !9
  %60 = sub i64 %58, %59
  %61 = sub i64 %60, 34
  store i64 %61, ptr %8, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #2
  %62 = load ptr, ptr %6, align 8, !tbaa !5
  store i8 1, ptr %62, align 1, !tbaa !14
  %63 = load i64, ptr %5, align 8, !tbaa !9
  %64 = load ptr, ptr %6, align 8, !tbaa !5
  %65 = getelementptr inbounds i8, ptr %64, i64 1
  store i64 %63, ptr %65, align 8, !tbaa !9
  %66 = load ptr, ptr %6, align 8, !tbaa !5
  %67 = getelementptr inbounds i8, ptr %66, i64 1
  %68 = getelementptr inbounds i8, ptr %67, i64 8
  store ptr null, ptr %68, align 8, !tbaa !5
  %69 = load ptr, ptr %6, align 8, !tbaa !5
  %70 = getelementptr inbounds i8, ptr %69, i64 1
  %71 = getelementptr inbounds i8, ptr %70, i64 8
  %72 = getelementptr inbounds i8, ptr %71, i64 8
  store ptr null, ptr %72, align 8, !tbaa !5
  %73 = load i64, ptr %5, align 8, !tbaa !9
  %74 = load ptr, ptr %6, align 8, !tbaa !5
  %75 = getelementptr inbounds i8, ptr %74, i64 1
  %76 = getelementptr inbounds i8, ptr %75, i64 8
  %77 = getelementptr inbounds i8, ptr %76, i64 8
  %78 = getelementptr inbounds i8, ptr %77, i64 8
  %79 = load ptr, ptr %6, align 8, !tbaa !5
  %80 = getelementptr inbounds i8, ptr %79, i64 1
  %81 = load i64, ptr %80, align 8, !tbaa !9
  %82 = mul i64 %81, 1
  %83 = getelementptr inbounds i8, ptr %78, i64 %82
  store i64 %73, ptr %83, align 8, !tbaa !9
  %84 = load ptr, ptr %6, align 8, !tbaa !5
  %85 = getelementptr inbounds i8, ptr %84, i64 1
  %86 = getelementptr inbounds i8, ptr %85, i64 8
  %87 = getelementptr inbounds i8, ptr %86, i64 8
  %88 = getelementptr inbounds i8, ptr %87, i64 8
  %89 = load ptr, ptr %6, align 8, !tbaa !5
  %90 = getelementptr inbounds i8, ptr %89, i64 1
  %91 = load i64, ptr %90, align 8, !tbaa !9
  %92 = mul i64 %91, 1
  %93 = getelementptr inbounds i8, ptr %88, i64 %92
  %94 = getelementptr inbounds i8, ptr %93, i64 8
  store i8 1, ptr %94, align 1, !tbaa !14
  %95 = load ptr, ptr %4, align 8, !tbaa !5
  %96 = getelementptr inbounds %struct.ALLOCATOR, ptr %95, i32 0, i32 3
  %97 = load ptr, ptr %6, align 8, !tbaa !5
  call void @allocator_list_push_back(ptr noundef %96, ptr noundef %97)
  %98 = load ptr, ptr %6, align 8, !tbaa !5
  %99 = getelementptr inbounds i8, ptr %98, i64 1
  %100 = getelementptr inbounds i8, ptr %99, i64 8
  %101 = getelementptr inbounds i8, ptr %100, i64 8
  %102 = getelementptr inbounds i8, ptr %101, i64 8
  %103 = load ptr, ptr %6, align 8, !tbaa !5
  %104 = getelementptr inbounds i8, ptr %103, i64 1
  %105 = load i64, ptr %104, align 8, !tbaa !9
  %106 = mul i64 %105, 1
  %107 = getelementptr inbounds i8, ptr %102, i64 %106
  %108 = getelementptr inbounds i8, ptr %107, i64 8
  %109 = getelementptr inbounds i8, ptr %108, i64 1
  store ptr %109, ptr %9, align 8, !tbaa !5
  %110 = load ptr, ptr %9, align 8, !tbaa !5
  store i8 0, ptr %110, align 1, !tbaa !14
  %111 = load i64, ptr %8, align 8, !tbaa !9
  %112 = load ptr, ptr %9, align 8, !tbaa !5
  %113 = getelementptr inbounds i8, ptr %112, i64 1
  store i64 %111, ptr %113, align 8, !tbaa !9
  %114 = load ptr, ptr %9, align 8, !tbaa !5
  %115 = getelementptr inbounds i8, ptr %114, i64 1
  %116 = getelementptr inbounds i8, ptr %115, i64 8
  store ptr null, ptr %116, align 8, !tbaa !5
  %117 = load ptr, ptr %9, align 8, !tbaa !5
  %118 = getelementptr inbounds i8, ptr %117, i64 1
  %119 = getelementptr inbounds i8, ptr %118, i64 8
  %120 = getelementptr inbounds i8, ptr %119, i64 8
  store ptr null, ptr %120, align 8, !tbaa !5
  %121 = load i64, ptr %8, align 8, !tbaa !9
  %122 = load ptr, ptr %9, align 8, !tbaa !5
  %123 = getelementptr inbounds i8, ptr %122, i64 1
  %124 = getelementptr inbounds i8, ptr %123, i64 8
  %125 = getelementptr inbounds i8, ptr %124, i64 8
  %126 = getelementptr inbounds i8, ptr %125, i64 8
  %127 = load ptr, ptr %9, align 8, !tbaa !5
  %128 = getelementptr inbounds i8, ptr %127, i64 1
  %129 = load i64, ptr %128, align 8, !tbaa !9
  %130 = mul i64 %129, 1
  %131 = getelementptr inbounds i8, ptr %126, i64 %130
  store i64 %121, ptr %131, align 8, !tbaa !9
  %132 = load ptr, ptr %9, align 8, !tbaa !5
  %133 = getelementptr inbounds i8, ptr %132, i64 1
  %134 = getelementptr inbounds i8, ptr %133, i64 8
  %135 = getelementptr inbounds i8, ptr %134, i64 8
  %136 = getelementptr inbounds i8, ptr %135, i64 8
  %137 = load ptr, ptr %9, align 8, !tbaa !5
  %138 = getelementptr inbounds i8, ptr %137, i64 1
  %139 = load i64, ptr %138, align 8, !tbaa !9
  %140 = mul i64 %139, 1
  %141 = getelementptr inbounds i8, ptr %136, i64 %140
  %142 = getelementptr inbounds i8, ptr %141, i64 8
  store i8 0, ptr %142, align 1, !tbaa !14
  %143 = load ptr, ptr %4, align 8, !tbaa !5
  %144 = getelementptr inbounds %struct.ALLOCATOR, ptr %143, i32 0, i32 2
  %145 = load ptr, ptr %9, align 8, !tbaa !5
  call void @allocator_list_insert_elem(ptr noundef %144, ptr noundef %145)
  %146 = load ptr, ptr %6, align 8, !tbaa !5
  %147 = getelementptr inbounds i8, ptr %146, i64 1
  %148 = getelementptr inbounds i8, ptr %147, i64 8
  %149 = getelementptr inbounds i8, ptr %148, i64 8
  %150 = getelementptr inbounds i8, ptr %149, i64 8
  store ptr %150, ptr %3, align 8
  store i32 1, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #2
  br label %151

151:                                              ; preds = %55, %34, %19
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #2
  %152 = load ptr, ptr %3, align 8
  ret ptr %152
}

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

; Function Attrs: nounwind uwtable
declare hidden void @allocator_list_remove_elem(ptr noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
declare hidden void @allocator_list_push_back(ptr noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
declare hidden void @allocator_list_insert_elem(ptr noundef, ptr noundef) #1

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 }

!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 24}
!12 = !{!"ALLOCATOR", !6, i64 0, !10, i64 8, !13, i64 16, !13, i64 48}
!13 = !{!"ALLOCATOR_LIST", !6, i64 0, !6, i64 8, !10, i64 16, !10, i64 24}
!14 = !{!7, !7, i64 0}


; 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 @allocator_malloc_block(ptr noundef %0, i64 noundef %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %0, i64 16
  %4 = getelementptr inbounds i8, ptr %0, i64 24
  %5 = load ptr, ptr %4, align 8, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %5, i64 1
  %7 = load i64, ptr %6, align 8, !tbaa !12
  %8 = add i64 %7, 34
  %9 = icmp ult i64 %8, %1
  br i1 %9, label %41, label %10

10:                                               ; preds = %2
  %11 = tail call ptr @allocator_list_search_by_sizemem(ptr noundef nonnull %3, i64 noundef %1)
  tail call void @allocator_list_remove_elem(ptr noundef nonnull %3, ptr noundef %11)
  %12 = getelementptr inbounds i8, ptr %11, i64 1
  %13 = load i64, ptr %12, align 8, !tbaa !12
  %14 = add i64 %1, 35
  %15 = icmp ult i64 %13, %14
  br i1 %15, label %16, label %21

16:                                               ; preds = %10
  store i8 1, ptr %11, align 1, !tbaa !13
  %17 = getelementptr inbounds i8, ptr %11, i64 25
  %18 = getelementptr inbounds i8, ptr %17, i64 %13
  %19 = getelementptr inbounds i8, ptr %18, i64 8
  store i8 1, ptr %19, align 1, !tbaa !13
  %20 = getelementptr inbounds i8, ptr %0, i64 48
  tail call void @allocator_list_push_back(ptr noundef nonnull %20, ptr noundef nonnull %11)
  br label %41

21:                                               ; preds = %10
  %22 = sub i64 %13, %1
  %23 = add i64 %22, -34
  store i8 1, ptr %11, align 1, !tbaa !13
  store i64 %1, ptr %12, align 8, !tbaa !12
  %24 = getelementptr inbounds i8, ptr %11, i64 9
  %25 = getelementptr inbounds i8, ptr %11, i64 25
  %26 = getelementptr inbounds i8, ptr %25, i64 %1
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %24, i8 0, i64 16, i1 false)
  store i64 %1, ptr %26, align 8, !tbaa !12
  %27 = load i64, ptr %12, align 8, !tbaa !12
  %28 = getelementptr inbounds i8, ptr %25, i64 %27
  %29 = getelementptr inbounds i8, ptr %28, i64 8
  store i8 1, ptr %29, align 1, !tbaa !13
  %30 = getelementptr inbounds i8, ptr %0, i64 48
  tail call void @allocator_list_push_back(ptr noundef nonnull %30, ptr noundef nonnull %11)
  %31 = load i64, ptr %12, align 8, !tbaa !12
  %32 = getelementptr inbounds i8, ptr %25, i64 %31
  %33 = getelementptr inbounds i8, ptr %32, i64 9
  store i8 0, ptr %33, align 1, !tbaa !13
  %34 = getelementptr inbounds i8, ptr %32, i64 10
  store i64 %23, ptr %34, align 8, !tbaa !12
  %35 = getelementptr inbounds i8, ptr %32, i64 18
  %36 = getelementptr inbounds i8, ptr %32, i64 34
  %37 = getelementptr i8, ptr %32, i64 %22
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %35, i8 0, i64 16, i1 false)
  store i64 %23, ptr %37, align 8, !tbaa !12
  %38 = load i64, ptr %34, align 8, !tbaa !12
  %39 = getelementptr inbounds i8, ptr %36, i64 %38
  %40 = getelementptr inbounds i8, ptr %39, i64 8
  store i8 0, ptr %40, align 1, !tbaa !13
  tail call void @allocator_list_insert_elem(ptr noundef nonnull %3, ptr noundef nonnull %33)
  br label %41

41:                                               ; preds = %2, %21, %16
  %.0 = phi ptr [ %17, %16 ], [ %25, %21 ], [ null, %2 ]
  ret ptr %.0
}

; Function Attrs: nounwind uwtable
declare hidden ptr @allocator_list_search_by_sizemem(ptr noundef, i64 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare hidden void @allocator_list_remove_elem(ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare hidden void @allocator_list_push_back(ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare hidden void @allocator_list_insert_elem(ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #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 = { nocallback nofree nounwind willreturn memory(argmem: write) }

!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 24}
!6 = !{!"ALLOCATOR", !7, i64 0, !10, i64 8, !11, i64 16, !11, i64 48}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!"ALLOCATOR_LIST", !7, i64 0, !7, i64 8, !10, i64 16, !10, i64 24}
!12 = !{!10, !10, i64 0}
!13 = !{!8, !8, i64 0}


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