; LLVM IR from 0intro/wmii :: lib/libstuff/x11/colors (xftcolor)

; 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.XftColor = type { i64, %struct.XRenderColor }
%struct.XRenderColor = type { i16, i16, i16, i16 }
%struct.Color = type { i16, i16, i16, i16, i64 }

; Function Attrs: nounwind uwtable
define dso_local ptr @xftcolor(ptr noundef %0, ptr noundef %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca %struct.XftColor, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  %7 = call ptr @emallocz(i32 noundef 16)
  store ptr %7, ptr %5, align 8, !tbaa !5
  %8 = load ptr, ptr %5, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.XftColor, ptr %6, i32 0, i32 0
  %10 = load ptr, ptr %3, align 8, !tbaa !5
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  %12 = call i64 @pixelvalue(ptr noundef %10, ptr noundef %11)
  store i64 %12, ptr %9, align 8, !tbaa !9
  %13 = getelementptr inbounds %struct.XftColor, ptr %6, i32 0, i32 1
  %14 = getelementptr inbounds %struct.XRenderColor, ptr %13, i32 0, i32 0
  %15 = load ptr, ptr %4, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.Color, ptr %15, i32 0, i32 0
  %17 = load i16, ptr %16, align 8, !tbaa !14
  store i16 %17, ptr %14, align 8, !tbaa !16
  %18 = getelementptr inbounds %struct.XRenderColor, ptr %13, i32 0, i32 1
  %19 = load ptr, ptr %4, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.Color, ptr %19, i32 0, i32 1
  %21 = load i16, ptr %20, align 2, !tbaa !17
  store i16 %21, ptr %18, align 2, !tbaa !18
  %22 = getelementptr inbounds %struct.XRenderColor, ptr %13, i32 0, i32 2
  %23 = load ptr, ptr %4, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.Color, ptr %23, i32 0, i32 2
  %25 = load i16, ptr %24, align 4, !tbaa !19
  store i16 %25, ptr %22, align 4, !tbaa !20
  %26 = getelementptr inbounds %struct.XRenderColor, ptr %13, i32 0, i32 3
  %27 = load ptr, ptr %4, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.Color, ptr %27, i32 0, i32 3
  %29 = load i16, ptr %28, align 2, !tbaa !21
  store i16 %29, ptr %26, align 2, !tbaa !22
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %8, ptr align 8 %6, i64 16, i1 false), !tbaa.struct !23
  %30 = load ptr, ptr %5, align 8, !tbaa !5
  %31 = call ptr @freelater(ptr noundef %30)
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  ret ptr %31
}

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

declare ptr @emallocz(i32 noundef) #2

declare i64 @pixelvalue(ptr noundef, ptr noundef) #2

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #3

declare ptr @freelater(ptr noundef) #2

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

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 = { "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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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, !11, i64 0}
!10 = !{!"XftColor", !11, i64 0, !12, i64 8}
!11 = !{!"long", !7, i64 0}
!12 = !{!"", !13, i64 0, !13, i64 2, !13, i64 4, !13, i64 6}
!13 = !{!"short", !7, i64 0}
!14 = !{!15, !13, i64 0}
!15 = !{!"Color", !13, i64 0, !13, i64 2, !13, i64 4, !13, i64 6, !11, i64 8}
!16 = !{!12, !13, i64 0}
!17 = !{!15, !13, i64 2}
!18 = !{!12, !13, i64 2}
!19 = !{!15, !13, i64 4}
!20 = !{!12, !13, i64 4}
!21 = !{!15, !13, i64 6}
!22 = !{!12, !13, i64 6}
!23 = !{i64 0, i64 8, !24, i64 8, i64 2, !25, i64 10, i64 2, !25, i64 12, i64 2, !25, i64 14, i64 2, !25}
!24 = !{!11, !11, i64 0}
!25 = !{!13, !13, i64 0}


; 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
define dso_local ptr @xftcolor(ptr noundef %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = tail call ptr @emallocz(i32 noundef 16) #2
  %4 = tail call i64 @pixelvalue(ptr noundef %0, ptr noundef %1) #2
  store i64 %4, ptr %3, align 8, !tbaa !5
  %.sroa.2.0..sroa_idx = getelementptr inbounds i8, ptr %3, i64 8
  %5 = load <4 x i16>, ptr %1, align 8, !tbaa !9
  store <4 x i16> %5, ptr %.sroa.2.0..sroa_idx, align 8, !tbaa !9
  %6 = tail call ptr @freelater(ptr noundef nonnull %3) #2
  ret ptr %6
}

declare ptr @emallocz(i32 noundef) local_unnamed_addr #1

declare i64 @pixelvalue(ptr noundef, ptr noundef) local_unnamed_addr #1

declare ptr @freelater(ptr noundef) local_unnamed_addr #1

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 = { "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 }

!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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"short", !7, i64 0}


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