; LLVM IR from leonmavr/gfx-v4 :: src (gfx)

; 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.XColor = type { i64, i16, i16, i16, i8, i8 }

@gfx_display = external hidden global ptr, align 8
@gfx_fast_color_mode = external hidden global i32, align 4
@gfx_gc = external hidden global ptr, align 8
@gfx_colormap = external hidden global i64, align 8

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

declare i32 @XSetForeground(ptr noundef, ptr noundef, i64 noundef) #1

; 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 @gfx_color(i32 noundef %0, i32 noundef %1, i32 noundef %2) #2 {
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca %struct.XColor, align 8
  store i32 %0, ptr %4, align 4, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !5
  store i32 %2, ptr %6, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 16, ptr %7) #3
  %8 = load i32, ptr @gfx_fast_color_mode, align 4, !tbaa !5
  %9 = icmp ne i32 %8, 0
  br i1 %9, label %10, label %23

10:                                               ; preds = %3
  %11 = load i32, ptr %6, align 4, !tbaa !5
  %12 = and i32 %11, 255
  %13 = load i32, ptr %5, align 4, !tbaa !5
  %14 = and i32 %13, 255
  %15 = shl i32 %14, 8
  %16 = or i32 %12, %15
  %17 = load i32, ptr %4, align 4, !tbaa !5
  %18 = and i32 %17, 255
  %19 = shl i32 %18, 16
  %20 = or i32 %16, %19
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds %struct.XColor, ptr %7, i32 0, i32 0
  store i64 %21, ptr %22, align 8, !tbaa !9
  br label %40

23:                                               ; preds = %3
  %24 = getelementptr inbounds %struct.XColor, ptr %7, i32 0, i32 0
  store i64 0, ptr %24, align 8, !tbaa !9
  %25 = load i32, ptr %4, align 4, !tbaa !5
  %26 = shl i32 %25, 8
  %27 = trunc i32 %26 to i16
  %28 = getelementptr inbounds %struct.XColor, ptr %7, i32 0, i32 1
  store i16 %27, ptr %28, align 8, !tbaa !13
  %29 = load i32, ptr %5, align 4, !tbaa !5
  %30 = shl i32 %29, 8
  %31 = trunc i32 %30 to i16
  %32 = getelementptr inbounds %struct.XColor, ptr %7, i32 0, i32 2
  store i16 %31, ptr %32, align 2, !tbaa !14
  %33 = load i32, ptr %6, align 4, !tbaa !5
  %34 = shl i32 %33, 8
  %35 = trunc i32 %34 to i16
  %36 = getelementptr inbounds %struct.XColor, ptr %7, i32 0, i32 3
  store i16 %35, ptr %36, align 4, !tbaa !15
  %37 = load ptr, ptr @gfx_display, align 8, !tbaa !16
  %38 = load i64, ptr @gfx_colormap, align 8, !tbaa !18
  %39 = call i32 @XAllocColor(ptr noundef %37, i64 noundef %38, ptr noundef %7)
  br label %40

40:                                               ; preds = %23, %10
  %41 = load ptr, ptr @gfx_display, align 8, !tbaa !16
  %42 = load ptr, ptr @gfx_gc, align 8, !tbaa !16
  %43 = getelementptr inbounds %struct.XColor, ptr %7, i32 0, i32 0
  %44 = load i64, ptr %43, align 8, !tbaa !9
  %45 = call i32 @XSetForeground(ptr noundef %41, ptr noundef %42, i64 noundef %44)
  call void @llvm.lifetime.end.p0(i64 16, ptr %7) #3
  ret void
}

declare i32 @XAllocColor(ptr noundef, i64 noundef, ptr noundef) #1

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !11, i64 0}
!10 = !{!"", !11, i64 0, !12, i64 8, !12, i64 10, !12, i64 12, !7, i64 14, !7, i64 15}
!11 = !{!"long", !7, i64 0}
!12 = !{!"short", !7, i64 0}
!13 = !{!10, !12, i64 8}
!14 = !{!10, !12, i64 10}
!15 = !{!10, !12, i64 12}
!16 = !{!17, !17, i64 0}
!17 = !{!"any pointer", !7, i64 0}
!18 = !{!11, !11, 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"

%struct.XColor = type { i64, i16, i16, i16, i8, i8 }

@gfx_display = external hidden local_unnamed_addr global ptr, align 8
@gfx_fast_color_mode = external hidden local_unnamed_addr global i32, align 4
@gfx_gc = external hidden local_unnamed_addr global ptr, align 8
@gfx_colormap = external hidden local_unnamed_addr global i64, align 8

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

declare i32 @XSetForeground(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #1

; 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 @gfx_color(i32 noundef %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #2 {
  %4 = alloca %struct.XColor, align 8
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %4) #3
  %5 = load i32, ptr @gfx_fast_color_mode, align 4, !tbaa !5
  %.not = icmp eq i32 %5, 0
  br i1 %.not, label %15, label %6

6:                                                ; preds = %3
  %7 = and i32 %2, 255
  %8 = shl i32 %1, 8
  %9 = and i32 %8, 65280
  %10 = shl i32 %0, 16
  %11 = and i32 %10, 16711680
  %12 = or disjoint i32 %9, %11
  %13 = or disjoint i32 %12, %7
  %14 = zext nneg i32 %13 to i64
  store i64 %14, ptr %4, align 8, !tbaa !9
  br label %25

15:                                               ; preds = %3
  store i64 0, ptr %4, align 8, !tbaa !9
  %.tr = trunc i32 %0 to i16
  %16 = shl i16 %.tr, 8
  %17 = getelementptr inbounds i8, ptr %4, i64 8
  store i16 %16, ptr %17, align 8, !tbaa !13
  %.tr6 = trunc i32 %1 to i16
  %18 = shl i16 %.tr6, 8
  %19 = getelementptr inbounds i8, ptr %4, i64 10
  store i16 %18, ptr %19, align 2, !tbaa !14
  %.tr7 = trunc i32 %2 to i16
  %20 = shl i16 %.tr7, 8
  %21 = getelementptr inbounds i8, ptr %4, i64 12
  store i16 %20, ptr %21, align 4, !tbaa !15
  %22 = load ptr, ptr @gfx_display, align 8, !tbaa !16
  %23 = load i64, ptr @gfx_colormap, align 8, !tbaa !18
  %24 = call i32 @XAllocColor(ptr noundef %22, i64 noundef %23, ptr noundef nonnull %4) #3
  %.pre = load i64, ptr %4, align 8, !tbaa !9
  br label %25

25:                                               ; preds = %15, %6
  %26 = phi i64 [ %.pre, %15 ], [ %14, %6 ]
  %27 = load ptr, ptr @gfx_display, align 8, !tbaa !16
  %28 = load ptr, ptr @gfx_gc, align 8, !tbaa !16
  %29 = call i32 @XSetForeground(ptr noundef %27, ptr noundef %28, i64 noundef %26) #3
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %4) #3
  ret void
}

declare i32 @XAllocColor(ptr noundef, i64 noundef, ptr noundef) local_unnamed_addr #1

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !11, i64 0}
!10 = !{!"", !11, i64 0, !12, i64 8, !12, i64 10, !12, i64 12, !7, i64 14, !7, i64 15}
!11 = !{!"long", !7, i64 0}
!12 = !{!"short", !7, i64 0}
!13 = !{!10, !12, i64 8}
!14 = !{!10, !12, i64 10}
!15 = !{!10, !12, i64 12}
!16 = !{!17, !17, i64 0}
!17 = !{!"any pointer", !7, i64 0}
!18 = !{!11, !11, i64 0}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,ReassociatePass,SROAPass