; LLVM IR from Discngine/fpocket :: src (mdpbase)

; 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.s_mdgrid = type { ptr, ptr, i32, i32, i32, float, i32 }

; 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 @reset_grid(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  store i32 0, ptr %3, align 4, !tbaa !9
  br label %6

6:                                                ; preds = %49, %1
  %7 = load i32, ptr %3, align 4, !tbaa !9
  %8 = load ptr, ptr %2, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.s_mdgrid, ptr %8, i32 0, i32 2
  %10 = load i32, ptr %9, align 8, !tbaa !11
  %11 = icmp slt i32 %7, %10
  br i1 %11, label %12, label %52

12:                                               ; preds = %6
  store i32 0, ptr %4, align 4, !tbaa !9
  br label %13

13:                                               ; preds = %45, %12
  %14 = load i32, ptr %4, align 4, !tbaa !9
  %15 = load ptr, ptr %2, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.s_mdgrid, ptr %15, i32 0, i32 3
  %17 = load i32, ptr %16, align 4, !tbaa !14
  %18 = icmp slt i32 %14, %17
  br i1 %18, label %19, label %48

19:                                               ; preds = %13
  store i32 0, ptr %5, align 4, !tbaa !9
  br label %20

20:                                               ; preds = %41, %19
  %21 = load i32, ptr %5, align 4, !tbaa !9
  %22 = load ptr, ptr %2, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.s_mdgrid, ptr %22, i32 0, i32 4
  %24 = load i32, ptr %23, align 8, !tbaa !15
  %25 = icmp slt i32 %21, %24
  br i1 %25, label %26, label %44

26:                                               ; preds = %20
  %27 = load ptr, ptr %2, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.s_mdgrid, ptr %27, i32 0, i32 0
  %29 = load ptr, ptr %28, align 8, !tbaa !16
  %30 = load i32, ptr %3, align 4, !tbaa !9
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds ptr, ptr %29, i64 %31
  %33 = load ptr, ptr %32, align 8, !tbaa !5
  %34 = load i32, ptr %4, align 4, !tbaa !9
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds ptr, ptr %33, i64 %35
  %37 = load ptr, ptr %36, align 8, !tbaa !5
  %38 = load i32, ptr %5, align 4, !tbaa !9
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds float, ptr %37, i64 %39
  store float 0.000000e+00, ptr %40, align 4, !tbaa !17
  br label %41

41:                                               ; preds = %26
  %42 = load i32, ptr %5, align 4, !tbaa !9
  %43 = add nsw i32 %42, 1
  store i32 %43, ptr %5, align 4, !tbaa !9
  br label %20, !llvm.loop !18

44:                                               ; preds = %20
  br label %45

45:                                               ; preds = %44
  %46 = load i32, ptr %4, align 4, !tbaa !9
  %47 = add nsw i32 %46, 1
  store i32 %47, ptr %4, align 4, !tbaa !9
  br label %13, !llvm.loop !20

48:                                               ; preds = %13
  br label %49

49:                                               ; preds = %48
  %50 = load i32, ptr %3, align 4, !tbaa !9
  %51 = add nsw i32 %50, 1
  store i32 %51, ptr %3, align 4, !tbaa !9
  br label %6, !llvm.loop !21

52:                                               ; preds = %6
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #2
  ret void
}

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 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 16}
!12 = !{!"s_mdgrid", !6, i64 0, !6, i64 8, !10, i64 16, !10, i64 20, !10, i64 24, !13, i64 28, !10, i64 32}
!13 = !{!"float", !7, i64 0}
!14 = !{!12, !10, i64 20}
!15 = !{!12, !10, i64 24}
!16 = !{!12, !6, i64 0}
!17 = !{!13, !13, 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: nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) uwtable
define dso_local void @reset_grid(ptr nocapture noundef readonly %0) local_unnamed_addr #0 {
  %2 = getelementptr inbounds i8, ptr %0, i64 16
  %3 = load i32, ptr %2, align 8, !tbaa !5
  %4 = icmp sgt i32 %3, 0
  br i1 %4, label %.preheader14.lr.ph, label %._crit_edge

