; 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
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [91 x i8], align 1
@curscr = external global ptr, align 8
@__PRETTY_FUNCTION__.init_extended_color = external hidden unnamed_addr constant [44 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
define dso_local i32 @init_extended_color(i32 noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3) #1 {
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  store i32 %0, ptr %6, align 4, !tbaa !5
  store i32 %1, ptr %7, align 4, !tbaa !5
  store i32 %2, ptr %8, align 4, !tbaa !5
  store i32 %3, ptr %9, align 4, !tbaa !5
  %10 = load ptr, ptr @SP, align 8, !tbaa !9
  %11 = icmp ne ptr %10, null
  br i1 %11, label %12, label %13

12:                                               ; preds = %4
  br label %14

13:                                               ; preds = %4
  call void @__assert_fail(ptr noundef @.str, ptr noundef @.str.1, i32 noundef 438, ptr noundef @__PRETTY_FUNCTION__.init_extended_color) #3
  unreachable

14:                                               ; preds = %12
  %15 = load ptr, ptr @SP, align 8, !tbaa !9
  %16 = icmp ne ptr %15, null
  br i1 %16, label %17, label %44

17:                                               ; preds = %14
  %18 = load i32, ptr %6, align 4, !tbaa !5
  %19 = icmp slt i32 %18, 0
  br i1 %19, label %44, label %20

20:                                               ; preds = %17
  %21 = load i32, ptr %6, align 4, !tbaa !5
  %22 = load i32, ptr @COLORS, align 4, !tbaa !5
  %23 = icmp sge i32 %21, %22
  br i1 %23, label %44, label %24

24:                                               ; preds = %20
  %25 = call zeroext i1 @PDC_can_change_color()
  br i1 %25, label %26, label %44

26:                                               ; preds = %24
  %27 = load i32, ptr %7, align 4, !tbaa !5
  %28 = icmp slt i32 %27, -1
  br i1 %28, label %44, label %29

29:                                               ; preds = %26
  %30 = load i32, ptr %7, align 4, !tbaa !5
  %31 = icmp sgt i32 %30, 1000
  br i1 %31, label %44, label %32

32:                                               ; preds = %29
  %33 = load i32, ptr %8, align 4, !tbaa !5
  %34 = icmp slt i32 %33, -1
  br i1 %34, label %44, label %35

35:                                               ; preds = %32
  %36 = load i32, ptr %8, align 4, !tbaa !5
  %37 = icmp sgt i32 %36, 1000
  br i1 %37, label %44, label %38

38:                                               ; preds = %35
  %39 = load i32, ptr %9, align 4, !tbaa !5
  %40 = icmp slt i32 %39, -1
  br i1 %40, label %44, label %41

41:                                               ; preds = %38
  %42 = load i32, ptr %9, align 4, !tbaa !5
  %43 = icmp sgt i32 %42, 1000
  br i1 %43, label %44, label %45

44:                                               ; preds = %41, %38, %35, %32, %29, %26, %24, %20, %17, %14
  store i32 -1, ptr %5, align 4
  br label %55

45:                                               ; preds = %41
  %46 = load ptr, ptr @SP, align 8, !tbaa !9
  %47 = getelementptr inbounds %struct.SCREEN, ptr %46, i32 0, i32 36
  store i8 1, ptr %47, align 1, !tbaa !11
  %48 = load ptr, ptr @curscr, align 8, !tbaa !9
  %49 = getelementptr inbounds %struct._win, ptr %48, i32 0, i32 9
  store i8 1, ptr %49, align 8, !tbaa !17
  %50 = load i32, ptr %6, align 4, !tbaa !5
  %51 = load i32, ptr %7, align 4, !tbaa !5
  %52 = load i32, ptr %8, align 4, !tbaa !5
  %53 = load i32, ptr %9, align 4, !tbaa !5
  %54 = call i32 @PDC_init_color(i32 noundef %50, i32 noundef %51, i32 noundef %52, i32 noundef %53)
  store i32 %54, ptr %5, align 4
  br label %55

55:                                               ; preds = %45, %44
  %56 = load i32, ptr %5, align 4
  ret i32 %56
}

declare zeroext i1 @PDC_can_change_color() #2

declare i32 @PDC_init_color(i32 noundef, i32 noundef, i32 noundef, i32 noundef) #2

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 = { "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 #3 = { 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 = !{!"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 161}
!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 = !{!18, !13, i64 48}
!18 = !{!"_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
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [91 x i8], align 1
@curscr = external local_unnamed_addr global ptr, align 8
@__PRETTY_FUNCTION__.init_extended_color = external hidden unnamed_addr constant [44 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
define dso_local i32 @init_extended_color(i32 noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3) local_unnamed_addr #1 {
  %5 = load ptr, ptr @SP, align 8, !tbaa !5
  %.not28 = icmp eq ptr %5, null
  br i1 %.not28, label %6, label %7

6:                                                ; preds = %4
  tail call void @__assert_fail(ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 438, ptr noundef nonnull @__PRETTY_FUNCTION__.init_extended_color) #3
  unreachable

7:                                                ; preds = %4
  %8 = icmp sgt i32 %0, -1
  %9 = load i32, ptr @COLORS, align 4
  %.not29 = icmp sgt i32 %9, %0
  %or.cond = select i1 %8, i1 %.not29, i1 false
  br i1 %or.cond, label %10, label %24

10:                                               ; preds = %7
  %11 = tail call zeroext i1 @PDC_can_change_color() #4
  %.not = xor i1 %11, true
  %12 = add i32 %1, -1001
  %13 = icmp ult i32 %12, -1002
  %or.cond5 = or i1 %13, %.not
  %14 = add i32 %2, -1001
  %15 = icmp ult i32 %14, -1002
  %or.cond9 = or i1 %15, %or.cond5
  %16 = add i32 %3, -1001
  %17 = icmp ult i32 %16, -1002
  %or.cond13 = or i1 %17, %or.cond9
  br i1 %or.cond13, label %24, label %18

18:                                               ; preds = %10
  %19 = load ptr, ptr @SP, align 8, !tbaa !5
  %20 = getelementptr inbounds i8, ptr %19, i64 161
  store i8 1, ptr %20, align 1, !tbaa !9
  %21 = load ptr, ptr @curscr, align 8, !tbaa !5
  %22 = getelementptr inbounds i8, ptr %21, i64 48
  store i8 1, ptr %22, align 8, !tbaa !16
  %23 = tail call i32 @PDC_init_color(i32 noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3) #4
  br label %24

24:                                               ; preds = %7, %10, %18
  %.0 = phi i32 [ %23, %18 ], [ -1, %10 ], [ -1, %7 ]
  ret i32 %.0
}

declare zeroext i1 @PDC_can_change_color() local_unnamed_addr #2

declare i32 @PDC_init_color(i32 noundef, i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #2

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


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