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

@label_fmt = 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
@__PRETTY_FUNCTION__.PDC_slk_initialize = external hidden unnamed_addr constant [30 x i8], align 1
@label_line = external hidden global i32, align 4
@COLS = external global i32, align 4
@LINES = external global i32, align 4

; Function Attrs: nounwind uwtable
define dso_local void @PDC_slk_initialize() #0 {
  %1 = load ptr, ptr @slk, align 8, !tbaa !5
  %2 = icmp ne ptr %1, null
  br i1 %2, label %3, label %50

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

6:                                                ; preds = %3
  br label %8

7:                                                ; preds = %3
  call void @__assert_fail(ptr noundef @.str, ptr noundef @.str.1, i32 noundef 525, ptr noundef @__PRETTY_FUNCTION__.PDC_slk_initialize) #3
  unreachable

8:                                                ; preds = %6
  %9 = load i32, ptr @label_fmt, align 4, !tbaa !9
  %10 = icmp slt i32 %9, 0
  br i1 %10, label %11, label %14

11:                                               ; preds = %8
  %12 = load ptr, ptr @SP, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.SCREEN, ptr %12, i32 0, i32 20
  store i32 2, ptr %13, align 4, !tbaa !11
  store i32 1, ptr @label_line, align 4, !tbaa !9
  br label %17

14:                                               ; preds = %8
  %15 = load ptr, ptr @SP, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.SCREEN, ptr %15, i32 0, i32 20
  store i32 1, ptr %16, align 4, !tbaa !11
  br label %17

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

22:                                               ; preds = %17
  %23 = load ptr, ptr @SP, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.SCREEN, ptr %23, i32 0, i32 20
  %25 = load i32, ptr %24, align 4, !tbaa !11
  %26 = load i32, ptr @COLS, align 4, !tbaa !9
  %27 = load i32, ptr @LINES, align 4, !tbaa !9
  %28 = load ptr, ptr @SP, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.SCREEN, ptr %28, i32 0, i32 20
  %30 = load i32, ptr %29, align 4, !tbaa !11
  %31 = sub nsw i32 %27, %30
  %32 = call ptr @newwin(i32 noundef %25, i32 noundef %26, i32 noundef %31, i32 noundef 0)
  %33 = load ptr, ptr @SP, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.SCREEN, ptr %33, i32 0, i32 21
  store ptr %32, ptr %34, align 8, !tbaa !17
  %35 = load ptr, ptr @SP, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.SCREEN, ptr %35, i32 0, i32 21
  %37 = load ptr, ptr %36, align 8, !tbaa !17
  %38 = icmp ne ptr %37, null
  br i1 %38, label %40, label %39

39:                                               ; preds = %22
  br label %50

40:                                               ; preds = %22
  %41 = load ptr, ptr @SP, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.SCREEN, ptr %41, i32 0, i32 21
  %43 = load ptr, ptr %42, align 8, !tbaa !17
  %44 = call i32 @wattrset(ptr noundef %43, i64 noundef 67108864)
  br label %45

45:                                               ; preds = %40, %17
  call void @_slk_calc()
  %46 = load ptr, ptr @SP, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.SCREEN, ptr %46, i32 0, i32 21
  %48 = load ptr, ptr %47, align 8, !tbaa !17
  %49 = call i32 @touchwin(ptr noundef %48)
  br label %50

50:                                               ; preds = %45, %39, %0
  ret void
}

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

declare i32 @touchwin(ptr noundef) #2

declare i32 @wattrset(ptr noundef, i64 noundef) #2

declare ptr @newwin(i32 noundef, i32 noundef, i32 noundef, i32 noundef) #2

; Function Attrs: nounwind uwtable
declare hidden void @_slk_calc() #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 = { 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 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 52}
!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, !10, i64 16, !10, i64 20, !10, i64 24, !10, i64 28, !10, i64 32, !10, i64 36, !15, i64 40, !10, i64 48, !10, i64 52, !6, i64 56, !10, i64 64, !10, i64 68, !10, i64 72, !13, i64 76, !10, i64 80, !15, i64 88, !13, i64 96, !13, i64 97, !16, i64 100, !14, i64 132, !15, i64 136, !6, i64 144, !6, i64 152, !13, i64 160, !13, i64 161, !10, i64 164, !10, i64 168, !6, i64 176, !10, i64 184, !10, i64 188, !6, i64 192, !10, i64 200, !10, i64 204, !6, i64 208}
!13 = !{!"_Bool", !7, i64 0}
!14 = !{!"short", !7, i64 0}
!15 = !{!"long", !7, i64 0}
!16 = !{!"", !10, i64 0, !10, i64 4, !7, i64 8, !10, i64 28}
!17 = !{!12, !6, i64 56}


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

@label_fmt = 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
@__PRETTY_FUNCTION__.PDC_slk_initialize = external hidden unnamed_addr constant [30 x i8], align 1
@label_line = external hidden local_unnamed_addr global i32, align 4
@COLS = external local_unnamed_addr global i32, align 4
@LINES = external local_unnamed_addr global i32, align 4

; Function Attrs: nounwind uwtable
define dso_local void @PDC_slk_initialize() local_unnamed_addr #0 {
  %1 = load ptr, ptr @slk, align 8, !tbaa !5
  %.not = icmp eq ptr %1, null
  br i1 %.not, label %28, label %2

2:                                                ; preds = %0
  %3 = load ptr, ptr @SP, align 8, !tbaa !5
  %.not2 = icmp eq ptr %3, null
  br i1 %.not2, label %4, label %5

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

5:                                                ; preds = %2
  %6 = load i32, ptr @label_fmt, align 4, !tbaa !9
  %7 = icmp slt i32 %6, 0
  br i1 %7, label %8, label %9

8:                                                ; preds = %5
  store i32 1, ptr @label_line, align 4, !tbaa !9
  br label %9

9:                                                ; preds = %5, %8
  %10 = phi i32 [ 2, %8 ], [ 1, %5 ]
  %11 = getelementptr inbounds i8, ptr %3, i64 52
  store i32 %10, ptr %11, align 4
  %12 = getelementptr inbounds i8, ptr %3, i64 56
  %13 = load ptr, ptr %12, align 8, !tbaa !11
  %.not3 = icmp eq ptr %13, null
  br i1 %.not3, label %14, label %23

14:                                               ; preds = %9
  %15 = load i32, ptr @COLS, align 4, !tbaa !9
  %16 = load i32, ptr @LINES, align 4, !tbaa !9
  %17 = sub nsw i32 %16, %10
  %18 = tail call ptr @newwin(i32 noundef %10, i32 noundef %15, i32 noundef %17, i32 noundef 0) #4
  %19 = load ptr, ptr @SP, align 8, !tbaa !5
  %20 = getelementptr inbounds i8, ptr %19, i64 56
  store ptr %18, ptr %20, align 8, !tbaa !11
  %.not4 = icmp eq ptr %18, null
  br i1 %.not4, label %28, label %21

21:                                               ; preds = %14
  %22 = tail call i32 @wattrset(ptr noundef nonnull %18, i64 noundef 67108864) #4
  br label %23

23:                                               ; preds = %21, %9
  tail call void @_slk_calc()
  %24 = load ptr, ptr @SP, align 8, !tbaa !5
  %25 = getelementptr inbounds i8, ptr %24, i64 56
  %26 = load ptr, ptr %25, align 8, !tbaa !11
  %27 = tail call i32 @touchwin(ptr noundef %26) #4
  br label %28

28:                                               ; preds = %14, %23, %0
  ret void
}

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

declare i32 @touchwin(ptr noundef) local_unnamed_addr #2

declare i32 @wattrset(ptr noundef, i64 noundef) local_unnamed_addr #2

declare ptr @newwin(i32 noundef, i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
declare hidden void @_slk_calc() 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 = { noreturn nounwind }
attributes #4 = { 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 = !{!"int", !7, i64 0}
!11 = !{!12, !6, i64 56}
!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, !10, i64 16, !10, i64 20, !10, i64 24, !10, i64 28, !10, i64 32, !10, i64 36, !15, i64 40, !10, i64 48, !10, i64 52, !6, i64 56, !10, i64 64, !10, i64 68, !10, i64 72, !13, i64 76, !10, i64 80, !15, i64 88, !13, i64 96, !13, i64 97, !16, i64 100, !14, i64 132, !15, i64 136, !6, i64 144, !6, i64 152, !13, i64 160, !13, i64 161, !10, i64 164, !10, i64 168, !6, i64 176, !10, i64 184, !10, i64 188, !6, i64 192, !10, i64 200, !10, i64 204, !6, i64 208}
!13 = !{!"_Bool", !7, i64 0}
!14 = !{!"short", !7, i64 0}
!15 = !{!"long", !7, i64 0}
!16 = !{!"", !10, i64 0, !10, i64 4, !7, i64 8, !10, i64 28}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InstCombinePass,JumpThreadingPass,MergedLoadStoreMotionPass,SimplifyCFGPass,TailCallElimPass