; 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
@labels = external hidden global i32, align 4
@slk = external hidden global ptr, align 8
@SP = external global ptr, align 8

; Function Attrs: nounwind uwtable
define dso_local i32 @slk_init(i32 noundef %0) #0 {
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  store i32 %0, ptr %2, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #6
  %4 = load i32, ptr %2, align 4, !tbaa !5
  switch i32 %4, label %10 [
    i32 0, label %5
    i32 1, label %6
    i32 2, label %7
    i32 3, label %8
    i32 55, label %9
  ]

5:                                                ; preds = %1
  store i32 803, ptr @label_fmt, align 4, !tbaa !5
  br label %12

6:                                                ; preds = %1
  store i32 68, ptr @label_fmt, align 4, !tbaa !5
  br label %12

7:                                                ; preds = %1
  store i32 1092, ptr @label_fmt, align 4, !tbaa !5
  br label %12

8:                                                ; preds = %1
  store i32 -1092, ptr @label_fmt, align 4, !tbaa !5
  br label %12

9:                                                ; preds = %1
  store i32 85, ptr @label_fmt, align 4, !tbaa !5
  br label %12

10:                                               ; preds = %1
  %11 = load i32, ptr %2, align 4, !tbaa !5
  store i32 %11, ptr @label_fmt, align 4, !tbaa !5
  br label %12

12:                                               ; preds = %10, %9, %8, %7, %6, %5
  store i32 0, ptr @labels, align 4, !tbaa !5
  %13 = load i32, ptr @label_fmt, align 4, !tbaa !5
  %14 = call i32 @llvm.abs.i32(i32 %13, i1 true)
  store i32 %14, ptr %3, align 4, !tbaa !5
  br label %15

15:                                               ; preds = %23, %12
  %16 = load i32, ptr %3, align 4, !tbaa !5
  %17 = icmp ne i32 %16, 0
  br i1 %17, label %18, label %26

18:                                               ; preds = %15
  %19 = load i32, ptr %3, align 4, !tbaa !5
  %20 = srem i32 %19, 16
  %21 = load i32, ptr @labels, align 4, !tbaa !5
  %22 = add nsw i32 %21, %20
  store i32 %22, ptr @labels, align 4, !tbaa !5
  br label %23

23:                                               ; preds = %18
  %24 = load i32, ptr %3, align 4, !tbaa !5
  %25 = sdiv i32 %24, 16
  store i32 %25, ptr %3, align 4, !tbaa !5
  br label %15, !llvm.loop !9

26:                                               ; preds = %15
  %27 = load ptr, ptr @slk, align 8, !tbaa !11
  %28 = icmp ne ptr %27, null
  br i1 %28, label %29, label %31

29:                                               ; preds = %26
  %30 = load ptr, ptr @slk, align 8, !tbaa !11
  call void @free(ptr noundef %30) #6
  br label %31

31:                                               ; preds = %29, %26
  %32 = load i32, ptr @labels, align 4, !tbaa !5
  %33 = sext i32 %32 to i64
  %34 = call noalias ptr @calloc(i64 noundef %33, i64 noundef 272) #7
  store ptr %34, ptr @slk, align 8, !tbaa !11
  %35 = load ptr, ptr @slk, align 8, !tbaa !11
  %36 = icmp ne ptr %35, null
  br i1 %36, label %38, label %37

37:                                               ; preds = %31
  store i32 0, ptr @labels, align 4, !tbaa !5
  br label %38

38:                                               ; preds = %37, %31
  %39 = load ptr, ptr @SP, align 8, !tbaa !11
  %40 = icmp ne ptr %39, null
  br i1 %40, label %41, label %52

41:                                               ; preds = %38
  %42 = load ptr, ptr @SP, align 8, !tbaa !11
  %43 = getelementptr inbounds %struct.SCREEN, ptr %42, i32 0, i32 21
  %44 = load ptr, ptr %43, align 8, !tbaa !13
  %45 = icmp ne ptr %44, null
  br i1 %45, label %46, label %51

