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

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

@.str = external hidden unnamed_addr constant [4 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [93 x i8], align 1
@curscr = external global ptr, align 8
@SP = external global ptr, align 8
@__PRETTY_FUNCTION__.wrefresh = external hidden unnamed_addr constant [23 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local i32 @wnoutrefresh(ptr noundef) #0

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

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

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

; Function Attrs: nounwind uwtable
declare dso_local i32 @doupdate() #0

; Function Attrs: nounwind uwtable
define dso_local i32 @wrefresh(ptr noundef %0) #0 {
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  %4 = alloca i8, align 1
  %5 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 1, ptr %4) #3
  %6 = load ptr, ptr %3, align 8, !tbaa !5
  %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 251, ptr noundef @__PRETTY_FUNCTION__.wrefresh) #4
  unreachable

10:                                               ; preds = %8
  %11 = load ptr, ptr %3, align 8, !tbaa !5
  %12 = icmp ne ptr %11, null
  br i1 %12, label %13, label %19

13:                                               ; preds = %10
  %14 = load ptr, ptr %3, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct._win, ptr %14, i32 0, i32 6
  %16 = load i32, ptr %15, align 8, !tbaa !9
  %17 = and i32 %16, 48
  %18 = icmp ne i32 %17, 0
  br i1 %18, label %19, label %20

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

20:                                               ; preds = %13
  %21 = load ptr, ptr %3, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct._win, ptr %21, i32 0, i32 9
  %23 = load i8, ptr %22, align 8, !tbaa !14, !range !15, !noundef !16
  %24 = trunc i8 %23 to i1
  %25 = zext i1 %24 to i8
  store i8 %25, ptr %4, align 1, !tbaa !17
  %26 = load ptr, ptr %3, align 8, !tbaa !5
  %27 = load ptr, ptr @curscr, align 8, !tbaa !5
  %28 = icmp eq ptr %26, %27
  br i1 %28, label %29, label %32

29:                                               ; preds = %20
  %30 = load ptr, ptr @curscr, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct._win, ptr %30, i32 0, i32 9
  store i8 1, ptr %31, align 8, !tbaa !14
  br label %35

32:                                               ; preds = %20
  %33 = load ptr, ptr %3, align 8, !tbaa !5
  %34 = call i32 @wnoutrefresh(ptr noundef %33)
  br label %35

35:                                               ; preds = %32, %29
  %36 = load i8, ptr %4, align 1, !tbaa !17, !range !15, !noundef !16
  %37 = trunc i8 %36 to i1
  br i1 %37, label %38, label %57

38:                                               ; preds = %35
  %39 = load ptr, ptr %3, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct._win, ptr %39, i32 0, i32 2
  %41 = load i32, ptr %40, align 8, !tbaa !18
  %42 = load ptr, ptr @SP, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.SCREEN, ptr %42, i32 0, i32 16
  %44 = load i32, ptr %43, align 8, !tbaa !19
  %45 = icmp eq i32 %41, %44
  br i1 %45, label %46, label %57

46:                                               ; preds = %38
  %47 = load ptr, ptr %3, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct._win, ptr %47, i32 0, i32 3
  %49 = load i32, ptr %48, align 4, !tbaa !23
  %50 = load ptr, ptr @SP, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.SCREEN, ptr %50, i32 0, i32 17
  %52 = load i32, ptr %51, align 4, !tbaa !24
  %53 = icmp eq i32 %49, %52
  br i1 %53, label %54, label %57

54:                                               ; preds = %46
  %55 = load ptr, ptr @curscr, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct._win, ptr %55, i32 0, i32 9
  store i8 1, ptr %56, align 8, !tbaa !14
  br label %57

57:                                               ; preds = %54, %46, %38, %35
  %58 = call i32 @doupdate()
  store i32 %58, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %59

59:                                               ; preds = %57, %19
  call void @llvm.lifetime.end.p0(i64 1, ptr %4) #3
  %60 = load i32, ptr %2, align 4
  ret i32 %60
}

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 = { 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 #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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !11, i64 24}
!10 = !{!"_win", !11, i64 0, !11, i64 4, !11, i64 8, !11, i64 12, !11, i64 16, !11, i64 20, !11, i64 24, !12, i64 32, !12, i64 40, !13, i64 48, !13, i64 49, !13, i64 50, !13, i64 51, !13, i64 52, !13, i64 53, !13, i64 54, !6, i64 56, !6, i64 64, !6, i64 72, !11, i64 80, !11, i64 84, !11, i64 88, !11, i64 92, !11, i64 96, !6, i64 104, !11, i64 112, !11, i64 116, !11, i64 120, !11, i64 124, !11, i64 128, !11, i64 132}
!11 = !{!"int", !7, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!"_Bool", !7, i64 0}
!14 = !{!10, !13, i64 48}
!15 = !{i8 0, i8 2}
!16 = !{}
!17 = !{!13, !13, i64 0}
!18 = !{!10, !11, i64 8}
!19 = !{!20, !11, i64 32}
!20 = !{!"", !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, !21, i64 10, !21, i64 12, !11, i64 16, !11, i64 20, !11, i64 24, !11, i64 28, !11, i64 32, !11, i64 36, !12, i64 40, !11, i64 48, !11, i64 52, !6, i64 56, !11, i64 64, !11, i64 68, !11, i64 72, !13, i64 76, !11, i64 80, !12, i64 88, !13, i64 96, !13, i64 97, !22, i64 100, !21, i64 132, !12, i64 136, !6, i64 144, !6, i64 152, !13, i64 160, !13, i64 161, !11, i64 164, !11, i64 168, !6, i64 176, !11, i64 184, !11, i64 188, !6, i64 192, !11, i64 200, !11, i64 204, !6, i64 208}
!21 = !{!"short", !7, i64 0}
!22 = !{!"", !11, i64 0, !11, i64 4, !7, i64 8, !11, i64 28}
!23 = !{!10, !11, i64 12}
!24 = !{!20, !11, i64 36}


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

@.str = external hidden unnamed_addr constant [4 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [93 x i8], align 1
@curscr = external local_unnamed_addr global ptr, align 8
@SP = external local_unnamed_addr global ptr, align 8
@__PRETTY_FUNCTION__.wrefresh = external hidden unnamed_addr constant [23 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local i32 @wnoutrefresh(ptr noundef) local_unnamed_addr #0

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

; Function Attrs: nounwind uwtable
declare dso_local i32 @doupdate() local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local i32 @wrefresh(ptr noundef %0) local_unnamed_addr #0 {
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %2, label %3

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

3:                                                ; preds = %1
  %4 = getelementptr inbounds i8, ptr %0, i64 24
  %5 = load i32, ptr %4, align 8, !tbaa !5
  %6 = and i32 %5, 48
  %.not11 = icmp eq i32 %6, 0
  br i1 %.not11, label %7, label %36

7:                                                ; preds = %3
  %8 = getelementptr inbounds i8, ptr %0, i64 48
  %9 = load i8, ptr %8, align 8, !tbaa !13, !range !14, !noundef !15
  %10 = trunc nuw i8 %9 to i1
  %11 = load ptr, ptr @curscr, align 8, !tbaa !16
  %12 = icmp eq ptr %11, %0
  br i1 %12, label %13, label %15

13:                                               ; preds = %7
  %14 = getelementptr inbounds i8, ptr %11, i64 48
  store i8 1, ptr %14, align 8, !tbaa !13
  br label %17

15:                                               ; preds = %7
  %16 = tail call i32 @wnoutrefresh(ptr noundef nonnull %0)
  br label %17

17:                                               ; preds = %15, %13
  br i1 %10, label %18, label %34

18:                                               ; preds = %17
  %19 = getelementptr inbounds i8, ptr %0, i64 8
  %20 = load i32, ptr %19, align 8, !tbaa !17
  %21 = load ptr, ptr @SP, align 8, !tbaa !16
  %22 = getelementptr inbounds i8, ptr %21, i64 32
  %23 = load i32, ptr %22, align 8, !tbaa !18
  %24 = icmp eq i32 %20, %23
  br i1 %24, label %25, label %34

25:                                               ; preds = %18
  %26 = getelementptr inbounds i8, ptr %0, i64 12
  %27 = load i32, ptr %26, align 4, !tbaa !22
  %28 = getelementptr inbounds i8, ptr %21, i64 36
  %29 = load i32, ptr %28, align 4, !tbaa !23
  %30 = icmp eq i32 %27, %29
  br i1 %30, label %31, label %34

31:                                               ; preds = %25
  %32 = load ptr, ptr @curscr, align 8, !tbaa !16
  %33 = getelementptr inbounds i8, ptr %32, i64 48
  store i8 1, ptr %33, align 8, !tbaa !13
  br label %34

34:                                               ; preds = %31, %25, %18, %17
  %35 = tail call i32 @doupdate()
  br label %36

36:                                               ; preds = %3, %34
  %.0 = phi i32 [ %35, %34 ], [ -1, %3 ]
  ret i32 %.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 = { 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, !7, i64 24}
!6 = !{!"_win", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12, !7, i64 16, !7, i64 20, !7, i64 24, !10, i64 32, !10, i64 40, !11, i64 48, !11, i64 49, !11, i64 50, !11, i64 51, !11, i64 52, !11, i64 53, !11, i64 54, !12, i64 56, !12, i64 64, !12, i64 72, !7, i64 80, !7, i64 84, !7, i64 88, !7, i64 92, !7, i64 96, !12, i64 104, !7, i64 112, !7, i64 116, !7, i64 120, !7, i64 124, !7, i64 128, !7, i64 132}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!"_Bool", !8, i64 0}
!12 = !{!"any pointer", !8, i64 0}
!13 = !{!6, !11, i64 48}
!14 = !{i8 0, i8 2}
!15 = !{}
!16 = !{!12, !12, i64 0}
!17 = !{!6, !7, i64 8}
!18 = !{!19, !7, i64 32}
!19 = !{!"", !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, !20, i64 10, !20, i64 12, !7, i64 16, !7, i64 20, !7, i64 24, !7, i64 28, !7, i64 32, !7, i64 36, !10, i64 40, !7, i64 48, !7, i64 52, !12, i64 56, !7, i64 64, !7, i64 68, !7, i64 72, !11, i64 76, !7, i64 80, !10, i64 88, !11, i64 96, !11, i64 97, !21, i64 100, !20, i64 132, !10, i64 136, !12, i64 144, !12, i64 152, !11, i64 160, !11, i64 161, !7, i64 164, !7, i64 168, !12, i64 176, !7, i64 184, !7, i64 188, !12, i64 192, !7, i64 200, !7, i64 204, !12, i64 208}
!20 = !{!"short", !8, i64 0}
!21 = !{!"", !7, i64 0, !7, i64 4, !8, i64 8, !7, i64 28}
!22 = !{!6, !7, i64 12}
!23 = !{!19, !7, i64 36}


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