; LLVM IR from AlgoGenesis/C :: Backtracking Algorithms/Chess-In-Terminal/src (main)

; 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_st = type { i16, i16, i16, i16, i16, i16, i16, i32, i32, i8, i8, i8, i8, i8, i8, i8, i8, i8, i32, ptr, i16, i16, i32, i32, ptr, %struct.pdat, i16 }
%struct.pdat = type { i16, i16, i16, i16, i16, i16 }

@.str.5 = external hidden unnamed_addr constant [3 x i8], align 1
@win_info = external dso_local global ptr, align 8
@info_ptr = external dso_local global ptr, align 8
@info_axis_0_size = external dso_local global i32, align 4

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

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

declare i32 @mvwprintw(ptr noundef, i32 noundef, i32 noundef, ptr noundef, ...) #1

declare i32 @wrefresh(ptr noundef) #1

declare i32 @wborder(ptr noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef) #1

declare i32 @wclear(ptr noundef) #1

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

6:                                                ; preds = %0
  %7 = load ptr, ptr @win_info, align 8, !tbaa !9
  %8 = getelementptr inbounds %struct._win_st, ptr %7, i32 0, i32 2
  %9 = load i16, ptr %8, align 4, !tbaa !11
  %10 = sext i16 %9 to i32
  %11 = add nsw i32 %10, 1
  br label %13

12:                                               ; preds = %0
  br label %13

13:                                               ; preds = %12, %6
  %14 = phi i32 [ %11, %6 ], [ -1, %12 ]
  %15 = sub nsw i32 %14, 2
  store i32 %15, ptr %3, align 4, !tbaa !5
  %16 = load i32, ptr @info_axis_0_size, align 4, !tbaa !5
  %17 = load i32, ptr %3, align 4, !tbaa !5
  %18 = icmp sgt i32 %16, %17
  br i1 %18, label %19, label %23

19:                                               ; preds = %13
  %20 = load i32, ptr @info_axis_0_size, align 4, !tbaa !5
  %21 = load i32, ptr %3, align 4, !tbaa !5
  %22 = sub nsw i32 %20, %21
  store i32 %22, ptr %2, align 4, !tbaa !5
  br label %23

23:                                               ; preds = %19, %13
  %24 = load ptr, ptr @win_info, align 8, !tbaa !9
  %25 = call i32 @wclear(ptr noundef %24)
  %26 = load ptr, ptr @win_info, align 8, !tbaa !9
  %27 = call i32 @wborder(ptr noundef %26, i32 noundef 0, i32 noundef 0, i32 noundef 0, i32 noundef 0, i32 noundef 0, i32 noundef 0, i32 noundef 0, i32 noundef 0)
  br label %28

28:                                               ; preds = %40, %23
  %29 = load i32, ptr %2, align 4, !tbaa !5
  %30 = load i32, ptr %1, align 4, !tbaa !5
  %31 = add nsw i32 %29, %30
  %32 = load i32, ptr @info_axis_0_size, align 4, !tbaa !5
  %33 = icmp slt i32 %31, %32
  br i1 %33, label %34, label %38

34:                                               ; preds = %28
  %35 = load i32, ptr %1, align 4, !tbaa !5
  %36 = load i32, ptr %3, align 4, !tbaa !5
  %37 = icmp slt i32 %35, %36
  br label %38

38:                                               ; preds = %34, %28
  %39 = phi i1 [ false, %28 ], [ %37, %34 ]
  br i1 %39, label %40, label %54

40:                                               ; preds = %38
  %41 = load ptr, ptr @win_info, align 8, !tbaa !9
  %42 = load i32, ptr %1, align 4, !tbaa !5
  %43 = add nsw i32 %42, 1
  %44 = load ptr, ptr @info_ptr, align 8, !tbaa !9
  %45 = load i32, ptr %2, align 4, !tbaa !5
  %46 = load i32, ptr %1, align 4, !tbaa !5
  %47 = add nsw i32 %45, %46
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds ptr, ptr %44, i64 %48
  %50 = load ptr, ptr %49, align 8, !tbaa !9
  %51 = call i32 (ptr, i32, i32, ptr, ...) @mvwprintw(ptr noundef %41, i32 noundef %43, i32 noundef 1, ptr noundef @.str.5, ptr noundef %50)
  %52 = load i32, ptr %1, align 4, !tbaa !5
  %53 = add nsw i32 %52, 1
  store i32 %53, ptr %1, align 4, !tbaa !5
  br label %28, !llvm.loop !16

54:                                               ; preds = %38
  %55 = load ptr, ptr @win_info, align 8, !tbaa !9
  %56 = call i32 @wrefresh(ptr noundef %55)
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #3
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !13, i64 4}
!12 = !{!"_win_st", !13, i64 0, !13, i64 2, !13, i64 4, !13, i64 6, !13, i64 8, !13, i64 10, !13, i64 12, !6, i64 16, !6, i64 20, !14, i64 24, !14, i64 25, !14, i64 26, !14, i64 27, !14, i64 28, !14, i64 29, !14, i64 30, !14, i64 31, !14, i64 32, !6, i64 36, !10, i64 40, !13, i64 48, !13, i64 50, !6, i64 52, !6, i64 56, !10, i64 64, !15, i64 72, !13, i64 84}
!13 = !{!"short", !7, i64 0}
!14 = !{!"_Bool", !7, i64 0}
!15 = !{!"pdat", !13, i64 0, !13, i64 2, !13, i64 4, !13, i64 6, !13, i64 8, !13, i64 10}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}


; 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.5 = external hidden unnamed_addr constant [3 x i8], align 1
@win_info = external dso_local local_unnamed_addr global ptr, align 8
@info_ptr = external dso_local local_unnamed_addr global ptr, align 8
@info_axis_0_size = external dso_local local_unnamed_addr global i32, align 4

declare i32 @mvwprintw(ptr noundef, i32 noundef, i32 noundef, ptr noundef, ...) local_unnamed_addr #0

declare i32 @wrefresh(ptr noundef) local_unnamed_addr #0

declare i32 @wborder(ptr noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #0

declare i32 @wclear(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @update_info_gui() local_unnamed_addr #1 {
  %1 = load ptr, ptr @win_info, align 8, !tbaa !5
  %.not = icmp eq ptr %1, null
  br i1 %.not, label %7, label %2

2:                                                ; preds = %0
  %3 = getelementptr inbounds i8, ptr %1, i64 4
  %4 = load i16, ptr %3, align 4, !tbaa !9
  %5 = sext i16 %4 to i32
  %6 = add nsw i32 %5, -1
  br label %7

7:                                                ; preds = %0, %2
  %8 = phi i32 [ %6, %2 ], [ -3, %0 ]
  %9 = load i32, ptr @info_axis_0_size, align 4, !tbaa !15
  %10 = icmp sgt i32 %9, %8
  %11 = sub nsw i32 %9, %8
  %spec.select = select i1 %10, i32 %11, i32 0
  %12 = tail call i32 @wclear(ptr noundef %1) #2
  %13 = load ptr, ptr @win_info, align 8, !tbaa !5
  %14 = tail call i32 @wborder(ptr noundef %13, i32 noundef 0, i32 noundef 0, i32 noundef 0, i32 noundef 0, i32 noundef 0, i32 noundef 0, i32 noundef 0, i32 noundef 0) #2
  %15 = load i32, ptr @info_axis_0_size, align 4, !tbaa !15
  %16 = icmp slt i32 %spec.select, %15
  %17 = icmp sgt i32 %8, 0
  %18 = and i1 %17, %16
  br i1 %18, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %7
  %19 = zext nneg i32 %8 to i64
  %20 = sext i32 %spec.select to i64
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next, %.lr.ph ]
  %21 = load ptr, ptr @win_info, align 8, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %22 = load ptr, ptr @info_ptr, align 8, !tbaa !5
  %23 = getelementptr ptr, ptr %22, i64 %indvars.iv
  %24 = getelementptr ptr, ptr %23, i64 %20
  %25 = load ptr, ptr %24, align 8, !tbaa !5
  %26 = trunc nuw nsw i64 %indvars.iv.next to i32
  %27 = tail call i32 (ptr, i32, i32, ptr, ...) @mvwprintw(ptr noundef %21, i32 noundef %26, i32 noundef 1, ptr noundef nonnull @.str.5, ptr noundef %25) #2
  %28 = add nsw i64 %indvars.iv.next, %20
  %29 = load i32, ptr @info_axis_0_size, align 4, !tbaa !15
  %30 = sext i32 %29 to i64
  %31 = icmp slt i64 %28, %30
  %32 = icmp ult i64 %indvars.iv.next, %19
  %33 = and i1 %32, %31
  br i1 %33, label %.lr.ph, label %._crit_edge, !llvm.loop !16

._crit_edge:                                      ; preds = %.lr.ph, %7
  %34 = load ptr, ptr @win_info, align 8, !tbaa !5
  %35 = tail call i32 @wrefresh(ptr noundef %34) #2
  ret void
}

attributes #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 = { 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 = { 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 4}
!10 = !{!"_win_st", !11, i64 0, !11, i64 2, !11, i64 4, !11, i64 6, !11, i64 8, !11, i64 10, !11, i64 12, !12, i64 16, !12, i64 20, !13, i64 24, !13, i64 25, !13, i64 26, !13, i64 27, !13, i64 28, !13, i64 29, !13, i64 30, !13, i64 31, !13, i64 32, !12, i64 36, !6, i64 40, !11, i64 48, !11, i64 50, !12, i64 52, !12, i64 56, !6, i64 64, !14, i64 72, !11, i64 84}
!11 = !{!"short", !7, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!"_Bool", !7, i64 0}
!14 = !{!"pdat", !11, i64 0, !11, i64 2, !11, i64 4, !11, i64 6, !11, i64 8, !11, i64 10}
!15 = !{!12, !12, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}


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