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

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

@.str.1 = external hidden unnamed_addr constant [90 x i8], align 1
@curscr = external global ptr, align 8
@.str.2 = external hidden unnamed_addr constant [7 x i8], align 1
@__PRETTY_FUNCTION__.flash = external hidden unnamed_addr constant [16 x i8], align 1
@LINES = external global i32, align 4
@COLS = external global i32, align 4

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

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

8:                                                ; preds = %0
  br label %10

9:                                                ; preds = %0
  call void @__assert_fail(ptr noundef @.str.2, ptr noundef @.str.1, i32 noundef 58, ptr noundef @__PRETTY_FUNCTION__.flash) #5
  unreachable

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

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

14:                                               ; preds = %10
  store i32 0, ptr %2, align 4, !tbaa !9
  br label %15

15:                                               ; preds = %56, %14
  %16 = load i32, ptr %2, align 4, !tbaa !9
  %17 = icmp slt i32 %16, 2
  br i1 %17, label %18, label %59

18:                                               ; preds = %15
  store i32 0, ptr %3, align 4, !tbaa !9
  br label %19

19:                                               ; preds = %45, %18
  %20 = load i32, ptr %3, align 4, !tbaa !9
  %21 = load i32, ptr @LINES, align 4, !tbaa !9
  %22 = icmp slt i32 %20, %21
  br i1 %22, label %23, label %48

23:                                               ; preds = %19
  store i32 0, ptr %4, align 4, !tbaa !9
  br label %24

24:                                               ; preds = %41, %23
  %25 = load i32, ptr %4, align 4, !tbaa !9
  %26 = load i32, ptr @COLS, align 4, !tbaa !9
  %27 = icmp slt i32 %25, %26
  br i1 %27, label %28, label %44

28:                                               ; preds = %24
  %29 = load ptr, ptr @curscr, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct._win, ptr %29, i32 0, i32 16
  %31 = load ptr, ptr %30, align 8, !tbaa !11
  %32 = load i32, ptr %3, align 4, !tbaa !9
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds ptr, ptr %31, i64 %33
  %35 = load ptr, ptr %34, align 8, !tbaa !5
  %36 = load i32, ptr %4, align 4, !tbaa !9
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds i64, ptr %35, i64 %37
  %39 = load i64, ptr %38, align 8, !tbaa !15
  %40 = xor i64 %39, 67108864
  store i64 %40, ptr %38, align 8, !tbaa !15
  br label %41

41:                                               ; preds = %28
  %42 = load i32, ptr %4, align 4, !tbaa !9
  %43 = add nsw i32 %42, 1
  store i32 %43, ptr %4, align 4, !tbaa !9
  br label %24, !llvm.loop !16

44:                                               ; preds = %24
  br label %45

45:                                               ; preds = %44
  %46 = load i32, ptr %3, align 4, !tbaa !9
  %47 = add nsw i32 %46, 1
  store i32 %47, ptr %3, align 4, !tbaa !9
  br label %19, !llvm.loop !18

48:                                               ; preds = %19
  %49 = load ptr, ptr @curscr, align 8, !tbaa !5
  %50 = call i32 @wrefresh(ptr noundef %49)
  %51 = load i32, ptr %2, align 4, !tbaa !9
  %52 = icmp ne i32 %51, 0
  br i1 %52, label %55, label %53

53:                                               ; preds = %48
  %54 = call i32 @napms(i32 noundef 50)
  br label %55

55:                                               ; preds = %53, %48
  br label %56

56:                                               ; preds = %55
  %57 = load i32, ptr %2, align 4, !tbaa !9
  %58 = add nsw i32 %57, 1
  store i32 %58, ptr %2, align 4, !tbaa !9
  br label %15, !llvm.loop !19

59:                                               ; preds = %15
  store i32 0, ptr %1, align 4
  store i32 1, ptr %5, align 4
  br label %60

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

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

declare i32 @wrefresh(ptr noundef) #3

declare i32 @napms(i32 noundef) #3

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { 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 = { nounwind }
attributes #5 = { 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, !6, i64 56}
!12 = !{!"_win", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20, !10, i64 24, !13, i64 32, !13, i64 40, !14, i64 48, !14, i64 49, !14, i64 50, !14, i64 51, !14, i64 52, !14, i64 53, !14, i64 54, !6, i64 56, !6, i64 64, !6, i64 72, !10, i64 80, !10, i64 84, !10, i64 88, !10, i64 92, !10, i64 96, !6, i64 104, !10, i64 112, !10, i64 116, !10, i64 120, !10, i64 124, !10, i64 128, !10, i64 132}
!13 = !{!"long", !7, i64 0}
!14 = !{!"_Bool", !7, i64 0}
!15 = !{!13, !13, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = distinct !{!18, !17}
!19 = distinct !{!19, !17}


; 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.1 = external hidden unnamed_addr constant [90 x i8], align 1
@curscr = external local_unnamed_addr global ptr, align 8
@.str.2 = external hidden unnamed_addr constant [7 x i8], align 1
@__PRETTY_FUNCTION__.flash = external hidden unnamed_addr constant [16 x i8], align 1
@LINES = external local_unnamed_addr global i32, align 4
@COLS = external local_unnamed_addr global i32, align 4

; 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 noundef i32 @flash() local_unnamed_addr #1 {
  %1 = load ptr, ptr @curscr, align 8
  %.not = icmp eq ptr %1, null
  br i1 %.not, label %4, label %.preheader14.preheader

.preheader14.preheader:                           ; preds = %0
  %2 = load i32, ptr @LINES, align 4, !tbaa !5
  %3 = icmp sgt i32 %2, 0
  br i1 %3, label %.preheader.lr.ph, label %.preheader14.1

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

.preheader.lr.ph:                                 ; preds = %.preheader14.preheader
  %5 = load i32, ptr @COLS, align 4, !tbaa !5
  %6 = icmp sgt i32 %5, 0
  br i1 %6, label %.preheader.lr.ph.split.us, label %.preheader14.1

.preheader.lr.ph.split.us:                        ; preds = %.preheader.lr.ph
  %7 = getelementptr inbounds i8, ptr %1, i64 56
  %8 = load ptr, ptr %7, align 8, !tbaa !9
  %wide.trip.count25 = zext nneg i32 %2 to i64
  %wide.trip.count = zext nneg i32 %5 to i64
  %min.iters.check = icmp ult i32 %5, 4
  %n.vec = and i64 %wide.trip.count, 2147483644
  %cmp.n = icmp eq i64 %n.vec, %wide.trip.count
  br label %.preheader.us

.preheader.us:                                    ; preds = %._crit_edge.us, %.preheader.lr.ph.split.us
  %indvars.iv22 = phi i64 [ %indvars.iv.next23, %._crit_edge.us ], [ 0, %.preheader.lr.ph.split.us ]
  %9 = getelementptr inbounds ptr, ptr %8, i64 %indvars.iv22
  %10 = load ptr, ptr %9, align 8, !tbaa !14
  br i1 %min.iters.check, label %scalar.ph.preheader, label %vector.body

vector.body:                                      ; preds = %.preheader.us, %vector.body
  %index = phi i64 [ %index.next, %vector.body ], [ 0, %.preheader.us ]
  %11 = getelementptr inbounds i64, ptr %10, i64 %index
  %12 = getelementptr inbounds i8, ptr %11, i64 16
  %wide.load = load <2 x i64>, ptr %11, align 8, !tbaa !15
  %wide.load27 = load <2 x i64>, ptr %12, align 8, !tbaa !15
  %13 = xor <2 x i64> %wide.load, <i64 67108864, i64 67108864>
  %14 = xor <2 x i64> %wide.load27, <i64 67108864, i64 67108864>
  store <2 x i64> %13, ptr %11, align 8, !tbaa !15
  store <2 x i64> %14, ptr %12, align 8, !tbaa !15
  %index.next = add nuw i64 %index, 4
  %15 = icmp eq i64 %index.next, %n.vec
  br i1 %15, label %middle.block, label %vector.body, !llvm.loop !16

middle.block:                                     ; preds = %vector.body
  br i1 %cmp.n, label %._crit_edge.us, label %scalar.ph.preheader

scalar.ph.preheader:                              ; preds = %middle.block, %.preheader.us
  %indvars.iv.ph = phi i64 [ 0, %.preheader.us ], [ %n.vec, %middle.block ]
  br label %scalar.ph

scalar.ph:                                        ; preds = %scalar.ph.preheader, %scalar.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %scalar.ph ], [ %indvars.iv.ph, %scalar.ph.preheader ]
  %16 = getelementptr inbounds i64, ptr %10, i64 %indvars.iv
  %17 = load i64, ptr %16, align 8, !tbaa !15
  %18 = xor i64 %17, 67108864
  store i64 %18, ptr %16, align 8, !tbaa !15
  %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 %._crit_edge.us, label %scalar.ph, !llvm.loop !20

._crit_edge.us:                                   ; preds = %scalar.ph, %middle.block
  %indvars.iv.next23 = add nuw nsw i64 %indvars.iv22, 1
  %exitcond26.not = icmp eq i64 %indvars.iv.next23, %wide.trip.count25
  br i1 %exitcond26.not, label %._crit_edge18.loopexit, label %.preheader.us, !llvm.loop !21

._crit_edge18.loopexit:                           ; preds = %._crit_edge.us
  %.pre = load ptr, ptr @curscr, align 8, !tbaa !14
  br label %.preheader14.1

.preheader14.1:                                   ; preds = %.preheader.lr.ph, %._crit_edge18.loopexit, %.preheader14.preheader
  %19 = phi ptr [ %.pre, %._crit_edge18.loopexit ], [ %1, %.preheader14.preheader ], [ %1, %.preheader.lr.ph ]
  %20 = tail call i32 @wrefresh(ptr noundef %19) #4
  %21 = tail call i32 @napms(i32 noundef 50) #4
  %22 = load i32, ptr @LINES, align 4, !tbaa !5
  %23 = icmp sgt i32 %22, 0
  br i1 %23, label %.preheader.lr.ph.1, label %.loopexit

.preheader.lr.ph.1:                               ; preds = %.preheader14.1
  %24 = load i32, ptr @COLS, align 4, !tbaa !5
  %25 = icmp sgt i32 %24, 0
  br i1 %25, label %.preheader.lr.ph.split.us.1, label %.loopexit

.preheader.lr.ph.split.us.1:                      ; preds = %.preheader.lr.ph.1
  %26 = load ptr, ptr @curscr, align 8
  %27 = getelementptr inbounds i8, ptr %26, i64 56
  %28 = load ptr, ptr %27, align 8, !tbaa !9
  %wide.trip.count25.1 = zext nneg i32 %22 to i64
  %wide.trip.count.1 = zext nneg i32 %24 to i64
  %min.iters.check30 = icmp ult i32 %24, 4
  %n.vec33 = and i64 %wide.trip.count.1, 2147483644
  %cmp.n40 = icmp eq i64 %n.vec33, %wide.trip.count.1
  br label %.preheader.us.1

.preheader.us.1:                                  ; preds = %._crit_edge.us.1, %.preheader.lr.ph.split.us.1
  %indvars.iv22.1 = phi i64 [ %indvars.iv.next23.1, %._crit_edge.us.1 ], [ 0, %.preheader.lr.ph.split.us.1 ]
  %29 = getelementptr inbounds ptr, ptr %28, i64 %indvars.iv22.1
  %30 = load ptr, ptr %29, align 8, !tbaa !14
  br i1 %min.iters.check30, label %scalar.ph29.preheader, label %vector.body35

vector.body35:                                    ; preds = %.preheader.us.1, %vector.body35
  %index36 = phi i64 [ %index.next39, %vector.body35 ], [ 0, %.preheader.us.1 ]
  %31 = getelementptr inbounds i64, ptr %30, i64 %index36
  %32 = getelementptr inbounds i8, ptr %31, i64 16
  %wide.load37 = load <2 x i64>, ptr %31, align 8, !tbaa !15
  %wide.load38 = load <2 x i64>, ptr %32, align 8, !tbaa !15
  %33 = xor <2 x i64> %wide.load37, <i64 67108864, i64 67108864>
  %34 = xor <2 x i64> %wide.load38, <i64 67108864, i64 67108864>
  store <2 x i64> %33, ptr %31, align 8, !tbaa !15
  store <2 x i64> %34, ptr %32, align 8, !tbaa !15
  %index.next39 = add nuw i64 %index36, 4
  %35 = icmp eq i64 %index.next39, %n.vec33
  br i1 %35, label %middle.block28, label %vector.body35, !llvm.loop !22

middle.block28:                                   ; preds = %vector.body35
  br i1 %cmp.n40, label %._crit_edge.us.1, label %scalar.ph29.preheader

scalar.ph29.preheader:                            ; preds = %middle.block28, %.preheader.us.1
  %indvars.iv.1.ph = phi i64 [ 0, %.preheader.us.1 ], [ %n.vec33, %middle.block28 ]
  br label %scalar.ph29

scalar.ph29:                                      ; preds = %scalar.ph29.preheader, %scalar.ph29
  %indvars.iv.1 = phi i64 [ %indvars.iv.next.1, %scalar.ph29 ], [ %indvars.iv.1.ph, %scalar.ph29.preheader ]
  %36 = getelementptr inbounds i64, ptr %30, i64 %indvars.iv.1
  %37 = load i64, ptr %36, align 8, !tbaa !15
  %38 = xor i64 %37, 67108864
  store i64 %38, ptr %36, align 8, !tbaa !15
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv.1, 1
  %exitcond.1.not = icmp eq i64 %indvars.iv.next.1, %wide.trip.count.1
  br i1 %exitcond.1.not, label %._crit_edge.us.1, label %scalar.ph29, !llvm.loop !23

._crit_edge.us.1:                                 ; preds = %scalar.ph29, %middle.block28
  %indvars.iv.next23.1 = add nuw nsw i64 %indvars.iv22.1, 1
  %exitcond26.1.not = icmp eq i64 %indvars.iv.next23.1, %wide.trip.count25.1
  br i1 %exitcond26.1.not, label %.loopexit, label %.preheader.us.1, !llvm.loop !21

.loopexit:                                        ; preds = %._crit_edge.us.1, %.preheader14.1, %.preheader.lr.ph.1
  %39 = load ptr, ptr @curscr, align 8, !tbaa !14
  %40 = tail call i32 @wrefresh(ptr noundef %39) #4
  ret i32 0
}

declare i32 @wrefresh(ptr noundef) local_unnamed_addr #2

declare i32 @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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !13, i64 56}
!10 = !{!"_win", !6, i64 0, !6, i64 4, !6, i64 8, !6, i64 12, !6, i64 16, !6, i64 20, !6, i64 24, !11, i64 32, !11, i64 40, !12, i64 48, !12, i64 49, !12, i64 50, !12, i64 51, !12, i64 52, !12, i64 53, !12, i64 54, !13, i64 56, !13, i64 64, !13, i64 72, !6, i64 80, !6, i64 84, !6, i64 88, !6, i64 92, !6, i64 96, !13, i64 104, !6, i64 112, !6, i64 116, !6, i64 120, !6, i64 124, !6, i64 128, !6, i64 132}
!11 = !{!"long", !7, i64 0}
!12 = !{!"_Bool", !7, i64 0}
!13 = !{!"any pointer", !7, i64 0}
!14 = !{!13, !13, i64 0}
!15 = !{!11, !11, i64 0}
!16 = distinct !{!16, !17, !18, !19}
!17 = !{!"llvm.loop.mustprogress"}
!18 = !{!"llvm.loop.isvectorized", i32 1}
!19 = !{!"llvm.loop.unroll.runtime.disable"}
!20 = distinct !{!20, !17, !19, !18}
!21 = distinct !{!21, !17}
!22 = distinct !{!22, !17, !18, !19}
!23 = distinct !{!23, !17, !19, !18}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopLoadEliminationPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,LoopVectorizePass,PostOrderFunctionAttrsPass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass