; 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

; Function Attrs: nounwind uwtable
define dso_local void @PAL_getColors(i16 noundef zeroext %0, ptr noundef %1, i16 noundef zeroext %2) #1 {
  %4 = alloca i16, align 2
  %5 = alloca ptr, align 8
  %6 = alloca i16, align 2
  %7 = alloca i16, align 2
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i64, align 8
  %11 = alloca i16, align 2
  %12 = alloca ptr, align 8
  %13 = alloca ptr, align 8
  %14 = alloca i16, align 2
  %15 = alloca i16, align 2
  store i16 %0, ptr %4, align 2, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !9
  store i16 %2, ptr %6, align 2, !tbaa !5
  call void @VDP_setAutoInc(i8 noundef zeroext 2)
  call void @llvm.lifetime.start.p0(i64 2, ptr %7) #3
  %16 = load i16, ptr %4, align 2, !tbaa !5
  %17 = zext i16 %16 to i32
  %18 = mul nsw i32 %17, 2
  %19 = trunc i32 %18 to i16
  store i16 %19, ptr %7, align 2, !tbaa !5
  %20 = load i16, ptr %7, align 2, !tbaa !5
  %21 = zext i16 %20 to i64
  %22 = and i64 %21, 127
  %23 = add i64 0, %22
  %24 = shl i64 %23, 16
  %25 = add i64 %24, 32
  store volatile i64 %25, ptr inttoptr (i64 12582916 to ptr), align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  store ptr inttoptr (i64 12582912 to ptr), ptr %8, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  %26 = load ptr, ptr %5, align 8, !tbaa !9
  store ptr %26, ptr %9, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  store i64 250482414, ptr %10, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 2, ptr %11) #3
  %27 = load i16, ptr %6, align 2, !tbaa !5
  %28 = zext i16 %27 to i32
  %29 = ashr i32 %28, 4
  %30 = trunc i32 %29 to i16
  store i16 %30, ptr %11, align 2, !tbaa !5
  br label %31

31:                                               ; preds = %35, %3
  %32 = load i16, ptr %11, align 2, !tbaa !5
  %33 = add i16 %32, -1
  store i16 %33, ptr %11, align 2, !tbaa !5
  %34 = icmp ne i16 %32, 0
  br i1 %34, label %35, label %84

35:                                               ; preds = %31
  %36 = load ptr, ptr %8, align 8, !tbaa !9
  %37 = load volatile i64, ptr %36, align 8, !tbaa !11
  %38 = load i64, ptr %10, align 8, !tbaa !11
  %39 = and i64 %37, %38
  %40 = load ptr, ptr %9, align 8, !tbaa !9
  %41 = getelementptr inbounds i64, ptr %40, i32 1
  store ptr %41, ptr %9, align 8, !tbaa !9
  store i64 %39, ptr %40, align 8, !tbaa !11
  %42 = load ptr, ptr %8, align 8, !tbaa !9
  %43 = load volatile i64, ptr %42, align 8, !tbaa !11
  %44 = load i64, ptr %10, align 8, !tbaa !11
  %45 = and i64 %43, %44
  %46 = load ptr, ptr %9, align 8, !tbaa !9
  %47 = getelementptr inbounds i64, ptr %46, i32 1
  store ptr %47, ptr %9, align 8, !tbaa !9
  store i64 %45, ptr %46, align 8, !tbaa !11
  %48 = load ptr, ptr %8, align 8, !tbaa !9
  %49 = load volatile i64, ptr %48, align 8, !tbaa !11
  %50 = load i64, ptr %10, align 8, !tbaa !11
  %51 = and i64 %49, %50
  %52 = load ptr, ptr %9, align 8, !tbaa !9
  %53 = getelementptr inbounds i64, ptr %52, i32 1
  store ptr %53, ptr %9, align 8, !tbaa !9
  store i64 %51, ptr %52, align 8, !tbaa !11
  %54 = load ptr, ptr %8, align 8, !tbaa !9
  %55 = load volatile i64, ptr %54, align 8, !tbaa !11
  %56 = load i64, ptr %10, align 8, !tbaa !11
  %57 = and i64 %55, %56
  %58 = load ptr, ptr %9, align 8, !tbaa !9
  %59 = getelementptr inbounds i64, ptr %58, i32 1
  store ptr %59, ptr %9, align 8, !tbaa !9
  store i64 %57, ptr %58, align 8, !tbaa !11
  %60 = load ptr, ptr %8, align 8, !tbaa !9
  %61 = load volatile i64, ptr %60, align 8, !tbaa !11
  %62 = load i64, ptr %10, align 8, !tbaa !11
  %63 = and i64 %61, %62
  %64 = load ptr, ptr %9, align 8, !tbaa !9
  %65 = getelementptr inbounds i64, ptr %64, i32 1
  store ptr %65, ptr %9, align 8, !tbaa !9
  store i64 %63, ptr %64, align 8, !tbaa !11
  %66 = load ptr, ptr %8, align 8, !tbaa !9
  %67 = load volatile i64, ptr %66, align 8, !tbaa !11
  %68 = load i64, ptr %10, align 8, !tbaa !11
  %69 = and i64 %67, %68
  %70 = load ptr, ptr %9, align 8, !tbaa !9
  %71 = getelementptr inbounds i64, ptr %70, i32 1
  store ptr %71, ptr %9, align 8, !tbaa !9
  store i64 %69, ptr %70, align 8, !tbaa !11
  %72 = load ptr, ptr %8, align 8, !tbaa !9
  %73 = load volatile i64, ptr %72, align 8, !tbaa !11
  %74 = load i64, ptr %10, align 8, !tbaa !11
  %75 = and i64 %73, %74
  %76 = load ptr, ptr %9, align 8, !tbaa !9
  %77 = getelementptr inbounds i64, ptr %76, i32 1
  store ptr %77, ptr %9, align 8, !tbaa !9
  store i64 %75, ptr %76, align 8, !tbaa !11
  %78 = load ptr, ptr %8, align 8, !tbaa !9
  %79 = load volatile i64, ptr %78, align 8, !tbaa !11
  %80 = load i64, ptr %10, align 8, !tbaa !11
  %81 = and i64 %79, %80
  %82 = load ptr, ptr %9, align 8, !tbaa !9
  %83 = getelementptr inbounds i64, ptr %82, i32 1
  store ptr %83, ptr %9, align 8, !tbaa !9
  store i64 %81, ptr %82, align 8, !tbaa !11
  br label %31, !llvm.loop !13

84:                                               ; preds = %31
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  %85 = load ptr, ptr %8, align 8, !tbaa !9
  store ptr %85, ptr %12, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #3
  %86 = load ptr, ptr %9, align 8, !tbaa !9
  store ptr %86, ptr %13, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 2, ptr %14) #3
  store i16 3822, ptr %14, align 2, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 2, ptr %15) #3
  %87 = load i16, ptr %6, align 2, !tbaa !5
  %88 = zext i16 %87 to i32
  %89 = and i32 %88, 15
  %90 = trunc i32 %89 to i16
  store i16 %90, ptr %15, align 2, !tbaa !5
  br label %91

91:                                               ; preds = %95, %84
  %92 = load i16, ptr %15, align 2, !tbaa !5
  %93 = add i16 %92, -1
  store i16 %93, ptr %15, align 2, !tbaa !5
  %94 = icmp ne i16 %92, 0
  br i1 %94, label %95, label %105

95:                                               ; preds = %91
  %96 = load ptr, ptr %12, align 8, !tbaa !9
  %97 = load volatile i16, ptr %96, align 2, !tbaa !5
  %98 = zext i16 %97 to i32
  %99 = load i16, ptr %14, align 2, !tbaa !5
  %100 = zext i16 %99 to i32
  %101 = and i32 %98, %100
  %102 = trunc i32 %101 to i16
  %103 = load ptr, ptr %13, align 8, !tbaa !9
  %104 = getelementptr inbounds i16, ptr %103, i32 1
  store ptr %104, ptr %13, align 8, !tbaa !9
  store i16 %102, ptr %103, align 2, !tbaa !5
  br label %91, !llvm.loop !15

105:                                              ; preds = %91
  call void @llvm.lifetime.end.p0(i64 2, ptr %15) #3
  call void @llvm.lifetime.end.p0(i64 2, ptr %14) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 2, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 2, ptr %7) #3
  ret void
}

declare void @VDP_setAutoInc(i8 noundef zeroext) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { "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}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}


; 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 void @PAL_getColors(i16 noundef zeroext %0, ptr nocapture noundef writeonly %1, i16 noundef zeroext %2) local_unnamed_addr #0 {
  tail call void @VDP_setAutoInc(i8 noundef zeroext 2) #2
  %4 = shl i16 %0, 1
  %5 = and i16 %4, 126
  %6 = zext nneg i16 %5 to i64
  %7 = shl nuw nsw i64 %6, 16
  %8 = or disjoint i64 %7, 32
  store volatile i64 %8, ptr inttoptr (i64 12582916 to ptr), align 8, !tbaa !5
  %.not39 = icmp ult i16 %2, 16
  br i1 %.not39, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %3
  %9 = lshr i16 %2, 4
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %.03541 = phi ptr [ %34, %.lr.ph ], [ %1, %.lr.ph.preheader ]
  %.03740 = phi i16 [ %10, %.lr.ph ], [ %9, %.lr.ph.preheader ]
  %10 = add nsw i16 %.03740, -1
  %11 = load volatile i64, ptr inttoptr (i64 12582912 to ptr), align 4194304, !tbaa !5
  %12 = and i64 %11, 250482414
  %13 = getelementptr inbounds i8, ptr %.03541, i64 8
  store i64 %12, ptr %.03541, 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 %.03541, i64 16
  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 %.03541, i64 24
  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 %.03541, i64 32
  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 %.03541, i64 40
  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 %.03541, i64 48
  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
  %31 = getelementptr inbounds i8, ptr %.03541, i64 56
  store i64 %30, ptr %28, align 8, !tbaa !5
  %32 = load volatile i64, ptr inttoptr (i64 12582912 to ptr), align 4194304, !tbaa !5
  %33 = and i64 %32, 250482414
  %34 = getelementptr inbounds i8, ptr %.03541, i64 64
  store i64 %33, ptr %31, align 8, !tbaa !5
  %.not = icmp eq i16 %10, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !9

._crit_edge:                                      ; preds = %.lr.ph, %3
  %.035.lcssa = phi ptr [ %1, %3 ], [ %34, %.lr.ph ]
  %35 = and i16 %2, 15
  %.not3842 = icmp eq i16 %35, 0
  br i1 %.not3842, label %._crit_edge47, label %.lr.ph46.preheader

.lr.ph46.preheader:                               ; preds = %._crit_edge
  %xtraiter = and i16 %2, 3
  %lcmp.mod.not = icmp eq i16 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.lr.ph46.prol.loopexit, label %.lr.ph46.prol

.lr.ph46.prol:                                    ; preds = %.lr.ph46.preheader, %.lr.ph46.prol
  %.044.prol = phi i16 [ %36, %.lr.ph46.prol ], [ %35, %.lr.ph46.preheader ]
  %.03643.prol = phi ptr [ %39, %.lr.ph46.prol ], [ %.035.lcssa, %.lr.ph46.preheader ]
  %prol.iter = phi i16 [ %prol.iter.next, %.lr.ph46.prol ], [ 0, %.lr.ph46.preheader ]
  %36 = add nsw i16 %.044.prol, -1
  %37 = load volatile i16, ptr inttoptr (i64 12582912 to ptr), align 4194304, !tbaa !11
  %38 = and i16 %37, 3822
  %39 = getelementptr inbounds i8, ptr %.03643.prol, i64 2
  store i16 %38, ptr %.03643.prol, align 2, !tbaa !11
  %prol.iter.next = add i16 %prol.iter, 1
  %prol.iter.cmp.not = icmp eq i16 %prol.iter.next, %xtraiter
  br i1 %prol.iter.cmp.not, label %.lr.ph46.prol.loopexit, label %.lr.ph46.prol, !llvm.loop !13

.lr.ph46.prol.loopexit:                           ; preds = %.lr.ph46.prol, %.lr.ph46.preheader
  %.044.unr = phi i16 [ %35, %.lr.ph46.preheader ], [ %36, %.lr.ph46.prol ]
  %.03643.unr = phi ptr [ %.035.lcssa, %.lr.ph46.preheader ], [ %39, %.lr.ph46.prol ]
  %40 = icmp ult i16 %35, 4
  br i1 %40, label %._crit_edge47, label %.lr.ph46

.lr.ph46:                                         ; preds = %.lr.ph46.prol.loopexit, %.lr.ph46
  %.044 = phi i16 [ %50, %.lr.ph46 ], [ %.044.unr, %.lr.ph46.prol.loopexit ]
  %.03643 = phi ptr [ %53, %.lr.ph46 ], [ %.03643.unr, %.lr.ph46.prol.loopexit ]
  %41 = load volatile i16, ptr inttoptr (i64 12582912 to ptr), align 4194304, !tbaa !11
  %42 = and i16 %41, 3822
  %43 = getelementptr inbounds i8, ptr %.03643, i64 2
  store i16 %42, ptr %.03643, align 2, !tbaa !11
  %44 = load volatile i16, ptr inttoptr (i64 12582912 to ptr), align 4194304, !tbaa !11
  %45 = and i16 %44, 3822
  %46 = getelementptr inbounds i8, ptr %.03643, i64 4
  store i16 %45, ptr %43, align 2, !tbaa !11
  %47 = load volatile i16, ptr inttoptr (i64 12582912 to ptr), align 4194304, !tbaa !11
  %48 = and i16 %47, 3822
  %49 = getelementptr inbounds i8, ptr %.03643, i64 6
  store i16 %48, ptr %46, align 2, !tbaa !11
  %50 = add nsw i16 %.044, -4
  %51 = load volatile i16, ptr inttoptr (i64 12582912 to ptr), align 4194304, !tbaa !11
  %52 = and i16 %51, 3822
  %53 = getelementptr inbounds i8, ptr %.03643, i64 8
  store i16 %52, ptr %49, align 2, !tbaa !11
  %.not38.3 = icmp eq i16 %50, 0
  br i1 %.not38.3, label %._crit_edge47, label %.lr.ph46, !llvm.loop !15

._crit_edge47:                                    ; preds = %.lr.ph46.prol.loopexit, %.lr.ph46, %._crit_edge
  ret void
}

declare void @VDP_setAutoInc(i8 noundef zeroext) 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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!12, !12, i64 0}
!12 = !{!"short", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.unroll.disable"}
!15 = distinct !{!15, !10}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass