; LLVM IR from Stephane-D/SGDK :: src (pal)

; 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"

; 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

declare void @VDP_setAutoInc(i8 noundef zeroext) #1

; Function Attrs: nounwind uwtable
define dso_local void @PAL_getPalette(i16 noundef zeroext %0, ptr noundef %1) #2 {
  %3 = alloca i16, align 2
  %4 = alloca ptr, align 8
  %5 = alloca i16, align 2
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i64, align 8
  store i16 %0, ptr %3, align 2, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !9
  call void @VDP_setAutoInc(i8 noundef zeroext 2)
  call void @llvm.lifetime.start.p0(i64 2, ptr %5) #3
  %9 = load i16, ptr %3, align 2, !tbaa !5
  %10 = zext i16 %9 to i32
  %11 = mul nsw i32 %10, 32
  %12 = trunc i32 %11 to i16
  store i16 %12, ptr %5, align 2, !tbaa !5
  %13 = load i16, ptr %5, align 2, !tbaa !5
  %14 = zext i16 %13 to i64
  %15 = and i64 %14, 127
  %16 = add i64 0, %15
  %17 = shl i64 %16, 16
  %18 = add i64 %17, 32
  store volatile i64 %18, ptr inttoptr (i64 12582916 to ptr), align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  store ptr inttoptr (i64 12582912 to ptr), ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %19 = load ptr, ptr %4, align 8, !tbaa !9
  store ptr %19, ptr %7, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  store i64 250482414, ptr %8, align 8, !tbaa !11
  %20 = load ptr, ptr %6, align 8, !tbaa !9
  %21 = load volatile i64, ptr %20, align 8, !tbaa !11
  %22 = load i64, ptr %8, align 8, !tbaa !11
  %23 = and i64 %21, %22
  %24 = load ptr, ptr %7, align 8, !tbaa !9
  %25 = getelementptr inbounds i64, ptr %24, i32 1
  store ptr %25, ptr %7, align 8, !tbaa !9
  store i64 %23, ptr %24, align 8, !tbaa !11
  %26 = load ptr, ptr %6, align 8, !tbaa !9
  %27 = load volatile i64, ptr %26, align 8, !tbaa !11
  %28 = load i64, ptr %8, align 8, !tbaa !11
  %29 = and i64 %27, %28
  %30 = load ptr, ptr %7, align 8, !tbaa !9
  %31 = getelementptr inbounds i64, ptr %30, i32 1
  store ptr %31, ptr %7, align 8, !tbaa !9
  store i64 %29, ptr %30, align 8, !tbaa !11
  %32 = load ptr, ptr %6, align 8, !tbaa !9
  %33 = load volatile i64, ptr %32, align 8, !tbaa !11
  %34 = load i64, ptr %8, align 8, !tbaa !11
  %35 = and i64 %33, %34
  %36 = load ptr, ptr %7, align 8, !tbaa !9
  %37 = getelementptr inbounds i64, ptr %36, i32 1
  store ptr %37, ptr %7, align 8, !tbaa !9
  store i64 %35, ptr %36, align 8, !tbaa !11
  %38 = load ptr, ptr %6, align 8, !tbaa !9
  %39 = load volatile i64, ptr %38, align 8, !tbaa !11
  %40 = load i64, ptr %8, align 8, !tbaa !11
  %41 = and i64 %39, %40
  %42 = load ptr, ptr %7, align 8, !tbaa !9
  %43 = getelementptr inbounds i64, ptr %42, i32 1
  store ptr %43, ptr %7, align 8, !tbaa !9
  store i64 %41, ptr %42, align 8, !tbaa !11
  %44 = load ptr, ptr %6, align 8, !tbaa !9
  %45 = load volatile i64, ptr %44, align 8, !tbaa !11
  %46 = load i64, ptr %8, align 8, !tbaa !11
  %47 = and i64 %45, %46
  %48 = load ptr, ptr %7, align 8, !tbaa !9
  %49 = getelementptr inbounds i64, ptr %48, i32 1
  store ptr %49, ptr %7, align 8, !tbaa !9
  store i64 %47, ptr %48, align 8, !tbaa !11
  %50 = load ptr, ptr %6, align 8, !tbaa !9
  %51 = load volatile i64, ptr %50, align 8, !tbaa !11
  %52 = load i64, ptr %8, align 8, !tbaa !11
  %53 = and i64 %51, %52
  %54 = load ptr, ptr %7, align 8, !tbaa !9
  %55 = getelementptr inbounds i64, ptr %54, i32 1
  store ptr %55, ptr %7, align 8, !tbaa !9
  store i64 %53, ptr %54, align 8, !tbaa !11
  %56 = load ptr, ptr %6, align 8, !tbaa !9
  %57 = load volatile i64, ptr %56, align 8, !tbaa !11
  %58 = load i64, ptr %8, align 8, !tbaa !11
  %59 = and i64 %57, %58
  %60 = load ptr, ptr %7, align 8, !tbaa !9
  %61 = getelementptr inbounds i64, ptr %60, i32 1
  store ptr %61, ptr %7, align 8, !tbaa !9
  store i64 %59, ptr %60, align 8, !tbaa !11
  %62 = load ptr, ptr %6, align 8, !tbaa !9
  %63 = load volatile i64, ptr %62, align 8, !tbaa !11
  %64 = load i64, ptr %8, align 8, !tbaa !11
  %65 = and i64 %63, %64
  %66 = load ptr, ptr %7, align 8, !tbaa !9
  %67 = getelementptr inbounds i64, ptr %66, i32 1
  store ptr %67, ptr %7, align 8, !tbaa !9
  store i64 %65, ptr %66, align 8, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 2, ptr %5) #3
  ret void
}

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

declare void @VDP_setAutoInc(i8 noundef zeroext) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @PAL_getPalette(i16 noundef zeroext %0, ptr nocapture noundef writeonly %1) local_unnamed_addr #1 {
  tail call void @VDP_setAutoInc(i8 noundef zeroext 2) #2
  %3 = shl i16 %0, 5
  %4 = and i16 %3, 96
  %5 = zext nneg i16 %4 to i64
  %6 = shl nuw nsw i64 %5, 16
  %7 = or disjoint i64 %6, 32
  store volatile i64 %7, ptr inttoptr (i64 12582916 to ptr), align 8, !tbaa !5
  %8 = load volatile i64, ptr inttoptr (i64 12582912 to ptr), align 4194304, !tbaa !5
  %9 = and i64 %8, 250482414
  %10 = getelementptr inbounds i8, ptr %1, i64 8
  store i64 %9, ptr %1, align 8, !tbaa !5
  %11 = load volatile i64, ptr inttoptr (i64 12582912 to ptr), align 4194304, !tbaa !5
  %12 = and i64 %11, 250482414
  %13 = getelementptr inbounds i8, ptr %1, i64 16
  store i64 %12, ptr %10, align 8, !tbaa !5
  %14 = load volatile i64, ptr inttoptr (i64 12582912 to ptr), align 4194304, !tbaa !5
  %15 = and i64 %14, 250482414
  %16 = getelementptr inbounds i8, ptr %1, i64 24
  store i64 %15, ptr %13, align 8, !tbaa !5
  %17 = load volatile i64, ptr inttoptr (i64 12582912 to ptr), align 4194304, !tbaa !5
  %18 = and i64 %17, 250482414
  %19 = getelementptr inbounds i8, ptr %1, i64 32
  store i64 %18, ptr %16, align 8, !tbaa !5
  %20 = load volatile i64, ptr inttoptr (i64 12582912 to ptr), align 4194304, !tbaa !5
  %21 = and i64 %20, 250482414
  %22 = getelementptr inbounds i8, ptr %1, i64 40
  store i64 %21, ptr %19, align 8, !tbaa !5
  %23 = load volatile i64, ptr inttoptr (i64 12582912 to ptr), align 4194304, !tbaa !5
  %24 = and i64 %23, 250482414
  %25 = getelementptr inbounds i8, ptr %1, i64 48
  store i64 %24, ptr %22, align 8, !tbaa !5
  %26 = load volatile i64, ptr inttoptr (i64 12582912 to ptr), align 4194304, !tbaa !5
  %27 = and i64 %26, 250482414
  %28 = getelementptr inbounds i8, ptr %1, i64 56
  store i64 %27, ptr %25, align 8, !tbaa !5
  %29 = load volatile i64, ptr inttoptr (i64 12582912 to ptr), align 4194304, !tbaa !5
  %30 = and i64 %29, 250482414
  store i64 %30, ptr %28, align 8, !tbaa !5
  ret void
}

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


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