; 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.2 = external hidden unnamed_addr constant [13 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_setHFlip(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.2)
  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, 2048
  %13 = icmp ne i32 %12, 0
  br i1 %13, label %14, label %39

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

17:                                               ; preds = %14
  %18 = load i16, ptr %5, align 2, !tbaa !14
  %19 = zext i16 %18 to i32
  %20 = and i32 %19, -2049
  %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
  %24 = load ptr, ptr %3, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.Sprite, ptr %24, i32 0, i32 0
  %26 = load i16, ptr %25, align 8, !tbaa !15
  %27 = zext i16 %26 to i32
  %28 = and i32 %27, 512
  %29 = icmp ne i32 %28, 0
  br i1 %29, label %30, label %37

30:                                               ; preds = %17
  %31 = load ptr, ptr %3, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.Sprite, ptr %31, i32 0, i32 0
  %33 = load i16, ptr %32, align 8, !tbaa !15
  %34 = zext i16 %33 to i32
  %35 = or i32 %34, 1
  %36 = trunc i32 %35 to i16
  store i16 %36, ptr %32, align 8, !tbaa !15
  br label %37

37:                                               ; preds = %30, %17
  br label %38

38:                                               ; preds = %37, %14
  br label %64

39:                                               ; preds = %2
  %40 = load i8, ptr %4, align 1, !tbaa !9
  %41 = icmp ne i8 %40, 0
  br i1 %41, label %42, label %63

42:                                               ; preds = %39
  %43 = load i16, ptr %5, align 2, !tbaa !14
  %44 = zext i16 %43 to i32
  %45 = or i32 %44, 2048
  %46 = trunc i32 %45 to i16
  %47 = load ptr, ptr %3, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.Sprite, ptr %47, i32 0, i32 12
  store i16 %46, ptr %48, align 4, !tbaa !10
  %49 = load ptr, ptr %3, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.Sprite, ptr %49, i32 0, i32 0
  %51 = load i16, ptr %50, align 8, !tbaa !15
  %52 = zext i16 %51 to i32
  %53 = and i32 %52, 512
  %54 = icmp ne i32 %53, 0
  br i1 %54, label %55, label %62

55:                                               ; preds = %42
  %56 = load ptr, ptr %3, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.Sprite, ptr %56, i32 0, i32 0
  %58 = load i16, ptr %57, align 8, !tbaa !15
  %59 = zext i16 %58 to i32
  %60 = or i32 %59, 1
  %61 = trunc i32 %60 to i16
  store i16 %61, ptr %57, align 8, !tbaa !15
  br label %62

62:                                               ; preds = %55, %42
  br label %63

63:                                               ; preds = %62, %39
  br label %64

64:                                               ; preds = %63, %38
  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}
!15 = !{!11, !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.2 = 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_setHFlip(ptr noundef %0, i8 noundef zeroext %1) local_unnamed_addr #0 {
  tail call void @checkSpriteValid(ptr noundef %0, ptr noundef nonnull @.str.2)
  %3 = getelementptr inbounds i8, ptr %0, i64 52
  %4 = load i16, ptr %3, align 4, !tbaa !5
  %5 = and i16 %4, 2048
  %.not = icmp eq i16 %5, 0
  %.not12 = icmp eq i8 %1, 0
  br i1 %.not, label %11, label %6

6:                                                ; preds = %2
  br i1 %.not12, label %7, label %17

7:                                                ; preds = %6
  %8 = and i16 %4, -2049
  store i16 %8, ptr %3, align 4, !tbaa !5
  %9 = load i16, ptr %0, align 8, !tbaa !12
  %10 = and i16 %9, 512
  %.not15 = icmp eq i16 %10, 0
  br i1 %.not15, label %17, label %.sink.split

11:                                               ; preds = %2
  br i1 %.not12, label %17, label %12

12:                                               ; preds = %11
  %13 = or disjoint i16 %4, 2048
  store i16 %13, ptr %3, align 4, !tbaa !5
  %14 = load i16, ptr %0, align 8, !tbaa !12
  %15 = and i16 %14, 512
  %.not13 = icmp eq i16 %15, 0
  br i1 %.not13, label %17, label %.sink.split

.sink.split:                                      ; preds = %12, %7
  %.sink16 = phi i16 [ %9, %7 ], [ %14, %12 ]
  %16 = or i16 %.sink16, 1
  store i16 %16, ptr %0, align 8, !tbaa !12
  br label %17

17:                                               ; preds = %.sink.split, %11, %12, %6, %7
  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}
!12 = !{!6, !7, i64 0}


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