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

@SP = external global ptr, align 8
@.str.1 = external hidden unnamed_addr constant [91 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [38 x i8], align 1
@__PRETTY_FUNCTION__.free_pair = external hidden unnamed_addr constant [19 x i8], align 1
@.str.12 = external hidden unnamed_addr constant [48 x i8], align 1
@.str.13 = external hidden unnamed_addr constant [25 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 hidden void @_init_pair_core(i32 noundef, i32 noundef, i32 noundef) #1

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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @free_pair(i32 noundef %0) #1 {
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  store i32 %0, ptr %3, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  %6 = load ptr, ptr @SP, align 8, !tbaa !9
  %7 = icmp ne ptr %6, null
  br i1 %7, label %8, label %21

8:                                                ; preds = %1
  %9 = load ptr, ptr @SP, align 8, !tbaa !9
  %10 = getelementptr inbounds %struct.SCREEN, ptr %9, i32 0, i32 45
  %11 = load ptr, ptr %10, align 8, !tbaa !11
  %12 = icmp ne ptr %11, null
  br i1 %12, label %13, label %21

13:                                               ; preds = %8
  %14 = load ptr, ptr @SP, align 8, !tbaa !9
  %15 = getelementptr inbounds %struct.SCREEN, ptr %14, i32 0, i32 45
  %16 = load ptr, ptr %15, align 8, !tbaa !11
  %17 = getelementptr inbounds %struct._opaque_screen_t, ptr %16, i32 0, i32 0
  %18 = load ptr, ptr %17, align 8, !tbaa !17
  %19 = icmp ne ptr %18, null
  br i1 %19, label %20, label %21

20:                                               ; preds = %13
  br label %22

21:                                               ; preds = %13, %8, %1
  call void @__assert_fail(ptr noundef @.str.11, ptr noundef @.str.1, i32 noundef 683, ptr noundef @__PRETTY_FUNCTION__.free_pair) #4
  unreachable

22:                                               ; preds = %20
  %23 = load i32, ptr %3, align 4, !tbaa !5
  %24 = icmp sge i32 %23, 1
  br i1 %24, label %25, label %34

25:                                               ; preds = %22
  %26 = load i32, ptr %3, align 4, !tbaa !5
  %27 = load ptr, ptr @SP, align 8, !tbaa !9
  %28 = getelementptr inbounds %struct.SCREEN, ptr %27, i32 0, i32 45
  %29 = load ptr, ptr %28, align 8, !tbaa !11
  %30 = getelementptr inbounds %struct._opaque_screen_t, ptr %29, i32 0, i32 1
  %31 = load i32, ptr %30, align 8, !tbaa !19
  %32 = icmp slt i32 %26, %31
  br i1 %32, label %33, label %34

33:                                               ; preds = %25
  br label %35

34:                                               ; preds = %25, %22
  call void @__assert_fail(ptr noundef @.str.12, ptr noundef @.str.1, i32 noundef 684, ptr noundef @__PRETTY_FUNCTION__.free_pair) #4
  unreachable

35:                                               ; preds = %33
  %36 = load ptr, ptr @SP, align 8, !tbaa !9
  %37 = getelementptr inbounds %struct.SCREEN, ptr %36, i32 0, i32 45
  %38 = load ptr, ptr %37, align 8, !tbaa !11
  %39 = getelementptr inbounds %struct._opaque_screen_t, ptr %38, i32 0, i32 0
  %40 = load ptr, ptr %39, align 8, !tbaa !17
  %41 = load i32, ptr %3, align 4, !tbaa !5
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds %struct._pdc_pair, ptr %40, i64 %42
  store ptr %43, ptr %4, align 8, !tbaa !9
  %44 = load ptr, ptr %4, align 8, !tbaa !9
  %45 = getelementptr inbounds %struct._pdc_pair, ptr %44, i32 0, i32 0
  %46 = load i32, ptr %45, align 4, !tbaa !20
  %47 = icmp ne i32 %46, -2
  br i1 %47, label %48, label %49

48:                                               ; preds = %35
  br label %50

49:                                               ; preds = %35
  call void @__assert_fail(ptr noundef @.str.13, ptr noundef @.str.1, i32 noundef 686, ptr noundef @__PRETTY_FUNCTION__.free_pair) #4
  unreachable

50:                                               ; preds = %48
  %51 = load ptr, ptr @SP, align 8, !tbaa !9
  %52 = icmp ne ptr %51, null
  br i1 %52, label %53, label %74

53:                                               ; preds = %50
  %54 = load ptr, ptr @SP, align 8, !tbaa !9
  %55 = getelementptr inbounds %struct.SCREEN, ptr %54, i32 0, i32 35
  %56 = load i8, ptr %55, align 8, !tbaa !22, !range !23, !noundef !24
  %57 = trunc i8 %56 to i1
  br i1 %57, label %58, label %74

58:                                               ; preds = %53
  %59 = load i32, ptr %3, align 4, !tbaa !5
  %60 = icmp slt i32 %59, 1
  br i1 %60, label %74, label %61

61:                                               ; preds = %58
  %62 = load i32, ptr %3, align 4, !tbaa !5
  %63 = load ptr, ptr @SP, align 8, !tbaa !9
  %64 = getelementptr inbounds %struct.SCREEN, ptr %63, i32 0, i32 45
  %65 = load ptr, ptr %64, align 8, !tbaa !11
  %66 = getelementptr inbounds %struct._opaque_screen_t, ptr %65, i32 0, i32 1
  %67 = load i32, ptr %66, align 8, !tbaa !19
  %68 = icmp sge i32 %62, %67
  br i1 %68, label %74, label %69

69:                                               ; preds = %61
  %70 = load ptr, ptr %4, align 8, !tbaa !9
  %71 = getelementptr inbounds %struct._pdc_pair, ptr %70, i32 0, i32 0
  %72 = load i32, ptr %71, align 4, !tbaa !20
  %73 = icmp eq i32 %72, -2
  br i1 %73, label %74, label %75

74:                                               ; preds = %69, %61, %58, %53, %50
  store i32 -1, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %77

75:                                               ; preds = %69
  %76 = load i32, ptr %3, align 4, !tbaa !5
  call void @_init_pair_core(i32 noundef %76, i32 noundef -2, i32 noundef 0)
  store i32 0, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %77

77:                                               ; preds = %75, %74
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  %78 = load i32, ptr %2, align 4
  ret i32 %78
}

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


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

@SP = external local_unnamed_addr global ptr, align 8
@.str.1 = external hidden unnamed_addr constant [91 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [38 x i8], align 1
@__PRETTY_FUNCTION__.free_pair = external hidden unnamed_addr constant [19 x i8], align 1
@.str.12 = external hidden unnamed_addr constant [48 x i8], align 1
@.str.13 = external hidden unnamed_addr constant [25 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 hidden void @_init_pair_core(i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #1

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

3:                                                ; preds = %1
  %4 = getelementptr inbounds i8, ptr %2, i64 208
  %5 = load ptr, ptr %4, align 8, !tbaa !9
  %.not16 = icmp eq ptr %5, null
  br i1 %.not16, label %8, label %6

6:                                                ; preds = %3
  %7 = load ptr, ptr %5, align 8, !tbaa !16
  %.not17 = icmp eq ptr %7, null
  br i1 %.not17, label %8, label %9

8:                                                ; preds = %6, %3, %1
  tail call void @__assert_fail(ptr noundef nonnull @.str.11, ptr noundef nonnull @.str.1, i32 noundef 683, ptr noundef nonnull @__PRETTY_FUNCTION__.free_pair) #2
  unreachable

9:                                                ; preds = %6
  %10 = icmp sgt i32 %0, 0
  br i1 %10, label %11, label %15

11:                                               ; preds = %9
  %12 = getelementptr inbounds i8, ptr %5, i64 8
  %13 = load i32, ptr %12, align 8, !tbaa !18
  %14 = icmp sgt i32 %13, %0
  br i1 %14, label %16, label %15

15:                                               ; preds = %11, %9
  tail call void @__assert_fail(ptr noundef nonnull @.str.12, ptr noundef nonnull @.str.1, i32 noundef 684, ptr noundef nonnull @__PRETTY_FUNCTION__.free_pair) #2
  unreachable

16:                                               ; preds = %11
  %17 = zext nneg i32 %0 to i64
  %18 = getelementptr inbounds %struct._pdc_pair, ptr %7, i64 %17
  %19 = load i32, ptr %18, align 4, !tbaa !19
  %.not18 = icmp eq i32 %19, -2
  br i1 %.not18, label %20, label %21

20:                                               ; preds = %16
  tail call void @__assert_fail(ptr noundef nonnull @.str.13, ptr noundef nonnull @.str.1, i32 noundef 686, ptr noundef nonnull @__PRETTY_FUNCTION__.free_pair) #2
  unreachable

21:                                               ; preds = %16
  %22 = getelementptr inbounds i8, ptr %2, i64 160
  %23 = load i8, ptr %22, align 8, !tbaa !21, !range !22, !noundef !23
  %24 = trunc nuw i8 %23 to i1
  br i1 %24, label %25, label %26

25:                                               ; preds = %21
  tail call void @_init_pair_core(i32 noundef %0, i32 noundef -2, i32 noundef 0)
  br label %26

26:                                               ; preds = %21, %25
  %.0 = phi i32 [ 0, %25 ], [ -1, %21 ]
  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, !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 0}
!20 = !{!"_pdc_pair", !13, i64 0, !13, i64 4, !13, i64 8, !13, i64 12}
!21 = !{!10, !11, i64 160}
!22 = !{i8 0, i8 2}
!23 = !{}


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