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

9:                                                ; preds = %36, %1
  %10 = load i32, ptr %3, align 4, !tbaa !13
  %11 = icmp sge i32 %10, 0
  br i1 %11, label %12, label %39

12:                                               ; preds = %9
  %13 = load ptr, ptr %2, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.s_mdgrid, ptr %13, i32 0, i32 3
  %15 = load i32, ptr %14, align 4, !tbaa !14
  %16 = sub nsw i32 %15, 1
  store i32 %16, ptr %4, align 4, !tbaa !13
  br label %17

17:                                               ; preds = %32, %12
  %18 = load i32, ptr %4, align 4, !tbaa !13
  %19 = icmp sge i32 %18, 0
  br i1 %19, label %20, label %35

20:                                               ; preds = %17
  %21 = load ptr, ptr %2, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.s_mdgrid, ptr %21, i32 0, i32 0
  %23 = load ptr, ptr %22, align 8, !tbaa !15
  %24 = load i32, ptr %3, align 4, !tbaa !13
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds ptr, ptr %23, i64 %25
  %27 = load ptr, ptr %26, align 8, !tbaa !5
  %28 = load i32, ptr %4, align 4, !tbaa !13
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds ptr, ptr %27, i64 %29
  %31 = load ptr, ptr %30, align 8, !tbaa !5
  call void @free(ptr noundef %31) #3
  br label %32

32:                                               ; preds = %20
  %33 = load i32, ptr %4, align 4, !tbaa !13
  %34 = add nsw i32 %33, -1
  store i32 %34, ptr %4, align 4, !tbaa !13
  br label %17, !llvm.loop !16

35:                                               ; preds = %17
  br label %36

36:                                               ; preds = %35
  %37 = load i32, ptr %3, align 4, !tbaa !13
  %38 = add nsw i32 %37, -1
  store i32 %38, ptr %3, align 4, !tbaa !13
  br label %9, !llvm.loop !18

39:                                               ; preds = %9
  %40 = load ptr, ptr %2, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.s_mdgrid, ptr %40, i32 0, i32 2
  %42 = load i32, ptr %41, align 8, !tbaa !9
  %43 = sub nsw i32 %42, 1
  store i32 %43, ptr %3, align 4, !tbaa !13
  br label %44

44:                                               ; preds = %55, %39
  %45 = load i32, ptr %3, align 4, !tbaa !13
  %46 = icmp sge i32 %45, 0
  br i1 %46, label %47, label %58

47:                                               ; preds = %44
  %48 = load ptr, ptr %2, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.s_mdgrid, ptr %48, i32 0, i32 0
  %50 = load ptr, ptr %49, align 8, !tbaa !15
  %51 = load i32, ptr %3, align 4, !tbaa !13
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds ptr, ptr %50, i64 %52
  %54 = load ptr, ptr %53, align 8, !tbaa !5
  call void @free(ptr noundef %54) #3
  br label %55

