; LLVM IR from xboot/libcg :: src (xft)

; 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.TWorker_ = type { i64, i64, i64, i64, i64, i64, i64, i64, i64, i32, i32, ptr, i64, i64, i64, i64, %struct.XCG_FT_Outline_, %struct.XCG_FT_BBox_, [256 x %struct.XCG_FT_Span_], i32, i32, ptr, ptr, i32, i32, [1 x %struct.__jmp_buf_tag], ptr, i64, ptr, i64 }
%struct.XCG_FT_Outline_ = type { i32, i32, ptr, ptr, ptr, ptr, i32 }
%struct.XCG_FT_BBox_ = type { i64, i64, i64, i64 }
%struct.XCG_FT_Span_ = type { i32, i32, i32, i8 }
%struct.__jmp_buf_tag = type { [8 x i64], i32, %struct.__sigset_t }
%struct.__sigset_t = type { [16 x i64] }

; 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 @XCG_FT_Raster_Render(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca [8192 x i8], align 16
  %4 = alloca i64, align 8
  %5 = alloca %struct.TWorker_, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8192, ptr %3) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  store i64 8192, ptr %4, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4560, ptr %5) #4
  %9 = getelementptr inbounds %struct.TWorker_, ptr %5, i32 0, i32 20
  store i32 0, ptr %9, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  store i32 0, ptr %6, align 4, !tbaa !16
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  %10 = getelementptr inbounds [8192 x i8], ptr %3, i64 0, i64 0
  %11 = load i64, ptr %4, align 8, !tbaa !9
  %12 = load ptr, ptr %2, align 8, !tbaa !5
  %13 = call i32 @gray_raster_render(ptr noundef %5, ptr noundef %10, i64 noundef %11, ptr noundef %12)
  store i32 %13, ptr %7, align 4, !tbaa !16
  br label %14

14:                                               ; preds = %27, %1
  %15 = load i32, ptr %7, align 4, !tbaa !16
  %16 = icmp eq i32 %15, -6
  br i1 %16, label %17, label %39

17:                                               ; preds = %14
  %18 = getelementptr inbounds %struct.TWorker_, ptr %5, i32 0, i32 20
  %19 = load i32, ptr %18, align 4, !tbaa !11
  %20 = icmp slt i32 %19, 0
  br i1 %20, label %21, label %27

21:                                               ; preds = %17
  %22 = getelementptr inbounds %struct.TWorker_, ptr %5, i32 0, i32 20
  %23 = load i32, ptr %22, align 4, !tbaa !11
  %24 = sub nsw i32 0, %23
  %25 = load i32, ptr %6, align 4, !tbaa !16
  %26 = add nsw i32 %25, %24
  store i32 %26, ptr %6, align 4, !tbaa !16
  br label %27

27:                                               ; preds = %21, %17
  %28 = load i32, ptr %6, align 4, !tbaa !16
  %29 = getelementptr inbounds %struct.TWorker_, ptr %5, i32 0, i32 20
  store i32 %28, ptr %29, align 4, !tbaa !11
  %30 = load i64, ptr %4, align 8, !tbaa !9
  %31 = mul i64 %30, 2
  store i64 %31, ptr %4, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  %32 = load i64, ptr %4, align 8, !tbaa !9
  %33 = call noalias ptr @malloc(i64 noundef %32) #5
  store ptr %33, ptr %8, align 8, !tbaa !5
  %34 = load ptr, ptr %8, align 8, !tbaa !5
  %35 = load i64, ptr %4, align 8, !tbaa !9
  %36 = load ptr, ptr %2, align 8, !tbaa !5
  %37 = call i32 @gray_raster_render(ptr noundef %5, ptr noundef %34, i64 noundef %35, ptr noundef %36)
  store i32 %37, ptr %7, align 4, !tbaa !16
  %38 = load ptr, ptr %8, align 8, !tbaa !5
  call void @free(ptr noundef %38) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  br label %14, !llvm.loop !17

