; 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.20 = external hidden unnamed_addr constant [18 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_setVisibility(ptr noundef %0, i32 noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i16, align 2
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !9
  %6 = load ptr, ptr %3, align 8, !tbaa !5
  call void @checkSpriteValid(ptr noundef %6, ptr noundef @.str.20)
  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 0
  %9 = load i16, ptr %8, align 8, !tbaa !11
  store i16 %9, ptr %5, align 2, !tbaa !15
  %10 = load i16, ptr %5, align 2, !tbaa !15
  %11 = zext i16 %10 to i32
  %12 = and i32 %11, 512
  %13 = icmp ne i32 %12, 0
  br i1 %13, label %14, label %55

14:                                               ; preds = %2
  %15 = load i32, ptr %4, align 4, !tbaa !9
  switch i32 %15, label %54 [
    i32 0, label %16
    i32 1, label %22
    i32 2, label %28
    i32 3, label %39
  ]

16:                                               ; preds = %14
  %17 = load i16, ptr %5, align 2, !tbaa !15
  %18 = zext i16 %17 to i32
  %19 = and i32 %18, -770
  %20 = trunc i32 %19 to i16
  store i16 %20, ptr %5, align 2, !tbaa !15
  %21 = load ptr, ptr %3, align 8, !tbaa !5
  call void @setVisibility(ptr noundef %21, i16 noundef zeroext -1)
  br label %54

22:                                               ; preds = %14
  %23 = load i16, ptr %5, align 2, !tbaa !15
  %24 = zext i16 %23 to i32
  %25 = and i32 %24, -770
  %26 = trunc i32 %25 to i16
  store i16 %26, ptr %5, align 2, !tbaa !15
  %27 = load ptr, ptr %3, align 8, !tbaa !5
  call void @setVisibility(ptr noundef %27, i16 noundef zeroext 0)
  br label %54

28:                                               ; preds = %14
  %29 = load i16, ptr %5, align 2, !tbaa !15
  %30 = zext i16 %29 to i32
  %31 = and i32 %30, 256
  %32 = icmp ne i32 %31, 0
  br i1 %32, label %38, label %33

33:                                               ; preds = %28
  %34 = load i16, ptr %5, align 2, !tbaa !15
  %35 = zext i16 %34 to i32
  %36 = or i32 %35, 257
  %37 = trunc i32 %36 to i16
  store i16 %37, ptr %5, align 2, !tbaa !15
  br label %38

38:                                               ; preds = %33, %28
  br label %54

39:                                               ; preds = %14
  %40 = load i16, ptr %5, align 2, !tbaa !15
  %41 = zext i16 %40 to i32
  %42 = and i32 %41, 256
  %43 = icmp ne i32 %42, 0
  br i1 %43, label %44, label %53

44:                                               ; preds = %39
  %45 = load i16, ptr %5, align 2, !tbaa !15
  %46 = zext i16 %45 to i32
  %47 = and i32 %46, -257
  %48 = trunc i32 %47 to i16
  store i16 %48, ptr %5, align 2, !tbaa !15
  %49 = load i16, ptr %5, align 2, !tbaa !15
  %50 = zext i16 %49 to i32
  %51 = or i32 %50, 1
  %52 = trunc i32 %51 to i16
  store i16 %52, ptr %5, align 2, !tbaa !15
  br label %53

53:                                               ; preds = %44, %39
  br label %54

54:                                               ; preds = %53, %38, %22, %16, %14
  br label %72

55:                                               ; preds = %2
  %56 = load i32, ptr %4, align 4, !tbaa !9
  switch i32 %56, label %71 [
    i32 0, label %57
    i32 1, label %59
    i32 2, label %61
    i32 3, label %66
  ]

57:                                               ; preds = %55
  %58 = load ptr, ptr %3, align 8, !tbaa !5
  call void @setVisibility(ptr noundef %58, i16 noundef zeroext -1)
  br label %71

59:                                               ; preds = %55
  %60 = load ptr, ptr %3, align 8, !tbaa !5
  call void @setVisibility(ptr noundef %60, i16 noundef zeroext 0)
  br label %71

61:                                               ; preds = %55
  %62 = load i16, ptr %5, align 2, !tbaa !15
  %63 = zext i16 %62 to i32
  %64 = or i32 %63, 769
  %65 = trunc i32 %64 to i16
  store i16 %65, ptr %5, align 2, !tbaa !15
  br label %71

66:                                               ; preds = %55
  %67 = load i16, ptr %5, align 2, !tbaa !15
  %68 = zext i16 %67 to i32
  %69 = or i32 %68, 513
  %70 = trunc i32 %69 to i16
  store i16 %70, ptr %5, align 2, !tbaa !15
  br label %71

71:                                               ; preds = %66, %61, %59, %57, %55
  br label %72

72:                                               ; preds = %71, %54
  %73 = load i16, ptr %5, align 2, !tbaa !15
  %74 = load ptr, ptr %3, align 8, !tbaa !5
  %75 = getelementptr inbounds %struct.Sprite, ptr %74, i32 0, i32 0
  store i16 %73, ptr %75, align 8, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 2, ptr %5) #2
  ret void
}

; Function Attrs: nounwind uwtable
declare hidden void @setVisibility(ptr noundef, i16 noundef zeroext) #1

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

@.str.20 = external hidden unnamed_addr constant [18 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_setVisibility(ptr noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  tail call void @checkSpriteValid(ptr noundef %0, ptr noundef nonnull @.str.20)
  %3 = load i16, ptr %0, align 8, !tbaa !5
  %4 = zext i16 %3 to i32
  %5 = and i32 %4, 512
  %.not = icmp eq i32 %5, 0
  br i1 %.not, label %19, label %6

6:                                                ; preds = %2
  switch i32 %1, label %26 [
    i32 0, label %7
    i32 1, label %9
    i32 2, label %11
    i32 3, label %14
  ]

7:                                                ; preds = %6
  %8 = and i16 %3, -770
  tail call void @setVisibility(ptr noundef nonnull %0, i16 noundef zeroext -1)
  br label %26

9:                                                ; preds = %6
  %10 = and i16 %3, -770
  tail call void @setVisibility(ptr noundef nonnull %0, i16 noundef zeroext 0)
  br label %26

11:                                               ; preds = %6
  %12 = and i32 %4, 256
  %.not20 = icmp eq i32 %12, 0
  %13 = or i16 %3, 257
  %spec.select = select i1 %.not20, i16 %13, i16 %3
  br label %26

14:                                               ; preds = %6
  %15 = and i32 %4, 256
  %.not19 = icmp eq i32 %15, 0
  br i1 %.not19, label %26, label %16

16:                                               ; preds = %14
  %17 = and i16 %3, -258
  %18 = or disjoint i16 %17, 1
  br label %26

19:                                               ; preds = %2
  switch i32 %1, label %26 [
    i32 0, label %20
    i32 1, label %21
    i32 2, label %22
    i32 3, label %24
  ]

20:                                               ; preds = %19
  tail call void @setVisibility(ptr noundef nonnull %0, i16 noundef zeroext -1)
  br label %26

21:                                               ; preds = %19
  tail call void @setVisibility(ptr noundef nonnull %0, i16 noundef zeroext 0)
  br label %26

22:                                               ; preds = %19
  %23 = or i16 %3, 769
  br label %26

24:                                               ; preds = %19
  %25 = or i16 %3, 513
  br label %26

26:                                               ; preds = %11, %19, %20, %21, %22, %24, %6, %7, %9, %16, %14
  %.0 = phi i16 [ %3, %6 ], [ %18, %16 ], [ %3, %14 ], [ %10, %9 ], [ %8, %7 ], [ %3, %19 ], [ %25, %24 ], [ %23, %22 ], [ %3, %21 ], [ %3, %20 ], [ %spec.select, %11 ]
  store i16 %.0, ptr %0, align 8, !tbaa !5
  ret void
}

; Function Attrs: nounwind uwtable
declare hidden void @setVisibility(ptr noundef, i16 noundef zeroext) 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 0}
!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