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

; 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 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [93 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [6 x i8], align 1
@__PRETTY_FUNCTION__.copywin = external hidden unnamed_addr constant [73 x i8], align 1
@curscr = external global ptr, align 8

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

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

; Function Attrs: nounwind uwtable
declare hidden i32 @_copy_win(ptr noundef, ptr noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef, i1 noundef zeroext) #2

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

; Function Attrs: nounwind uwtable
define dso_local i32 @copywin(ptr noundef %0, ptr noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4, i32 noundef %5, i32 noundef %6, i32 noundef %7, i32 noundef %8) #2 {
  %10 = alloca i32, align 4
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  %15 = alloca i32, align 4
  %16 = alloca i32, align 4
  %17 = alloca i32, align 4
  %18 = alloca i32, align 4
  %19 = alloca i32, align 4
  %20 = alloca i32, align 4
  %21 = alloca i32, align 4
  %22 = alloca i32, align 4
  %23 = alloca i32, align 4
  %24 = alloca i32, align 4
  %25 = alloca i32, align 4
  %26 = alloca i32, align 4
  %27 = alloca i32, align 4
  %28 = alloca i32, align 4
  store ptr %0, ptr %11, align 8, !tbaa !5
  store ptr %1, ptr %12, align 8, !tbaa !5
  store i32 %2, ptr %13, align 4, !tbaa !9
  store i32 %3, ptr %14, align 4, !tbaa !9
  store i32 %4, ptr %15, align 4, !tbaa !9
  store i32 %5, ptr %16, align 4, !tbaa !9
  store i32 %6, ptr %17, align 4, !tbaa !9
  store i32 %7, ptr %18, align 4, !tbaa !9
  store i32 %8, ptr %19, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %20) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %21) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %22) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %23) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %24) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %25) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %26) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %27) #3
  %29 = load ptr, ptr %11, align 8, !tbaa !5
  %30 = icmp ne ptr %29, null
  br i1 %30, label %31, label %32

31:                                               ; preds = %9
  br label %33

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

33:                                               ; preds = %31
  %34 = load ptr, ptr %12, align 8, !tbaa !5
  %35 = icmp ne ptr %34, null
  br i1 %35, label %36, label %37

36:                                               ; preds = %33
  br label %38

37:                                               ; preds = %33
  call void @__assert_fail(ptr noundef @.str.2, ptr noundef @.str.1, i32 noundef 186, ptr noundef @__PRETTY_FUNCTION__.copywin) #4
  unreachable

38:                                               ; preds = %36
  %39 = load ptr, ptr %11, align 8, !tbaa !5
  %40 = icmp ne ptr %39, null
  br i1 %40, label %41, label %66

41:                                               ; preds = %38
  %42 = load ptr, ptr %12, align 8, !tbaa !5
  %43 = icmp ne ptr %42, null
  br i1 %43, label %44, label %66

44:                                               ; preds = %41
  %45 = load ptr, ptr %12, align 8, !tbaa !5
  %46 = load ptr, ptr @curscr, align 8, !tbaa !5
  %47 = icmp eq ptr %45, %46
  br i1 %47, label %66, label %48

48:                                               ; preds = %44
  %49 = load i32, ptr %17, align 4, !tbaa !9
  %50 = load ptr, ptr %12, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct._win, ptr %50, i32 0, i32 2
  %52 = load i32, ptr %51, align 8, !tbaa !11
  %53 = icmp sge i32 %49, %52
  br i1 %53, label %66, label %54

54:                                               ; preds = %48
  %55 = load i32, ptr %18, align 4, !tbaa !9
  %56 = load ptr, ptr %12, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct._win, ptr %56, i32 0, i32 3
  %58 = load i32, ptr %57, align 4, !tbaa !15
  %59 = icmp sge i32 %55, %58
  br i1 %59, label %66, label %60

60:                                               ; preds = %54
  %61 = load i32, ptr %15, align 4, !tbaa !9
  %62 = icmp slt i32 %61, 0
  br i1 %62, label %66, label %63

63:                                               ; preds = %60
  %64 = load i32, ptr %16, align 4, !tbaa !9
  %65 = icmp slt i32 %64, 0
  br i1 %65, label %66, label %67

66:                                               ; preds = %63, %60, %54, %48, %44, %41, %38
  store i32 -1, ptr %10, align 4
  store i32 1, ptr %28, align 4
  br label %121

67:                                               ; preds = %63
  %68 = load ptr, ptr %11, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct._win, ptr %68, i32 0, i32 2
  %70 = load i32, ptr %69, align 8, !tbaa !11
  %71 = load i32, ptr %13, align 4, !tbaa !9
  %72 = sub nsw i32 %70, %71
  store i32 %72, ptr %22, align 4, !tbaa !9
  %73 = load ptr, ptr %11, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct._win, ptr %73, i32 0, i32 3
  %75 = load i32, ptr %74, align 4, !tbaa !15
  %76 = load i32, ptr %14, align 4, !tbaa !9
  %77 = sub nsw i32 %75, %76
  store i32 %77, ptr %23, align 4, !tbaa !9
  %78 = load i32, ptr %17, align 4, !tbaa !9
  %79 = load i32, ptr %15, align 4, !tbaa !9
  %80 = sub nsw i32 %78, %79
  %81 = add nsw i32 %80, 1
  store i32 %81, ptr %24, align 4, !tbaa !9
  %82 = load i32, ptr %18, align 4, !tbaa !9
  %83 = load i32, ptr %16, align 4, !tbaa !9
  %84 = sub nsw i32 %82, %83
  %85 = add nsw i32 %84, 1
  store i32 %85, ptr %25, align 4, !tbaa !9
  %86 = load i32, ptr %22, align 4, !tbaa !9
  %87 = load i32, ptr %24, align 4, !tbaa !9
  %88 = icmp slt i32 %86, %87
  br i1 %88, label %89, label %91

89:                                               ; preds = %67
  %90 = load i32, ptr %22, align 4, !tbaa !9
  br label %93

91:                                               ; preds = %67
  %92 = load i32, ptr %24, align 4, !tbaa !9
  br label %93

93:                                               ; preds = %91, %89
  %94 = phi i32 [ %90, %89 ], [ %92, %91 ]
  store i32 %94, ptr %26, align 4, !tbaa !9
  %95 = load i32, ptr %23, align 4, !tbaa !9
  %96 = load i32, ptr %25, align 4, !tbaa !9
  %97 = icmp slt i32 %95, %96
  br i1 %97, label %98, label %100

98:                                               ; preds = %93
  %99 = load i32, ptr %23, align 4, !tbaa !9
  br label %102

100:                                              ; preds = %93
  %101 = load i32, ptr %25, align 4, !tbaa !9
  br label %102

102:                                              ; preds = %100, %98
  %103 = phi i32 [ %99, %98 ], [ %101, %100 ]
  store i32 %103, ptr %27, align 4, !tbaa !9
  %104 = load i32, ptr %13, align 4, !tbaa !9
  %105 = load i32, ptr %26, align 4, !tbaa !9
  %106 = add nsw i32 %104, %105
  store i32 %106, ptr %21, align 4, !tbaa !9
  %107 = load i32, ptr %14, align 4, !tbaa !9
  %108 = load i32, ptr %27, align 4, !tbaa !9
  %109 = add nsw i32 %107, %108
  store i32 %109, ptr %20, align 4, !tbaa !9
  %110 = load ptr, ptr %11, align 8, !tbaa !5
  %111 = load ptr, ptr %12, align 8, !tbaa !5
  %112 = load i32, ptr %13, align 4, !tbaa !9
  %113 = load i32, ptr %14, align 4, !tbaa !9
  %114 = load i32, ptr %21, align 4, !tbaa !9
  %115 = load i32, ptr %20, align 4, !tbaa !9
  %116 = load i32, ptr %15, align 4, !tbaa !9
  %117 = load i32, ptr %16, align 4, !tbaa !9
  %118 = load i32, ptr %19, align 4, !tbaa !9
  %119 = icmp ne i32 %118, 0
  %120 = call i32 @_copy_win(ptr noundef %110, ptr noundef %111, i32 noundef %112, i32 noundef %113, i32 noundef %114, i32 noundef %115, i32 noundef %116, i32 noundef %117, i1 noundef zeroext %119)
  store i32 %120, ptr %10, align 4
  store i32 1, ptr %28, align 4
  br label %121

121:                                              ; preds = %102, %66
  call void @llvm.lifetime.end.p0(i64 4, ptr %27) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %26) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %25) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %24) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %23) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %22) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %21) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %20) #3
  %122 = load i32, ptr %10, align 4
  ret i32 %122
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 #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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 8}
!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 = !{!12, !10, i64 12}


; 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 [6 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [93 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [6 x i8], align 1
@__PRETTY_FUNCTION__.copywin = external hidden unnamed_addr constant [73 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 hidden i32 @_copy_win(ptr noundef, ptr noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef, i1 noundef zeroext) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local i32 @copywin(ptr noundef %0, ptr noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4, i32 noundef %5, i32 noundef %6, i32 noundef %7, i32 noundef %8) local_unnamed_addr #1 {
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %10, label %11

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

11:                                               ; preds = %9
  %.not51 = icmp eq ptr %1, null
  br i1 %.not51, label %12, label %13

12:                                               ; preds = %11
  tail call void @__assert_fail(ptr noundef nonnull @.str.2, ptr noundef nonnull @.str.1, i32 noundef 186, ptr noundef nonnull @__PRETTY_FUNCTION__.copywin) #3
  unreachable

13:                                               ; preds = %11
  %14 = load ptr, ptr @curscr, align 8, !tbaa !5
  %15 = icmp eq ptr %14, %1
  br i1 %15, label %40, label %16

16:                                               ; preds = %13
  %17 = getelementptr inbounds i8, ptr %1, i64 8
  %18 = load i32, ptr %17, align 8, !tbaa !9
  %.not52 = icmp sgt i32 %18, %6
  br i1 %.not52, label %19, label %40

19:                                               ; preds = %16
  %20 = getelementptr inbounds i8, ptr %1, i64 12
  %21 = load i32, ptr %20, align 4, !tbaa !14
  %22 = icmp sle i32 %21, %7
  %23 = or i32 %5, %4
  %24 = icmp slt i32 %23, 0
  %or.cond5 = or i1 %24, %22
  br i1 %or.cond5, label %40, label %25

25:                                               ; preds = %19
  %26 = getelementptr inbounds i8, ptr %0, i64 8
  %27 = load i32, ptr %26, align 8, !tbaa !9
  %28 = sub nsw i32 %27, %2
  %29 = getelementptr inbounds i8, ptr %0, i64 12
  %30 = load i32, ptr %29, align 4, !tbaa !14
  %31 = sub nsw i32 %30, %3
  %reass.sub = sub i32 %6, %4
  %32 = add i32 %reass.sub, 1
  %reass.sub54 = sub i32 %7, %5
  %33 = add i32 %reass.sub54, 1
  %34 = tail call i32 @llvm.smin.i32(i32 %28, i32 %32)
  %35 = tail call i32 @llvm.smin.i32(i32 %31, i32 %33)
  %36 = add nsw i32 %34, %2
  %37 = add nsw i32 %35, %3
  %38 = icmp ne i32 %8, 0
  %39 = tail call i32 @_copy_win(ptr noundef nonnull %0, ptr noundef nonnull %1, i32 noundef %2, i32 noundef %3, i32 noundef %36, i32 noundef %37, i32 noundef %4, i32 noundef %5, i1 noundef zeroext %38)
  br label %40

40:                                               ; preds = %13, %16, %19, %25
  %.0 = phi i32 [ %39, %25 ], [ -1, %19 ], [ -1, %16 ], [ -1, %13 ]
  ret i32 %.0
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.smin.i32(i32, i32) #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 speculatable willreturn memory(none) }
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, !11, i64 8}
!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, !11, i64 12}


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