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

@COLORS = external dso_local global i32, align 4
@SP = external global ptr, align 8
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [91 x i8], align 1
@__PRETTY_FUNCTION__.PDC_set_line_color = external hidden unnamed_addr constant [30 x i8], align 1

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #0

; Function Attrs: nounwind uwtable
declare dso_local void @PDC_set_cells_to_refresh_for_attr_change(i64 noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @PDC_set_line_color(i16 noundef signext %0) #1 {
  %2 = alloca i32, align 4
  %3 = alloca i16, align 2
  store i16 %0, ptr %3, align 2, !tbaa !5
  %4 = load ptr, ptr @SP, align 8, !tbaa !9
  %5 = icmp ne ptr %4, null
  br i1 %5, label %6, label %7

6:                                                ; preds = %1
  br label %8

7:                                                ; preds = %1
  call void @__assert_fail(ptr noundef @.str, ptr noundef @.str.1, i32 noundef 532, ptr noundef @__PRETTY_FUNCTION__.PDC_set_line_color) #2
  unreachable

8:                                                ; preds = %6
  %9 = load ptr, ptr @SP, align 8, !tbaa !9
  %10 = icmp ne ptr %9, null
  br i1 %10, label %11, label %20

11:                                               ; preds = %8
  %12 = load i16, ptr %3, align 2, !tbaa !5
  %13 = sext i16 %12 to i32
  %14 = icmp slt i32 %13, -1
  br i1 %14, label %20, label %15

15:                                               ; preds = %11
  %16 = load i16, ptr %3, align 2, !tbaa !5
  %17 = sext i16 %16 to i32
  %18 = load i32, ptr @COLORS, align 4, !tbaa !11
  %19 = icmp sge i32 %17, %18
  br i1 %19, label %20, label %21

20:                                               ; preds = %15, %11, %8
  store i32 -1, ptr %2, align 4
  br label %34

21:                                               ; preds = %15
  %22 = load ptr, ptr @SP, align 8, !tbaa !9
  %23 = getelementptr inbounds %struct.SCREEN, ptr %22, i32 0, i32 31
  %24 = load i16, ptr %23, align 4, !tbaa !13
  %25 = sext i16 %24 to i32
  %26 = load i16, ptr %3, align 2, !tbaa !5
  %27 = sext i16 %26 to i32
  %28 = icmp ne i32 %25, %27
  br i1 %28, label %29, label %30

29:                                               ; preds = %21
  call void @PDC_set_cells_to_refresh_for_attr_change(i64 noundef 1656750080)
  br label %30

30:                                               ; preds = %29, %21
  %31 = load i16, ptr %3, align 2, !tbaa !5
  %32 = load ptr, ptr @SP, align 8, !tbaa !9
  %33 = getelementptr inbounds %struct.SCREEN, ptr %32, i32 0, i32 31
  store i16 %31, ptr %33, align 4, !tbaa !13
  store i32 0, ptr %2, align 4
  br label %34

34:                                               ; preds = %30, %20
  %35 = load i32, ptr %2, align 4
  ret i32 %35
}

attributes #0 = { noreturn nounwind "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 = { 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 = { noreturn 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 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !6, i64 132}
!14 = !{!"", !15, i64 0, !15, i64 1, !15, i64 2, !15, i64 3, !15, i64 4, !15, i64 5, !15, i64 6, !15, i64 7, !15, i64 8, !15, i64 9, !6, i64 10, !6, i64 12, !12, i64 16, !12, i64 20, !12, i64 24, !12, i64 28, !12, i64 32, !12, i64 36, !16, i64 40, !12, i64 48, !12, i64 52, !10, i64 56, !12, i64 64, !12, i64 68, !12, i64 72, !15, i64 76, !12, i64 80, !16, i64 88, !15, i64 96, !15, i64 97, !17, i64 100, !6, i64 132, !16, i64 136, !10, i64 144, !10, i64 152, !15, i64 160, !15, i64 161, !12, i64 164, !12, i64 168, !10, i64 176, !12, i64 184, !12, i64 188, !10, i64 192, !12, i64 200, !12, i64 204, !10, i64 208}
!15 = !{!"_Bool", !7, i64 0}
!16 = !{!"long", !7, i64 0}
!17 = !{!"", !12, i64 0, !12, i64 4, !7, i64 8, !12, i64 28}


; 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
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [91 x i8], align 1
@__PRETTY_FUNCTION__.PDC_set_line_color = external hidden unnamed_addr constant [30 x i8], align 1

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local void @PDC_set_cells_to_refresh_for_attr_change(i64 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local range(i32 -1, 1) i32 @PDC_set_line_color(i16 noundef signext %0) local_unnamed_addr #1 {
  %2 = load ptr, ptr @SP, align 8, !tbaa !5
  %.not = icmp eq ptr %2, null
  br i1 %.not, label %3, label %4

3:                                                ; preds = %1
  tail call void @__assert_fail(ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 532, ptr noundef nonnull @__PRETTY_FUNCTION__.PDC_set_line_color) #2
  unreachable

4:                                                ; preds = %1
  %5 = icmp slt i16 %0, -1
  br i1 %5, label %16, label %6

6:                                                ; preds = %4
  %7 = sext i16 %0 to i32
  %8 = load i32, ptr @COLORS, align 4, !tbaa !9
  %.not9 = icmp sgt i32 %8, %7
  br i1 %.not9, label %9, label %16

9:                                                ; preds = %6
  %10 = getelementptr inbounds i8, ptr %2, i64 132
  %11 = load i16, ptr %10, align 4, !tbaa !11
  %.not10 = icmp eq i16 %11, %0
  br i1 %.not10, label %13, label %12

12:                                               ; preds = %9
  tail call void @PDC_set_cells_to_refresh_for_attr_change(i64 noundef 1656750080)
  %.pre = load ptr, ptr @SP, align 8, !tbaa !5
  br label %13

13:                                               ; preds = %12, %9
  %14 = phi ptr [ %.pre, %12 ], [ %2, %9 ]
  %15 = getelementptr inbounds i8, ptr %14, i64 132
  store i16 %0, ptr %15, align 4, !tbaa !11
  br label %16

16:                                               ; preds = %4, %6, %13
  %.0 = phi i32 [ 0, %13 ], [ -1, %6 ], [ -1, %4 ]
  ret i32 %.0
}

attributes #0 = { noreturn nounwind "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 = { 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 = { noreturn 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, !14, i64 132}
!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, !10, i64 16, !10, i64 20, !10, i64 24, !10, i64 28, !10, i64 32, !10, i64 36, !15, i64 40, !10, i64 48, !10, i64 52, !6, i64 56, !10, i64 64, !10, i64 68, !10, i64 72, !13, i64 76, !10, i64 80, !15, i64 88, !13, i64 96, !13, i64 97, !16, i64 100, !14, i64 132, !15, i64 136, !6, i64 144, !6, i64 152, !13, i64 160, !13, i64 161, !10, i64 164, !10, i64 168, !6, i64 176, !10, i64 184, !10, i64 188, !6, i64 192, !10, i64 200, !10, i64 204, !6, i64 208}
!13 = !{!"_Bool", !7, i64 0}
!14 = !{!"short", !7, i64 0}
!15 = !{!"long", !7, i64 0}
!16 = !{!"", !10, i64 0, !10, i64 4, !7, i64 8, !10, i64 28}


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