; LLVM IR from clangen/musikcube :: src/3rdparty/win32_src/pdcurses (color)

; 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.SCREEN = type { i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i16, i16, i32, i32, i32, i32, i32, i32, i64, i32, i32, ptr, i32, i32, i32, i8, i32, i64, i8, i8, %struct.MOUSE_STATUS, i16, i64, ptr, ptr, i8, i8, i32, i32, ptr, i32, i32, ptr, i32, i32, ptr }
%struct.MOUSE_STATUS = type { i32, i32, [9 x i16], i32 }
%struct._win = type { i32, i32, i32, i32, i32, i32, i32, i64, i64, i8, i8, i8, i8, i8, i8, i8, ptr, ptr, ptr, i32, i32, i32, i32, i32, ptr, i32, i32, i32, i32, i32, i32 }

@COLORS = external dso_local global i32, align 4
@SP = external global ptr, align 8
@curscr = external global ptr, align 8

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

; Function Attrs: nounwind uwtable
define dso_local i32 @assume_default_colors(i32 noundef %0, i32 noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  store i32 %0, ptr %4, align 4, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !5
  %6 = load i32, ptr %4, align 4, !tbaa !5
  %7 = icmp slt i32 %6, -1
  br i1 %7, label %19, label %8

8:                                                ; preds = %2
  %9 = load i32, ptr %4, align 4, !tbaa !5
  %10 = load i32, ptr @COLORS, align 4, !tbaa !5
  %11 = icmp sge i32 %9, %10
  br i1 %11, label %19, label %12

12:                                               ; preds = %8
  %13 = load i32, ptr %5, align 4, !tbaa !5
  %14 = icmp slt i32 %13, -1
  br i1 %14, label %19, label %15

15:                                               ; preds = %12
  %16 = load i32, ptr %5, align 4, !tbaa !5
  %17 = load i32, ptr @COLORS, align 4, !tbaa !5
  %18 = icmp sge i32 %16, %17
  br i1 %18, label %19, label %20

19:                                               ; preds = %15, %12, %8, %2
  store i32 -1, ptr %3, align 4
  br label %31

20:                                               ; preds = %15
  %21 = load ptr, ptr @SP, align 8, !tbaa !9
  %22 = getelementptr inbounds %struct.SCREEN, ptr %21, i32 0, i32 35
  %23 = load i8, ptr %22, align 8, !tbaa !11, !range !17, !noundef !18
  %24 = trunc i8 %23 to i1
  br i1 %24, label %25, label %30

25:                                               ; preds = %20
  %26 = load i32, ptr %4, align 4, !tbaa !5
  %27 = load i32, ptr %5, align 4, !tbaa !5
  call void @_init_pair_core(i32 noundef 0, i32 noundef %26, i32 noundef %27)
  %28 = load ptr, ptr @curscr, align 8, !tbaa !9
  %29 = getelementptr inbounds %struct._win, ptr %28, i32 0, i32 9
  store i8 1, ptr %29, align 8, !tbaa !19
  br label %30

30:                                               ; preds = %25, %20
  store i32 0, ptr %3, align 4
  br label %31

31:                                               ; preds = %30, %19
  %32 = load i32, ptr %3, align 4
  ret i32 %32
}

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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !13, i64 160}
!12 = !{!"", !13, i64 0, !13, i64 1, !13, i64 2, !13, i64 3, !13, i64 4, !13, i64 5, !13, i64 6, !13, i64 7, !13, i64 8, !13, i64 9, !14, i64 10, !14, i64 12, !6, i64 16, !6, i64 20, !6, i64 24, !6, i64 28, !6, i64 32, !6, i64 36, !15, i64 40, !6, i64 48, !6, i64 52, !10, i64 56, !6, i64 64, !6, i64 68, !6, i64 72, !13, i64 76, !6, i64 80, !15, i64 88, !13, i64 96, !13, i64 97, !16, i64 100, !14, i64 132, !15, i64 136, !10, i64 144, !10, i64 152, !13, i64 160, !13, i64 161, !6, i64 164, !6, i64 168, !10, i64 176, !6, i64 184, !6, i64 188, !10, i64 192, !6, i64 200, !6, i64 204, !10, i64 208}
!13 = !{!"_Bool", !7, i64 0}
!14 = !{!"short", !7, i64 0}
!15 = !{!"long", !7, i64 0}
!16 = !{!"", !6, i64 0, !6, i64 4, !7, i64 8, !6, i64 28}
!17 = !{i8 0, i8 2}
!18 = !{}
!19 = !{!20, !13, i64 48}
!20 = !{!"_win", !6, i64 0, !6, i64 4, !6, i64 8, !6, i64 12, !6, i64 16, !6, i64 20, !6, i64 24, !15, i64 32, !15, i64 40, !13, i64 48, !13, i64 49, !13, i64 50, !13, i64 51, !13, i64 52, !13, i64 53, !13, i64 54, !10, i64 56, !10, i64 64, !10, i64 72, !6, i64 80, !6, i64 84, !6, i64 88, !6, i64 92, !6, i64 96, !10, i64 104, !6, i64 112, !6, i64 116, !6, i64 120, !6, i64 124, !6, i64 128, !6, i64 132}


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

@COLORS = external dso_local local_unnamed_addr global i32, align 4
@SP = external local_unnamed_addr global ptr, align 8
@curscr = external local_unnamed_addr global ptr, align 8

; Function Attrs: nounwind uwtable
declare hidden void @_init_pair_core(i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local range(i32 -1, 1) i32 @assume_default_colors(i32 noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = icmp slt i32 %0, -1
  br i1 %3, label %16, label %4

4:                                                ; preds = %2
  %5 = load i32, ptr @COLORS, align 4, !tbaa !5
  %6 = icmp sgt i32 %5, %0
  %7 = icmp sgt i32 %1, -2
  %or.cond.not14 = and i1 %7, %6
  %.not = icmp sgt i32 %5, %1
  %or.cond11 = and i1 %.not, %or.cond.not14
  br i1 %or.cond11, label %8, label %16

8:                                                ; preds = %4
  %9 = load ptr, ptr @SP, align 8, !tbaa !9
  %10 = getelementptr inbounds i8, ptr %9, i64 160
  %11 = load i8, ptr %10, align 8, !tbaa !11, !range !17, !noundef !18
  %12 = trunc nuw i8 %11 to i1
  br i1 %12, label %13, label %16

13:                                               ; preds = %8
  tail call void @_init_pair_core(i32 noundef 0, i32 noundef %0, i32 noundef %1)
  %14 = load ptr, ptr @curscr, align 8, !tbaa !9
  %15 = getelementptr inbounds i8, ptr %14, i64 48
  store i8 1, ptr %15, align 8, !tbaa !19
  br label %16

16:                                               ; preds = %8, %13, %2, %4
  %.0 = phi i32 [ -1, %4 ], [ -1, %2 ], [ 0, %13 ], [ 0, %8 ]
  ret i32 %.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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !13, i64 160}
!12 = !{!"", !13, i64 0, !13, i64 1, !13, i64 2, !13, i64 3, !13, i64 4, !13, i64 5, !13, i64 6, !13, i64 7, !13, i64 8, !13, i64 9, !14, i64 10, !14, i64 12, !6, i64 16, !6, i64 20, !6, i64 24, !6, i64 28, !6, i64 32, !6, i64 36, !15, i64 40, !6, i64 48, !6, i64 52, !10, i64 56, !6, i64 64, !6, i64 68, !6, i64 72, !13, i64 76, !6, i64 80, !15, i64 88, !13, i64 96, !13, i64 97, !16, i64 100, !14, i64 132, !15, i64 136, !10, i64 144, !10, i64 152, !13, i64 160, !13, i64 161, !6, i64 164, !6, i64 168, !10, i64 176, !6, i64 184, !6, i64 188, !10, i64 192, !6, i64 200, !6, i64 204, !10, i64 208}
!13 = !{!"_Bool", !7, i64 0}
!14 = !{!"short", !7, i64 0}
!15 = !{!"long", !7, i64 0}
!16 = !{!"", !6, i64 0, !6, i64 4, !7, i64 8, !6, i64 28}
!17 = !{i8 0, i8 2}
!18 = !{}
!19 = !{!20, !13, i64 48}
!20 = !{!"_win", !6, i64 0, !6, i64 4, !6, i64 8, !6, i64 12, !6, i64 16, !6, i64 20, !6, i64 24, !15, i64 32, !15, i64 40, !13, i64 48, !13, i64 49, !13, i64 50, !13, i64 51, !13, i64 52, !13, i64 53, !13, i64 54, !10, i64 56, !10, i64 64, !10, i64 72, !6, i64 80, !6, i64 84, !6, i64 88, !6, i64 92, !6, i64 96, !10, i64 104, !6, i64 112, !6, i64 116, !6, i64 120, !6, i64 124, !6, i64 128, !6, i64 132}


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