; LLVM IR from txus/libtreadmill :: src/treadmill (gc)

; 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.tm_chunk_s = type { ptr, ptr }
%struct.tm_cell_s = type { ptr, ptr, ptr, i8 }

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

; Function Attrs: nounwind allocsize(0,1)
declare noalias ptr @calloc(i64 noundef, i64 noundef) #1

; Function Attrs: nounwind uwtable
define dso_local { ptr, ptr } @TmChunk_new(i32 noundef %0) #2 {
  %2 = alloca %struct.tm_chunk_s, align 8
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  store i32 %0, ptr %3, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  %10 = load i32, ptr %3, align 4, !tbaa !5
  %11 = sext i32 %10 to i64
  %12 = call noalias ptr @calloc(i64 noundef %11, i64 noundef 32) #4
  store ptr %12, ptr %4, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  %13 = load ptr, ptr %4, align 8, !tbaa !9
  store ptr %13, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  store i32 0, ptr %6, align 4, !tbaa !5
  br label %14

14:                                               ; preds = %43, %1
  %15 = load i32, ptr %6, align 4, !tbaa !5
  %16 = load i32, ptr %3, align 4, !tbaa !5
  %17 = icmp slt i32 %15, %16
  br i1 %17, label %19, label %18

18:                                               ; preds = %14
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  br label %46

19:                                               ; preds = %14
  %20 = load i32, ptr %6, align 4, !tbaa !5
  %21 = icmp sgt i32 %20, 0
  br i1 %21, label %22, label %29

22:                                               ; preds = %19
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %23 = load ptr, ptr %5, align 8, !tbaa !9
  store ptr %23, ptr %7, align 8, !tbaa !9
  %24 = load ptr, ptr %7, align 8, !tbaa !9
  %25 = getelementptr inbounds %struct.tm_cell_s, ptr %24, i32 -1
  store ptr %25, ptr %7, align 8, !tbaa !9
  %26 = load ptr, ptr %7, align 8, !tbaa !9
  %27 = load ptr, ptr %5, align 8, !tbaa !9
  %28 = getelementptr inbounds %struct.tm_cell_s, ptr %27, i32 0, i32 1
  store ptr %26, ptr %28, align 8, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  br label %29

29:                                               ; preds = %22, %19
  %30 = load i32, ptr %6, align 4, !tbaa !5
  %31 = load i32, ptr %3, align 4, !tbaa !5
  %32 = icmp slt i32 %30, %31
  br i1 %32, label %33, label %40

33:                                               ; preds = %29
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %34 = load ptr, ptr %5, align 8, !tbaa !9
  store ptr %34, ptr %8, align 8, !tbaa !9
  %35 = load ptr, ptr %8, align 8, !tbaa !9
  %36 = getelementptr inbounds %struct.tm_cell_s, ptr %35, i32 1
  store ptr %36, ptr %8, align 8, !tbaa !9
  %37 = load ptr, ptr %8, align 8, !tbaa !9
  %38 = load ptr, ptr %5, align 8, !tbaa !9
  %39 = getelementptr inbounds %struct.tm_cell_s, ptr %38, i32 0, i32 0
  store ptr %37, ptr %39, align 8, !tbaa !13
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  br label %40

40:                                               ; preds = %33, %29
  %41 = load ptr, ptr %5, align 8, !tbaa !9
  %42 = getelementptr inbounds %struct.tm_cell_s, ptr %41, i32 1
  store ptr %42, ptr %5, align 8, !tbaa !9
  br label %43

43:                                               ; preds = %40
  %44 = load i32, ptr %6, align 4, !tbaa !5
  %45 = add nsw i32 %44, 1
  store i32 %45, ptr %6, align 4, !tbaa !5
  br label %14, !llvm.loop !14

