; 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: inlinehint nounwind uwtable
declare hidden i32 @hash(i32 noundef, i32 noundef, i32 noundef) #1

; Function Attrs: nounwind uwtable
define dso_local ptr @dfont_lookup(ptr noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3) #2 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca ptr, align 8
  %12 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store i32 %1, ptr %7, align 4, !tbaa !9
  store i32 %2, ptr %8, align 4, !tbaa !9
  store i32 %3, ptr %9, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  %13 = load i32, ptr %7, align 4, !tbaa !9
  %14 = load i32, ptr %8, align 4, !tbaa !9
  %15 = load i32, ptr %9, align 4, !tbaa !9
  %16 = call i32 @hash(i32 noundef %13, i32 noundef %14, i32 noundef %15)
  store i32 %16, ptr %10, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  %17 = load ptr, ptr %6, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.dfont, ptr %17, i32 0, i32 7
  %19 = load i32, ptr %10, align 4, !tbaa !9
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds [4096 x ptr], ptr %18, i64 0, i64 %20
  %22 = load ptr, ptr %21, align 8, !tbaa !5
  store ptr %22, ptr %11, align 8, !tbaa !5
  br label %23

23:                                               ; preds = %56, %4
  %24 = load ptr, ptr %11, align 8, !tbaa !5
  %25 = icmp ne ptr %24, null
  br i1 %25, label %26, label %60

26:                                               ; preds = %23
  %27 = load ptr, ptr %11, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.hash_rect, ptr %27, i32 0, i32 4
  %29 = load i32, ptr %28, align 4, !tbaa !11
  %30 = load i32, ptr %7, align 4, !tbaa !9
  %31 = icmp eq i32 %29, %30
  br i1 %31, label %32, label %56

32:                                               ; preds = %26
  %33 = load ptr, ptr %11, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.hash_rect, ptr %33, i32 0, i32 6
  %35 = load i32, ptr %34, align 4, !tbaa !15
  %36 = load i32, ptr %8, align 4, !tbaa !9
  %37 = icmp eq i32 %35, %36
  br i1 %37, label %38, label %56

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

44:                                               ; preds = %38
  %45 = load ptr, ptr %11, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.hash_rect, ptr %45, i32 0, i32 2
  %47 = load ptr, ptr %6, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.dfont, ptr %47, i32 0, i32 4
  call void @list_move_tail(ptr noundef %46, ptr noundef %48)
  %49 = load ptr, ptr %6, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.dfont, ptr %49, i32 0, i32 3
  %51 = load i32, ptr %50, align 4, !tbaa !17
  %52 = load ptr, ptr %11, 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
  %54 = load ptr, ptr %11, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.hash_rect, ptr %54, i32 0, i32 8
  store ptr %55, ptr %5, align 8
  store i32 1, ptr %12, align 4
  br label %61

56:                                               ; preds = %38, %32, %26
  %57 = load ptr, ptr %11, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.hash_rect, ptr %57, i32 0, i32 0
  %59 = load ptr, ptr %58, align 8, !tbaa !20
  store ptr %59, ptr %11, align 8, !tbaa !5
  br label %23, !llvm.loop !21

60:                                               ; preds = %23
  store ptr null, ptr %5, align 8
  store i32 1, ptr %12, align 4
  br label %61

61:                                               ; preds = %60, %44
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  %62 = load ptr, ptr %5, align 8
  ret ptr %62
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @list_move_tail(ptr noundef, ptr noundef) #1

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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" }
attributes #2 = { 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: inlinehint nounwind uwtable
declare hidden i32 @hash(i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local ptr @dfont_lookup(ptr noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3) local_unnamed_addr #1 {
  %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
  %.020 = load ptr, ptr %8, align 8, !tbaa !5
  %.not21 = icmp eq ptr %.020, null
  br i1 %.not21, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %4, %27
  %.022 = phi ptr [ %.0, %27 ], [ %.020, %4 ]
  %9 = getelementptr inbounds i8, ptr %.022, 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 %.022, 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 %.022, 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 %.022, i64 24
  %22 = getelementptr inbounds i8, ptr %0, i64 16
  tail call void @list_move_tail(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 = getelementptr inbounds i8, ptr %.022, i64 40
  store i32 %24, ptr %25, align 8, !tbaa !18
  %26 = getelementptr inbounds i8, ptr %.022, i64 60
  br label %.loopexit

27:                                               ; preds = %16, %12, %.lr.ph
  %.0 = load ptr, ptr %.022, 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
  %.018 = phi ptr [ %26, %20 ], [ null, %4 ], [ null, %27 ]
  ret ptr %.018
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @list_move_tail(ptr noundef, ptr noundef) local_unnamed_addr #0

attributes #0 = { 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 #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" }

!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