; 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_heap_s = type { ptr, ptr, ptr, ptr, i32, i32, i32, i32, i64, ptr, ptr, ptr, ptr }
%struct.tm_state_header_s = type { ptr }
%struct.tm_cell_s = type { ptr, ptr, ptr, i8 }
%struct.tm_darray_s = type { i32, i32, i64, i64, ptr }

@stderr = external global ptr, align 8
@.str.8 = external hidden unnamed_addr constant [39 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [70 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

; 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 void @TmHeap_destroy(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  %6 = load ptr, ptr @stderr, align 8, !tbaa !5
  %7 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %6, ptr noundef @.str.8, ptr noundef @.str.9, i32 noundef 243) #5
  %8 = load ptr, ptr %2, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.tm_heap_s, ptr %8, i32 0, i32 11
  %10 = load ptr, ptr %9, align 8, !tbaa !9
  %11 = getelementptr inbounds %struct.tm_state_header_s, ptr %10, i32 0, i32 0
  store ptr @null_rootset, ptr %11, align 8, !tbaa !13
  %12 = load ptr, ptr %2, align 8, !tbaa !5
  call void @Tm_flip(ptr noundef %12)
  %13 = load ptr, ptr %2, align 8, !tbaa !5
  call void @Tm_flip(ptr noundef %13)
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #5
  store ptr null, ptr %3, align 8, !tbaa !5
  %14 = load ptr, ptr %2, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.tm_heap_s, ptr %14, i32 0, i32 0
  %16 = load ptr, ptr %15, align 8, !tbaa !15
  store ptr %16, ptr %3, align 8, !tbaa !5
  br label %17

17:                                               ; preds = %23, %1
  %18 = load ptr, ptr %3, align 8, !tbaa !5
  %19 = load ptr, ptr %2, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.tm_heap_s, ptr %19, i32 0, i32 2
  %21 = load ptr, ptr %20, align 8, !tbaa !16
  %22 = icmp ne ptr %18, %21
  br i1 %22, label %23, label %33

23:                                               ; preds = %17
  %24 = load ptr, ptr %2, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.tm_heap_s, ptr %24, i32 0, i32 9
  %26 = load ptr, ptr %25, align 8, !tbaa !17
  %27 = load ptr, ptr %3, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.tm_cell_s, ptr %27, i32 0, i32 2
  %29 = load ptr, ptr %28, align 8, !tbaa !18
  call void %26(ptr noundef %29)
  %30 = load ptr, ptr %3, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.tm_cell_s, ptr %30, i32 0, i32 0
  %32 = load ptr, ptr %31, align 8, !tbaa !20
  store ptr %32, ptr %3, align 8, !tbaa !5
  br label %17, !llvm.loop !21

33:                                               ; preds = %17
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #5
  store i32 0, ptr %4, align 4, !tbaa !23
  br label %34

34:                                               ; preds = %54, %33
  %35 = load i32, ptr %4, align 4, !tbaa !23
  %36 = load ptr, ptr %2, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.tm_heap_s, ptr %36, i32 0, i32 12
  %38 = load ptr, ptr %37, align 8, !tbaa !24
  %39 = getelementptr inbounds %struct.tm_darray_s, ptr %38, i32 0, i32 0
  %40 = load i32, ptr %39, align 8, !tbaa !25
  %41 = icmp slt i32 %35, %40
  br i1 %41, label %43, label %42

42:                                               ; preds = %34
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #5
  br label %57

43:                                               ; preds = %34
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #5
  %44 = load ptr, ptr %2, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.tm_heap_s, ptr %44, i32 0, i32 12
  %46 = load ptr, ptr %45, align 8, !tbaa !24
  %47 = getelementptr inbounds %struct.tm_darray_s, ptr %46, i32 0, i32 4
  %48 = load ptr, ptr %47, align 8, !tbaa !27
  %49 = load i32, ptr %4, align 4, !tbaa !23
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds ptr, ptr %48, i64 %50
  %52 = load ptr, ptr %51, align 8, !tbaa !5
  store ptr %52, ptr %5, align 8, !tbaa !5
  %53 = load ptr, ptr %5, align 8, !tbaa !5
  call void @free(ptr noundef %53) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #5
  br label %54

54:                                               ; preds = %43
  %55 = load i32, ptr %4, align 4, !tbaa !23
  %56 = add nsw i32 %55, 1
  store i32 %56, ptr %4, align 4, !tbaa !23
  br label %34, !llvm.loop !28

57:                                               ; preds = %42
  %58 = load ptr, ptr %2, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.tm_heap_s, ptr %58, i32 0, i32 12
  %60 = load ptr, ptr %59, align 8, !tbaa !24
  call void @Tm_DArray_destroy(ptr noundef %60)
  %61 = load ptr, ptr %2, align 8, !tbaa !5
  call void @free(ptr noundef %61) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #5
  ret void
}

; Function Attrs: nounwind
declare i32 @fprintf(ptr noundef, ptr noundef, ...) #2

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

; Function Attrs: nounwind uwtable
declare dso_local void @Tm_flip(ptr noundef) #1

; Function Attrs: nounwind
declare void @free(ptr noundef) #2

declare void @Tm_DArray_destroy(ptr noundef) #4

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 "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 = { "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 #5 = { 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, !6, i64 72}
!10 = !{!"tm_heap_s", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !11, i64 32, !11, i64 36, !11, i64 40, !11, i64 44, !12, i64 48, !6, i64 56, !6, i64 64, !6, i64 72, !6, i64 80}
!11 = !{!"int", !7, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!14, !6, i64 0}
!14 = !{!"tm_state_header_s", !6, i64 0}
!15 = !{!10, !6, i64 0}
!16 = !{!10, !6, i64 16}
!17 = !{!10, !6, i64 56}
!18 = !{!19, !6, i64 16}
!19 = !{!"tm_cell_s", !6, i64 0, !6, i64 8, !6, i64 16, !7, i64 24}
!20 = !{!19, !6, i64 0}
!21 = distinct !{!21, !22}
!22 = !{!"llvm.loop.mustprogress"}
!23 = !{!11, !11, i64 0}
!24 = !{!10, !6, i64 80}
!25 = !{!26, !11, i64 0}
!26 = !{!"tm_darray_s", !11, i64 0, !11, i64 4, !12, i64 8, !12, i64 16, !6, i64 24}
!27 = !{!26, !6, i64 24}
!28 = distinct !{!28, !22}


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

@stderr = external local_unnamed_addr global ptr, align 8
@.str.8 = external hidden unnamed_addr constant [39 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [70 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local void @TmHeap_destroy(ptr noundef %0) local_unnamed_addr #0 {
  %2 = load ptr, ptr @stderr, align 8, !tbaa !5
  %3 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %2, ptr noundef nonnull @.str.8, ptr noundef nonnull @.str.9, i32 noundef 243) #5
  %4 = getelementptr inbounds i8, ptr %0, i64 72
  %5 = load ptr, ptr %4, align 8, !tbaa !9
  store ptr @null_rootset, ptr %5, align 8, !tbaa !13
  tail call void @Tm_flip(ptr noundef %0)
  tail call void @Tm_flip(ptr noundef %0)
  %6 = getelementptr inbounds i8, ptr %0, i64 16
  %.017 = load ptr, ptr %0, align 8, !tbaa !5
  %7 = load ptr, ptr %6, align 8, !tbaa !15
  %.not18 = icmp eq ptr %.017, %7
  br i1 %.not18, label %.preheader, label %.lr.ph

.lr.ph:                                           ; preds = %1
  %8 = getelementptr inbounds i8, ptr %0, i64 56
  br label %13

.preheader:                                       ; preds = %13, %1
  %9 = getelementptr inbounds i8, ptr %0, i64 80
  %10 = load ptr, ptr %9, align 8, !tbaa !16
  %11 = load i32, ptr %10, align 8, !tbaa !17
  %12 = icmp sgt i32 %11, 0
  br i1 %12, label %.lr.ph21, label %._crit_edge

13:                                               ; preds = %.lr.ph, %13
  %.019 = phi ptr [ %.017, %.lr.ph ], [ %.0, %13 ]
  %14 = load ptr, ptr %8, align 8, !tbaa !19
  %15 = getelementptr inbounds i8, ptr %.019, i64 16
  %16 = load ptr, ptr %15, align 8, !tbaa !20
  tail call void %14(ptr noundef %16) #6
  %.0 = load ptr, ptr %.019, align 8, !tbaa !5
  %17 = load ptr, ptr %6, align 8, !tbaa !15
  %.not = icmp eq ptr %.0, %17
  br i1 %.not, label %.preheader, label %13, !llvm.loop !22

._crit_edge:                                      ; preds = %.lr.ph21, %.preheader
  %.lcssa = phi ptr [ %10, %.preheader ], [ %23, %.lr.ph21 ]
  tail call void @Tm_DArray_destroy(ptr noundef nonnull %.lcssa) #6
  tail call void @free(ptr noundef nonnull %0) #6
  ret void

.lr.ph21:                                         ; preds = %.preheader, %.lr.ph21
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph21 ], [ 0, %.preheader ]
  %18 = phi ptr [ %23, %.lr.ph21 ], [ %10, %.preheader ]
  %19 = getelementptr inbounds i8, ptr %18, i64 24
  %20 = load ptr, ptr %19, align 8, !tbaa !24
  %21 = getelementptr inbounds ptr, ptr %20, i64 %indvars.iv
  %22 = load ptr, ptr %21, align 8, !tbaa !5
  tail call void @free(ptr noundef %22) #6
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %23 = load ptr, ptr %9, align 8, !tbaa !16
  %24 = load i32, ptr %23, align 8, !tbaa !17
  %25 = sext i32 %24 to i64
  %26 = icmp slt i64 %indvars.iv.next, %25
  br i1 %26, label %.lr.ph21, label %._crit_edge, !llvm.loop !25
}

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden ptr @null_rootset(ptr noundef) #2

; Function Attrs: nounwind uwtable
declare dso_local void @Tm_flip(ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #3

declare void @Tm_DArray_destroy(ptr noundef) local_unnamed_addr #4

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 = { 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 #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 = { mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, 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 #4 = { "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 #5 = { cold nounwind }
attributes #6 = { 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, !6, i64 72}
!10 = !{!"tm_heap_s", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !11, i64 32, !11, i64 36, !11, i64 40, !11, i64 44, !12, i64 48, !6, i64 56, !6, i64 64, !6, i64 72, !6, i64 80}
!11 = !{!"int", !7, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!14, !6, i64 0}
!14 = !{!"tm_state_header_s", !6, i64 0}
!15 = !{!10, !6, i64 16}
!16 = !{!10, !6, i64 80}
!17 = !{!18, !11, i64 0}
!18 = !{!"tm_darray_s", !11, i64 0, !11, i64 4, !12, i64 8, !12, i64 16, !6, i64 24}
!19 = !{!10, !6, i64 56}
!20 = !{!21, !6, i64 16}
!21 = !{!"tm_cell_s", !6, i64 0, !6, i64 8, !6, i64 16, !7, i64 24}
!22 = distinct !{!22, !23}
!23 = !{!"llvm.loop.mustprogress"}
!24 = !{!18, !6, i64 24}
!25 = distinct !{!25, !23}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass