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

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

@SP = external global ptr, align 8
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [92 x i8], align 1
@__PRETTY_FUNCTION__.napms = external hidden unnamed_addr constant [15 x i8], align 1
@curscr = external global ptr, align 8

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

; Function Attrs: nounwind uwtable
declare dso_local i32 @curs_set(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 @napms(i32 noundef %0) #1 {
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i8, align 1
  store i32 %0, ptr %3, align 4, !tbaa !5
  %6 = load ptr, ptr @SP, align 8, !tbaa !9
  %7 = icmp ne ptr %6, null
  br i1 %7, label %8, label %9

8:                                                ; preds = %1
  br label %10

9:                                                ; preds = %1
  call void @__assert_fail(ptr noundef @.str, ptr noundef @.str.1, i32 noundef 247, ptr noundef @__PRETTY_FUNCTION__.napms) #4
  unreachable

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

13:                                               ; preds = %10
  store i32 -1, ptr %2, align 4
  br label %44

14:                                               ; preds = %10
  %15 = load ptr, ptr @SP, align 8, !tbaa !9
  %16 = getelementptr inbounds %struct.SCREEN, ptr %15, i32 0, i32 36
  %17 = load i8, ptr %16, align 1, !tbaa !11, !range !17, !noundef !18
  %18 = trunc i8 %17 to i1
  br i1 %18, label %19, label %38

19:                                               ; preds = %14
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #5
  %20 = load ptr, ptr @SP, align 8, !tbaa !9
  %21 = getelementptr inbounds %struct.SCREEN, ptr %20, i32 0, i32 14
  %22 = load i32, ptr %21, align 8, !tbaa !19
  store i32 %22, ptr %4, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 1, ptr %5) #5
  %23 = load ptr, ptr @curscr, align 8, !tbaa !9
  %24 = call zeroext i1 @is_leaveok(ptr noundef %23)
  %25 = zext i1 %24 to i8
  store i8 %25, ptr %5, align 1, !tbaa !20
  %26 = load ptr, ptr @SP, align 8, !tbaa !9
  %27 = getelementptr inbounds %struct.SCREEN, ptr %26, i32 0, i32 36
  store i8 0, ptr %27, align 1, !tbaa !11
  %28 = load ptr, ptr @curscr, align 8, !tbaa !9
  %29 = call i32 @leaveok(ptr noundef %28, i1 noundef zeroext true)
  %30 = load ptr, ptr @curscr, align 8, !tbaa !9
  %31 = call i32 @wrefresh(ptr noundef %30)
  %32 = load ptr, ptr @curscr, align 8, !tbaa !9
  %33 = load i8, ptr %5, align 1, !tbaa !20, !range !17, !noundef !18
  %34 = trunc i8 %33 to i1
  %35 = call i32 @leaveok(ptr noundef %32, i1 noundef zeroext %34)
  %36 = load i32, ptr %4, align 4, !tbaa !5
  %37 = call i32 @curs_set(i32 noundef %36)
  call void @llvm.lifetime.end.p0(i64 1, ptr %5) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #5
  br label %38

38:                                               ; preds = %19, %14
  %39 = load i32, ptr %3, align 4, !tbaa !5
  %40 = icmp ne i32 %39, 0
  br i1 %40, label %41, label %43

41:                                               ; preds = %38
  %42 = load i32, ptr %3, align 4, !tbaa !5
  call void @PDC_napms(i32 noundef %42)
  br label %43

43:                                               ; preds = %41, %38
  store i32 0, ptr %2, align 4
  br label %44

44:                                               ; preds = %43, %13
  %45 = load i32, ptr %2, align 4
  ret i32 %45
}

declare zeroext i1 @is_leaveok(ptr noundef) #3

declare i32 @leaveok(ptr noundef, i1 noundef zeroext) #3

declare i32 @wrefresh(ptr noundef) #3

declare void @PDC_napms(i32 noundef) #3

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 = { "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 = { noreturn nounwind }
attributes #5 = { 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, !13, i64 161}
!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 = !{i8 0, i8 2}
!18 = !{}
!19 = !{!12, !6, i64 24}
!20 = !{!13, !13, i64 0}


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

@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 [92 x i8], align 1
@__PRETTY_FUNCTION__.napms = external hidden unnamed_addr constant [15 x i8], align 1
@curscr = external local_unnamed_addr global ptr, align 8

; 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 dso_local i32 @curs_set(i32 noundef) local_unnamed_addr #1

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

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

4:                                                ; preds = %1
  %5 = getelementptr inbounds i8, ptr %2, i64 161
  %6 = load i8, ptr %5, align 1, !tbaa !9, !range !16, !noundef !17
  %7 = trunc nuw i8 %6 to i1
  br i1 %7, label %8, label %22

8:                                                ; preds = %4
  %9 = getelementptr inbounds i8, ptr %2, i64 24
  %10 = load i32, ptr %9, align 8, !tbaa !18
  %11 = load ptr, ptr @curscr, align 8, !tbaa !5
  %12 = tail call zeroext i1 @is_leaveok(ptr noundef %11) #4
  %13 = load ptr, ptr @SP, align 8, !tbaa !5
  %14 = getelementptr inbounds i8, ptr %13, i64 161
  store i8 0, ptr %14, align 1, !tbaa !9
  %15 = load ptr, ptr @curscr, align 8, !tbaa !5
  %16 = tail call i32 @leaveok(ptr noundef %15, i1 noundef zeroext true) #4
  %17 = load ptr, ptr @curscr, align 8, !tbaa !5
  %18 = tail call i32 @wrefresh(ptr noundef %17) #4
  %19 = load ptr, ptr @curscr, align 8, !tbaa !5
  %20 = tail call i32 @leaveok(ptr noundef %19, i1 noundef zeroext %12) #4
  %21 = tail call i32 @curs_set(i32 noundef %10)
  br label %22

22:                                               ; preds = %8, %4
  %.not7 = icmp eq i32 %0, 0
  br i1 %.not7, label %24, label %23

23:                                               ; preds = %22
  tail call void @PDC_napms(i32 noundef %0) #4
  br label %24

24:                                               ; preds = %22, %23
  ret i32 0
}

declare zeroext i1 @is_leaveok(ptr noundef) local_unnamed_addr #2

declare i32 @leaveok(ptr noundef, i1 noundef zeroext) local_unnamed_addr #2

declare i32 @wrefresh(ptr noundef) local_unnamed_addr #2

declare void @PDC_napms(i32 noundef) local_unnamed_addr #2

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 = { "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, !11, i64 161}
!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 = !{i8 0, i8 2}
!17 = !{}
!18 = !{!10, !13, i64 24}


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