; LLVM IR from ejoy/ejoy2d :: lib (dfont)

; 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.dfont = type { i32, i32, i32, i32, %struct.list_head, ptr, ptr, [4096 x ptr] }
%struct.list_head = type { ptr, ptr }
%struct.hash_rect = type { ptr, %struct.list_head, %struct.list_head, i32, i32, i32, i32, i32, %struct.dfont_rect }
%struct.dfont_rect = type { i32, i32, i32, 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 @dfont_remove(ptr noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3) #1 {
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !9
  store i32 %2, ptr %7, align 4, !tbaa !9
  store i32 %3, ptr %8, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  %12 = load i32, ptr %6, align 4, !tbaa !9
  %13 = load i32, ptr %7, align 4, !tbaa !9
  %14 = load i32, ptr %8, align 4, !tbaa !9
  %15 = call i32 @hash(i32 noundef %12, i32 noundef %13, i32 noundef %14)
  store i32 %15, ptr %9, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  %16 = load ptr, ptr %5, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.dfont, ptr %16, i32 0, i32 7
  %18 = load i32, ptr %9, align 4, !tbaa !9
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds [4096 x ptr], ptr %17, i64 0, i64 %19
  %21 = load ptr, ptr %20, align 8, !tbaa !5
  store ptr %21, ptr %10, align 8, !tbaa !5
  br label %22

22:                                               ; preds = %54, %4
  %23 = load ptr, ptr %10, align 8, !tbaa !5
  %24 = icmp ne ptr %23, null
  br i1 %24, label %25, label %58

25:                                               ; preds = %22
  %26 = load ptr, ptr %10, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.hash_rect, ptr %26, i32 0, i32 4
  %28 = load i32, ptr %27, align 4, !tbaa !11
  %29 = load i32, ptr %6, align 4, !tbaa !9
  %30 = icmp eq i32 %28, %29
  br i1 %30, label %31, label %54

31:                                               ; preds = %25
  %32 = load ptr, ptr %10, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.hash_rect, ptr %32, i32 0, i32 6
  %34 = load i32, ptr %33, align 4, !tbaa !15
  %35 = load i32, ptr %7, align 4, !tbaa !9
  %36 = icmp eq i32 %34, %35
  br i1 %36, label %37, label %54

37:                                               ; preds = %31
  %38 = load ptr, ptr %10, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.hash_rect, ptr %38, i32 0, i32 7
  %40 = load i32, ptr %39, align 8, !tbaa !16
  %41 = load i32, ptr %8, align 4, !tbaa !9
  %42 = icmp eq i32 %40, %41
  br i1 %42, label %43, label %54

43:                                               ; preds = %37
  %44 = load ptr, ptr %10, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.hash_rect, ptr %44, i32 0, i32 2
  %46 = load ptr, ptr %5, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.dfont, ptr %46, i32 0, i32 4
  call void @list_move(ptr noundef %45, ptr noundef %47)
  %48 = load ptr, ptr %5, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.dfont, ptr %48, i32 0, i32 3
  %50 = load i32, ptr %49, align 4, !tbaa !17
  %51 = sub nsw i32 %50, 1
  %52 = load ptr, ptr %10, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.hash_rect, ptr %52, i32 0, i32 3
  store i32 %51, ptr %53, align 8, !tbaa !19
  store i32 1, ptr %11, align 4
  br label %59

54:                                               ; preds = %37, %31, %25
  %55 = load ptr, ptr %10, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.hash_rect, ptr %55, i32 0, i32 0
  %57 = load ptr, ptr %56, align 8, !tbaa !20
  store ptr %57, ptr %10, align 8, !tbaa !5
  br label %22, !llvm.loop !21

58:                                               ; preds = %22
  store i32 0, ptr %11, align 4
  br label %59

59:                                               ; preds = %58, %43
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  %60 = load i32, ptr %11, align 4
  switch i32 %60, label %62 [
    i32 0, label %61
    i32 1, label %61
  ]

61:                                               ; preds = %59, %59
  ret void

62:                                               ; preds = %59
  unreachable
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @hash(i32 noundef, i32 noundef, i32 noundef) #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @list_move(ptr noundef, 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 = { 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 = { 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 44}
!12 = !{!"hash_rect", !6, i64 0, !13, i64 8, !13, i64 24, !10, i64 40, !10, i64 44, !10, i64 48, !10, i64 52, !10, i64 56, !14, i64 60}
!13 = !{!"list_head", !6, i64 0, !6, i64 8}
!14 = !{!"dfont_rect", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12}
!15 = !{!12, !10, i64 52}
!16 = !{!12, !10, i64 56}
!17 = !{!18, !10, i64 12}
!18 = !{!"dfont", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !13, i64 16, !6, i64 32, !6, i64 40, !7, i64 48}
!19 = !{!12, !10, i64 40}
!20 = !{!12, !6, i64 0}
!21 = distinct !{!21, !22}
!22 = !{!"llvm.loop.mustprogress"}


; 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 @dfont_remove(ptr noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3) local_unnamed_addr #0 {
  %5 = tail call i32 @hash(i32 noundef %1, i32 noundef %2, i32 noundef %3)
  %6 = getelementptr inbounds i8, ptr %0, i64 48
  %7 = sext i32 %5 to i64
  %8 = getelementptr inbounds [4096 x ptr], ptr %6, i64 0, i64 %7
  %.017 = load ptr, ptr %8, align 8, !tbaa !5
  %.not18 = icmp eq ptr %.017, null
  br i1 %.not18, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %4, %27
  %.019 = phi ptr [ %.0, %27 ], [ %.017, %4 ]
  %9 = getelementptr inbounds i8, ptr %.019, i64 44
  %10 = load i32, ptr %9, align 4, !tbaa !9
  %11 = icmp eq i32 %10, %1
  br i1 %11, label %12, label %27

12:                                               ; preds = %.lr.ph
  %13 = getelementptr inbounds i8, ptr %.019, i64 52
  %14 = load i32, ptr %13, align 4, !tbaa !14
  %15 = icmp eq i32 %14, %2
  br i1 %15, label %16, label %27

16:                                               ; preds = %12
  %17 = getelementptr inbounds i8, ptr %.019, i64 56
  %18 = load i32, ptr %17, align 8, !tbaa !15
  %19 = icmp eq i32 %18, %3
  br i1 %19, label %20, label %27

20:                                               ; preds = %16
  %21 = getelementptr inbounds i8, ptr %.019, i64 24
  %22 = getelementptr inbounds i8, ptr %0, i64 16
  tail call void @list_move(ptr noundef nonnull %21, ptr noundef nonnull %22)
  %23 = getelementptr inbounds i8, ptr %0, i64 12
  %24 = load i32, ptr %23, align 4, !tbaa !16
  %25 = add nsw i32 %24, -1
  %26 = getelementptr inbounds i8, ptr %.019, i64 40
  store i32 %25, ptr %26, align 8, !tbaa !18
  br label %.loopexit

27:                                               ; preds = %16, %12, %.lr.ph
  %.0 = load ptr, ptr %.019, align 8, !tbaa !5
  %.not = icmp eq ptr %.0, null
  br i1 %.not, label %.loopexit, label %.lr.ph, !llvm.loop !19

.loopexit:                                        ; preds = %27, %4, %20
  ret void
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @hash(i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @list_move(ptr noundef, ptr 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 = { 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" }

!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, !12, i64 44}
!10 = !{!"hash_rect", !6, i64 0, !11, i64 8, !11, i64 24, !12, i64 40, !12, i64 44, !12, i64 48, !12, i64 52, !12, i64 56, !13, i64 60}
!11 = !{!"list_head", !6, i64 0, !6, i64 8}
!12 = !{!"int", !7, i64 0}
!13 = !{!"dfont_rect", !12, i64 0, !12, i64 4, !12, i64 8, !12, i64 12}
!14 = !{!10, !12, i64 52}
!15 = !{!10, !12, i64 56}
!16 = !{!17, !12, i64 12}
!17 = !{!"dfont", !12, i64 0, !12, i64 4, !12, i64 8, !12, i64 12, !11, i64 16, !6, i64 32, !6, i64 40, !7, i64 48}
!18 = !{!10, !12, i64 40}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}


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