; 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_matrix_t = type { double, double, double, double, double, double }
%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_stroke_data_t = type { double, double, i32, i32, ptr }

; Function Attrs: nounwind uwtable
declare dso_local void @cg_matrix_init_identity(ptr noundef) #0

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

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

; Function Attrs: nounwind uwtable
declare hidden ptr @cg_path_create() #0

; Function Attrs: nounwind uwtable
declare hidden ptr @cg_rle_create() #0

; Function Attrs: nounwind uwtable
declare hidden void @cg_path_destroy(ptr noundef) #0

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @cg_path_add_rectangle(ptr noundef, double noundef, double noundef, double noundef, double 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) #0

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

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

14:                                               ; preds = %1
  %15 = load ptr, ptr %2, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.cg_ctx_t, ptr %15, i32 0, i32 4
  %17 = load ptr, ptr %16, align 8, !tbaa !24
  %18 = icmp eq ptr %17, null
  br i1 %18, label %19, label %49

19:                                               ; preds = %14
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  %20 = call ptr @cg_path_create()
  store ptr %20, ptr %4, align 8, !tbaa !5
  %21 = load ptr, ptr %4, align 8, !tbaa !5
  %22 = load ptr, ptr %2, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.cg_ctx_t, ptr %22, i32 0, i32 5
  %24 = getelementptr inbounds %struct.cg_rect_t, ptr %23, i32 0, i32 0
  %25 = load double, ptr %24, align 8, !tbaa !25
  %26 = load ptr, ptr %2, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.cg_ctx_t, ptr %26, i32 0, i32 5
  %28 = getelementptr inbounds %struct.cg_rect_t, ptr %27, i32 0, i32 1
  %29 = load double, ptr %28, align 8, !tbaa !26
  %30 = load ptr, ptr %2, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.cg_ctx_t, ptr %30, i32 0, i32 5
  %32 = getelementptr inbounds %struct.cg_rect_t, ptr %31, i32 0, i32 2
  %33 = load double, ptr %32, align 8, !tbaa !27
  %34 = load ptr, ptr %2, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.cg_ctx_t, ptr %34, i32 0, i32 5
  %36 = getelementptr inbounds %struct.cg_rect_t, ptr %35, i32 0, i32 3
  %37 = load double, ptr %36, align 8, !tbaa !28
  call void @cg_path_add_rectangle(ptr noundef %21, double noundef %25, double noundef %29, double noundef %33, double noundef %37)
  call void @llvm.lifetime.start.p0(i64 48, ptr %5) #3
  call void @cg_matrix_init_identity(ptr noundef %5)
  %38 = call ptr @cg_rle_create()
  %39 = load ptr, ptr %2, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.cg_ctx_t, ptr %39, i32 0, i32 4
  store ptr %38, ptr %40, align 8, !tbaa !24
  %41 = load ptr, ptr %2, align 8, !tbaa !5
  %42 = load ptr, ptr %2, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.cg_ctx_t, ptr %42, i32 0, i32 4
  %44 = load ptr, ptr %43, align 8, !tbaa !24
  %45 = load ptr, ptr %4, align 8, !tbaa !5
  %46 = load ptr, ptr %2, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.cg_ctx_t, ptr %46, i32 0, i32 5
  call void @cg_rle_rasterize(ptr noundef %41, ptr noundef %44, ptr noundef %45, ptr noundef %5, ptr noundef %47, ptr noundef null, i32 noundef 0)
  %48 = load ptr, ptr %4, align 8, !tbaa !5
  call void @cg_path_destroy(ptr noundef %48)
  call void @llvm.lifetime.end.p0(i64 48, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  br label %49

49:                                               ; preds = %19, %14, %1
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %50 = load ptr, ptr %3, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.cg_state_t, ptr %50, i32 0, i32 0
  %52 = load ptr, ptr %51, align 8, !tbaa !14
  %53 = icmp ne ptr %52, null
  br i1 %53, label %54, label %58

54:                                               ; preds = %49
  %55 = load ptr, ptr %3, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.cg_state_t, ptr %55, i32 0, i32 0
  %57 = load ptr, ptr %56, align 8, !tbaa !14
  br label %62

58:                                               ; preds = %49
  %59 = load ptr, ptr %2, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.cg_ctx_t, ptr %59, i32 0, i32 4
  %61 = load ptr, ptr %60, align 8, !tbaa !24
  br label %62

62:                                               ; preds = %58, %54
  %63 = phi ptr [ %57, %54 ], [ %61, %58 ]
  store ptr %63, ptr %6, align 8, !tbaa !5
  %64 = load ptr, ptr %2, align 8, !tbaa !5
  %65 = load ptr, ptr %6, align 8, !tbaa !5
  call void @cg_blend(ptr noundef %64, ptr noundef %65)
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  ret void
}

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 32}
!25 = !{!10, !12, i64 40}
!26 = !{!10, !12, i64 48}
!27 = !{!10, !12, i64 56}
!28 = !{!10, !12, i64 64}


; 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.cg_matrix_t = type { double, double, double, double, double, double }

; Function Attrs: nounwind uwtable
declare dso_local void @cg_matrix_init_identity(ptr noundef) local_unnamed_addr #0

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

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

; Function Attrs: nounwind uwtable
declare hidden ptr @cg_path_create() local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare hidden ptr @cg_rle_create() local_unnamed_addr #0

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @cg_path_add_rectangle(ptr noundef, double noundef, double noundef, double noundef, double noundef) local_unnamed_addr #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) local_unnamed_addr #0

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

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

7:                                                ; preds = %1
  %8 = getelementptr inbounds i8, ptr %0, i64 32
  %9 = load ptr, ptr %8, align 8, !tbaa !23
  %10 = icmp eq ptr %9, null
  br i1 %10, label %11, label %.thread21

11:                                               ; preds = %7
  %12 = tail call ptr @cg_path_create()
  %13 = getelementptr inbounds i8, ptr %0, i64 40
  %14 = load double, ptr %13, align 8, !tbaa !24
  %15 = getelementptr inbounds i8, ptr %0, i64 48
  %16 = load double, ptr %15, align 8, !tbaa !25
  %17 = getelementptr inbounds i8, ptr %0, i64 56
  %18 = load double, ptr %17, align 8, !tbaa !26
  %19 = getelementptr inbounds i8, ptr %0, i64 64
  %20 = load double, ptr %19, align 8, !tbaa !27
  tail call void @cg_path_add_rectangle(ptr noundef %12, double noundef %14, double noundef %16, double noundef %18, double noundef %20)
  call void @llvm.lifetime.start.p0(i64 48, ptr nonnull %2) #3
  call void @cg_matrix_init_identity(ptr noundef nonnull %2)
  %21 = call ptr @cg_rle_create()
  store ptr %21, ptr %8, align 8, !tbaa !23
  call void @cg_rle_rasterize(ptr noundef nonnull %0, ptr noundef %21, ptr noundef %12, ptr noundef nonnull %2, ptr noundef nonnull %13, ptr noundef null, i32 noundef 0)
  call void @cg_path_destroy(ptr noundef %12)
  call void @llvm.lifetime.end.p0(i64 48, ptr nonnull %2) #3
  %.pr.pre = load ptr, ptr %4, align 8, !tbaa !13
  %.not = icmp eq ptr %.pr.pre, null
  br i1 %.not, label %.thread21, label %.thread

.thread21:                                        ; preds = %7, %11
  %22 = load ptr, ptr %8, align 8, !tbaa !23
  br label %.thread

.thread:                                          ; preds = %1, %11, %.thread21
  %23 = phi ptr [ %22, %.thread21 ], [ %.pr.pre, %11 ], [ %5, %1 ]
  call void @cg_blend(ptr noundef nonnull %0, ptr noundef %23)
  ret void
}

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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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, !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 32}
!24 = !{!6, !11, i64 40}
!25 = !{!6, !11, i64 48}
!26 = !{!6, !11, i64 56}
!27 = !{!6, !11, i64 64}


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