39:                                               ; preds = %14
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 4560, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 8192, ptr %3) #4
  ret void
}

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

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #2

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

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 allocsize(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 "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 #4 = { nounwind }
attributes #5 = { nounwind allocsize(0) }

!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 = !{!"long", !7, i64 0}
!11 = !{!12, !13, i64 4300}
!12 = !{!"TWorker_", !10, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !10, i64 32, !10, i64 40, !10, i64 48, !10, i64 56, !10, i64 64, !13, i64 72, !13, i64 76, !6, i64 80, !10, i64 88, !10, i64 96, !10, i64 104, !10, i64 112, !14, i64 120, !15, i64 168, !7, i64 200, !13, i64 4296, !13, i64 4300, !6, i64 4304, !6, i64 4312, !13, i64 4320, !13, i64 4324, !7, i64 4328, !6, i64 4528, !10, i64 4536, !6, i64 4544, !10, i64 4552}
!13 = !{!"int", !7, i64 0}
!14 = !{!"XCG_FT_Outline_", !13, i64 0, !13, i64 4, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !13, i64 40}
!15 = !{!"XCG_FT_BBox_", !10, i64 0, !10, i64 8, !10, i64 16, !10, i64 24}
!16 = !{!13, !13, i64 0}
!17 = distinct !{!17, !18}
!18 = !{!"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"

%struct.TWorker_ = type { i64, i64, i64, i64, i64, i64, i64, i64, i64, i32, i32, ptr, i64, i64, i64, i64, %struct.XCG_FT_Outline_, %struct.XCG_FT_BBox_, [256 x %struct.XCG_FT_Span_], i32, i32, ptr, ptr, i32, i32, [1 x %struct.__jmp_buf_tag], ptr, i64, ptr, i64 }
%struct.XCG_FT_Outline_ = type { i32, i32, ptr, ptr, ptr, ptr, i32 }
%struct.XCG_FT_BBox_ = type { i64, i64, i64, i64 }
%struct.XCG_FT_Span_ = type { i32, i32, i32, i8 }
%struct.__jmp_buf_tag = type { [8 x i64], i32, %struct.__sigset_t }
%struct.__sigset_t = type { [16 x i64] }

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: mustprogress 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 @XCG_FT_Raster_Render(ptr noundef %0) local_unnamed_addr #1 {
  %2 = alloca [8192 x i8], align 16
  %3 = alloca %struct.TWorker_, align 8
  call void @llvm.lifetime.start.p0(i64 8192, ptr nonnull %2) #5
  call void @llvm.lifetime.start.p0(i64 4560, ptr nonnull %3) #5
  %4 = getelementptr inbounds i8, ptr %3, i64 4300
  store i32 0, ptr %4, align 4, !tbaa !5
  %5 = call i32 @gray_raster_render(ptr noundef nonnull %3, ptr noundef nonnull %2, i64 noundef 8192, ptr noundef %0)
  %6 = icmp eq i32 %5, -6
  br i1 %6, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %1, %.lr.ph
  %.014 = phi i64 [ %9, %.lr.ph ], [ 8192, %1 ]
  %.01113 = phi i32 [ %spec.select, %.lr.ph ], [ 0, %1 ]
  %7 = load i32, ptr %4, align 4, !tbaa !5
  %8 = call i32 @llvm.smin.i32(i32 %7, i32 0)
  %spec.select = sub i32 %.01113, %8
  store i32 %spec.select, ptr %4, align 4, !tbaa !5
  %9 = shl i64 %.014, 1
  %10 = call noalias ptr @malloc(i64 noundef %9) #6
  %11 = call i32 @gray_raster_render(ptr noundef nonnull %3, ptr noundef %10, i64 noundef %9, ptr noundef %0)
  call void @free(ptr noundef %10) #5
  %12 = icmp eq i32 %11, -6
  br i1 %12, label %.lr.ph, label %._crit_edge, !llvm.loop !14

._crit_edge:                                      ; preds = %.lr.ph, %1
  call void @llvm.lifetime.end.p0(i64 4560, ptr nonnull %3) #5
  call void @llvm.lifetime.end.p0(i64 8192, ptr nonnull %2) #5
  ret void
}

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

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #2

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.smin.i32(i32, i32) #4

attributes #0 = { mustprogress 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 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(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 #3 = { 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 #4 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #5 = { nounwind }
attributes #6 = { nounwind allocsize(0) }

!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 4300}
!6 = !{!"TWorker_", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !7, i64 32, !7, i64 40, !7, i64 48, !7, i64 56, !7, i64 64, !10, i64 72, !10, i64 76, !11, i64 80, !7, i64 88, !7, i64 96, !7, i64 104, !7, i64 112, !12, i64 120, !13, i64 168, !8, i64 200, !10, i64 4296, !10, i64 4300, !11, i64 4304, !11, i64 4312, !10, i64 4320, !10, i64 4324, !8, i64 4328, !11, i64 4528, !7, i64 4536, !11, i64 4544, !7, i64 4552}
!7 = !{!"long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"any pointer", !8, i64 0}
!12 = !{!"XCG_FT_Outline_", !10, i64 0, !10, i64 4, !11, i64 8, !11, i64 16, !11, i64 24, !11, i64 32, !10, i64 40}
!13 = !{!"XCG_FT_BBox_", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass