; 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._opaque_screen_t = type { ptr, i32, i32, i8, ptr, i32, i32, i32, ptr, i32, i8, ptr, ptr }
%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
@COLOR_PAIRS = 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__.start_color = external hidden unnamed_addr constant [22 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [20 x i8], align 1
@_default_foreground_idx = external hidden global i32, align 4
@_default_background_idx = external hidden global i32, align 4
@curscr = external global ptr, align 8

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

4:                                                ; preds = %0
  br label %6

5:                                                ; preds = %0
  call void @__assert_fail(ptr noundef @.str, ptr noundef @.str.1, i32 noundef 233, ptr noundef @__PRETTY_FUNCTION__.start_color) #4
  unreachable

6:                                                ; preds = %4
  %7 = load ptr, ptr @SP, align 8, !tbaa !5
  %8 = icmp ne ptr %7, null
  br i1 %8, label %9, label %14

9:                                                ; preds = %6
  %10 = load ptr, ptr @SP, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.SCREEN, ptr %10, i32 0, i32 7
  %12 = load i8, ptr %11, align 1, !tbaa !9, !range !16, !noundef !17
  %13 = trunc i8 %12 to i1
  br i1 %13, label %14, label %15

14:                                               ; preds = %9, %6
  store i32 -1, ptr %1, align 4
  br label %70

15:                                               ; preds = %9
  %16 = load ptr, ptr @SP, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.SCREEN, ptr %16, i32 0, i32 35
  store i8 1, ptr %17, align 8, !tbaa !18
  %18 = call i32 @PDC_set_blink(i1 noundef zeroext false)
  %19 = load ptr, ptr @SP, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.SCREEN, ptr %19, i32 0, i32 45
  %21 = load ptr, ptr %20, align 8, !tbaa !19
  %22 = getelementptr inbounds %struct._opaque_screen_t, ptr %21, i32 0, i32 3
  %23 = load i8, ptr %22, align 8, !tbaa !20, !range !16, !noundef !17
  %24 = trunc i8 %23 to i1
  br i1 %24, label %38, label %25

25:                                               ; preds = %15
  %26 = load ptr, ptr @SP, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.SCREEN, ptr %26, i32 0, i32 9
  %28 = load i8, ptr %27, align 1, !tbaa !22, !range !16, !noundef !17
  %29 = trunc i8 %28 to i1
  br i1 %29, label %30, label %38

30:                                               ; preds = %25
  %31 = call ptr @getenv(ptr noundef @.str.2) #5
  %32 = icmp ne ptr %31, null
  br i1 %32, label %33, label %38

33:                                               ; preds = %30
  %34 = load ptr, ptr @SP, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.SCREEN, ptr %34, i32 0, i32 45
  %36 = load ptr, ptr %35, align 8, !tbaa !19
  %37 = getelementptr inbounds %struct._opaque_screen_t, ptr %36, i32 0, i32 3
  store i8 1, ptr %37, align 8, !tbaa !20
  br label %38

38:                                               ; preds = %33, %30, %25, %15
  %39 = load i32, ptr @_default_foreground_idx, align 4, !tbaa !23
  %40 = load i32, ptr @_default_background_idx, align 4, !tbaa !23
  call void @_init_pair_core(i32 noundef 0, i32 noundef %39, i32 noundef %40)
  %41 = load ptr, ptr @SP, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.SCREEN, ptr %41, i32 0, i32 25
  %43 = load i8, ptr %42, align 4, !tbaa !24, !range !16, !noundef !17
  %44 = trunc i8 %43 to i1
  br i1 %44, label %48, label %45

45:                                               ; preds = %38
  %46 = load ptr, ptr @curscr, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct._win, ptr %46, i32 0, i32 9
  store i8 1, ptr %47, align 8, !tbaa !25
  br label %48

48:                                               ; preds = %45, %38
  %49 = load i32, ptr @COLORS, align 4, !tbaa !23
  %50 = icmp sge i32 %49, 1024
  br i1 %50, label %51, label %52

51:                                               ; preds = %48
  store i32 1048576, ptr @COLOR_PAIRS, align 4, !tbaa !23
  br label %69

52:                                               ; preds = %48
  %53 = load i32, ptr @COLORS, align 4, !tbaa !23
  %54 = icmp sge i32 %53, 16
  br i1 %54, label %55, label %68

55:                                               ; preds = %52
  %56 = load i32, ptr @COLORS, align 4, !tbaa !23
  %57 = sext i32 %56 to i64
  %58 = load i32, ptr @COLORS, align 4, !tbaa !23
  %59 = sext i32 %58 to i64
  %60 = mul nsw i64 %57, %59
  %61 = icmp slt i64 %60, 2147483647
  br i1 %61, label %62, label %66

62:                                               ; preds = %55
  %63 = load i32, ptr @COLORS, align 4, !tbaa !23
  %64 = load i32, ptr @COLORS, align 4, !tbaa !23
  %65 = mul nsw i32 %63, %64
  store i32 %65, ptr @COLOR_PAIRS, align 4, !tbaa !23
  br label %67

66:                                               ; preds = %55
  store i32 2147483647, ptr @COLOR_PAIRS, align 4, !tbaa !23
  br label %67

67:                                               ; preds = %66, %62
  br label %68

68:                                               ; preds = %67, %52
  br label %69

69:                                               ; preds = %68, %51
  store i32 0, ptr %1, align 4
  br label %70

70:                                               ; preds = %69, %14
  %71 = load i32, ptr %1, align 4
  ret i32 %71
}

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

