; LLVM IR from brewlin/garbage-collect :: copying (copying)

; 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.header = type { i64, i64, i64, i64, ptr, ptr }

@free_p = external dso_local global ptr, align 8
@.str.1 = external hidden unnamed_addr constant [44 x i8], align 1

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

declare i32 @printf(ptr noundef, ...) #1

; 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 dso_local ptr @get_header_by_from(ptr noundef) #2

; Function Attrs: nounwind uwtable
define dso_local ptr @gc_copy(ptr noundef %0) #2 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  %8 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  %9 = load ptr, ptr %3, align 8, !tbaa !5
  %10 = call ptr @get_header_by_from(ptr noundef %9)
  store ptr %10, ptr %4, align 8, !tbaa !5
  %11 = icmp ne ptr %10, null
  br i1 %11, label %13, label %12

12:                                               ; preds = %1
  store ptr null, ptr %2, align 8
  store i32 1, ptr %5, align 4
  br label %90

13:                                               ; preds = %1
  %14 = load ptr, ptr %4, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.header, ptr %14, i32 0, i32 1
  %16 = load i64, ptr %15, align 8, !tbaa !9
  %17 = and i64 %16, 1
  %18 = icmp ne i64 %17, 0
  br i1 %18, label %19, label %25

19:                                               ; preds = %13
  %20 = load ptr, ptr %4, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.header, ptr %20, i32 0, i32 1
  %22 = load i64, ptr %21, align 8, !tbaa !9
  %23 = and i64 %22, 4
  %24 = icmp ne i64 %23, 0
  br i1 %24, label %85, label %25

25:                                               ; preds = %19, %13
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  %26 = load ptr, ptr @free_p, align 8, !tbaa !5
  store ptr %26, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %27 = load ptr, ptr %6, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.header, ptr %27, i32 0, i32 2
  %29 = load i64, ptr %28, align 8, !tbaa !12
  store i64 %29, ptr %7, align 8, !tbaa !13
  %30 = load ptr, ptr %6, align 8, !tbaa !5
  %31 = load ptr, ptr %4, align 8, !tbaa !5
  %32 = load ptr, ptr %4, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.header, ptr %32, i32 0, i32 2
  %34 = load i64, ptr %33, align 8, !tbaa !12
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %30, ptr align 8 %31, i64 %34, i1 false)
  %35 = load ptr, ptr %4, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.header, ptr %35, i32 0, i32 1
  %37 = load i64, ptr %36, align 8, !tbaa !9
  %38 = or i64 %37, 4
  store i64 %38, ptr %36, align 8, !tbaa !9
  %39 = load ptr, ptr %4, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.header, ptr %39, i32 0, i32 1
  store i64 1, ptr %40, align 8, !tbaa !9
  %41 = load ptr, ptr %4, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.header, ptr %41, i32 0, i32 2
  %43 = load i64, ptr %42, align 8, !tbaa !12
  %44 = load ptr, ptr @free_p, align 8, !tbaa !5
  %45 = getelementptr inbounds i8, ptr %44, i64 %43
  store ptr %45, ptr @free_p, align 8, !tbaa !5
  %46 = load i64, ptr %7, align 8, !tbaa !13
  %47 = load ptr, ptr %4, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.header, ptr %47, i32 0, i32 2
  %49 = load i64, ptr %48, align 8, !tbaa !12
  %50 = sub i64 %46, %49
  %51 = load ptr, ptr @free_p, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.header, ptr %51, i32 0, i32 2
  store i64 %50, ptr %52, align 8, !tbaa !12
  %53 = load ptr, ptr %6, align 8, !tbaa !5
  %54 = load ptr, ptr %4, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.header, ptr %54, i32 0, i32 5
  store ptr %53, ptr %55, align 8, !tbaa !14
  %56 = load ptr, ptr %3, align 8, !tbaa !5
  %57 = load ptr, ptr %4, align 8, !tbaa !5
  %58 = load ptr, ptr %6, align 8, !tbaa !5
  %59 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, ptr noundef %56, ptr noundef %57, ptr noundef %58)
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  %60 = load ptr, ptr %6, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.header, ptr %60, i64 1
  store ptr %61, ptr %8, align 8, !tbaa !5
  br label %62

62:                                               ; preds = %79, %25
  %63 = load ptr, ptr %8, align 8, !tbaa !5
  %64 = load ptr, ptr %6, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.header, ptr %64, i64 1
  %66 = ptrtoint ptr %65 to i64
  %67 = load ptr, ptr %6, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.header, ptr %67, i32 0, i32 2
  %69 = load i64, ptr %68, align 8, !tbaa !12
  %70 = sub i64 %69, 48
  %71 = add i64 %66, %70
  %72 = inttoptr i64 %71 to ptr
  %73 = icmp ult ptr %63, %72
  br i1 %73, label %75, label %74

74:                                               ; preds = %62
  store i32 2, ptr %5, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  br label %82

75:                                               ; preds = %62
  %76 = load ptr, ptr %8, align 8, !tbaa !5
  %77 = load ptr, ptr %76, align 8, !tbaa !5
  %78 = call ptr @gc_copy(ptr noundef %77)
  br label %79

79:                                               ; preds = %75
  %80 = load ptr, ptr %8, align 8, !tbaa !5
  %81 = getelementptr inbounds i8, ptr %80, i32 1
  store ptr %81, ptr %8, align 8, !tbaa !5
  br label %62, !llvm.loop !15

82:                                               ; preds = %74
  %83 = load ptr, ptr %6, align 8, !tbaa !5
  %84 = getelementptr inbounds %struct.header, ptr %83, i64 1
  store ptr %84, ptr %2, align 8
  store i32 1, ptr %5, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  br label %90

85:                                               ; preds = %19
  %86 = load ptr, ptr %4, align 8, !tbaa !5
  %87 = getelementptr inbounds %struct.header, ptr %86, i32 0, i32 5
  %88 = load ptr, ptr %87, align 8, !tbaa !14
  %89 = getelementptr inbounds %struct.header, ptr %88, i64 1
  store ptr %89, ptr %2, align 8
  store i32 1, ptr %5, align 4
  br label %90

90:                                               ; preds = %85, %82, %12
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  %91 = load ptr, ptr %2, align 8
  ret ptr %91
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #3

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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { 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, !11, i64 8}
!10 = !{!"header", !11, i64 0, !11, i64 8, !11, i64 16, !11, i64 24, !6, i64 32, !6, i64 40}
!11 = !{!"long", !7, i64 0}
!12 = !{!10, !11, i64 16}
!13 = !{!11, !11, i64 0}
!14 = !{!10, !6, i64 40}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}


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

@free_p = external dso_local local_unnamed_addr global ptr, align 8
@.str.1 = external hidden unnamed_addr constant [44 x i8], align 1

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local ptr @get_header_by_from(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local ptr @gc_copy(ptr noundef %0) local_unnamed_addr #1 {
  %2 = tail call ptr @get_header_by_from(ptr noundef %0)
  %.not = icmp eq ptr %2, null
  br i1 %.not, label %.loopexit, label %3

3:                                                ; preds = %1
  %4 = getelementptr inbounds i8, ptr %2, i64 8
  %5 = load i64, ptr %4, align 8, !tbaa !5
  %6 = and i64 %5, 5
  %or.cond.not = icmp eq i64 %6, 5
  br i1 %or.cond.not, label %34, label %7

7:                                                ; preds = %3
  %8 = load ptr, ptr @free_p, align 8, !tbaa !11
  %9 = getelementptr inbounds i8, ptr %8, i64 16
  %10 = load i64, ptr %9, align 8, !tbaa !12
  %11 = getelementptr inbounds i8, ptr %2, i64 16
  %12 = load i64, ptr %11, align 8, !tbaa !12
  tail call void @llvm.memcpy.p0.p0.i64(ptr align 8 %8, ptr nonnull align 8 %2, i64 %12, i1 false)
  store i64 1, ptr %4, align 8, !tbaa !5
  %13 = load i64, ptr %11, align 8, !tbaa !12
  %14 = load ptr, ptr @free_p, align 8, !tbaa !11
  %15 = getelementptr inbounds i8, ptr %14, i64 %13
  store ptr %15, ptr @free_p, align 8, !tbaa !11
  %16 = sub i64 %10, %13
  %17 = getelementptr inbounds i8, ptr %15, i64 16
  store i64 %16, ptr %17, align 8, !tbaa !12
  %18 = getelementptr inbounds i8, ptr %2, i64 40
  store ptr %8, ptr %18, align 8, !tbaa !13
  %19 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, ptr noundef %0, ptr noundef nonnull %2, ptr noundef %8)
  %20 = getelementptr inbounds i8, ptr %8, i64 48
  %21 = ptrtoint ptr %20 to i64
  %22 = add i64 %21, -48
  %23 = load i64, ptr %9, align 8, !tbaa !12
  %24 = add i64 %22, %23
  %25 = inttoptr i64 %24 to ptr
  %26 = icmp ult ptr %20, %25
  br i1 %26, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %7, %.lr.ph
  %.029 = phi ptr [ %29, %.lr.ph ], [ %20, %7 ]
  %27 = load ptr, ptr %.029, align 8, !tbaa !11
  %28 = tail call ptr @gc_copy(ptr noundef %27)
  %29 = getelementptr inbounds i8, ptr %.029, i64 1
  %30 = load i64, ptr %9, align 8, !tbaa !12
  %31 = add i64 %22, %30
  %32 = inttoptr i64 %31 to ptr
  %33 = icmp ult ptr %29, %32
  br i1 %33, label %.lr.ph, label %.loopexit, !llvm.loop !14

34:                                               ; preds = %3
  %35 = getelementptr inbounds i8, ptr %2, i64 40
  %36 = load ptr, ptr %35, align 8, !tbaa !13
  %37 = getelementptr inbounds i8, ptr %36, i64 48
  br label %.loopexit

.loopexit:                                        ; preds = %.lr.ph, %7, %1, %34
  %.025 = phi ptr [ %37, %34 ], [ null, %1 ], [ %20, %7 ], [ %20, %.lr.ph ]
  ret ptr %.025
}

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

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

!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 8}
!6 = !{!"header", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !10, i64 32, !10, i64 40}
!7 = !{!"long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!10, !10, i64 0}
!12 = !{!6, !7, i64 16}
!13 = !{!6, !10, i64 40}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass