; 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.6 = external hidden unnamed_addr constant [13 x i8], align 1

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

; Function Attrs: nounwind uwtable
define dso_local void @SPR_setDepth(ptr noundef %0, i16 noundef signext %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca i16, align 2
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i16 %1, ptr %4, align 2, !tbaa !9
  %5 = load ptr, ptr %3, align 8, !tbaa !5
  call void @checkSpriteValid(ptr noundef %5, ptr noundef @.str.6)
  %6 = load ptr, ptr %3, align 8, !tbaa !5
  %7 = getelementptr inbounds %struct.Sprite, ptr %6, i32 0, i32 11
  %8 = load i16, ptr %7, align 2, !tbaa !11
  %9 = sext i16 %8 to i32
  %10 = load i16, ptr %4, align 2, !tbaa !9
  %11 = sext i16 %10 to i32
  %12 = icmp ne i32 %9, %11
  br i1 %12, label %13, label %19

13:                                               ; preds = %2
  %14 = load i16, ptr %4, align 2, !tbaa !9
  %15 = load ptr, ptr %3, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.Sprite, ptr %15, i32 0, i32 11
  store i16 %14, ptr %16, align 2, !tbaa !11
  %17 = load ptr, ptr %3, align 8, !tbaa !5
  %18 = call ptr @sortSprite(ptr noundef %17)
  br label %19

19:                                               ; preds = %13, %2
  ret void
}

; Function Attrs: nounwind uwtable
declare hidden ptr @sortSprite(ptr noundef) #0

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

@.str.6 = external hidden unnamed_addr constant [13 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_setDepth(ptr noundef %0, i16 noundef signext %1) local_unnamed_addr #0 {
  tail call void @checkSpriteValid(ptr noundef %0, ptr noundef nonnull @.str.6)
  %3 = getelementptr inbounds i8, ptr %0, i64 50
  %4 = load i16, ptr %3, align 2, !tbaa !5
  %.not = icmp eq i16 %4, %1
  br i1 %.not, label %7, label %5

5:                                                ; preds = %2
  store i16 %1, ptr %3, align 2, !tbaa !5
  %6 = tail call ptr @sortSprite(ptr noundef nonnull %0)
  br label %7

7:                                                ; preds = %5, %2
  ret void
}

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

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 50}
!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: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,InstCombinePass,SROAPass,TailCallElimPass