; LLVM IR from clangen/musikcube :: src/3rdparty/win32_src/pdcurses (slk)

; 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 }
%struct.SLK = type { [32 x i64], i32, i32, i32 }

@labels = external hidden global i32, align 4
@slk = external hidden global ptr, align 8
@SP = external global ptr, align 8
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [89 x i8], align 1
@hidden = external hidden global i8, align 1
@label_line = external hidden global i32, align 4
@label_length = external hidden global i32, align 4
@__PRETTY_FUNCTION__.PDC_mouse_in_slk = external hidden unnamed_addr constant [31 x i8], align 1

; 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: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #1

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

10:                                               ; preds = %2
  br label %12

11:                                               ; preds = %2
  call void @__assert_fail(ptr noundef @.str, ptr noundef @.str.1, i32 noundef 580, ptr noundef @__PRETTY_FUNCTION__.PDC_mouse_in_slk) #4
  unreachable

12:                                               ; preds = %10
  %13 = load ptr, ptr @slk, align 8, !tbaa !9
  %14 = icmp ne ptr %13, null
  br i1 %14, label %15, label %33

15:                                               ; preds = %12
  %16 = load i8, ptr @hidden, align 1, !tbaa !11, !range !13, !noundef !14
  %17 = trunc i8 %16 to i1
  br i1 %17, label %33, label %18

18:                                               ; preds = %15
  %19 = load ptr, ptr @SP, align 8, !tbaa !9
  %20 = getelementptr inbounds %struct.SCREEN, ptr %19, i32 0, i32 21
  %21 = load ptr, ptr %20, align 8, !tbaa !15
  %22 = icmp ne ptr %21, null
  br i1 %22, label %23, label %33

23:                                               ; preds = %18
  %24 = load i32, ptr %4, align 4, !tbaa !5
  %25 = load ptr, ptr @SP, align 8, !tbaa !9
  %26 = getelementptr inbounds %struct.SCREEN, ptr %25, i32 0, i32 21
  %27 = load ptr, ptr %26, align 8, !tbaa !15
  %28 = getelementptr inbounds %struct._win, ptr %27, i32 0, i32 4
  %29 = load i32, ptr %28, align 8, !tbaa !20
  %30 = load i32, ptr @label_line, align 4, !tbaa !5
  %31 = add nsw i32 %29, %30
  %32 = icmp ne i32 %24, %31
  br i1 %32, label %33, label %34

33:                                               ; preds = %23, %18, %15, %12
  store i32 0, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %67

34:                                               ; preds = %23
  store i32 0, ptr %6, align 4, !tbaa !5
  br label %35

35:                                               ; preds = %63, %34
  %36 = load i32, ptr %6, align 4, !tbaa !5
  %37 = load i32, ptr @labels, align 4, !tbaa !5
  %38 = icmp slt i32 %36, %37
  br i1 %38, label %39, label %66

39:                                               ; preds = %35
  %40 = load i32, ptr %5, align 4, !tbaa !5
  %41 = load ptr, ptr @slk, align 8, !tbaa !9
  %42 = load i32, ptr %6, align 4, !tbaa !5
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds %struct.SLK, ptr %41, i64 %43
  %45 = getelementptr inbounds %struct.SLK, ptr %44, i32 0, i32 3
  %46 = load i32, ptr %45, align 8, !tbaa !22
  %47 = icmp sge i32 %40, %46
  br i1 %47, label %48, label %62

48:                                               ; preds = %39
  %49 = load i32, ptr %5, align 4, !tbaa !5
  %50 = load ptr, ptr @slk, align 8, !tbaa !9
  %51 = load i32, ptr %6, align 4, !tbaa !5
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds %struct.SLK, ptr %50, i64 %52
  %54 = getelementptr inbounds %struct.SLK, ptr %53, i32 0, i32 3
  %55 = load i32, ptr %54, align 8, !tbaa !22
  %56 = load i32, ptr @label_length, align 4, !tbaa !5
  %57 = add nsw i32 %55, %56
  %58 = icmp slt i32 %49, %57
  br i1 %58, label %59, label %62

59:                                               ; preds = %48
  %60 = load i32, ptr %6, align 4, !tbaa !5
  %61 = add nsw i32 %60, 1
  store i32 %61, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %67

62:                                               ; preds = %48, %39
  br label %63

63:                                               ; preds = %62
  %64 = load i32, ptr %6, align 4, !tbaa !5
  %65 = add nsw i32 %64, 1
  store i32 %65, ptr %6, align 4, !tbaa !5
  br label %35, !llvm.loop !24

66:                                               ; preds = %35
  store i32 0, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %67

67:                                               ; preds = %66, %59, %33
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  %68 = load i32, ptr %3, align 4
  ret i32 %68
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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, !12, i64 0}
!12 = !{!"_Bool", !7, i64 0}
!13 = !{i8 0, i8 2}
!14 = !{}
!15 = !{!16, !10, i64 56}
!16 = !{!"", !12, i64 0, !12, i64 1, !12, i64 2, !12, i64 3, !12, i64 4, !12, i64 5, !12, i64 6, !12, i64 7, !12, i64 8, !12, i64 9, !17, i64 10, !17, i64 12, !6, i64 16, !6, i64 20, !6, i64 24, !6, i64 28, !6, i64 32, !6, i64 36, !18, i64 40, !6, i64 48, !6, i64 52, !10, i64 56, !6, i64 64, !6, i64 68, !6, i64 72, !12, i64 76, !6, i64 80, !18, i64 88, !12, i64 96, !12, i64 97, !19, i64 100, !17, i64 132, !18, i64 136, !10, i64 144, !10, i64 152, !12, i64 160, !12, 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}
!17 = !{!"short", !7, i64 0}
!18 = !{!"long", !7, i64 0}
!19 = !{!"", !6, i64 0, !6, i64 4, !7, i64 8, !6, i64 28}
!20 = !{!21, !6, i64 16}
!21 = !{!"_win", !6, i64 0, !6, i64 4, !6, i64 8, !6, i64 12, !6, i64 16, !6, i64 20, !6, i64 24, !18, i64 32, !18, i64 40, !12, i64 48, !12, i64 49, !12, i64 50, !12, i64 51, !12, i64 52, !12, i64 53, !12, 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}
!22 = !{!23, !6, i64 264}
!23 = !{!"SLK", !7, i64 0, !6, i64 256, !6, i64 260, !6, i64 264}
!24 = distinct !{!24, !25}
!25 = !{!"llvm.loop.mustprogress"}


; 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.SLK = type { [32 x i64], i32, i32, i32 }

@labels = external hidden local_unnamed_addr global i32, align 4
@slk = external hidden local_unnamed_addr global ptr, align 8
@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 [89 x i8], align 1
@hidden = external hidden local_unnamed_addr global i8, align 1
@label_line = external hidden local_unnamed_addr global i32, align 4
@label_length = external hidden local_unnamed_addr global i32, align 4
@__PRETTY_FUNCTION__.PDC_mouse_in_slk = external hidden unnamed_addr constant [31 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 @PDC_mouse_in_slk(i32 noundef %0, i32 noundef %1) local_unnamed_addr #1 {
  %3 = load ptr, ptr @SP, align 8, !tbaa !5
  %.not = icmp eq ptr %3, null
  br i1 %.not, label %4, label %5

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

5:                                                ; preds = %2
  %6 = load ptr, ptr @slk, align 8, !tbaa !5
  %.not14 = icmp eq ptr %6, null
  br i1 %.not14, label %.loopexit, label %7

7:                                                ; preds = %5
  %8 = load i8, ptr @hidden, align 1, !tbaa !9, !range !11, !noundef !12
  %9 = trunc nuw i8 %8 to i1
  br i1 %9, label %.loopexit, label %10

10:                                               ; preds = %7
  %11 = getelementptr inbounds i8, ptr %3, i64 56
  %12 = load ptr, ptr %11, align 8, !tbaa !13
  %.not15 = icmp eq ptr %12, null
  br i1 %.not15, label %.loopexit, label %13

13:                                               ; preds = %10
  %14 = getelementptr inbounds i8, ptr %12, i64 16
  %15 = load i32, ptr %14, align 8, !tbaa !19
  %16 = load i32, ptr @label_line, align 4, !tbaa !21
  %17 = add nsw i32 %16, %15
  %.not16 = icmp eq i32 %17, %0
  br i1 %.not16, label %.preheader, label %.loopexit

.preheader:                                       ; preds = %13
  %18 = load i32, ptr @labels, align 4, !tbaa !21
  %19 = icmp sgt i32 %18, 0
  br i1 %19, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %.preheader
  %20 = load i32, ptr @label_length, align 4
  %wide.trip.count = zext nneg i32 %18 to i64
  br label %21

21:                                               ; preds = %.lr.ph, %29
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %29 ]
  %22 = getelementptr inbounds %struct.SLK, ptr %6, i64 %indvars.iv, i32 3
  %23 = load i32, ptr %22, align 8, !tbaa !22
  %.not17 = icmp sle i32 %23, %1
  %24 = add nsw i32 %20, %23
  %25 = icmp sgt i32 %24, %1
  %or.cond = select i1 %.not17, i1 %25, i1 false
  br i1 %or.cond, label %26, label %29

26:                                               ; preds = %21
  %27 = trunc nuw nsw i64 %indvars.iv to i32
  %28 = add nuw nsw i32 %27, 1
  br label %.loopexit

29:                                               ; preds = %21
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %.loopexit, label %21, !llvm.loop !24

.loopexit:                                        ; preds = %29, %.preheader, %5, %7, %10, %13, %26
  %.09 = phi i32 [ %28, %26 ], [ 0, %13 ], [ 0, %10 ], [ 0, %7 ], [ 0, %5 ], [ 0, %.preheader ], [ 0, %29 ]
  ret i32 %.09
}

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


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass