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

; 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.cg_ctx_t = type { ptr, ptr, ptr, ptr, ptr, %struct.cg_rect_t, ptr, i64 }
%struct.cg_rect_t = type { double, double, double, double }
%struct.cg_state_t = type { ptr, %struct.cg_paint_t, %struct.cg_matrix_t, i32, %struct.cg_stroke_data_t, i32, double, ptr }
%struct.cg_paint_t = type { i32, %struct.cg_color_t, %struct.cg_gradient_t, %struct.cg_texture_t }
%struct.cg_color_t = type { double, double, double, double }
%struct.cg_gradient_t = type { i32, i32, %struct.cg_matrix_t, [6 x double], double, %struct.anon }
%struct.anon = type { ptr, i32, i32 }
%struct.cg_texture_t = type { i32, ptr, %struct.cg_matrix_t, double }
%struct.cg_matrix_t = type { double, double, double, double, double, double }
%struct.cg_stroke_data_t = type { double, double, i32, i32, ptr }

; 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 hidden ptr @cg_rle_create() #1

; Function Attrs: nounwind uwtable
define dso_local void @cg_clip_preserve(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  %4 = load ptr, ptr %2, align 8, !tbaa !5
  %5 = getelementptr inbounds %struct.cg_ctx_t, ptr %4, i32 0, i32 1
  %6 = load ptr, ptr %5, align 8, !tbaa !9
  store ptr %6, ptr %3, align 8, !tbaa !5
  %7 = load ptr, ptr %3, align 8, !tbaa !5
  %8 = getelementptr inbounds %struct.cg_state_t, ptr %7, i32 0, i32 0
  %9 = load ptr, ptr %8, align 8, !tbaa !14
  %10 = icmp ne ptr %9, null
  br i1 %10, label %11, label %35

11:                                               ; preds = %1
  %12 = load ptr, ptr %2, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.cg_ctx_t, ptr %12, i32 0, i32 3
  %14 = load ptr, ptr %13, align 8, !tbaa !24
  call void @cg_rle_clear(ptr noundef %14)
  %15 = load ptr, ptr %2, align 8, !tbaa !5
  %16 = load ptr, ptr %2, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.cg_ctx_t, ptr %16, i32 0, i32 3
  %18 = load ptr, ptr %17, align 8, !tbaa !24
  %19 = load ptr, ptr %2, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.cg_ctx_t, ptr %19, i32 0, i32 2
  %21 = load ptr, ptr %20, align 8, !tbaa !25
  %22 = load ptr, ptr %3, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.cg_state_t, ptr %22, i32 0, i32 2
  %24 = load ptr, ptr %2, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.cg_ctx_t, ptr %24, i32 0, i32 5
  %26 = load ptr, ptr %3, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.cg_state_t, ptr %26, i32 0, i32 3
  %28 = load i32, ptr %27, align 8, !tbaa !26
  call void @cg_rle_rasterize(ptr noundef %15, ptr noundef %18, ptr noundef %21, ptr noundef %23, ptr noundef %25, ptr noundef null, i32 noundef %28)
  %29 = load ptr, ptr %3, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.cg_state_t, ptr %29, i32 0, i32 0
  %31 = load ptr, ptr %30, align 8, !tbaa !14
  %32 = load ptr, ptr %2, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.cg_ctx_t, ptr %32, i32 0, i32 3
  %34 = load ptr, ptr %33, align 8, !tbaa !24
  call void @cg_rle_clip_path(ptr noundef %31, ptr noundef %34)
  br label %53

35:                                               ; preds = %1
  %36 = call ptr @cg_rle_create()
  %37 = load ptr, ptr %3, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.cg_state_t, ptr %37, i32 0, i32 0
  store ptr %36, ptr %38, align 8, !tbaa !14
  %39 = load ptr, ptr %2, align 8, !tbaa !5
  %40 = load ptr, ptr %3, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.cg_state_t, ptr %40, i32 0, i32 0
  %42 = load ptr, ptr %41, align 8, !tbaa !14
  %43 = load ptr, ptr %2, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.cg_ctx_t, ptr %43, i32 0, i32 2
  %45 = load ptr, ptr %44, align 8, !tbaa !25
  %46 = load ptr, ptr %3, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.cg_state_t, ptr %46, i32 0, i32 2
  %48 = load ptr, ptr %2, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.cg_ctx_t, ptr %48, i32 0, i32 5
  %50 = load ptr, ptr %3, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.cg_state_t, ptr %50, i32 0, i32 3
  %52 = load i32, ptr %51, align 8, !tbaa !26
  call void @cg_rle_rasterize(ptr noundef %39, ptr noundef %42, ptr noundef %45, ptr noundef %47, ptr noundef %49, ptr noundef null, i32 noundef %52)
  br label %53

53:                                               ; preds = %35, %11
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  ret void
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @cg_rle_clear(ptr noundef) #2

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

; Function Attrs: nounwind uwtable
declare hidden void @cg_rle_clip_path(ptr noundef, ptr 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 = { 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, !6, i64 8}
!10 = !{!"cg_ctx_t", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !11, i64 40, !6, i64 72, !13, i64 80}
!11 = !{!"cg_rect_t", !12, i64 0, !12, i64 8, !12, i64 16, !12, i64 24}
!12 = !{!"double", !7, i64 0}
!13 = !{!"long", !7, i64 0}
!14 = !{!15, !6, i64 0}
!15 = !{!"cg_state_t", !6, i64 0, !16, i64 8, !20, i64 248, !17, i64 296, !23, i64 304, !17, i64 336, !12, i64 344, !6, i64 352}
!16 = !{!"cg_paint_t", !17, i64 0, !18, i64 8, !19, i64 40, !22, i64 168}
!17 = !{!"int", !7, i64 0}
!18 = !{!"cg_color_t", !12, i64 0, !12, i64 8, !12, i64 16, !12, i64 24}
!19 = !{!"cg_gradient_t", !17, i64 0, !17, i64 4, !20, i64 8, !7, i64 56, !12, i64 104, !21, i64 112}
!20 = !{!"cg_matrix_t", !12, i64 0, !12, i64 8, !12, i64 16, !12, i64 24, !12, i64 32, !12, i64 40}
!21 = !{!"", !6, i64 0, !17, i64 8, !17, i64 12}
!22 = !{!"cg_texture_t", !17, i64 0, !6, i64 8, !20, i64 16, !12, i64 64}
!23 = !{!"cg_stroke_data_t", !12, i64 0, !12, i64 8, !17, i64 16, !17, i64 20, !6, i64 24}
!24 = !{!10, !6, i64 24}
!25 = !{!10, !6, i64 16}
!26 = !{!15, !17, i64 296}


; 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
declare hidden ptr @cg_rle_create() local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @cg_clip_preserve(ptr noundef %0) local_unnamed_addr #0 {
  %2 = getelementptr inbounds i8, ptr %0, i64 8
  %3 = load ptr, ptr %2, align 8, !tbaa !5
  %4 = load ptr, ptr %3, align 8, !tbaa !13
  %.not = icmp eq ptr %4, null
  br i1 %.not, label %17, label %5

5:                                                ; preds = %1
  %6 = getelementptr inbounds i8, ptr %0, i64 24
  %7 = load ptr, ptr %6, align 8, !tbaa !23
  tail call void @cg_rle_clear(ptr noundef %7)
  %8 = load ptr, ptr %6, align 8, !tbaa !23
  %9 = getelementptr inbounds i8, ptr %0, i64 16
  %10 = load ptr, ptr %9, align 8, !tbaa !24
  %11 = getelementptr inbounds i8, ptr %3, i64 248
  %12 = getelementptr inbounds i8, ptr %0, i64 40
  %13 = getelementptr inbounds i8, ptr %3, i64 296
  %14 = load i32, ptr %13, align 8, !tbaa !25
  tail call void @cg_rle_rasterize(ptr noundef nonnull %0, ptr noundef %8, ptr noundef %10, ptr noundef nonnull %11, ptr noundef nonnull %12, ptr noundef null, i32 noundef %14)
  %15 = load ptr, ptr %3, align 8, !tbaa !13
  %16 = load ptr, ptr %6, align 8, !tbaa !23
  tail call void @cg_rle_clip_path(ptr noundef %15, ptr noundef %16)
  br label %25

17:                                               ; preds = %1
  %18 = tail call ptr @cg_rle_create()
  store ptr %18, ptr %3, align 8, !tbaa !13
  %19 = getelementptr inbounds i8, ptr %0, i64 16
  %20 = load ptr, ptr %19, align 8, !tbaa !24
  %21 = getelementptr inbounds i8, ptr %3, i64 248
  %22 = getelementptr inbounds i8, ptr %0, i64 40
  %23 = getelementptr inbounds i8, ptr %3, i64 296
  %24 = load i32, ptr %23, align 8, !tbaa !25
  tail call void @cg_rle_rasterize(ptr noundef nonnull %0, ptr noundef %18, ptr noundef %20, ptr noundef nonnull %21, ptr noundef nonnull %22, ptr noundef null, i32 noundef %24)
  br label %25

25:                                               ; preds = %17, %5
  ret void
}

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

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

; Function Attrs: nounwind uwtable
declare hidden void @cg_rle_clip_path(ptr noundef, ptr 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 = { 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, !7, i64 8}
!6 = !{!"cg_ctx_t", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !7, i64 32, !10, i64 40, !7, i64 72, !12, i64 80}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"cg_rect_t", !11, i64 0, !11, i64 8, !11, i64 16, !11, i64 24}
!11 = !{!"double", !8, i64 0}
!12 = !{!"long", !8, i64 0}
!13 = !{!14, !7, i64 0}
!14 = !{!"cg_state_t", !7, i64 0, !15, i64 8, !19, i64 248, !16, i64 296, !22, i64 304, !16, i64 336, !11, i64 344, !7, i64 352}
!15 = !{!"cg_paint_t", !16, i64 0, !17, i64 8, !18, i64 40, !21, i64 168}
!16 = !{!"int", !8, i64 0}
!17 = !{!"cg_color_t", !11, i64 0, !11, i64 8, !11, i64 16, !11, i64 24}
!18 = !{!"cg_gradient_t", !16, i64 0, !16, i64 4, !19, i64 8, !8, i64 56, !11, i64 104, !20, i64 112}
!19 = !{!"cg_matrix_t", !11, i64 0, !11, i64 8, !11, i64 16, !11, i64 24, !11, i64 32, !11, i64 40}
!20 = !{!"", !7, i64 0, !16, i64 8, !16, i64 12}
!21 = !{!"cg_texture_t", !16, i64 0, !7, i64 8, !19, i64 16, !11, i64 64}
!22 = !{!"cg_stroke_data_t", !11, i64 0, !11, i64 8, !16, i64 16, !16, i64 20, !7, i64 24}
!23 = !{!6, !7, i64 24}
!24 = !{!6, !7, i64 16}
!25 = !{!14, !16, i64 296}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,SROAPass,TailCallElimPass