.preheader14.lr.ph:                               ; preds = %1
  %5 = getelementptr inbounds i8, ptr %0, i64 20
  %6 = load i32, ptr %5, align 4, !tbaa !12
  %7 = icmp sgt i32 %6, 0
  br i1 %7, label %.preheader14.lr.ph.split.us, label %._crit_edge

.preheader14.lr.ph.split.us:                      ; preds = %.preheader14.lr.ph
  %8 = getelementptr inbounds i8, ptr %0, i64 24
  %9 = load i32, ptr %8, align 8, !tbaa !13
  %10 = icmp sgt i32 %9, 0
  br i1 %10, label %.preheader14.lr.ph.split.us.split.us, label %._crit_edge

.preheader14.lr.ph.split.us.split.us:             ; preds = %.preheader14.lr.ph.split.us
  %11 = load ptr, ptr %0, align 8, !tbaa !14
  %12 = zext nneg i32 %9 to i64
  %13 = shl nuw nsw i64 %12, 2
  %wide.trip.count30 = zext nneg i32 %3 to i64
  %wide.trip.count = zext nneg i32 %6 to i64
  %xtraiter = and i64 %wide.trip.count, 7
  %14 = icmp ult i32 %6, 8
  %unroll_iter = and i64 %wide.trip.count, 2147483640
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br label %.preheader14.us.us

.preheader14.us.us:                               ; preds = %._crit_edge17.split.us.us.us, %.preheader14.lr.ph.split.us.split.us
  %indvars.iv27 = phi i64 [ %indvars.iv.next28, %._crit_edge17.split.us.us.us ], [ 0, %.preheader14.lr.ph.split.us.split.us ]
  %15 = getelementptr inbounds ptr, ptr %11, i64 %indvars.iv27
  %16 = load ptr, ptr %15, align 8, !tbaa !15
  br i1 %14, label %._crit_edge17.split.us.us.us.unr-lcssa, label %.preheader.us.us.us

.preheader.us.us.us:                              ; preds = %.preheader14.us.us, %.preheader.us.us.us
  %indvars.iv = phi i64 [ %indvars.iv.next.7, %.preheader.us.us.us ], [ 0, %.preheader14.us.us ]
  %niter = phi i64 [ %niter.next.7, %.preheader.us.us.us ], [ 0, %.preheader14.us.us ]
  %17 = getelementptr inbounds ptr, ptr %16, i64 %indvars.iv
  %18 = load ptr, ptr %17, align 8, !tbaa !15
  tail call void @llvm.memset.p0.i64(ptr align 4 %18, i8 0, i64 %13, i1 false), !tbaa !16
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %19 = getelementptr inbounds ptr, ptr %16, i64 %indvars.iv.next
  %20 = load ptr, ptr %19, align 8, !tbaa !15
  tail call void @llvm.memset.p0.i64(ptr align 4 %20, i8 0, i64 %13, i1 false), !tbaa !16
  %indvars.iv.next.1 = or disjoint i64 %indvars.iv, 2
  %21 = getelementptr inbounds ptr, ptr %16, i64 %indvars.iv.next.1
  %22 = load ptr, ptr %21, align 8, !tbaa !15
  tail call void @llvm.memset.p0.i64(ptr align 4 %22, i8 0, i64 %13, i1 false), !tbaa !16
  %indvars.iv.next.2 = or disjoint i64 %indvars.iv, 3
  %23 = getelementptr inbounds ptr, ptr %16, i64 %indvars.iv.next.2
  %24 = load ptr, ptr %23, align 8, !tbaa !15
  tail call void @llvm.memset.p0.i64(ptr align 4 %24, i8 0, i64 %13, i1 false), !tbaa !16
  %indvars.iv.next.3 = or disjoint i64 %indvars.iv, 4
  %25 = getelementptr inbounds ptr, ptr %16, i64 %indvars.iv.next.3
  %26 = load ptr, ptr %25, align 8, !tbaa !15
  tail call void @llvm.memset.p0.i64(ptr align 4 %26, i8 0, i64 %13, i1 false), !tbaa !16
  %indvars.iv.next.4 = or disjoint i64 %indvars.iv, 5
  %27 = getelementptr inbounds ptr, ptr %16, i64 %indvars.iv.next.4
  %28 = load ptr, ptr %27, align 8, !tbaa !15
  tail call void @llvm.memset.p0.i64(ptr align 4 %28, i8 0, i64 %13, i1 false), !tbaa !16
  %indvars.iv.next.5 = or disjoint i64 %indvars.iv, 6
  %29 = getelementptr inbounds ptr, ptr %16, i64 %indvars.iv.next.5
  %30 = load ptr, ptr %29, align 8, !tbaa !15
  tail call void @llvm.memset.p0.i64(ptr align 4 %30, i8 0, i64 %13, i1 false), !tbaa !16
  %indvars.iv.next.6 = or disjoint i64 %indvars.iv, 7
  %31 = getelementptr inbounds ptr, ptr %16, i64 %indvars.iv.next.6
  %32 = load ptr, ptr %31, align 8, !tbaa !15
  tail call void @llvm.memset.p0.i64(ptr align 4 %32, i8 0, i64 %13, i1 false), !tbaa !16
  %indvars.iv.next.7 = add nuw nsw i64 %indvars.iv, 8
  %niter.next.7 = add i64 %niter, 8
  %niter.ncmp.7 = icmp eq i64 %niter.next.7, %unroll_iter
  br i1 %niter.ncmp.7, label %._crit_edge17.split.us.us.us.unr-lcssa, label %.preheader.us.us.us, !llvm.loop !17

._crit_edge17.split.us.us.us.unr-lcssa:           ; preds = %.preheader.us.us.us, %.preheader14.us.us
  %indvars.iv.unr = phi i64 [ 0, %.preheader14.us.us ], [ %indvars.iv.next.7, %.preheader.us.us.us ]
  br i1 %lcmp.mod.not, label %._crit_edge17.split.us.us.us, label %.preheader.us.us.us.epil

.preheader.us.us.us.epil:                         ; preds = %._crit_edge17.split.us.us.us.unr-lcssa, %.preheader.us.us.us.epil
  %indvars.iv.epil = phi i64 [ %indvars.iv.next.epil, %.preheader.us.us.us.epil ], [ %indvars.iv.unr, %._crit_edge17.split.us.us.us.unr-lcssa ]
  %epil.iter = phi i64 [ %epil.iter.next, %.preheader.us.us.us.epil ], [ 0, %._crit_edge17.split.us.us.us.unr-lcssa ]
  %33 = getelementptr inbounds ptr, ptr %16, i64 %indvars.iv.epil
  %34 = load ptr, ptr %33, align 8, !tbaa !15
  tail call void @llvm.memset.p0.i64(ptr align 4 %34, i8 0, i64 %13, i1 false), !tbaa !16
  %indvars.iv.next.epil = add nuw nsw i64 %indvars.iv.epil, 1
  %epil.iter.next = add i64 %epil.iter, 1
  %epil.iter.cmp.not = icmp eq i64 %epil.iter.next, %xtraiter
  br i1 %epil.iter.cmp.not, label %._crit_edge17.split.us.us.us, label %.preheader.us.us.us.epil, !llvm.loop !19

._crit_edge17.split.us.us.us:                     ; preds = %.preheader.us.us.us.epil, %._crit_edge17.split.us.us.us.unr-lcssa
  %indvars.iv.next28 = add nuw nsw i64 %indvars.iv27, 1
  %exitcond31.not = icmp eq i64 %indvars.iv.next28, %wide.trip.count30
  br i1 %exitcond31.not, label %._crit_edge, label %.preheader14.us.us, !llvm.loop !21

._crit_edge:                                      ; preds = %._crit_edge17.split.us.us.us, %.preheader14.lr.ph.split.us, %.preheader14.lr.ph, %1
  ret void
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #1

attributes #0 = { nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) 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 nounwind willreturn memory(argmem: write) }

!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, !10, i64 16}
!6 = !{!"s_mdgrid", !7, i64 0, !7, i64 8, !10, i64 16, !10, i64 20, !10, i64 24, !11, i64 28, !10, i64 32}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"float", !8, i64 0}
!12 = !{!6, !10, i64 20}
!13 = !{!6, !10, i64 24}
!14 = !{!6, !7, i64 0}
!15 = !{!7, !7, i64 0}
!16 = !{!11, !11, i64 0}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.unroll.disable"}
!21 = distinct !{!21, !18}


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