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

; 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.panel = type { ptr, i32, i32, i32, i32, ptr, ptr, ptr, ptr }

@.str.1 = external hidden unnamed_addr constant [91 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [4 x i8], align 1
@__PRETTY_FUNCTION__.new_panel = external hidden unnamed_addr constant [27 x i8], align 1
@_stdscr_pseudo_panel = external hidden global %struct.panel, align 8
@stdscr = external global ptr, align 8
@LINES = external global i32, align 4
@COLS = external global i32, align 4
@.str.3 = external hidden unnamed_addr constant [7 x i8], align 1

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

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

declare i32 @getbegy(ptr noundef) #2

declare i32 @getbegx(ptr noundef) #2

declare i32 @getmaxy(ptr noundef) #2

declare i32 @getmaxx(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
define dso_local ptr @new_panel(ptr noundef %0) #3 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #5
  %8 = load ptr, ptr %3, align 8, !tbaa !5
  %9 = icmp ne ptr %8, null
  br i1 %9, label %10, label %11

10:                                               ; preds = %1
  br label %12

11:                                               ; preds = %1
  call void @__assert_fail(ptr noundef @.str.2, ptr noundef @.str.1, i32 noundef 520, ptr noundef @__PRETTY_FUNCTION__.new_panel) #6
  unreachable

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

15:                                               ; preds = %12
  store ptr null, ptr %2, align 8
  store i32 1, ptr %5, align 4
  br label %69

16:                                               ; preds = %12
  %17 = call noalias ptr @malloc(i64 noundef 56) #7
  store ptr %17, ptr %4, align 8, !tbaa !5
  %18 = load ptr, ptr @_stdscr_pseudo_panel, align 8, !tbaa !9
  %19 = icmp ne ptr %18, null
  br i1 %19, label %24, label %20

20:                                               ; preds = %16
  %21 = load ptr, ptr @stdscr, align 8, !tbaa !5
  store ptr %21, ptr @_stdscr_pseudo_panel, align 8, !tbaa !9
  store i32 0, ptr getelementptr inbounds (%struct.panel, ptr @_stdscr_pseudo_panel, i32 0, i32 1), align 8, !tbaa !12
  store i32 0, ptr getelementptr inbounds (%struct.panel, ptr @_stdscr_pseudo_panel, i32 0, i32 3), align 8, !tbaa !13
  %22 = load i32, ptr @LINES, align 4, !tbaa !14
  store i32 %22, ptr getelementptr inbounds (%struct.panel, ptr @_stdscr_pseudo_panel, i32 0, i32 2), align 4, !tbaa !15
  %23 = load i32, ptr @COLS, align 4, !tbaa !14
  store i32 %23, ptr getelementptr inbounds (%struct.panel, ptr @_stdscr_pseudo_panel, i32 0, i32 4), align 4, !tbaa !16
  store ptr @.str.3, ptr getelementptr inbounds (%struct.panel, ptr @_stdscr_pseudo_panel, i32 0, i32 7), align 8, !tbaa !17
  store ptr null, ptr getelementptr inbounds (%struct.panel, ptr @_stdscr_pseudo_panel, i32 0, i32 8), align 8, !tbaa !18
  br label %24

24:                                               ; preds = %20, %16
  %25 = load ptr, ptr %4, align 8, !tbaa !5
  %26 = icmp ne ptr %25, null
  br i1 %26, label %27, label %67

27:                                               ; preds = %24
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #5
  %28 = load ptr, ptr %3, align 8, !tbaa !5
  %29 = load ptr, ptr %4, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.panel, ptr %29, i32 0, i32 0
  store ptr %28, ptr %30, align 8, !tbaa !9
  %31 = load ptr, ptr %4, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.panel, ptr %31, i32 0, i32 6
  store ptr null, ptr %32, align 8, !tbaa !19
  %33 = load ptr, ptr %4, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.panel, ptr %33, i32 0, i32 5
  store ptr null, ptr %34, align 8, !tbaa !20
  %35 = load ptr, ptr %3, align 8, !tbaa !5
  %36 = call i32 @getbegy(ptr noundef %35)
  %37 = load ptr, ptr %4, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.panel, ptr %37, i32 0, i32 1
  store i32 %36, ptr %38, align 8, !tbaa !12
  %39 = load ptr, ptr %3, align 8, !tbaa !5
  %40 = call i32 @getbegx(ptr noundef %39)
  %41 = load ptr, ptr %4, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.panel, ptr %41, i32 0, i32 3
  store i32 %40, ptr %42, align 8, !tbaa !13
  %43 = load ptr, ptr %3, align 8, !tbaa !5
  %44 = call i32 @getmaxy(ptr noundef %43)
  store i32 %44, ptr %6, align 4, !tbaa !14
  %45 = load ptr, ptr %3, align 8, !tbaa !5
  %46 = call i32 @getmaxx(ptr noundef %45)
  store i32 %46, ptr %7, align 4, !tbaa !14
  %47 = load ptr, ptr %4, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.panel, ptr %47, i32 0, i32 1
  %49 = load i32, ptr %48, align 8, !tbaa !12
  %50 = load i32, ptr %6, align 4, !tbaa !14
  %51 = add nsw i32 %49, %50
  %52 = load ptr, ptr %4, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.panel, ptr %52, i32 0, i32 2
  store i32 %51, ptr %53, align 4, !tbaa !15
  %54 = load ptr, ptr %4, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.panel, ptr %54, i32 0, i32 3
  %56 = load i32, ptr %55, align 8, !tbaa !13
  %57 = load i32, ptr %7, align 4, !tbaa !14
  %58 = add nsw i32 %56, %57
  %59 = load ptr, ptr %4, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.panel, ptr %59, i32 0, i32 4
  store i32 %58, ptr %60, align 4, !tbaa !16
  %61 = load ptr, ptr %4, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.panel, ptr %61, i32 0, i32 7
  store ptr null, ptr %62, align 8, !tbaa !17
  %63 = load ptr, ptr %4, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.panel, ptr %63, i32 0, i32 8
  store ptr null, ptr %64, align 8, !tbaa !18
  %65 = load ptr, ptr %4, align 8, !tbaa !5
  %66 = call i32 @show_panel(ptr noundef %65)
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #5
  br label %67

67:                                               ; preds = %27, %24
  %68 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %68, ptr %2, align 8
  store i32 1, ptr %5, align 4
  br label %69

69:                                               ; preds = %67, %15
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #5
  %70 = load ptr, ptr %2, align 8
  ret ptr %70
}

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

; Function Attrs: nounwind uwtable
declare dso_local i32 @show_panel(ptr 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 #4 = { nounwind allocsize(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 #5 = { nounwind }
attributes #6 = { noreturn nounwind }
attributes #7 = { nounwind allocsize(0) }

!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, !6, i64 0}
!10 = !{!"panel", !6, i64 0, !11, i64 8, !11, i64 12, !11, i64 16, !11, i64 20, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !11, i64 8}
!13 = !{!10, !11, i64 16}
!14 = !{!11, !11, i64 0}
!15 = !{!10, !11, i64 12}
!16 = !{!10, !11, i64 20}
!17 = !{!10, !6, i64 40}
!18 = !{!10, !6, i64 48}
!19 = !{!10, !6, i64 32}
!20 = !{!10, !6, i64 24}


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

%struct.panel = type { ptr, i32, i32, i32, i32, ptr, ptr, ptr, ptr }

@.str.1 = external hidden unnamed_addr constant [91 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [4 x i8], align 1
@__PRETTY_FUNCTION__.new_panel = external hidden unnamed_addr constant [27 x i8], align 1
@_stdscr_pseudo_panel = external hidden local_unnamed_addr global %struct.panel, align 8
@stdscr = external local_unnamed_addr global ptr, align 8
@LINES = external local_unnamed_addr global i32, align 4
@COLS = external local_unnamed_addr global i32, align 4
@.str.3 = external hidden unnamed_addr constant [7 x i8], align 1

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

declare i32 @getbegy(ptr noundef) local_unnamed_addr #1

declare i32 @getbegx(ptr noundef) local_unnamed_addr #1

declare i32 @getmaxy(ptr noundef) local_unnamed_addr #1

declare i32 @getmaxx(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local noundef ptr @new_panel(ptr noundef %0) local_unnamed_addr #2 {
  %.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.2, ptr noundef nonnull @.str.1, i32 noundef 520, ptr noundef nonnull @__PRETTY_FUNCTION__.new_panel) #5
  unreachable

3:                                                ; preds = %1
  %4 = tail call noalias dereferenceable_or_null(56) ptr @malloc(i64 noundef 56) #6
  %5 = load ptr, ptr @_stdscr_pseudo_panel, align 8, !tbaa !5
  %.not25 = icmp eq ptr %5, null
  br i1 %.not25, label %6, label %10

6:                                                ; preds = %3
  %7 = load ptr, ptr @stdscr, align 8, !tbaa !11
  store ptr %7, ptr @_stdscr_pseudo_panel, align 8, !tbaa !5
  store i32 0, ptr getelementptr inbounds (i8, ptr @_stdscr_pseudo_panel, i64 8), align 8, !tbaa !12
  store i32 0, ptr getelementptr inbounds (i8, ptr @_stdscr_pseudo_panel, i64 16), align 8, !tbaa !13
  %8 = load i32, ptr @LINES, align 4, !tbaa !14
  store i32 %8, ptr getelementptr inbounds (i8, ptr @_stdscr_pseudo_panel, i64 12), align 4, !tbaa !15
  %9 = load i32, ptr @COLS, align 4, !tbaa !14
  store i32 %9, ptr getelementptr inbounds (i8, ptr @_stdscr_pseudo_panel, i64 20), align 4, !tbaa !16
  store ptr @.str.3, ptr getelementptr inbounds (i8, ptr @_stdscr_pseudo_panel, i64 40), align 8, !tbaa !17
  store ptr null, ptr getelementptr inbounds (i8, ptr @_stdscr_pseudo_panel, i64 48), align 8, !tbaa !18
  br label %10

10:                                               ; preds = %6, %3
  %.not26 = icmp eq ptr %4, null
  br i1 %.not26, label %25, label %11

11:                                               ; preds = %10
  store ptr %0, ptr %4, align 8, !tbaa !5
  %12 = getelementptr inbounds i8, ptr %4, i64 24
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %12, i8 0, i64 16, i1 false)
  %13 = tail call i32 @getbegy(ptr noundef nonnull %0) #7
  %14 = getelementptr inbounds i8, ptr %4, i64 8
  store i32 %13, ptr %14, align 8, !tbaa !12
  %15 = tail call i32 @getbegx(ptr noundef nonnull %0) #7
  %16 = getelementptr inbounds i8, ptr %4, i64 16
  store i32 %15, ptr %16, align 8, !tbaa !13
  %17 = tail call i32 @getmaxy(ptr noundef nonnull %0) #7
  %18 = tail call i32 @getmaxx(ptr noundef nonnull %0) #7
  %19 = add nsw i32 %13, %17
  %20 = getelementptr inbounds i8, ptr %4, i64 12
  store i32 %19, ptr %20, align 4, !tbaa !15
  %21 = add nsw i32 %15, %18
  %22 = getelementptr inbounds i8, ptr %4, i64 20
  store i32 %21, ptr %22, align 4, !tbaa !16
  %23 = getelementptr inbounds i8, ptr %4, i64 40
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %23, i8 0, i64 16, i1 false)
  %24 = tail call i32 @show_panel(ptr noundef nonnull %4)
  br label %25

25:                                               ; preds = %10, %11
  ret ptr %4
}

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

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #4

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 = { "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 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) 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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #5 = { noreturn nounwind }
attributes #6 = { nounwind allocsize(0) }
attributes #7 = { 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 0}
!6 = !{!"panel", !7, i64 0, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20, !7, i64 24, !7, i64 32, !7, i64 40, !7, i64 48}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!7, !7, i64 0}
!12 = !{!6, !10, i64 8}
!13 = !{!6, !10, i64 16}
!14 = !{!10, !10, i64 0}
!15 = !{!6, !10, i64 12}
!16 = !{!6, !10, i64 20}
!17 = !{!6, !7, i64 40}
!18 = !{!6, !7, i64 48}


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