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

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

@.str.4 = external hidden unnamed_addr constant [16 x i8], align 1

; 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
declare hidden void @checkSpriteValid(ptr noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local void @SPR_setPriority(ptr noundef %0, i8 noundef zeroext %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca i8, align 1
  %5 = alloca i16, align 2
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i8 %1, ptr %4, align 1, !tbaa !9
  %6 = load ptr, ptr %3, align 8, !tbaa !5
  call void @checkSpriteValid(ptr noundef %6, ptr noundef @.str.4)
  call void @llvm.lifetime.start.p0(i64 2, ptr %5) #2
  %7 = load ptr, ptr %3, align 8, !tbaa !5
  %8 = getelementptr inbounds %struct.Sprite, ptr %7, i32 0, i32 12
  %9 = load i16, ptr %8, align 4, !tbaa !10
  store i16 %9, ptr %5, align 2, !tbaa !14
  %10 = load i16, ptr %5, align 2, !tbaa !14
  %11 = zext i16 %10 to i32
  %12 = and i32 %11, 32768
  %13 = icmp ne i32 %12, 0
  br i1 %13, label %14, label %25

14:                                               ; preds = %2
  %15 = load i8, ptr %4, align 1, !tbaa !9
  %16 = icmp ne i8 %15, 0
  br i1 %16, label %24, label %17

17:                                               ; preds = %14
  %18 = load i16, ptr %5, align 2, !tbaa !14
  %19 = zext i16 %18 to i32
  %20 = and i32 %19, -32769
  %21 = trunc i32 %20 to i16
  %22 = load ptr, ptr %3, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.Sprite, ptr %22, i32 0, i32 12
  store i16 %21, ptr %23, align 4, !tbaa !10
  br label %24

24:                                               ; preds = %17, %14
  br label %36

25:                                               ; preds = %2
  %26 = load i8, ptr %4, align 1, !tbaa !9
  %27 = icmp ne i8 %26, 0
  br i1 %27, label %28, label %35

28:                                               ; preds = %25
  %29 = load i16, ptr %5, align 2, !tbaa !14
  %30 = zext i16 %29 to i32
  %31 = or i32 %30, 32768
  %32 = trunc i32 %31 to i16
  %33 = load ptr, ptr %3, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.Sprite, ptr %33, i32 0, i32 12
  store i16 %32, ptr %34, align 4, !tbaa !10
  br label %35

35:                                               ; preds = %28, %25
  br label %36

36:                                               ; preds = %35, %24
  call void @llvm.lifetime.end.p0(i64 2, ptr %5) #2
  ret void
}

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 = { 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 = !{!7, !7, i64 0}
!10 = !{!11, !12, i64 52}
!11 = !{!"Sprite", !12, i64 0, !12, i64 2, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !12, i64 40, !12, i64 42, !12, i64 44, !12, i64 46, !12, i64 48, !12, i64 50, !12, i64 52, !13, i64 56, !6, i64 64, !6, i64 72}
!12 = !{!"short", !7, i64 0}
!13 = !{!"long", !7, i64 0}
!14 = !{!12, !12, 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"

@.str.4 = external hidden unnamed_addr constant [16 x i8], align 1

; Function Attrs: nounwind uwtable
declare hidden void @checkSpriteValid(ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @SPR_setPriority(ptr noundef %0, i8 noundef zeroext %1) local_unnamed_addr #0 {
  tail call void @checkSpriteValid(ptr noundef %0, ptr noundef nonnull @.str.4)
  %3 = getelementptr inbounds i8, ptr %0, i64 52
  %4 = load i16, ptr %3, align 4, !tbaa !5
  %.not = icmp sgt i16 %4, -1
  %.not8 = icmp eq i8 %1, 0
  br i1 %.not, label %8, label %5

5:                                                ; preds = %2
  br i1 %.not8, label %6, label %11

6:                                                ; preds = %5
  %7 = and i16 %4, 32767
  br label %.sink.split

8:                                                ; preds = %2
  br i1 %.not8, label %11, label %9

9:                                                ; preds = %8
  %10 = or disjoint i16 %4, -32768
  br label %.sink.split

.sink.split:                                      ; preds = %6, %9
  %.sink = phi i16 [ %10, %9 ], [ %7, %6 ]
  store i16 %.sink, ptr %3, align 4, !tbaa !5
  br label %11

11:                                               ; preds = %.sink.split, %8, %5
  ret void
}

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

!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, !7, i64 52}
!6 = !{!"Sprite", !7, i64 0, !7, i64 2, !10, i64 8, !10, i64 16, !10, i64 24, !10, i64 32, !7, i64 40, !7, i64 42, !7, i64 44, !7, i64 46, !7, i64 48, !7, i64 50, !7, i64 52, !11, i64 56, !10, i64 64, !10, i64 72}
!7 = !{!"short", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!"long", !8, i64 0}


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