; 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_surface_t = type { i32, i32, i32, 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 allocsize(0)
declare noalias ptr @malloc(i64 noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local ptr @cg_surface_reference(ptr noundef) #2

; Function Attrs: nounwind uwtable
define dso_local ptr @cg_create(ptr noundef %0) #2 {
  %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 = call noalias ptr @malloc(i64 noundef 88) #4
  store ptr %4, ptr %3, align 8, !tbaa !5
  %5 = load ptr, ptr %2, align 8, !tbaa !5
  %6 = call ptr @cg_surface_reference(ptr noundef %5)
  %7 = load ptr, ptr %3, align 8, !tbaa !5
  %8 = getelementptr inbounds %struct.cg_ctx_t, ptr %7, i32 0, i32 0
  store ptr %6, ptr %8, align 8, !tbaa !9
  %9 = call ptr @cg_state_create()
  %10 = load ptr, ptr %3, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.cg_ctx_t, ptr %10, i32 0, i32 1
  store ptr %9, ptr %11, align 8, !tbaa !14
  %12 = call ptr @cg_path_create()
  %13 = load ptr, ptr %3, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.cg_ctx_t, ptr %13, i32 0, i32 2
  store ptr %12, ptr %14, align 8, !tbaa !15
  %15 = call ptr @cg_rle_create()
  %16 = load ptr, ptr %3, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.cg_ctx_t, ptr %16, i32 0, i32 3
  store ptr %15, ptr %17, align 8, !tbaa !16
  %18 = load ptr, ptr %3, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.cg_ctx_t, ptr %18, i32 0, i32 4
  store ptr null, ptr %19, align 8, !tbaa !17
  %20 = load ptr, ptr %3, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.cg_ctx_t, ptr %20, i32 0, i32 5
  %22 = getelementptr inbounds %struct.cg_rect_t, ptr %21, i32 0, i32 0
  store double 0.000000e+00, ptr %22, align 8, !tbaa !18
  %23 = load ptr, ptr %3, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.cg_ctx_t, ptr %23, i32 0, i32 5
  %25 = getelementptr inbounds %struct.cg_rect_t, ptr %24, i32 0, i32 1
  store double 0.000000e+00, ptr %25, align 8, !tbaa !19
  %26 = load ptr, ptr %2, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.cg_surface_t, ptr %26, i32 0, i32 1
  %28 = load i32, ptr %27, align 4, !tbaa !20
  %29 = sitofp i32 %28 to double
  %30 = load ptr, ptr %3, 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
  store double %29, ptr %32, align 8, !tbaa !23
  %33 = load ptr, ptr %2, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.cg_surface_t, ptr %33, i32 0, i32 2
  %35 = load i32, ptr %34, align 8, !tbaa !24
  %36 = sitofp i32 %35 to double
  %37 = load ptr, ptr %3, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.cg_ctx_t, ptr %37, i32 0, i32 5
  %39 = getelementptr inbounds %struct.cg_rect_t, ptr %38, i32 0, i32 3
  store double %36, ptr %39, align 8, !tbaa !25
  %40 = load ptr, ptr %3, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.cg_ctx_t, ptr %40, i32 0, i32 6
  store ptr null, ptr %41, align 8, !tbaa !26
  %42 = load ptr, ptr %3, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.cg_ctx_t, ptr %42, i32 0, i32 7
  store i64 0, ptr %43, align 8, !tbaa !27
  %44 = load ptr, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  ret ptr %44
}

; Function Attrs: nounwind uwtable
declare hidden ptr @cg_state_create() #2

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

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 }
attributes #4 = { 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, !6, i64 0}
!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 = !{!10, !6, i64 8}
!15 = !{!10, !6, i64 16}
!16 = !{!10, !6, i64 24}
!17 = !{!10, !6, i64 32}
!18 = !{!10, !12, i64 40}
!19 = !{!10, !12, i64 48}
!20 = !{!21, !22, i64 4}
!21 = !{!"cg_surface_t", !22, i64 0, !22, i64 4, !22, i64 8, !22, i64 12, !22, i64 16, !6, i64 24}
!22 = !{!"int", !7, i64 0}
!23 = !{!10, !12, i64 56}
!24 = !{!21, !22, i64 8}
!25 = !{!10, !12, i64 64}
!26 = !{!10, !6, i64 72}
!27 = !{!10, !13, i64 80}


; 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: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local ptr @cg_surface_reference(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local noalias noundef ptr @cg_create(ptr noundef %0) local_unnamed_addr #1 {
  %2 = tail call noalias dereferenceable_or_null(88) ptr @malloc(i64 noundef 88) #3
  %3 = tail call ptr @cg_surface_reference(ptr noundef %0)
  store ptr %3, ptr %2, align 8, !tbaa !5
  %4 = tail call ptr @cg_state_create()
  %5 = getelementptr inbounds i8, ptr %2, i64 8
  store ptr %4, ptr %5, align 8, !tbaa !13
  %6 = tail call ptr @cg_path_create()
  %7 = getelementptr inbounds i8, ptr %2, i64 16
  store ptr %6, ptr %7, align 8, !tbaa !14
  %8 = tail call ptr @cg_rle_create()
  %9 = getelementptr inbounds i8, ptr %2, i64 24
  store ptr %8, ptr %9, align 8, !tbaa !15
  %10 = getelementptr inbounds i8, ptr %2, i64 32
  %11 = getelementptr inbounds i8, ptr %0, i64 4
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(24) %10, i8 0, i64 24, i1 false)
  %12 = getelementptr inbounds i8, ptr %2, i64 56
  %13 = load <2 x i32>, ptr %11, align 4, !tbaa !16
  %14 = sitofp <2 x i32> %13 to <2 x double>
  store <2 x double> %14, ptr %12, align 8, !tbaa !18
  %15 = getelementptr inbounds i8, ptr %2, i64 72
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %15, i8 0, i64 16, i1 false)
  ret ptr %2
}

; Function Attrs: nounwind uwtable
declare hidden ptr @cg_state_create() local_unnamed_addr #1

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

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

attributes #0 = { 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 #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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { 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, !7, i64 0}
!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 = !{!6, !7, i64 8}
!14 = !{!6, !7, i64 16}
!15 = !{!6, !7, i64 24}
!16 = !{!17, !17, i64 0}
!17 = !{!"int", !8, i64 0}
!18 = !{!11, !11, i64 0}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,MemCpyOptPass,PostOrderFunctionAttrsPass,SLPVectorizerPass,SROAPass,TailCallElimPass