; LLVM IR from yettabaa/cub3D :: mlx-linux (mlx_get_color_value)

; 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 }
%struct.s_xvar = type { ptr, i64, i32, i32, ptr, i64, i32, ptr, ptr, ptr, i32, i32, i32, [6 x i32], i64, i64, i32 }

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

12:                                               ; preds = %2
  %13 = load i32, ptr %5, align 4, !tbaa !9
  store i32 %13, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %78

14:                                               ; preds = %2
  %15 = load i32, ptr %5, align 4, !tbaa !9
  %16 = ashr i32 %15, 8
  %17 = and i32 %16, 65280
  %18 = trunc i32 %17 to i16
  %19 = getelementptr inbounds %struct.XColor, ptr %6, i32 0, i32 1
  store i16 %18, ptr %19, align 8, !tbaa !14
  %20 = load i32, ptr %5, align 4, !tbaa !9
  %21 = and i32 %20, 65280
  %22 = trunc i32 %21 to i16
  %23 = getelementptr inbounds %struct.XColor, ptr %6, i32 0, i32 2
  store i16 %22, ptr %23, align 2, !tbaa !17
  %24 = load i32, ptr %5, align 4, !tbaa !9
  %25 = shl i32 %24, 8
  %26 = and i32 %25, 65280
  %27 = trunc i32 %26 to i16
  %28 = getelementptr inbounds %struct.XColor, ptr %6, i32 0, i32 3
  store i16 %27, ptr %28, align 4, !tbaa !18
  %29 = getelementptr inbounds %struct.XColor, ptr %6, i32 0, i32 1
  %30 = load i16, ptr %29, align 8, !tbaa !14
  %31 = zext i16 %30 to i32
  %32 = load ptr, ptr %4, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.s_xvar, ptr %32, i32 0, i32 13
  %34 = getelementptr inbounds [6 x i32], ptr %33, i64 0, i64 1
  %35 = load i32, ptr %34, align 4, !tbaa !9
  %36 = sub nsw i32 16, %35
  %37 = ashr i32 %31, %36
  %38 = load ptr, ptr %4, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.s_xvar, ptr %38, i32 0, i32 13
  %40 = getelementptr inbounds [6 x i32], ptr %39, i64 0, i64 0
  %41 = load i32, ptr %40, align 4, !tbaa !9
  %42 = shl i32 %37, %41
  %43 = getelementptr inbounds %struct.XColor, ptr %6, i32 0, i32 2
  %44 = load i16, ptr %43, align 2, !tbaa !17
  %45 = zext i16 %44 to i32
  %46 = load ptr, ptr %4, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.s_xvar, ptr %46, i32 0, i32 13
  %48 = getelementptr inbounds [6 x i32], ptr %47, i64 0, i64 3
  %49 = load i32, ptr %48, align 4, !tbaa !9
  %50 = sub nsw i32 16, %49
  %51 = ashr i32 %45, %50
  %52 = load ptr, ptr %4, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.s_xvar, ptr %52, i32 0, i32 13
  %54 = getelementptr inbounds [6 x i32], ptr %53, i64 0, i64 2
  %55 = load i32, ptr %54, align 4, !tbaa !9
  %56 = shl i32 %51, %55
  %57 = add nsw i32 %42, %56
  %58 = getelementptr inbounds %struct.XColor, ptr %6, i32 0, i32 3
  %59 = load i16, ptr %58, align 4, !tbaa !18
  %60 = zext i16 %59 to i32
  %61 = load ptr, ptr %4, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.s_xvar, ptr %61, i32 0, i32 13
  %63 = getelementptr inbounds [6 x i32], ptr %62, i64 0, i64 5
  %64 = load i32, ptr %63, align 4, !tbaa !9
  %65 = sub nsw i32 16, %64
  %66 = ashr i32 %60, %65
  %67 = load ptr, ptr %4, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.s_xvar, ptr %67, i32 0, i32 13
  %69 = getelementptr inbounds [6 x i32], ptr %68, i64 0, i64 4
  %70 = load i32, ptr %69, align 4, !tbaa !9
  %71 = shl i32 %66, %70
  %72 = add nsw i32 %57, %71
  %73 = sext i32 %72 to i64
  %74 = getelementptr inbounds %struct.XColor, ptr %6, i32 0, i32 0
  store i64 %73, ptr %74, align 8, !tbaa !19
  %75 = getelementptr inbounds %struct.XColor, ptr %6, i32 0, i32 0
  %76 = load i64, ptr %75, align 8, !tbaa !19
  %77 = trunc i64 %76 to i32
  store i32 %77, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %78

78:                                               ; preds = %14, %12
  call void @llvm.lifetime.end.p0(i64 16, ptr %6) #2
  %79 = load i32, ptr %3, align 4
  ret i32 %79
}

; 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

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 = { 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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 20}
!12 = !{!"s_xvar", !6, i64 0, !13, i64 8, !10, i64 16, !10, i64 20, !6, i64 24, !13, i64 32, !10, i64 40, !6, i64 48, !6, i64 56, !6, i64 64, !10, i64 72, !10, i64 76, !10, i64 80, !7, i64 84, !13, i64 112, !13, i64 120, !10, i64 128}
!13 = !{!"long", !7, i64 0}
!14 = !{!15, !16, i64 8}
!15 = !{!"", !13, i64 0, !16, i64 8, !16, i64 10, !16, i64 12, !7, i64 14, !7, i64 15}
!16 = !{!"short", !7, i64 0}
!17 = !{!15, !16, i64 10}
!18 = !{!15, !16, i64 12}
!19 = !{!15, !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: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: read) uwtable
define dso_local i32 @mlx_int_get_good_color(ptr nocapture noundef readonly %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %0, i64 20
  %4 = load i32, ptr %3, align 4, !tbaa !5
  %5 = icmp sgt i32 %4, 23
  br i1 %5, label %35, label %6

6:                                                ; preds = %2
  %7 = lshr i32 %1, 8
  %8 = and i32 %7, 65280
  %9 = and i32 %1, 65280
  %10 = shl i32 %1, 8
  %11 = getelementptr inbounds i8, ptr %0, i64 84
  %12 = getelementptr inbounds i8, ptr %0, i64 88
  %13 = load i32, ptr %12, align 4, !tbaa !12
  %14 = sub nsw i32 16, %13
  %15 = lshr i32 %8, %14
  %16 = load i32, ptr %11, align 4, !tbaa !12
  %17 = shl i32 %15, %16
  %18 = getelementptr inbounds i8, ptr %0, i64 96
  %19 = load i32, ptr %18, align 4, !tbaa !12
  %20 = sub nsw i32 16, %19
  %21 = lshr i32 %9, %20
  %22 = getelementptr inbounds i8, ptr %0, i64 92
  %23 = load i32, ptr %22, align 4, !tbaa !12
  %24 = shl i32 %21, %23
  %25 = add nsw i32 %24, %17
  %26 = and i32 %10, 65280
  %27 = getelementptr inbounds i8, ptr %0, i64 104
  %28 = load i32, ptr %27, align 4, !tbaa !12
  %29 = sub nsw i32 16, %28
  %30 = lshr i32 %26, %29
  %31 = getelementptr inbounds i8, ptr %0, i64 100
  %32 = load i32, ptr %31, align 4, !tbaa !12
  %33 = shl i32 %30, %32
  %34 = add nsw i32 %25, %33
  br label %35

35:                                               ; preds = %2, %6
  %.0 = phi i32 [ %34, %6 ], [ %1, %2 ]
  ret i32 %.0
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: read) 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, !11, i64 20}
!6 = !{!"s_xvar", !7, i64 0, !10, i64 8, !11, i64 16, !11, i64 20, !7, i64 24, !10, i64 32, !11, i64 40, !7, i64 48, !7, i64 56, !7, i64 64, !11, i64 72, !11, i64 76, !11, i64 80, !8, i64 84, !10, i64 112, !10, i64 120, !11, i64 128}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!"int", !8, i64 0}
!12 = !{!11, !11, i64 0}


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