; 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._pdc_pair = type { i32, i32, i32, i32 }

@COLOR_PAIRS = external dso_local global i32, align 4
@SP = external global ptr, align 8
@.str.1 = external hidden unnamed_addr constant [91 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [5 x i8], align 1
@__PRETTY_FUNCTION__.alloc_pair = external hidden unnamed_addr constant [25 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [11 x i8], align 1

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

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nounwind uwtable
declare dso_local i32 @init_extended_pair(i32 noundef, i32 noundef, i32 noundef) #2

; Function Attrs: nounwind uwtable
declare dso_local i32 @find_pair(i32 noundef, i32 noundef) #2

; Function Attrs: nounwind uwtable
define dso_local i32 @alloc_pair(i32 noundef %0, i32 noundef %1) #2 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  store i32 %0, ptr %3, align 4, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  %7 = load i32, ptr %3, align 4, !tbaa !5
  %8 = load i32, ptr %4, align 4, !tbaa !5
  %9 = call i32 @find_pair(i32 noundef %7, i32 noundef %8)
  store i32 %9, ptr %5, align 4, !tbaa !5
  %10 = load i32, ptr %5, align 4, !tbaa !5
  %11 = icmp eq i32 -1, %10
  br i1 %11, label %12, label %54

12:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %13 = load ptr, ptr @SP, align 8, !tbaa !9
  %14 = getelementptr inbounds %struct.SCREEN, ptr %13, i32 0, i32 45
  %15 = load ptr, ptr %14, align 8, !tbaa !11
  %16 = getelementptr inbounds %struct._opaque_screen_t, ptr %15, i32 0, i32 0
  %17 = load ptr, ptr %16, align 8, !tbaa !17
  store ptr %17, ptr %6, align 8, !tbaa !9
  %18 = load ptr, ptr %6, align 8, !tbaa !9
  %19 = load ptr, ptr @SP, align 8, !tbaa !9
  %20 = getelementptr inbounds %struct.SCREEN, ptr %19, i32 0, i32 45
  %21 = load ptr, ptr %20, align 8, !tbaa !11
  %22 = getelementptr inbounds %struct._opaque_screen_t, ptr %21, i32 0, i32 1
  %23 = load i32, ptr %22, align 8, !tbaa !19
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds %struct._pdc_pair, ptr %18, i64 %24
  %26 = getelementptr inbounds %struct._pdc_pair, ptr %25, i32 0, i32 2
  %27 = load i32, ptr %26, align 4, !tbaa !20
  store i32 %27, ptr %5, align 4, !tbaa !5
  %28 = load i32, ptr %5, align 4, !tbaa !5
  %29 = icmp ne i32 %28, 0
  br i1 %29, label %30, label %31

30:                                               ; preds = %12
  br label %32

31:                                               ; preds = %12
  call void @__assert_fail(ptr noundef @.str.9, ptr noundef @.str.1, i32 noundef 669, ptr noundef @__PRETTY_FUNCTION__.alloc_pair) #4
  unreachable

32:                                               ; preds = %30
  %33 = load i32, ptr @COLOR_PAIRS, align 4, !tbaa !5
  %34 = load i32, ptr %5, align 4, !tbaa !5
  %35 = icmp eq i32 %33, %34
  br i1 %35, label %36, label %41

36:                                               ; preds = %32
  %37 = load ptr, ptr %6, align 8, !tbaa !9
  %38 = getelementptr inbounds %struct._pdc_pair, ptr %37, i64 0
  %39 = getelementptr inbounds %struct._pdc_pair, ptr %38, i32 0, i32 2
  %40 = load i32, ptr %39, align 4, !tbaa !20
  store i32 %40, ptr %5, align 4, !tbaa !5
  br label %41

41:                                               ; preds = %36, %32
  %42 = load i32, ptr %5, align 4, !tbaa !5
  %43 = load i32, ptr %3, align 4, !tbaa !5
  %44 = load i32, ptr %4, align 4, !tbaa !5
  %45 = call i32 @init_extended_pair(i32 noundef %42, i32 noundef %43, i32 noundef %44)
  %46 = icmp eq i32 -1, %45
  br i1 %46, label %47, label %48

47:                                               ; preds = %41
  store i32 -1, ptr %5, align 4, !tbaa !5
  br label %48

48:                                               ; preds = %47, %41
  %49 = load i32, ptr %5, align 4, !tbaa !5
  %50 = icmp ne i32 %49, -1
  br i1 %50, label %51, label %52

51:                                               ; preds = %48
  br label %53

52:                                               ; preds = %48
  call void @__assert_fail(ptr noundef @.str.10, ptr noundef @.str.1, i32 noundef 674, ptr noundef @__PRETTY_FUNCTION__.alloc_pair) #4
  unreachable

53:                                               ; preds = %51
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  br label %54

54:                                               ; preds = %53, %2
  %55 = load i32, ptr %5, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  ret i32 %55
}

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #3 = { nounwind }
attributes #4 = { 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, !10, i64 208}
!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, !10, i64 0}
!18 = !{!"_opaque_screen_t", !10, i64 0, !6, i64 8, !6, i64 12, !13, i64 16, !10, i64 24, !6, i64 32, !6, i64 36, !6, i64 40, !10, i64 48, !6, i64 56, !13, i64 60, !10, i64 64, !10, i64 72}
!19 = !{!18, !6, i64 8}
!20 = !{!21, !6, i64 8}
!21 = !{!"_pdc_pair", !6, i64 0, !6, i64 4, !6, i64 8, !6, i64 12}


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

%struct._pdc_pair = type { i32, i32, i32, i32 }

@COLOR_PAIRS = external dso_local local_unnamed_addr global i32, align 4
@SP = external local_unnamed_addr global ptr, align 8
@.str.1 = external hidden unnamed_addr constant [91 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [5 x i8], align 1
@__PRETTY_FUNCTION__.alloc_pair = external hidden unnamed_addr constant [25 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [11 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 i32 @init_extended_pair(i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local i32 @find_pair(i32 noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, -1) i32 @alloc_pair(i32 noundef %0, i32 noundef %1) local_unnamed_addr #1 {
  %3 = tail call i32 @find_pair(i32 noundef %0, i32 noundef %1)
  %4 = icmp eq i32 %3, -1
  br i1 %4, label %5, label %26

5:                                                ; preds = %2
  %6 = load ptr, ptr @SP, align 8, !tbaa !5
  %7 = getelementptr inbounds i8, ptr %6, i64 208
  %8 = load ptr, ptr %7, align 8, !tbaa !9
  %9 = load ptr, ptr %8, align 8, !tbaa !16
  %10 = getelementptr inbounds i8, ptr %8, i64 8
  %11 = load i32, ptr %10, align 8, !tbaa !18
  %12 = sext i32 %11 to i64
  %13 = getelementptr inbounds %struct._pdc_pair, ptr %9, i64 %12, i32 2
  %14 = load i32, ptr %13, align 4, !tbaa !19
  %.not = icmp eq i32 %14, 0
  br i1 %.not, label %15, label %16

15:                                               ; preds = %5
  tail call void @__assert_fail(ptr noundef nonnull @.str.9, ptr noundef nonnull @.str.1, i32 noundef 669, ptr noundef nonnull @__PRETTY_FUNCTION__.alloc_pair) #2
  unreachable

16:                                               ; preds = %5
  %17 = load i32, ptr @COLOR_PAIRS, align 4, !tbaa !21
  %18 = icmp eq i32 %17, %14
  br i1 %18, label %19, label %22

19:                                               ; preds = %16
  %20 = getelementptr inbounds i8, ptr %9, i64 8
  %21 = load i32, ptr %20, align 4, !tbaa !19
  br label %22

22:                                               ; preds = %19, %16
  %.0 = phi i32 [ %21, %19 ], [ %14, %16 ]
  %23 = tail call i32 @init_extended_pair(i32 noundef %.0, i32 noundef %0, i32 noundef %1)
  %24 = icmp eq i32 %23, -1
  %.not1314 = icmp eq i32 %.0, -1
  %.not13 = or i1 %.not1314, %24
  br i1 %.not13, label %25, label %26

25:                                               ; preds = %22
  tail call void @__assert_fail(ptr noundef nonnull @.str.10, ptr noundef nonnull @.str.1, i32 noundef 674, ptr noundef nonnull @__PRETTY_FUNCTION__.alloc_pair) #2
  unreachable

26:                                               ; preds = %22, %2
  %.2 = phi i32 [ %3, %2 ], [ %.0, %22 ]
  ret i32 %.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 = { 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, !6, i64 208}
!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, !6, i64 0}
!17 = !{!"_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}
!18 = !{!17, !13, i64 8}
!19 = !{!20, !13, i64 8}
!20 = !{!"_pdc_pair", !13, i64 0, !13, i64 4, !13, i64 8, !13, i64 12}
!21 = !{!13, !13, i64 0}


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