46:                                               ; preds = %18
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  %47 = load ptr, ptr %5, align 8, !tbaa !9
  %48 = getelementptr inbounds %struct.tm_cell_s, ptr %47, i32 -1
  store ptr %48, ptr %5, align 8, !tbaa !9
  store ptr %48, ptr %9, align 8, !tbaa !9
  %49 = load ptr, ptr %4, align 8, !tbaa !9
  %50 = getelementptr inbounds %struct.tm_cell_s, ptr %49, i32 0, i32 1
  store ptr null, ptr %50, align 8, !tbaa !11
  %51 = load ptr, ptr %9, align 8, !tbaa !9
  %52 = getelementptr inbounds %struct.tm_cell_s, ptr %51, i32 0, i32 0
  store ptr null, ptr %52, align 8, !tbaa !13
  %53 = getelementptr inbounds %struct.tm_chunk_s, ptr %2, i32 0, i32 0
  %54 = load ptr, ptr %4, align 8, !tbaa !9
  store ptr %54, ptr %53, align 8, !tbaa !16
  %55 = getelementptr inbounds %struct.tm_chunk_s, ptr %2, i32 0, i32 1
  %56 = load ptr, ptr %9, align 8, !tbaa !9
  store ptr %56, ptr %55, align 8, !tbaa !18
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  %57 = load { ptr, ptr }, ptr %2, align 8
  ret { ptr, ptr } %57
}

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

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

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

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,zeroed") allocsize(0,1) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @calloc(i64 noundef, i64 noundef) local_unnamed_addr #0

; Function Attrs: nofree nounwind memory(write, inaccessiblemem: readwrite) uwtable
define dso_local { ptr, ptr } @TmChunk_new(i32 noundef %0) local_unnamed_addr #1 {
  %2 = sext i32 %0 to i64
  %3 = tail call noalias ptr @calloc(i64 noundef %2, i64 noundef 32) #2
  %4 = icmp sgt i32 %0, 0
  br i1 %4, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %1
  %5 = getelementptr inbounds i8, ptr %3, i64 32
  store ptr %5, ptr %3, align 8, !tbaa !5
  %exitcond.peel.not = icmp eq i32 %0, 1
  br i1 %exitcond.peel.not, label %._crit_edge, label %.lr.ph.peel.next.preheader

.lr.ph.peel.next.preheader:                       ; preds = %.lr.ph.preheader
  %6 = add nsw i32 %0, -1
  %7 = add nsw i32 %0, -2
  %xtraiter = and i32 %6, 7
  %8 = icmp ult i32 %7, 7
  br i1 %8, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph.peel.next.preheader.new

.lr.ph.peel.next.preheader.new:                   ; preds = %.lr.ph.peel.next.preheader
  %unroll_iter = and i32 %6, -8
  br label %.lr.ph.peel.next

._crit_edge.loopexit.unr-lcssa:                   ; preds = %.lr.ph.peel.next, %.lr.ph.peel.next.preheader
  %.lcssa.ph = phi ptr [ poison, %.lr.ph.peel.next.preheader ], [ %36, %.lr.ph.peel.next ]
  %.023.unr = phi ptr [ %5, %.lr.ph.peel.next.preheader ], [ %36, %.lr.ph.peel.next ]
  %lcmp.mod.not = icmp eq i32 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge, label %.lr.ph.peel.next.epil

.lr.ph.peel.next.epil:                            ; preds = %._crit_edge.loopexit.unr-lcssa, %.lr.ph.peel.next.epil
  %.023.epil = phi ptr [ %11, %.lr.ph.peel.next.epil ], [ %.023.unr, %._crit_edge.loopexit.unr-lcssa ]
  %epil.iter = phi i32 [ %epil.iter.next, %.lr.ph.peel.next.epil ], [ 0, %._crit_edge.loopexit.unr-lcssa ]
  %9 = getelementptr inbounds i8, ptr %.023.epil, i64 -32
  %10 = getelementptr inbounds i8, ptr %.023.epil, i64 8
  store ptr %9, ptr %10, align 8, !tbaa !10
  %11 = getelementptr inbounds i8, ptr %.023.epil, i64 32
  store ptr %11, ptr %.023.epil, align 8, !tbaa !5
  %epil.iter.next = add i32 %epil.iter, 1
  %epil.iter.cmp.not = icmp eq i32 %epil.iter.next, %xtraiter
  br i1 %epil.iter.cmp.not, label %._crit_edge, label %.lr.ph.peel.next.epil, !llvm.loop !11

._crit_edge:                                      ; preds = %._crit_edge.loopexit.unr-lcssa, %.lr.ph.peel.next.epil, %.lr.ph.preheader, %1
  %.0.lcssa = phi ptr [ %3, %1 ], [ %5, %.lr.ph.preheader ], [ %.lcssa.ph, %._crit_edge.loopexit.unr-lcssa ], [ %11, %.lr.ph.peel.next.epil ]
  %12 = getelementptr inbounds i8, ptr %.0.lcssa, i64 -32
  %13 = getelementptr inbounds i8, ptr %3, i64 8
  store ptr null, ptr %13, align 8, !tbaa !10
  store ptr null, ptr %12, align 8, !tbaa !5
  %.fca.0.insert = insertvalue { ptr, ptr } poison, ptr %3, 0
  %.fca.1.insert = insertvalue { ptr, ptr } %.fca.0.insert, ptr %12, 1
  ret { ptr, ptr } %.fca.1.insert

.lr.ph.peel.next:                                 ; preds = %.lr.ph.peel.next, %.lr.ph.peel.next.preheader.new
  %.023 = phi ptr [ %5, %.lr.ph.peel.next.preheader.new ], [ %36, %.lr.ph.peel.next ]
  %niter = phi i32 [ 0, %.lr.ph.peel.next.preheader.new ], [ %niter.next.7, %.lr.ph.peel.next ]
  %14 = getelementptr inbounds i8, ptr %.023, i64 -32
  %15 = getelementptr inbounds i8, ptr %.023, i64 8
  store ptr %14, ptr %15, align 8, !tbaa !10
  %16 = getelementptr inbounds i8, ptr %.023, i64 32
  store ptr %16, ptr %.023, align 8, !tbaa !5
  %17 = getelementptr inbounds i8, ptr %.023, i64 40
  store ptr %.023, ptr %17, align 8, !tbaa !10
  %18 = getelementptr inbounds i8, ptr %.023, i64 64
  store ptr %18, ptr %16, align 8, !tbaa !5
  %19 = getelementptr inbounds i8, ptr %.023, i64 32
  %20 = getelementptr inbounds i8, ptr %.023, i64 72
  store ptr %19, ptr %20, align 8, !tbaa !10
  %21 = getelementptr inbounds i8, ptr %.023, i64 96
  store ptr %21, ptr %18, align 8, !tbaa !5
  %22 = getelementptr inbounds i8, ptr %.023, i64 64
  %23 = getelementptr inbounds i8, ptr %.023, i64 104
  store ptr %22, ptr %23, align 8, !tbaa !10
  %24 = getelementptr inbounds i8, ptr %.023, i64 128
  store ptr %24, ptr %21, align 8, !tbaa !5
  %25 = getelementptr inbounds i8, ptr %.023, i64 96
  %26 = getelementptr inbounds i8, ptr %.023, i64 136
  store ptr %25, ptr %26, align 8, !tbaa !10
  %27 = getelementptr inbounds i8, ptr %.023, i64 160
  store ptr %27, ptr %24, align 8, !tbaa !5
  %28 = getelementptr inbounds i8, ptr %.023, i64 128
  %29 = getelementptr inbounds i8, ptr %.023, i64 168
  store ptr %28, ptr %29, align 8, !tbaa !10
  %30 = getelementptr inbounds i8, ptr %.023, i64 192
  store ptr %30, ptr %27, align 8, !tbaa !5
  %31 = getelementptr inbounds i8, ptr %.023, i64 160
  %32 = getelementptr inbounds i8, ptr %.023, i64 200
  store ptr %31, ptr %32, align 8, !tbaa !10
  %33 = getelementptr inbounds i8, ptr %.023, i64 224
  store ptr %33, ptr %30, align 8, !tbaa !5
  %34 = getelementptr inbounds i8, ptr %.023, i64 192
  %35 = getelementptr inbounds i8, ptr %.023, i64 232
  store ptr %34, ptr %35, align 8, !tbaa !10
  %36 = getelementptr inbounds i8, ptr %.023, i64 256
  store ptr %36, ptr %33, align 8, !tbaa !5
  %niter.next.7 = add i32 %niter, 8
  %niter.ncmp.7 = icmp eq i32 %niter.next.7, %unroll_iter
  br i1 %niter.ncmp.7, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph.peel.next, !llvm.loop !13
}

attributes #0 = { mustprogress nofree nounwind willreturn allockind("alloc,zeroed") allocsize(0,1) 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 #1 = { nofree nounwind memory(write, inaccessiblemem: readwrite) 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,1) }

!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 = !{!"tm_cell_s", !7, i64 0, !7, i64 8, !7, i64 16, !8, i64 24}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!6, !7, i64 8}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.unroll.disable"}
!13 = distinct !{!13, !14, !15}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{!"llvm.loop.peeled.count", i32 1}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopFullUnrollPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass