; LLVM IR from daanx/mimalloc-bench :: bench/cache-scratch (cache-scratch)

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

%class.workerArg = type <{ ptr, i32, i32, i32, [4 x i8] }>

; Function Attrs: mustprogress uwtable
define dso_local ptr @worker(ptr noundef %0) #0 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca %class.workerArg, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i8, align 1
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #5
  %11 = load ptr, ptr %2, align 8, !tbaa !5
  store ptr %11, ptr %3, align 8, !tbaa !5
  %12 = load ptr, ptr %3, align 8, !tbaa !5
  %13 = getelementptr inbounds %class.workerArg, ptr %12, i32 0, i32 0
  %14 = load ptr, ptr %13, align 8, !tbaa !9
  %15 = icmp eq ptr %14, null
  br i1 %15, label %17, label %16

16:                                               ; preds = %1
  call void @_ZdlPvm(ptr noundef %14, i64 noundef 1) #6
  br label %17

17:                                               ; preds = %16, %1
  call void @llvm.lifetime.start.p0(i64 24, ptr %4) #5
  %18 = load ptr, ptr %3, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %4, ptr align 8 %18, i64 24, i1 false), !tbaa.struct !12
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #5
  store i32 0, ptr %5, align 4, !tbaa !13
  br label %19

19:                                               ; preds = %69, %17
  %20 = load i32, ptr %5, align 4, !tbaa !13
  %21 = getelementptr inbounds %class.workerArg, ptr %4, i32 0, i32 2
  %22 = load i32, ptr %21, align 4, !tbaa !14
  %23 = icmp slt i32 %20, %22
  br i1 %23, label %25, label %24

24:                                               ; preds = %19
  store i32 2, ptr %6, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #5
  br label %72

25:                                               ; preds = %19
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #5
  %26 = getelementptr inbounds %class.workerArg, ptr %4, i32 0, i32 1
  %27 = load i32, ptr %26, align 8, !tbaa !15
  %28 = sext i32 %27 to i64
  %29 = call noalias noundef nonnull ptr @_Znam(i64 noundef %28) #7
  store ptr %29, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #5
  store i32 0, ptr %8, align 4, !tbaa !13
  br label %30

30:                                               ; preds = %61, %25
  %31 = load i32, ptr %8, align 4, !tbaa !13
  %32 = getelementptr inbounds %class.workerArg, ptr %4, i32 0, i32 3
  %33 = load i32, ptr %32, align 8, !tbaa !16
  %34 = icmp slt i32 %31, %33
  br i1 %34, label %36, label %35

35:                                               ; preds = %30
  store i32 5, ptr %6, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #5
  br label %64

36:                                               ; preds = %30
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #5
  store i32 0, ptr %9, align 4, !tbaa !13
  br label %37

37:                                               ; preds = %57, %36
  %38 = load i32, ptr %9, align 4, !tbaa !13
  %39 = getelementptr inbounds %class.workerArg, ptr %4, i32 0, i32 1
  %40 = load i32, ptr %39, align 8, !tbaa !15
  %41 = icmp slt i32 %38, %40
  br i1 %41, label %43, label %42

42:                                               ; preds = %37
  store i32 8, ptr %6, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #5
  br label %60

43:                                               ; preds = %37
  %44 = load i32, ptr %9, align 4, !tbaa !13
  %45 = trunc i32 %44 to i8
  %46 = load ptr, ptr %7, align 8, !tbaa !5
  %47 = load i32, ptr %9, align 4, !tbaa !13
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds i8, ptr %46, i64 %48
  store i8 %45, ptr %49, align 1, !tbaa !17
  call void @llvm.lifetime.start.p0(i64 1, ptr %10) #5
  %50 = load ptr, ptr %7, align 8, !tbaa !5
  %51 = load i32, ptr %9, align 4, !tbaa !13
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds i8, ptr %50, i64 %52
  %54 = load i8, ptr %53, align 1, !tbaa !17
  store volatile i8 %54, ptr %10, align 1, !tbaa !17
  %55 = load volatile i8, ptr %10, align 1, !tbaa !17
  %56 = add i8 %55, 1
  store volatile i8 %56, ptr %10, align 1, !tbaa !17
  call void @llvm.lifetime.end.p0(i64 1, ptr %10) #5
  br label %57

57:                                               ; preds = %43
  %58 = load i32, ptr %9, align 4, !tbaa !13
  %59 = add nsw i32 %58, 1
  store i32 %59, ptr %9, align 4, !tbaa !13
  br label %37, !llvm.loop !18

60:                                               ; preds = %42
  br label %61

61:                                               ; preds = %60
  %62 = load i32, ptr %8, align 4, !tbaa !13
  %63 = add nsw i32 %62, 1
  store i32 %63, ptr %8, align 4, !tbaa !13
  br label %30, !llvm.loop !20

64:                                               ; preds = %35
  %65 = load ptr, ptr %7, align 8, !tbaa !5
  %66 = icmp eq ptr %65, null
  br i1 %66, label %68, label %67

67:                                               ; preds = %64
  call void @_ZdaPv(ptr noundef %65) #6
  br label %68

68:                                               ; preds = %67, %64
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #5
  br label %69

69:                                               ; preds = %68
  %70 = load i32, ptr %5, align 4, !tbaa !13
  %71 = add nsw i32 %70, 1
  store i32 %71, ptr %5, align 4, !tbaa !13
  br label %19, !llvm.loop !21

72:                                               ; preds = %24
  store i32 1, ptr %6, align 4
  call void @llvm.lifetime.end.p0(i64 24, ptr %4) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #5
  ret ptr null
}

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

; Function Attrs: nobuiltin nounwind
declare void @_ZdlPvm(ptr noundef, i64 noundef) #2

; 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

; Function Attrs: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znam(i64 noundef) #4

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

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

attributes #0 = { mustprogress 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 nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nobuiltin 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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { nobuiltin allocsize(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 #5 = { nounwind }
attributes #6 = { builtin nounwind }
attributes #7 = { builtin allocsize(0) }

!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++ TBAA"}
!9 = !{!10, !6, i64 0}
!10 = !{!"_ZTS9workerArg", !6, i64 0, !11, i64 8, !11, i64 12, !11, i64 16}
!11 = !{!"int", !7, i64 0}
!12 = !{i64 0, i64 8, !5, i64 8, i64 4, !13, i64 12, i64 4, !13, i64 16, i64 4, !13}
!13 = !{!11, !11, i64 0}
!14 = !{!10, !11, i64 12}
!15 = !{!10, !11, i64 8}
!16 = !{!10, !11, i64 16}
!17 = !{!7, !7, i64 0}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}
!20 = distinct !{!20, !19}
!21 = distinct !{!21, !19}


; 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 nounwind uwtable
define dso_local noalias noundef ptr @worker(ptr nocapture noundef readonly %0) local_unnamed_addr #0 {
  %2 = alloca i8, align 1
  %3 = load ptr, ptr %0, align 8, !tbaa !5
  %4 = icmp eq ptr %3, null
  br i1 %4, label %6, label %5

5:                                                ; preds = %1
  tail call void @_ZdlPvm(ptr noundef nonnull %3, i64 noundef 1) #3
  br label %6

6:                                                ; preds = %5, %1
  %.sroa.3.0..sroa_idx = getelementptr inbounds i8, ptr %0, i64 8
  %.sroa.3.0.copyload = load i32, ptr %.sroa.3.0..sroa_idx, align 8, !tbaa !11
  %7 = freeze i32 %.sroa.3.0.copyload
  %.sroa.5.0..sroa_idx = getelementptr inbounds i8, ptr %0, i64 12
  %.sroa.5.0.copyload = load i32, ptr %.sroa.5.0..sroa_idx, align 4, !tbaa !11
  %.sroa.6.0..sroa_idx = getelementptr inbounds i8, ptr %0, i64 16
  %.sroa.6.0.copyload = load i32, ptr %.sroa.6.0..sroa_idx, align 8, !tbaa !11
  %8 = icmp sgt i32 %.sroa.5.0.copyload, 0
  %9 = icmp sgt i32 %.sroa.6.0.copyload, 0
  %or.cond = select i1 %8, i1 %9, i1 false
  %10 = icmp sgt i32 %7, 0
  %or.cond32 = select i1 %or.cond, i1 %10, i1 false
  br i1 %or.cond32, label %.preheader19.us.us.preheader, label %._crit_edge

.preheader19.us.us.preheader:                     ; preds = %6
  %xtraiter = and i32 %7, 3
  %11 = icmp ult i32 %7, 4
  %unroll_iter = and i32 %7, -4
  %lcmp.mod.not = icmp eq i32 %xtraiter, 0
  br label %.preheader19.us.us

.preheader19.us.us:                               ; preds = %.preheader19.us.us.preheader, %._crit_edge22.split.us.us.us
  %.01723.us.us = phi i32 [ %28, %._crit_edge22.split.us.us.us ], [ 0, %.preheader19.us.us.preheader ]
  br label %.preheader.us.us.us

.preheader.us.us.us:                              ; preds = %._crit_edge.us.us.us, %.preheader19.us.us
  %.01621.us.us.us = phi i32 [ 0, %.preheader19.us.us ], [ %27, %._crit_edge.us.us.us ]
  br i1 %11, label %._crit_edge.us.us.us.unr-lcssa, label %.preheader.us.us.us.new

.preheader.us.us.us.new:                          ; preds = %.preheader.us.us.us, %.preheader.us.us.us.new
  %.020.us.us.us = phi i32 [ %23, %.preheader.us.us.us.new ], [ 0, %.preheader.us.us.us ]
  %niter = phi i32 [ %niter.next.3, %.preheader.us.us.us.new ], [ 0, %.preheader.us.us.us ]
  %12 = trunc i32 %.020.us.us.us to i8
  call void @llvm.lifetime.start.p0(i64 1, ptr nonnull %2)
  store volatile i8 %12, ptr %2, align 1, !tbaa !12
  %.0..0..0..0..us.us.us = load volatile i8, ptr %2, align 1, !tbaa !12
  %13 = add i8 %.0..0..0..0..us.us.us, 1
  store volatile i8 %13, ptr %2, align 1, !tbaa !12
  call void @llvm.lifetime.end.p0(i64 1, ptr nonnull %2)
  %14 = trunc i32 %.020.us.us.us to i8
  %15 = or disjoint i8 %14, 1
  call void @llvm.lifetime.start.p0(i64 1, ptr nonnull %2)
  store volatile i8 %15, ptr %2, align 1, !tbaa !12
  %.0..0..0..0..us.us.us.1 = load volatile i8, ptr %2, align 1, !tbaa !12
  %16 = add i8 %.0..0..0..0..us.us.us.1, 1
  store volatile i8 %16, ptr %2, align 1, !tbaa !12
  call void @llvm.lifetime.end.p0(i64 1, ptr nonnull %2)
  %17 = trunc i32 %.020.us.us.us to i8
  %18 = or disjoint i8 %17, 2
  call void @llvm.lifetime.start.p0(i64 1, ptr nonnull %2)
  store volatile i8 %18, ptr %2, align 1, !tbaa !12
  %.0..0..0..0..us.us.us.2 = load volatile i8, ptr %2, align 1, !tbaa !12
  %19 = add i8 %.0..0..0..0..us.us.us.2, 1
  store volatile i8 %19, ptr %2, align 1, !tbaa !12
  call void @llvm.lifetime.end.p0(i64 1, ptr nonnull %2)
  %20 = trunc i32 %.020.us.us.us to i8
  %21 = or disjoint i8 %20, 3
  call void @llvm.lifetime.start.p0(i64 1, ptr nonnull %2)
  store volatile i8 %21, ptr %2, align 1, !tbaa !12
  %.0..0..0..0..us.us.us.3 = load volatile i8, ptr %2, align 1, !tbaa !12
  %22 = add i8 %.0..0..0..0..us.us.us.3, 1
  store volatile i8 %22, ptr %2, align 1, !tbaa !12
  call void @llvm.lifetime.end.p0(i64 1, ptr nonnull %2)
  %23 = add nuw nsw i32 %.020.us.us.us, 4
  %niter.next.3 = add i32 %niter, 4
  %niter.ncmp.3 = icmp eq i32 %niter.next.3, %unroll_iter
  br i1 %niter.ncmp.3, label %._crit_edge.us.us.us.unr-lcssa, label %.preheader.us.us.us.new, !llvm.loop !13

._crit_edge.us.us.us.unr-lcssa:                   ; preds = %.preheader.us.us.us.new, %.preheader.us.us.us
  %.020.us.us.us.unr = phi i32 [ 0, %.preheader.us.us.us ], [ %23, %.preheader.us.us.us.new ]
  br i1 %lcmp.mod.not, label %._crit_edge.us.us.us, label %.epil.preheader

.epil.preheader:                                  ; preds = %._crit_edge.us.us.us.unr-lcssa, %.epil.preheader
  %.020.us.us.us.epil = phi i32 [ %26, %.epil.preheader ], [ %.020.us.us.us.unr, %._crit_edge.us.us.us.unr-lcssa ]
  %epil.iter = phi i32 [ %epil.iter.next, %.epil.preheader ], [ 0, %._crit_edge.us.us.us.unr-lcssa ]
  %24 = trunc i32 %.020.us.us.us.epil to i8
  call void @llvm.lifetime.start.p0(i64 1, ptr nonnull %2)
  store volatile i8 %24, ptr %2, align 1, !tbaa !12
  %.0..0..0..0..us.us.us.epil = load volatile i8, ptr %2, align 1, !tbaa !12
  %25 = add i8 %.0..0..0..0..us.us.us.epil, 1
  store volatile i8 %25, ptr %2, align 1, !tbaa !12
  call void @llvm.lifetime.end.p0(i64 1, ptr nonnull %2)
  %26 = add nuw nsw i32 %.020.us.us.us.epil, 1
  %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.us.us.us, label %.epil.preheader, !llvm.loop !15

._crit_edge.us.us.us:                             ; preds = %.epil.preheader, %._crit_edge.us.us.us.unr-lcssa
  %27 = add nuw nsw i32 %.01621.us.us.us, 1
  %exitcond30.not = icmp eq i32 %27, %.sroa.6.0.copyload
  br i1 %exitcond30.not, label %._crit_edge22.split.us.us.us, label %.preheader.us.us.us, !llvm.loop !17

._crit_edge22.split.us.us.us:                     ; preds = %._crit_edge.us.us.us
  %28 = add nuw nsw i32 %.01723.us.us, 1
  %exitcond31.not = icmp eq i32 %28, %.sroa.5.0.copyload
  br i1 %exitcond31.not, label %._crit_edge, label %.preheader19.us.us, !llvm.loop !18

._crit_edge:                                      ; preds = %._crit_edge22.split.us.us.us, %6
  ret ptr null
}

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

; Function Attrs: nobuiltin nounwind
declare void @_ZdlPvm(ptr noundef, i64 noundef) local_unnamed_addr #2

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

attributes #0 = { mustprogress 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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nobuiltin 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 = { builtin 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, !7, i64 0}
!6 = !{!"_ZTS9workerArg", !7, i64 0, !10, i64 8, !10, i64 12, !10, i64 16}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!10, !10, i64 0}
!12 = !{!8, !8, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.unroll.disable"}
!17 = distinct !{!17, !14}
!18 = distinct !{!18, !14}


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