; 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

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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @extended_pair_content(i32 noundef %0, ptr noundef %1, ptr noundef %2) #1 {
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  store i32 %0, ptr %5, align 4, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !9
  store ptr %2, ptr %7, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #2
  %10 = load ptr, ptr @SP, align 8, !tbaa !9
  %11 = getelementptr inbounds %struct.SCREEN, ptr %10, i32 0, i32 45
  %12 = load ptr, ptr %11, align 8, !tbaa !11
  %13 = getelementptr inbounds %struct._opaque_screen_t, ptr %12, i32 0, i32 0
  %14 = load ptr, ptr %13, align 8, !tbaa !17
  %15 = load i32, ptr %5, align 4, !tbaa !5
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds %struct._pdc_pair, ptr %14, i64 %16
  store ptr %17, ptr %8, align 8, !tbaa !9
  %18 = load i32, ptr %5, align 4, !tbaa !5
  %19 = icmp slt i32 %18, 0
  br i1 %19, label %30, label %20

20:                                               ; preds = %3
  %21 = load i32, ptr %5, align 4, !tbaa !5
  %22 = load i32, ptr @COLOR_PAIRS, align 4, !tbaa !5
  %23 = icmp sge i32 %21, %22
  br i1 %23, label %30, label %24

24:                                               ; preds = %20
  %25 = load ptr, ptr %6, align 8, !tbaa !9
  %26 = icmp ne ptr %25, null
  br i1 %26, label %27, label %30

27:                                               ; preds = %24
  %28 = load ptr, ptr %7, align 8, !tbaa !9
  %29 = icmp ne ptr %28, null
  br i1 %29, label %31, label %30

30:                                               ; preds = %27, %24, %20, %3
  store i32 -1, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %60

31:                                               ; preds = %27
  %32 = load i32, ptr %5, align 4, !tbaa !5
  %33 = load ptr, ptr @SP, align 8, !tbaa !9
  %34 = getelementptr inbounds %struct.SCREEN, ptr %33, i32 0, i32 45
  %35 = load ptr, ptr %34, align 8, !tbaa !11
  %36 = getelementptr inbounds %struct._opaque_screen_t, ptr %35, i32 0, i32 1
  %37 = load i32, ptr %36, align 8, !tbaa !19
  %38 = icmp sge i32 %32, %37
  br i1 %38, label %47, label %39

39:                                               ; preds = %31
  %40 = load i32, ptr %5, align 4, !tbaa !5
  %41 = icmp ne i32 %40, 0
  br i1 %41, label %42, label %50

42:                                               ; preds = %39
  %43 = load ptr, ptr %8, align 8, !tbaa !9
  %44 = getelementptr inbounds %struct._pdc_pair, ptr %43, i32 0, i32 0
  %45 = load i32, ptr %44, align 4, !tbaa !20
  %46 = icmp eq i32 %45, -2
  br i1 %46, label %47, label %50

47:                                               ; preds = %42, %31
  %48 = load ptr, ptr %6, align 8, !tbaa !9
  store i32 4, ptr %48, align 4, !tbaa !5
  %49 = load ptr, ptr %7, align 8, !tbaa !9
  store i32 1, ptr %49, align 4, !tbaa !5
  br label %59

50:                                               ; preds = %42, %39
  %51 = load ptr, ptr %8, align 8, !tbaa !9
  %52 = getelementptr inbounds %struct._pdc_pair, ptr %51, i32 0, i32 0
  %53 = load i32, ptr %52, align 4, !tbaa !20
  %54 = load ptr, ptr %6, align 8, !tbaa !9
  store i32 %53, ptr %54, align 4, !tbaa !5
  %55 = load ptr, ptr %8, align 8, !tbaa !9
  %56 = getelementptr inbounds %struct._pdc_pair, ptr %55, i32 0, i32 1
  %57 = load i32, ptr %56, align 4, !tbaa !22
  %58 = load ptr, ptr %7, align 8, !tbaa !9
  store i32 %57, ptr %58, align 4, !tbaa !5
  br label %59

59:                                               ; preds = %50, %47
  store i32 0, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %60

60:                                               ; preds = %59, %30
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #2
  %61 = load i32, ptr %4, align 4
  ret i32 %61
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 0}
!21 = !{!"_pdc_pair", !6, i64 0, !6, i64 4, !6, i64 8, !6, i64 12}
!22 = !{!21, !6, i64 4}


; 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

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(read, argmem: readwrite, inaccessiblemem: none) uwtable
define dso_local range(i32 -1, 1) i32 @extended_pair_content(i32 noundef %0, ptr noundef writeonly %1, ptr noundef writeonly %2) local_unnamed_addr #0 {
  %4 = load ptr, ptr @SP, align 8, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %4, i64 208
  %6 = load ptr, ptr %5, align 8, !tbaa !9
  %7 = load ptr, ptr %6, align 8, !tbaa !16
  %8 = sext i32 %0 to i64
  %9 = getelementptr inbounds %struct._pdc_pair, ptr %7, i64 %8
  %10 = icmp slt i32 %0, 0
  br i1 %10, label %26, label %11

11:                                               ; preds = %3
  %12 = load i32, ptr @COLOR_PAIRS, align 4, !tbaa !18
  %13 = icmp sgt i32 %12, %0
  %14 = icmp ne ptr %1, null
  %or.cond = and i1 %14, %13
  %15 = icmp ne ptr %2, null
  %or.cond3 = and i1 %15, %or.cond
  br i1 %or.cond3, label %16, label %26

16:                                               ; preds = %11
  %17 = getelementptr inbounds i8, ptr %6, i64 8
  %18 = load i32, ptr %17, align 8, !tbaa !19
  %.not = icmp sgt i32 %18, %0
  br i1 %.not, label %19, label %21

19:                                               ; preds = %16
  %.not20 = icmp ne i32 %0, 0
  %.pre = load i32, ptr %9, align 4, !tbaa !20
  %20 = icmp eq i32 %.pre, -2
  %or.cond21 = select i1 %.not20, i1 %20, i1 false
  br i1 %or.cond21, label %21, label %22

21:                                               ; preds = %19, %16
  store i32 4, ptr %1, align 4, !tbaa !18
  br label %25

22:                                               ; preds = %19
  store i32 %.pre, ptr %1, align 4, !tbaa !18
  %23 = getelementptr inbounds i8, ptr %9, i64 4
  %24 = load i32, ptr %23, align 4, !tbaa !22
  br label %25

25:                                               ; preds = %22, %21
  %storemerge = phi i32 [ %24, %22 ], [ 1, %21 ]
  store i32 %storemerge, ptr %2, align 4, !tbaa !18
  br label %26

26:                                               ; preds = %3, %11, %25
  %.0 = phi i32 [ 0, %25 ], [ -1, %11 ], [ -1, %3 ]
  ret i32 %.0
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(read, argmem: readwrite, inaccessiblemem: none) 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 = !{!"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 = !{!13, !13, i64 0}
!19 = !{!17, !13, i64 8}
!20 = !{!21, !13, i64 0}
!21 = !{!"_pdc_pair", !13, i64 0, !13, i64 4, !13, i64 8, !13, i64 12}
!22 = !{!21, !13, i64 4}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass