; LLVM IR from alekmaul/pvsneslib :: snes-examples/graphics/Effects/Window (Window)

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

@tablelefttriangle = external dso_local constant [68 x i8], align 16
@tablerighttriangle = external dso_local constant [68 x i8], align 16
@patternsbg1 = external global i8, align 1
@palettebg1 = external global i8, align 1
@patternsbg1_end = external global i8, align 1
@patternsbg2 = external global i8, align 1
@palettebg2 = external global i8, align 1
@patternsbg2_end = external global i8, align 1
@mapbg1 = external global i8, align 1
@mapbg1_end = external global i8, align 1
@mapbg2 = external global i8, align 1
@mapbg2_end = external global i8, align 1
@pad_keys = external global [5 x i16], align 2
@pad0 = external dso_local global i16, align 2
@pada = external dso_local global i8, align 1
@padx = external dso_local global i8, align 1
@padb = external dso_local global i8, align 1

; Function Attrs: nounwind uwtable
define dso_local i32 @main() #0 {
  %1 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  call void @bgInitTileSet(i8 noundef zeroext 0, ptr noundef @patternsbg1, ptr noundef @palettebg1, i8 noundef zeroext 0, i16 noundef zeroext trunc (i64 sub (i64 ptrtoint (ptr @patternsbg1_end to i64), i64 ptrtoint (ptr @patternsbg1 to i64)) to i16), i16 noundef zeroext 32, i16 noundef zeroext 16, i16 noundef zeroext 16384)
  call void @bgInitTileSet(i8 noundef zeroext 1, ptr noundef @patternsbg2, ptr noundef @palettebg2, i8 noundef zeroext 1, i16 noundef zeroext trunc (i64 sub (i64 ptrtoint (ptr @patternsbg2_end to i64), i64 ptrtoint (ptr @patternsbg2 to i64)) to i16), i16 noundef zeroext 32, i16 noundef zeroext 16, i16 noundef zeroext 24576)
  call void @bgInitMapSet(i8 noundef zeroext 0, ptr noundef @mapbg1, i16 noundef zeroext trunc (i64 sub (i64 ptrtoint (ptr @mapbg1_end to i64), i64 ptrtoint (ptr @mapbg1 to i64)) to i16), i8 noundef zeroext 0, i16 noundef zeroext 0)
  call void @bgInitMapSet(i8 noundef zeroext 1, ptr noundef @mapbg2, i16 noundef zeroext trunc (i64 sub (i64 ptrtoint (ptr @mapbg2_end to i64), i64 ptrtoint (ptr @mapbg2 to i64)) to i16), i8 noundef zeroext 0, i16 noundef zeroext 4096)
  call void @setMode(i8 noundef zeroext 1, i8 noundef zeroext 0)
  call void @bgSetEnable(i8 noundef zeroext 1)
  call void @bgSetDisable(i8 noundef zeroext 2)
  call void @setScreenOn()
  call void @setModeHdmaWindow(i8 noundef zeroext 3, i8 noundef zeroext 51, ptr noundef @tablelefttriangle, ptr noundef @tablerighttriangle)
  br label %2

2:                                                ; preds = %36, %0
  %3 = load i16, ptr @pad_keys, align 2, !tbaa !5
  store i16 %3, ptr @pad0, align 2, !tbaa !5
  %4 = load i16, ptr @pad0, align 2, !tbaa !5
  %5 = zext i16 %4 to i32
  %6 = and i32 %5, 128
  %7 = icmp ne i32 %6, 0
  br i1 %7, label %8, label %13

8:                                                ; preds = %2
  %9 = load i8, ptr @pada, align 1, !tbaa !9
  %10 = icmp ne i8 %9, 0
  br i1 %10, label %12, label %11

11:                                               ; preds = %8
  store i8 1, ptr @pada, align 1, !tbaa !9
  call void @setModeHdmaWindow(i8 noundef zeroext 1, i8 noundef zeroext 3, ptr noundef @tablelefttriangle, ptr noundef @tablerighttriangle)
  br label %12

12:                                               ; preds = %11, %8
  br label %14

13:                                               ; preds = %2
  store i8 0, ptr @pada, align 1, !tbaa !9
  br label %14

14:                                               ; preds = %13, %12
  %15 = load i16, ptr @pad0, align 2, !tbaa !5
  %16 = zext i16 %15 to i32
  %17 = and i32 %16, 64
  %18 = icmp ne i32 %17, 0
  br i1 %18, label %19, label %24

19:                                               ; preds = %14
  %20 = load i8, ptr @padx, align 1, !tbaa !9
  %21 = icmp ne i8 %20, 0
  br i1 %21, label %23, label %22

22:                                               ; preds = %19
  store i8 1, ptr @padx, align 1, !tbaa !9
  call void @setModeHdmaWindow(i8 noundef zeroext 2, i8 noundef zeroext 48, ptr noundef @tablelefttriangle, ptr noundef @tablerighttriangle)
  br label %23

23:                                               ; preds = %22, %19
  br label %25

24:                                               ; preds = %14
  store i8 0, ptr @padx, align 1, !tbaa !9
  br label %25

25:                                               ; preds = %24, %23
  %26 = load i16, ptr @pad0, align 2, !tbaa !5
  %27 = zext i16 %26 to i32
  %28 = and i32 %27, 32768
  %29 = icmp ne i32 %28, 0
  br i1 %29, label %30, label %35

30:                                               ; preds = %25
  %31 = load i8, ptr @padb, align 1, !tbaa !9
  %32 = icmp ne i8 %31, 0
  br i1 %32, label %34, label %33

33:                                               ; preds = %30
  store i8 1, ptr @padb, align 1, !tbaa !9
  call void @setModeHdmaWindow(i8 noundef zeroext 3, i8 noundef zeroext 51, ptr noundef @tablelefttriangle, ptr noundef @tablerighttriangle)
  br label %34

34:                                               ; preds = %33, %30
  br label %36

35:                                               ; preds = %25
  store i8 0, ptr @padb, align 1, !tbaa !9
  br label %36

36:                                               ; preds = %35, %34
  call void @WaitForVBlank()
  br label %2
}

declare void @bgInitTileSet(i8 noundef zeroext, ptr noundef, ptr noundef, i8 noundef zeroext, i16 noundef zeroext, i16 noundef zeroext, i16 noundef zeroext, i16 noundef zeroext) #1

declare void @bgInitMapSet(i8 noundef zeroext, ptr noundef, i16 noundef zeroext, i8 noundef zeroext, i16 noundef zeroext) #1

declare void @setMode(i8 noundef zeroext, i8 noundef zeroext) #1

declare void @bgSetEnable(i8 noundef zeroext) #1

declare void @bgSetDisable(i8 noundef zeroext) #1

declare void @setScreenOn() #1

declare void @setModeHdmaWindow(i8 noundef zeroext, i8 noundef zeroext, ptr noundef, ptr noundef) #1

declare void @WaitForVBlank() #1

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" }
attributes #1 = { "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"}
!9 = !{!7, !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"

@tablelefttriangle = external dso_local constant [68 x i8], align 16
@tablerighttriangle = external dso_local constant [68 x i8], align 16
@patternsbg1 = external global i8, align 1
@palettebg1 = external global i8, align 1
@patternsbg1_end = external global i8, align 1
@patternsbg2 = external global i8, align 1
@palettebg2 = external global i8, align 1
@patternsbg2_end = external global i8, align 1
@mapbg1 = external global i8, align 1
@mapbg1_end = external global i8, align 1
@mapbg2 = external global i8, align 1
@mapbg2_end = external global i8, align 1
@pad_keys = external local_unnamed_addr global [5 x i16], align 2
@pad0 = external dso_local local_unnamed_addr global i16, align 2
@pada = external dso_local local_unnamed_addr global i8, align 1
@padx = external dso_local local_unnamed_addr global i8, align 1
@padb = external dso_local local_unnamed_addr global i8, align 1

; Function Attrs: noreturn nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  tail call void @bgInitTileSet(i8 noundef zeroext 0, ptr noundef nonnull @patternsbg1, ptr noundef nonnull @palettebg1, i8 noundef zeroext 0, i16 noundef zeroext trunc (i64 sub (i64 ptrtoint (ptr @patternsbg1_end to i64), i64 ptrtoint (ptr @patternsbg1 to i64)) to i16), i16 noundef zeroext 32, i16 noundef zeroext 16, i16 noundef zeroext 16384) #2
  tail call void @bgInitTileSet(i8 noundef zeroext 1, ptr noundef nonnull @patternsbg2, ptr noundef nonnull @palettebg2, i8 noundef zeroext 1, i16 noundef zeroext trunc (i64 sub (i64 ptrtoint (ptr @patternsbg2_end to i64), i64 ptrtoint (ptr @patternsbg2 to i64)) to i16), i16 noundef zeroext 32, i16 noundef zeroext 16, i16 noundef zeroext 24576) #2
  tail call void @bgInitMapSet(i8 noundef zeroext 0, ptr noundef nonnull @mapbg1, i16 noundef zeroext trunc (i64 sub (i64 ptrtoint (ptr @mapbg1_end to i64), i64 ptrtoint (ptr @mapbg1 to i64)) to i16), i8 noundef zeroext 0, i16 noundef zeroext 0) #2
  tail call void @bgInitMapSet(i8 noundef zeroext 1, ptr noundef nonnull @mapbg2, i16 noundef zeroext trunc (i64 sub (i64 ptrtoint (ptr @mapbg2_end to i64), i64 ptrtoint (ptr @mapbg2 to i64)) to i16), i8 noundef zeroext 0, i16 noundef zeroext 4096) #2
  tail call void @setMode(i8 noundef zeroext 1, i8 noundef zeroext 0) #2
  tail call void @bgSetEnable(i8 noundef zeroext 1) #2
  tail call void @bgSetDisable(i8 noundef zeroext 2) #2
  tail call void @setScreenOn() #2
  tail call void @setModeHdmaWindow(i8 noundef zeroext 3, i8 noundef zeroext 51, ptr noundef nonnull @tablelefttriangle, ptr noundef nonnull @tablerighttriangle) #2
  br label %1

1:                                                ; preds = %20, %0
  %2 = load i16, ptr @pad_keys, align 2, !tbaa !5
  store i16 %2, ptr @pad0, align 2, !tbaa !5
  %3 = and i16 %2, 128
  %.not = icmp eq i16 %3, 0
  br i1 %.not, label %7, label %4

4:                                                ; preds = %1
  %5 = load i8, ptr @pada, align 1, !tbaa !9
  %.not1 = icmp eq i8 %5, 0
  br i1 %.not1, label %6, label %8

6:                                                ; preds = %4
  store i8 1, ptr @pada, align 1, !tbaa !9
  tail call void @setModeHdmaWindow(i8 noundef zeroext 1, i8 noundef zeroext 3, ptr noundef nonnull @tablelefttriangle, ptr noundef nonnull @tablerighttriangle) #2
  %.pre = load i16, ptr @pad0, align 2, !tbaa !5
  br label %8

7:                                                ; preds = %1
  store i8 0, ptr @pada, align 1, !tbaa !9
  br label %8

8:                                                ; preds = %4, %6, %7
  %9 = phi i16 [ %2, %4 ], [ %.pre, %6 ], [ %2, %7 ]
  %10 = and i16 %9, 64
  %.not2 = icmp eq i16 %10, 0
  br i1 %.not2, label %14, label %11

11:                                               ; preds = %8
  %12 = load i8, ptr @padx, align 1, !tbaa !9
  %.not3 = icmp eq i8 %12, 0
  br i1 %.not3, label %13, label %thread-pre-split

13:                                               ; preds = %11
  store i8 1, ptr @padx, align 1, !tbaa !9
  tail call void @setModeHdmaWindow(i8 noundef zeroext 2, i8 noundef zeroext 48, ptr noundef nonnull @tablelefttriangle, ptr noundef nonnull @tablerighttriangle) #2
  %.pr.pre = load i16, ptr @pad0, align 2, !tbaa !5
  br label %thread-pre-split

14:                                               ; preds = %8
  store i8 0, ptr @padx, align 1, !tbaa !9
  br label %thread-pre-split

thread-pre-split:                                 ; preds = %11, %13, %14
  %15 = phi i16 [ %9, %14 ], [ %.pr.pre, %13 ], [ %9, %11 ]
  %.not4 = icmp sgt i16 %15, -1
  br i1 %.not4, label %19, label %16

16:                                               ; preds = %thread-pre-split
  %17 = load i8, ptr @padb, align 1, !tbaa !9
  %.not5 = icmp eq i8 %17, 0
  br i1 %.not5, label %18, label %20

18:                                               ; preds = %16
  store i8 1, ptr @padb, align 1, !tbaa !9
  tail call void @setModeHdmaWindow(i8 noundef zeroext 3, i8 noundef zeroext 51, ptr noundef nonnull @tablelefttriangle, ptr noundef nonnull @tablerighttriangle) #2
  br label %20

19:                                               ; preds = %thread-pre-split
  store i8 0, ptr @padb, align 1, !tbaa !9
  br label %20

20:                                               ; preds = %16, %18, %19
  tail call void @WaitForVBlank() #2
  br label %1
}

declare void @bgInitTileSet(i8 noundef zeroext, ptr noundef, ptr noundef, i8 noundef zeroext, i16 noundef zeroext, i16 noundef zeroext, i16 noundef zeroext, i16 noundef zeroext) local_unnamed_addr #1

declare void @bgInitMapSet(i8 noundef zeroext, ptr noundef, i16 noundef zeroext, i8 noundef zeroext, i16 noundef zeroext) local_unnamed_addr #1

declare void @setMode(i8 noundef zeroext, i8 noundef zeroext) local_unnamed_addr #1

declare void @bgSetEnable(i8 noundef zeroext) local_unnamed_addr #1

declare void @bgSetDisable(i8 noundef zeroext) local_unnamed_addr #1

declare void @setScreenOn() local_unnamed_addr #1

declare void @setModeHdmaWindow(i8 noundef zeroext, i8 noundef zeroext, ptr noundef, ptr noundef) local_unnamed_addr #1

declare void @WaitForVBlank() local_unnamed_addr #1

attributes #0 = { noreturn 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 #1 = { "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 = !{!"short", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!7, !7, i64 0}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InstCombinePass,JumpThreadingPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass