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

; 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.GARBAGE_COLLECTOR = type { ptr, ptr, %struct.ALLOCATOR, %struct.ALLOCATOR, %struct.PTRS_MAP, i32 }
%struct.ALLOCATOR = type { ptr, i64, %struct.ALLOCATOR_LIST, %struct.ALLOCATOR_LIST }
%struct.ALLOCATOR_LIST = type { ptr, ptr, i64, i64 }
%struct.PTRS_MAP = type { 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
declare hidden void @run_gc(ptr noundef, ptr noundef, i64 noundef) #1

; Function Attrs: nounwind uwtable
define dso_local ptr @garbage_collector_malloc_arr(ptr noundef %0, i64 noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  %8 = 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) #2
  %9 = load i64, ptr %5, align 8, !tbaa !9
  %10 = mul i64 %9, 2
  store i64 %10, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  %11 = load i64, ptr %6, align 8, !tbaa !9
  %12 = mul i64 24, %11
  %13 = add i64 17, %12
  store i64 %13, ptr %7, align 8, !tbaa !9
  %14 = load ptr, ptr %4, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.GARBAGE_COLLECTOR, ptr %14, i32 0, i32 2
  %16 = getelementptr inbounds %struct.ALLOCATOR, ptr %15, i32 0, i32 2
  %17 = getelementptr inbounds %struct.ALLOCATOR_LIST, ptr %16, i32 0, i32 1
  %18 = load ptr, ptr %17, align 8, !tbaa !11
  %19 = icmp ne ptr %18, null
  br i1 %19, label %20, label %36

20:                                               ; preds = %2
  %21 = load ptr, ptr %4, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.GARBAGE_COLLECTOR, ptr %21, i32 0, i32 2
  %23 = getelementptr inbounds %struct.ALLOCATOR, ptr %22, i32 0, i32 2
  %24 = getelementptr inbounds %struct.ALLOCATOR_LIST, ptr %23, i32 0, i32 1
  %25 = load ptr, ptr %24, align 8, !tbaa !11
  %26 = getelementptr inbounds i8, ptr %25, i64 1
  %27 = load i64, ptr %26, align 8, !tbaa !9
  %28 = load i64, ptr %7, align 8, !tbaa !9
  %29 = add i64 %28, 34
  %30 = icmp uge i64 %27, %29
  br i1 %30, label %31, label %36

31:                                               ; preds = %20
  %32 = load ptr, ptr %4, align 8, !tbaa !5
  %33 = load i64, ptr %6, align 8, !tbaa !9
  %34 = load i64, ptr %7, align 8, !tbaa !9
  %35 = call ptr @malloc_arr_force(ptr noundef %32, i64 noundef %33, i64 noundef %34)
  store ptr %35, ptr %3, align 8
  store i32 1, ptr %8, align 4
  br label %43

36:                                               ; preds = %20, %2
  %37 = load ptr, ptr %4, align 8, !tbaa !5
  %38 = load i64, ptr %7, align 8, !tbaa !9
  call void @run_gc(ptr noundef %37, ptr noundef null, i64 noundef %38)
  %39 = load ptr, ptr %4, align 8, !tbaa !5
  %40 = load i64, ptr %6, align 8, !tbaa !9
  %41 = load i64, ptr %7, align 8, !tbaa !9
  %42 = call ptr @malloc_arr_force(ptr noundef %39, i64 noundef %40, i64 noundef %41)
  store ptr %42, ptr %3, align 8
  store i32 1, ptr %8, align 4
  br label %43

43:                                               ; preds = %36, %31
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #2
  %44 = load ptr, ptr %3, align 8
  ret ptr %44
}

; Function Attrs: nounwind uwtable
declare hidden ptr @malloc_arr_force(ptr noundef, i64 noundef, i64 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 40}
!12 = !{!"GARBAGE_COLLECTOR", !6, i64 0, !6, i64 8, !13, i64 16, !13, i64 96, !15, i64 176, !16, i64 200}
!13 = !{!"ALLOCATOR", !6, i64 0, !10, i64 8, !14, i64 16, !14, i64 48}
!14 = !{!"ALLOCATOR_LIST", !6, i64 0, !6, i64 8, !10, i64 16, !10, i64 24}
!15 = !{!"PTRS_MAP", !6, i64 0, !10, i64 8, !10, i64 16}
!16 = !{!"int", !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
declare hidden void @run_gc(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local ptr @garbage_collector_malloc_arr(ptr noundef %0, i64 noundef %1) local_unnamed_addr #0 {
  %3 = mul i64 %1, 48
  %4 = add i64 %3, 17
  %5 = getelementptr inbounds i8, ptr %0, i64 40
  %6 = load ptr, ptr %5, align 8, !tbaa !5
  %.not = icmp eq ptr %6, null
  br i1 %.not, label %11, label %7

7:                                                ; preds = %2
  %8 = getelementptr inbounds i8, ptr %6, i64 1
  %9 = load i64, ptr %8, align 8, !tbaa !15
  %10 = add i64 %3, 51
  %.not14 = icmp ult i64 %9, %10
  br i1 %.not14, label %11, label %12

11:                                               ; preds = %7, %2
  tail call void @run_gc(ptr noundef nonnull %0, ptr noundef null, i64 noundef %4)
  br label %12

12:                                               ; preds = %7, %11
  %13 = shl i64 %1, 1
  %14 = tail call ptr @malloc_arr_force(ptr noundef nonnull %0, i64 noundef %13, i64 noundef %4)
  ret ptr %14
}

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

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

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


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