declare i32 @PDC_set_blink(i1 noundef zeroext) #2

; Function Attrs: nounwind
declare ptr @getenv(ptr noundef) #3

; Function Attrs: nounwind uwtable
declare hidden void @_init_pair_core(i32 noundef, i32 noundef, i32 noundef) #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" }
attributes #1 = { 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 #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 = { 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 #4 = { noreturn nounwind }
attributes #5 = { 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 7}
!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 = !{i8 0, i8 2}
!17 = !{}
!18 = !{!10, !11, i64 160}
!19 = !{!10, !6, i64 208}
!20 = !{!21, !11, i64 16}
!21 = !{!"_opaque_screen_t", !6, i64 0, !13, i64 8, !13, i64 12, !11, i64 16, !6, i64 24, !13, i64 32, !13, i64 36, !13, i64 40, !6, i64 48, !13, i64 56, !11, i64 60, !6, i64 64, !6, i64 72}
!22 = !{!10, !11, i64 9}
!23 = !{!13, !13, i64 0}
!24 = !{!10, !11, i64 76}
!25 = !{!26, !11, i64 48}
!26 = !{!"_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}


; 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
@COLOR_PAIRS = 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__.start_color = external hidden unnamed_addr constant [22 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [20 x i8], align 1
@_default_foreground_idx = external hidden local_unnamed_addr global i32, align 4
@_default_background_idx = external hidden local_unnamed_addr global i32, align 4
@curscr = external local_unnamed_addr global ptr, align 8

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

2:                                                ; preds = %0
  tail call void @__assert_fail(ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 233, ptr noundef nonnull @__PRETTY_FUNCTION__.start_color) #4
  unreachable

3:                                                ; preds = %0
  %4 = getelementptr inbounds i8, ptr %1, i64 7
  %5 = load i8, ptr %4, align 1, !tbaa !9, !range !16, !noundef !17
  %6 = trunc nuw i8 %5 to i1
  br i1 %6, label %40, label %7

7:                                                ; preds = %3
  %8 = getelementptr inbounds i8, ptr %1, i64 160
  store i8 1, ptr %8, align 8, !tbaa !18
  %9 = tail call i32 @PDC_set_blink(i1 noundef zeroext false) #5
  %10 = load ptr, ptr @SP, align 8, !tbaa !5
  %11 = getelementptr inbounds i8, ptr %10, i64 208
  %12 = load ptr, ptr %11, align 8, !tbaa !19
  %13 = getelementptr inbounds i8, ptr %12, i64 16
  %14 = load i8, ptr %13, align 8, !tbaa !20, !range !16, !noundef !17
  %15 = trunc nuw i8 %14 to i1
  br i1 %15, label %23, label %16

16:                                               ; preds = %7
  %17 = getelementptr inbounds i8, ptr %10, i64 9
  %18 = load i8, ptr %17, align 1, !tbaa !22, !range !16, !noundef !17
  %19 = trunc nuw i8 %18 to i1
  br i1 %19, label %20, label %23

20:                                               ; preds = %16
  %21 = tail call ptr @getenv(ptr noundef nonnull @.str.2) #5
  %.not3 = icmp eq ptr %21, null
  br i1 %.not3, label %23, label %22

22:                                               ; preds = %20
  store i8 1, ptr %13, align 8, !tbaa !20
  br label %23

23:                                               ; preds = %22, %20, %16, %7
  %24 = load i32, ptr @_default_foreground_idx, align 4, !tbaa !23
  %25 = load i32, ptr @_default_background_idx, align 4, !tbaa !23
  tail call void @_init_pair_core(i32 noundef 0, i32 noundef %24, i32 noundef %25)
  %26 = load ptr, ptr @SP, align 8, !tbaa !5
  %27 = getelementptr inbounds i8, ptr %26, i64 76
  %28 = load i8, ptr %27, align 4, !tbaa !24, !range !16, !noundef !17
  %29 = trunc nuw i8 %28 to i1
  br i1 %29, label %33, label %30

30:                                               ; preds = %23
  %31 = load ptr, ptr @curscr, align 8, !tbaa !5
  %32 = getelementptr inbounds i8, ptr %31, i64 48
  store i8 1, ptr %32, align 8, !tbaa !25
  br label %33

33:                                               ; preds = %30, %23
  %34 = load i32, ptr @COLORS, align 4, !tbaa !23
  %35 = icmp sgt i32 %34, 1023
  br i1 %35, label %.sink.split, label %36

36:                                               ; preds = %33
  %37 = icmp sgt i32 %34, 15
  br i1 %37, label %38, label %40

38:                                               ; preds = %36
  %39 = mul nuw nsw i32 %34, %34
  br label %.sink.split

.sink.split:                                      ; preds = %33, %38
  %.sink = phi i32 [ %39, %38 ], [ 1048576, %33 ]
  store i32 %.sink, ptr @COLOR_PAIRS, align 4, !tbaa !23
  br label %40

40:                                               ; preds = %.sink.split, %36, %3
  %.0 = phi i32 [ -1, %3 ], [ 0, %36 ], [ 0, %.sink.split ]
  ret i32 %.0
}

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

declare i32 @PDC_set_blink(i1 noundef zeroext) local_unnamed_addr #2

; Function Attrs: nofree nounwind memory(read)
declare noundef ptr @getenv(ptr nocapture noundef) local_unnamed_addr #3

; Function Attrs: nounwind uwtable
declare hidden void @_init_pair_core(i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #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" }
attributes #1 = { 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 #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 = { nofree nounwind memory(read) "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 #4 = { noreturn nounwind }
attributes #5 = { 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 7}
!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 = !{i8 0, i8 2}
!17 = !{}
!18 = !{!10, !11, i64 160}
!19 = !{!10, !6, i64 208}
!20 = !{!21, !11, i64 16}
!21 = !{!"_opaque_screen_t", !6, i64 0, !13, i64 8, !13, i64 12, !11, i64 16, !6, i64 24, !13, i64 32, !13, i64 36, !13, i64 40, !6, i64 48, !13, i64 56, !11, i64 60, !6, i64 64, !6, i64 72}
!22 = !{!10, !11, i64 9}
!23 = !{!13, !13, i64 0}
!24 = !{!10, !11, i64 76}
!25 = !{!26, !11, i64 48}
!26 = !{!"_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,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,SROAPass,SimplifyCFGPass,TailCallElimPass