55:                                               ; preds = %47
  %56 = load i32, ptr %3, align 4, !tbaa !13
  %57 = add nsw i32 %56, -1
  store i32 %57, ptr %3, align 4, !tbaa !13
  br label %44, !llvm.loop !19

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

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

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 = { 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 16}
!10 = !{!"s_mdgrid", !6, i64 0, !6, i64 8, !11, i64 16, !11, i64 20, !11, i64 24, !12, i64 28, !11, i64 32}
!11 = !{!"int", !7, i64 0}
!12 = !{!"float", !7, i64 0}
!13 = !{!11, !11, i64 0}
!14 = !{!10, !11, i64 20}
!15 = !{!10, !6, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = distinct !{!18, !17}
!19 = distinct !{!19, !17}


; 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: nounwind uwtable
define dso_local void @free_md_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 %.lr.ph18, label %._crit_edge22

.lr.ph18:                                         ; 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 %.lr.ph18.split.preheader, label %.lr.ph21.preheader

.lr.ph18.split.preheader:                         ; preds = %.lr.ph18
  %.01416 = add nsw i32 %3, -1
  %8 = zext nneg i32 %.01416 to i64
  br label %.lr.ph18.split

.loopexit:                                        ; preds = %13, %.lr.ph18.split
  %9 = icmp sgt i64 %indvars.iv25, 0
  br i1 %9, label %.lr.ph18.splitthread-pre-split, label %._crit_edge, !llvm.loop !13

.lr.ph18.splitthread-pre-split:                   ; preds = %.loopexit
  %indvars.iv.next26 = add nsw i64 %indvars.iv25, -1
  %.pr = load i32, ptr %5, align 4, !tbaa !12
  br label %.lr.ph18.split

.lr.ph18.split:                                   ; preds = %.lr.ph18.splitthread-pre-split, %.lr.ph18.split.preheader
  %10 = phi i32 [ %.pr, %.lr.ph18.splitthread-pre-split ], [ %6, %.lr.ph18.split.preheader ]
  %indvars.iv25 = phi i64 [ %indvars.iv.next26, %.lr.ph18.splitthread-pre-split ], [ %8, %.lr.ph18.split.preheader ]
  %11 = icmp sgt i32 %10, 0
  br i1 %11, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %.lr.ph18.split
  %12 = zext nneg i32 %10 to i64
  br label %13

13:                                               ; preds = %.lr.ph, %13
  %indvars.iv = phi i64 [ %12, %.lr.ph ], [ %indvars.iv.next, %13 ]
  %indvars.iv.next = add nsw i64 %indvars.iv, -1
  %14 = load ptr, ptr %0, align 8, !tbaa !16
  %15 = getelementptr inbounds ptr, ptr %14, i64 %indvars.iv25
  %16 = load ptr, ptr %15, align 8, !tbaa !17
  %17 = getelementptr inbounds ptr, ptr %16, i64 %indvars.iv.next
  %18 = load ptr, ptr %17, align 8, !tbaa !17
  tail call void @free(ptr noundef %18) #2
  %19 = icmp ugt i64 %indvars.iv, 1
  br i1 %19, label %13, label %.loopexit, !llvm.loop !18

._crit_edge:                                      ; preds = %.loopexit
  %.pre = load i32, ptr %2, align 8, !tbaa !5
  %20 = icmp sgt i32 %.pre, 0
  br i1 %20, label %.lr.ph21.preheader, label %._crit_edge22

.lr.ph21.preheader:                               ; preds = %.lr.ph18, %._crit_edge
  %21 = phi i32 [ %.pre, %._crit_edge ], [ %3, %.lr.ph18 ]
  %22 = zext nneg i32 %21 to i64
  br label %.lr.ph21

.lr.ph21:                                         ; preds = %.lr.ph21.preheader, %.lr.ph21
  %indvars.iv28 = phi i64 [ %22, %.lr.ph21.preheader ], [ %indvars.iv.next29, %.lr.ph21 ]
  %indvars.iv.next29 = add nsw i64 %indvars.iv28, -1
  %23 = load ptr, ptr %0, align 8, !tbaa !16
  %24 = getelementptr inbounds ptr, ptr %23, i64 %indvars.iv.next29
  %25 = load ptr, ptr %24, align 8, !tbaa !17
  tail call void @free(ptr noundef %25) #2
  %26 = icmp ugt i64 %indvars.iv28, 1
  br i1 %26, label %.lr.ph21, label %._crit_edge22, !llvm.loop !19

._crit_edge22:                                    ; preds = %.lr.ph21, %1, %._crit_edge
  %27 = load ptr, ptr %0, align 8, !tbaa !16
  tail call void @free(ptr noundef %27) #2
  ret void
}

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

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 = { 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 #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, !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 = distinct !{!13, !14, !15}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{!"llvm.loop.unswitch.partial.disable"}
!16 = !{!6, !7, i64 0}
!17 = !{!7, !7, i64 0}
!18 = distinct !{!18, !14}
!19 = distinct !{!19, !14}


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