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

@.str = external hidden unnamed_addr constant [37 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [57 x i8], align 1
@__PRETTY_FUNCTION__.dfont_insert = external hidden unnamed_addr constant [79 x i8], align 1

; 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
declare dso_local ptr @dfont_lookup(ptr noundef, i32 noundef, i32 noundef, i32 noundef) #1

; Function Attrs: nounwind uwtable
define dso_local ptr @dfont_insert(ptr noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4, i32 noundef %5) #1 {
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca ptr, align 8
  %15 = alloca i32, align 4
  %16 = alloca ptr, align 8
  %17 = alloca ptr, align 8
  store ptr %0, ptr %8, align 8, !tbaa !5
  store i32 %1, ptr %9, align 4, !tbaa !9
  store i32 %2, ptr %10, align 4, !tbaa !9
  store i32 %3, ptr %11, align 4, !tbaa !9
  store i32 %4, ptr %12, align 4, !tbaa !9
  store i32 %5, ptr %13, align 4, !tbaa !9
  %18 = load i32, ptr %11, align 4, !tbaa !9
  %19 = load ptr, ptr %8, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.dfont, ptr %19, i32 0, i32 0
  %21 = load i32, ptr %20, align 8, !tbaa !11
  %22 = icmp sgt i32 %18, %21
  br i1 %22, label %23, label %24

23:                                               ; preds = %6
  store ptr null, ptr %7, align 8
  br label %77

24:                                               ; preds = %6
  %25 = load ptr, ptr %8, align 8, !tbaa !5
  %26 = load i32, ptr %9, align 4, !tbaa !9
  %27 = load i32, ptr %10, align 4, !tbaa !9
  %28 = load i32, ptr %13, align 4, !tbaa !9
  %29 = call ptr @dfont_lookup(ptr noundef %25, i32 noundef %26, i32 noundef %27, i32 noundef %28)
  %30 = icmp eq ptr %29, null
  br i1 %30, label %31, label %32

31:                                               ; preds = %24
  br label %33

32:                                               ; preds = %24
  call void @__assert_fail(ptr noundef @.str, ptr noundef @.str.1, i32 noundef 323, ptr noundef @__PRETTY_FUNCTION__.dfont_insert) #3
  unreachable

33:                                               ; preds = %31
  br label %34

34:                                               ; preds = %60, %33
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #4
  %35 = load ptr, ptr %8, align 8, !tbaa !5
  %36 = load i32, ptr %11, align 4, !tbaa !9
  %37 = load i32, ptr %12, align 4, !tbaa !9
  %38 = call ptr @find_line(ptr noundef %35, i32 noundef %36, i32 noundef %37)
  store ptr %38, ptr %14, align 8, !tbaa !5
  %39 = load ptr, ptr %14, align 8, !tbaa !5
  %40 = icmp eq ptr %39, null
  br i1 %40, label %41, label %42

41:                                               ; preds = %34
  store i32 2, ptr %15, align 4
  br label %58

42:                                               ; preds = %34
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #4
  %43 = load ptr, ptr %8, align 8, !tbaa !5
  %44 = load ptr, ptr %14, align 8, !tbaa !5
  %45 = load i32, ptr %11, align 4, !tbaa !9
  %46 = call ptr @find_space(ptr noundef %43, ptr noundef %44, i32 noundef %45)
  store ptr %46, ptr %16, align 8, !tbaa !5
  %47 = load ptr, ptr %16, align 8, !tbaa !5
  %48 = icmp ne ptr %47, null
  br i1 %48, label %49, label %56

49:                                               ; preds = %42
  %50 = load ptr, ptr %8, align 8, !tbaa !5
  %51 = load i32, ptr %9, align 4, !tbaa !9
  %52 = load i32, ptr %10, align 4, !tbaa !9
  %53 = load ptr, ptr %16, align 8, !tbaa !5
  %54 = load i32, ptr %13, align 4, !tbaa !9
  %55 = call ptr @insert_char(ptr noundef %50, i32 noundef %51, i32 noundef %52, ptr noundef %53, i32 noundef %54)
  store ptr %55, ptr %7, align 8
  store i32 1, ptr %15, align 4
  br label %57

56:                                               ; preds = %42
  store i32 0, ptr %15, align 4
  br label %57

57:                                               ; preds = %56, %49
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #4
  br label %58

58:                                               ; preds = %57, %41
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #4
  %59 = load i32, ptr %15, align 4
  switch i32 %59, label %79 [
    i32 0, label %60
    i32 2, label %61
    i32 1, label %77
  ]

60:                                               ; preds = %58
  br label %34

61:                                               ; preds = %58
  call void @llvm.lifetime.start.p0(i64 8, ptr %17) #4
  %62 = load ptr, ptr %8, align 8, !tbaa !5
  %63 = load i32, ptr %11, align 4, !tbaa !9
  %64 = load i32, ptr %12, align 4, !tbaa !9
  %65 = call ptr @release_space(ptr noundef %62, i32 noundef %63, i32 noundef %64)
  store ptr %65, ptr %17, align 8, !tbaa !5
  %66 = load ptr, ptr %17, align 8, !tbaa !5
  %67 = icmp ne ptr %66, null
  br i1 %67, label %68, label %75

68:                                               ; preds = %61
  %69 = load ptr, ptr %8, align 8, !tbaa !5
  %70 = load i32, ptr %9, align 4, !tbaa !9
  %71 = load i32, ptr %10, align 4, !tbaa !9
  %72 = load ptr, ptr %17, align 8, !tbaa !5
  %73 = load i32, ptr %13, align 4, !tbaa !9
  %74 = call ptr @insert_char(ptr noundef %69, i32 noundef %70, i32 noundef %71, ptr noundef %72, i32 noundef %73)
  store ptr %74, ptr %7, align 8
  store i32 1, ptr %15, align 4
  br label %76

75:                                               ; preds = %61
  store ptr null, ptr %7, align 8
  store i32 1, ptr %15, align 4
  br label %76

76:                                               ; preds = %75, %68
  call void @llvm.lifetime.end.p0(i64 8, ptr %17) #4
  br label %77

77:                                               ; preds = %76, %58, %23
  %78 = load ptr, ptr %7, align 8
  ret ptr %78

79:                                               ; preds = %58
  unreachable
}

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #2

; Function Attrs: nounwind uwtable
declare hidden ptr @find_line(ptr noundef, i32 noundef, i32 noundef) #1

; Function Attrs: nounwind uwtable
declare hidden ptr @find_space(ptr noundef, ptr noundef, i32 noundef) #1

; Function Attrs: nounwind uwtable
declare hidden ptr @insert_char(ptr noundef, i32 noundef, i32 noundef, ptr noundef, i32 noundef) #1

; Function Attrs: nounwind uwtable
declare hidden ptr @release_space(ptr noundef, i32 noundef, i32 noundef) #1

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 = { noreturn 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 = { noreturn nounwind }
attributes #4 = { 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 0}
!12 = !{!"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}
!13 = !{!"list_head", !6, i64 0, !6, i64 8}


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

@.str = external hidden unnamed_addr constant [37 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [57 x i8], align 1
@__PRETTY_FUNCTION__.dfont_insert = external hidden unnamed_addr constant [79 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local ptr @dfont_lookup(ptr noundef, i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local ptr @dfont_insert(ptr noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4, i32 noundef %5) local_unnamed_addr #0 {
  %7 = load i32, ptr %0, align 8, !tbaa !5
  %8 = icmp slt i32 %7, %3
  br i1 %8, label %20, label %9

9:                                                ; preds = %6
  %10 = tail call ptr @dfont_lookup(ptr noundef nonnull %0, i32 noundef %1, i32 noundef %2, i32 noundef %5)
  %11 = icmp eq ptr %10, null
  br i1 %11, label %.preheader, label %12

12:                                               ; preds = %9
  tail call void @__assert_fail(ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 323, ptr noundef nonnull @__PRETTY_FUNCTION__.dfont_insert) #2
  unreachable

.preheader:                                       ; preds = %9, %15
  %13 = tail call ptr @find_line(ptr noundef nonnull %0, i32 noundef %3, i32 noundef %4)
  %14 = icmp eq ptr %13, null
  br i1 %14, label %17, label %15

15:                                               ; preds = %.preheader
  %16 = tail call ptr @find_space(ptr noundef nonnull %0, ptr noundef nonnull %13, i32 noundef %3)
  %.not = icmp eq ptr %16, null
  br i1 %.not, label %.preheader, label %.sink.split

17:                                               ; preds = %.preheader
  %18 = tail call ptr @release_space(ptr noundef nonnull %0, i32 noundef %3, i32 noundef %4)
  %.not35 = icmp eq ptr %18, null
  br i1 %.not35, label %20, label %.sink.split

.sink.split:                                      ; preds = %15, %17
  %.lcssa.sink = phi ptr [ %18, %17 ], [ %16, %15 ]
  %19 = tail call ptr @insert_char(ptr noundef nonnull %0, i32 noundef %1, i32 noundef %2, ptr noundef nonnull %.lcssa.sink, i32 noundef %5)
  br label %20

20:                                               ; preds = %.sink.split, %17, %6
  %.4 = phi ptr [ null, %6 ], [ null, %17 ], [ %19, %.sink.split ]
  ret ptr %.4
}

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare hidden ptr @find_line(ptr noundef, i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare hidden ptr @find_space(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare hidden ptr @insert_char(ptr noundef, i32 noundef, i32 noundef, ptr noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare hidden ptr @release_space(ptr noundef, i32 noundef, i32 noundef) local_unnamed_addr #0

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 = { noreturn 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 #2 = { noreturn 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 = !{!"dfont", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12, !10, i64 16, !11, i64 32, !11, i64 40, !8, i64 48}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"list_head", !11, i64 0, !11, i64 8}
!11 = !{!"any pointer", !8, i64 0}


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