46:                                               ; preds = %41
  %47 = load ptr, ptr @SP, align 8, !tbaa !11
  %48 = getelementptr inbounds %struct.SCREEN, ptr %47, i32 0, i32 21
  %49 = load ptr, ptr %48, align 8, !tbaa !13
  %50 = call i32 @wclear(ptr noundef %49)
  br label %51

51:                                               ; preds = %46, %41
  call void @PDC_slk_initialize()
  br label %52

52:                                               ; preds = %51, %38
  %53 = load ptr, ptr @slk, align 8, !tbaa !11
  %54 = icmp ne ptr %53, null
  %55 = zext i1 %54 to i64
  %56 = select i1 %54, i32 0, i32 -1
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #6
  ret i32 %56
}

; 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 speculatable willreturn memory(none)
declare i32 @llvm.abs.i32(i32, i1 immarg) #2

; Function Attrs: nounwind
declare void @free(ptr noundef) #3

; Function Attrs: nounwind allocsize(0,1)
declare noalias ptr @calloc(i64 noundef, i64 noundef) #4

declare i32 @wclear(ptr noundef) #5

; Function Attrs: nounwind uwtable
declare dso_local void @PDC_slk_initialize() #0

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

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #3 = { 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 #4 = { nounwind allocsize(0,1) "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 #5 = { "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 #6 = { nounwind }
attributes #7 = { nounwind allocsize(0,1) }

!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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!12, !12, i64 0}
!12 = !{!"any pointer", !7, i64 0}
!13 = !{!14, !12, i64 56}
!14 = !{!"", !15, i64 0, !15, i64 1, !15, i64 2, !15, i64 3, !15, i64 4, !15, i64 5, !15, i64 6, !15, i64 7, !15, i64 8, !15, i64 9, !16, i64 10, !16, i64 12, !6, i64 16, !6, i64 20, !6, i64 24, !6, i64 28, !6, i64 32, !6, i64 36, !17, i64 40, !6, i64 48, !6, i64 52, !12, i64 56, !6, i64 64, !6, i64 68, !6, i64 72, !15, i64 76, !6, i64 80, !17, i64 88, !15, i64 96, !15, i64 97, !18, i64 100, !16, i64 132, !17, i64 136, !12, i64 144, !12, i64 152, !15, i64 160, !15, i64 161, !6, i64 164, !6, i64 168, !12, i64 176, !6, i64 184, !6, i64 188, !12, i64 192, !6, i64 200, !6, i64 204, !12, i64 208}
!15 = !{!"_Bool", !7, i64 0}
!16 = !{!"short", !7, i64 0}
!17 = !{!"long", !7, i64 0}
!18 = !{!"", !6, i64 0, !6, i64 4, !7, i64 8, !6, i64 28}


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

; Function Attrs: nounwind uwtable
define dso_local range(i32 -1, 1) i32 @slk_init(i32 noundef %0) local_unnamed_addr #0 {
  switch i32 %0, label %6 [
    i32 0, label %.lr.ph.preheader
    i32 1, label %2
    i32 2, label %3
    i32 3, label %4
    i32 55, label %5
  ]

2:                                                ; preds = %1
  br label %.lr.ph.preheader

3:                                                ; preds = %1
  br label %.lr.ph.preheader

4:                                                ; preds = %1
  br label %.lr.ph.preheader

5:                                                ; preds = %1
  br label %.lr.ph.preheader

6:                                                ; preds = %1
  br label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %1, %2, %3, %4, %5, %6
  %.sink = phi i32 [ 68, %2 ], [ 1092, %3 ], [ -1092, %4 ], [ 85, %5 ], [ %0, %6 ], [ 803, %1 ]
  store i32 %.sink, ptr @label_fmt, align 4, !tbaa !5
  %7 = tail call i32 @llvm.abs.i32(i32 %.sink, i1 true)
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %.014 = phi i32 [ %11, %.lr.ph ], [ %7, %.lr.ph.preheader ]
  %8 = phi i32 [ %10, %.lr.ph ], [ 0, %.lr.ph.preheader ]
  %9 = and i32 %.014, 15
  %10 = add nuw nsw i32 %8, %9
  %11 = lshr i32 %.014, 4
  %.not = icmp ult i32 %.014, 16
  br i1 %.not, label %12, label %.lr.ph, !llvm.loop !9

12:                                               ; preds = %.lr.ph
  store i32 %10, ptr @labels, align 4, !tbaa !5
  %13 = load ptr, ptr @slk, align 8, !tbaa !11
  %.not8 = icmp eq ptr %13, null
  br i1 %.not8, label %15, label %14

14:                                               ; preds = %12
  tail call void @free(ptr noundef nonnull %13) #5
  %.pre = load i32, ptr @labels, align 4, !tbaa !5
  br label %15

15:                                               ; preds = %14, %12
  %16 = phi i32 [ %.pre, %14 ], [ %10, %12 ]
  %17 = sext i32 %16 to i64
  %18 = tail call noalias ptr @calloc(i64 noundef %17, i64 noundef 272) #6
  store ptr %18, ptr @slk, align 8, !tbaa !11
  %.not9 = icmp eq ptr %18, null
  br i1 %.not9, label %19, label %20

19:                                               ; preds = %15
  store i32 0, ptr @labels, align 4, !tbaa !5
  br label %20

20:                                               ; preds = %19, %15
  %21 = load ptr, ptr @SP, align 8, !tbaa !11
  %.not10 = icmp eq ptr %21, null
  br i1 %.not10, label %28, label %22

22:                                               ; preds = %20
  %23 = getelementptr inbounds i8, ptr %21, i64 56
  %24 = load ptr, ptr %23, align 8, !tbaa !13
  %.not11 = icmp eq ptr %24, null
  br i1 %.not11, label %27, label %25

25:                                               ; preds = %22
  %26 = tail call i32 @wclear(ptr noundef nonnull %24) #5
  br label %27

27:                                               ; preds = %25, %22
  tail call void @PDC_slk_initialize()
  %.pre15 = load ptr, ptr @slk, align 8, !tbaa !11
  br label %28

28:                                               ; preds = %27, %20
  %29 = phi ptr [ %.pre15, %27 ], [ %18, %20 ]
  %.not12 = icmp eq ptr %29, null
  %30 = sext i1 %.not12 to i32
  ret i32 %30
}

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.abs.i32(i32, i1 immarg) #1

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,zeroed") allocsize(0,1) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @calloc(i64 noundef, i64 noundef) local_unnamed_addr #3

declare i32 @wclear(ptr noundef) local_unnamed_addr #4

; Function Attrs: nounwind uwtable
declare dso_local void @PDC_slk_initialize() 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 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #2 = { mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" "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 = { mustprogress nofree nounwind willreturn allockind("alloc,zeroed") allocsize(0,1) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "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 #4 = { "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 #5 = { nounwind }
attributes #6 = { nounwind allocsize(0,1) }

!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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!12, !12, i64 0}
!12 = !{!"any pointer", !7, i64 0}
!13 = !{!14, !12, i64 56}
!14 = !{!"", !15, i64 0, !15, i64 1, !15, i64 2, !15, i64 3, !15, i64 4, !15, i64 5, !15, i64 6, !15, i64 7, !15, i64 8, !15, i64 9, !16, i64 10, !16, i64 12, !6, i64 16, !6, i64 20, !6, i64 24, !6, i64 28, !6, i64 32, !6, i64 36, !17, i64 40, !6, i64 48, !6, i64 52, !12, i64 56, !6, i64 64, !6, i64 68, !6, i64 72, !15, i64 76, !6, i64 80, !17, i64 88, !15, i64 96, !15, i64 97, !18, i64 100, !16, i64 132, !17, i64 136, !12, i64 144, !12, i64 152, !15, i64 160, !15, i64 161, !6, i64 164, !6, i64 168, !12, i64 176, !6, i64 184, !6, i64 188, !12, i64 192, !6, i64 200, !6, i64 204, !12, i64 208}
!15 = !{!"_Bool", !7, i64 0}
!16 = !{!"short", !7, i64 0}
!17 = !{!"long", !7, i64 0}
!18 = !{!"", !6, i64 0, !6, i64 4, !7, i64 8, !6, i64 28}


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