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

@_bottom_panel = external hidden global ptr, align 8
@_stdscr_pseudo_panel = external hidden global %struct.panel, align 8
@stdscr = 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: nounwind uwtable
declare hidden void @_override(ptr noundef, i32 noundef) #1

; 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 void @update_panels() #1 {
  %1 = alloca ptr, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %1) #3
  %2 = load ptr, ptr @_bottom_panel, align 8, !tbaa !5
  store ptr %2, ptr %1, align 8, !tbaa !5
  br label %3

3:                                                ; preds = %6, %0
  %4 = load ptr, ptr %1, align 8, !tbaa !5
  %5 = icmp ne ptr %4, null
  br i1 %5, label %6, label %11

6:                                                ; preds = %3
  %7 = load ptr, ptr %1, align 8, !tbaa !5
  call void @_override(ptr noundef %7, i32 noundef -1)
  %8 = load ptr, ptr %1, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.panel, ptr %8, i32 0, i32 6
  %10 = load ptr, ptr %9, align 8, !tbaa !9
  store ptr %10, ptr %1, align 8, !tbaa !5
  br label %3, !llvm.loop !12

11:                                               ; preds = %3
  %12 = load ptr, ptr @stdscr, align 8, !tbaa !5
  %13 = call zeroext i1 @is_wintouched(ptr noundef %12)
  br i1 %13, label %14, label %17

14:                                               ; preds = %11
  %15 = load ptr, ptr @_stdscr_pseudo_panel, align 8, !tbaa !14
  %16 = call i32 @wnoutrefresh(ptr noundef %15)
  br label %17

17:                                               ; preds = %14, %11
  %18 = load ptr, ptr @_bottom_panel, align 8, !tbaa !5
  store ptr %18, ptr %1, align 8, !tbaa !5
  br label %19

19:                                               ; preds = %37, %17
  %20 = load ptr, ptr %1, align 8, !tbaa !5
  %21 = icmp ne ptr %20, null
  br i1 %21, label %22, label %41

22:                                               ; preds = %19
  %23 = load ptr, ptr %1, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.panel, ptr %23, i32 0, i32 0
  %25 = load ptr, ptr %24, align 8, !tbaa !14
  %26 = call zeroext i1 @is_wintouched(ptr noundef %25)
  br i1 %26, label %32, label %27

27:                                               ; preds = %22
  %28 = load ptr, ptr %1, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.panel, ptr %28, i32 0, i32 6
  %30 = load ptr, ptr %29, align 8, !tbaa !9
  %31 = icmp ne ptr %30, null
  br i1 %31, label %37, label %32

32:                                               ; preds = %27, %22
  %33 = load ptr, ptr %1, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.panel, ptr %33, i32 0, i32 0
  %35 = load ptr, ptr %34, align 8, !tbaa !14
  %36 = call i32 @wnoutrefresh(ptr noundef %35)
  br label %37

37:                                               ; preds = %32, %27
  %38 = load ptr, ptr %1, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.panel, ptr %38, i32 0, i32 6
  %40 = load ptr, ptr %39, align 8, !tbaa !9
  store ptr %40, ptr %1, align 8, !tbaa !5
  br label %19, !llvm.loop !15

41:                                               ; preds = %19
  call void @llvm.lifetime.end.p0(i64 8, ptr %1) #3
  ret void
}

declare zeroext i1 @is_wintouched(ptr noundef) #2

declare i32 @wnoutrefresh(ptr noundef) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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, !6, i64 32}
!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 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = !{!10, !6, i64 0}
!15 = distinct !{!15, !13}


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

@_bottom_panel = external hidden local_unnamed_addr global ptr, align 8
@_stdscr_pseudo_panel = external hidden local_unnamed_addr global %struct.panel, align 8
@stdscr = external local_unnamed_addr global ptr, align 8

; Function Attrs: nounwind uwtable
declare hidden void @_override(ptr noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @update_panels() local_unnamed_addr #0 {
  %.010 = load ptr, ptr @_bottom_panel, align 8, !tbaa !5
  %.not11 = icmp eq ptr %.010, null
  br i1 %.not11, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %0, %.lr.ph
  %.012 = phi ptr [ %.0, %.lr.ph ], [ %.010, %0 ]
  tail call void @_override(ptr noundef nonnull %.012, i32 noundef -1)
  %1 = getelementptr inbounds i8, ptr %.012, i64 32
  %.0 = load ptr, ptr %1, align 8, !tbaa !5
  %.not = icmp eq ptr %.0, null
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !9

._crit_edge:                                      ; preds = %.lr.ph, %0
  %2 = load ptr, ptr @stdscr, align 8, !tbaa !5
  %3 = tail call zeroext i1 @is_wintouched(ptr noundef %2) #2
  br i1 %3, label %4, label %7

4:                                                ; preds = %._crit_edge
  %5 = load ptr, ptr @_stdscr_pseudo_panel, align 8, !tbaa !11
  %6 = tail call i32 @wnoutrefresh(ptr noundef %5) #2
  br label %7

7:                                                ; preds = %4, %._crit_edge
  %.113 = load ptr, ptr @_bottom_panel, align 8, !tbaa !5
  %.not814 = icmp eq ptr %.113, null
  br i1 %.not814, label %._crit_edge18, label %.lr.ph17

.lr.ph17:                                         ; preds = %7, %16
  %.115 = phi ptr [ %.1, %16 ], [ %.113, %7 ]
  %8 = load ptr, ptr %.115, align 8, !tbaa !11
  %9 = tail call zeroext i1 @is_wintouched(ptr noundef %8) #2
  br i1 %9, label %13, label %10

10:                                               ; preds = %.lr.ph17
  %11 = getelementptr inbounds i8, ptr %.115, i64 32
  %12 = load ptr, ptr %11, align 8, !tbaa !5
  %.not9 = icmp eq ptr %12, null
  br i1 %.not9, label %13, label %16

13:                                               ; preds = %10, %.lr.ph17
  %14 = load ptr, ptr %.115, align 8, !tbaa !11
  %15 = tail call i32 @wnoutrefresh(ptr noundef %14) #2
  %.phi.trans.insert = getelementptr inbounds i8, ptr %.115, i64 32
  %.1.pre = load ptr, ptr %.phi.trans.insert, align 8, !tbaa !5
  br label %16

16:                                               ; preds = %13, %10
  %.1 = phi ptr [ %.1.pre, %13 ], [ %12, %10 ]
  %.not8 = icmp eq ptr %.1, null
  br i1 %.not8, label %._crit_edge18, label %.lr.ph17, !llvm.loop !14

._crit_edge18:                                    ; preds = %16, %7
  ret void
}

declare zeroext i1 @is_wintouched(ptr noundef) local_unnamed_addr #1

declare i32 @wnoutrefresh(ptr noundef) local_unnamed_addr #1

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 = { "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 }

!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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!12, !6, i64 0}
!12 = !{!"panel", !6, i64 0, !13, i64 8, !13, i64 12, !13, i64 16, !13, i64 20, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48}
!13 = !{!"int", !7, i64 0}
!14 = distinct !{!14, !10}


; Effective O3 passes: BDCEPass,EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass