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

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

@flag = external hidden global i16, align 2
@VBlankProcess = external global i16, align 2

; Function Attrs: nounwind uwtable
define dso_local void @DMA_setAutoFlush(i8 noundef zeroext %0) #0 {
  %2 = alloca i8, align 1
  store i8 %0, ptr %2, align 1, !tbaa !5
  %3 = load i8, ptr %2, align 1, !tbaa !5
  %4 = icmp ne i8 %3, 0
  br i1 %4, label %5, label %14

5:                                                ; preds = %1
  %6 = load i16, ptr @flag, align 2, !tbaa !8
  %7 = zext i16 %6 to i32
  %8 = or i32 %7, 1
  %9 = trunc i32 %8 to i16
  store i16 %9, ptr @flag, align 2, !tbaa !8
  %10 = load volatile i16, ptr @VBlankProcess, align 2, !tbaa !8
  %11 = zext i16 %10 to i32
  %12 = or i32 %11, 4
  %13 = trunc i32 %12 to i16
  store volatile i16 %13, ptr @VBlankProcess, align 2, !tbaa !8
  br label %23

14:                                               ; preds = %1
  %15 = load i16, ptr @flag, align 2, !tbaa !8
  %16 = zext i16 %15 to i32
  %17 = and i32 %16, -2
  %18 = trunc i32 %17 to i16
  store i16 %18, ptr @flag, align 2, !tbaa !8
  %19 = load volatile i16, ptr @VBlankProcess, align 2, !tbaa !8
  %20 = zext i16 %19 to i32
  %21 = and i32 %20, -5
  %22 = trunc i32 %21 to i16
  store volatile i16 %22, ptr @VBlankProcess, align 2, !tbaa !8
  br label %23

23:                                               ; preds = %14, %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, !6, i64 0}
!6 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = !{!9, !9, i64 0}
!9 = !{!"short", !6, 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"

@flag = external hidden local_unnamed_addr global i16, align 2
@VBlankProcess = external global i16, align 2

; Function Attrs: nofree norecurse nounwind memory(readwrite, argmem: none) uwtable
define dso_local void @DMA_setAutoFlush(i8 noundef zeroext %0) local_unnamed_addr #0 {
  %.not = icmp ne i8 %0, 0
  %2 = load i16, ptr @flag, align 2, !tbaa !5
  %3 = load volatile i16, ptr @VBlankProcess, align 2, !tbaa !5
  %4 = and i16 %2, -2
  %5 = and i16 %3, -5
  %masksel = select i1 %.not, i16 4, i16 0
  %.sink1 = or disjoint i16 %5, %masksel
  %masksel2 = zext i1 %.not to i16
  %.sink = or disjoint i16 %4, %masksel2
  store volatile i16 %.sink1, ptr @VBlankProcess, align 2, !tbaa !5
  store i16 %.sink, ptr @flag, align 2
  ret void
}

attributes #0 = { nofree norecurse nounwind memory(readwrite, argmem: none) 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 = !{!"short", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}


; Effective O3 passes: GlobalOptPass,IPSCCPPass,InstCombinePass,MergedLoadStoreMotionPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass