; 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.Game = type { i32, [8 x [8 x i16]], i32, i32, i32 }

@win_board = external dso_local global ptr, align 8
@.str = external hidden unnamed_addr constant [5 x i8], align 1

; 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

; Function Attrs: nounwind uwtable
declare dso_local i32 @get_piece_type(i32 noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local signext i8 @get_piece_repr(i32 noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local void @transform_to_win(ptr noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local i32 @get_tile_attr(ptr noundef byval(%struct.Game) align 8, i32 noundef, i32 noundef, i1 noundef zeroext, i1 noundef zeroext, i1 noundef zeroext, i32 noundef) #1

; Function Attrs: nounwind uwtable
define dso_local void @draw_board_tile(ptr noundef byval(%struct.Game) align 8 %0, i32 noundef %1, i32 noundef %2, i1 noundef zeroext %3, i1 noundef zeroext %4, i1 noundef zeroext %5, i32 noundef %6) #1 {
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i8, align 1
  %11 = alloca i8, align 1
  %12 = alloca i8, align 1
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  %15 = alloca i32, align 4
  %16 = alloca i8, align 1
  store i32 %1, ptr %8, align 4, !tbaa !5
  store i32 %2, ptr %9, align 4, !tbaa !5
  %17 = zext i1 %3 to i8
  store i8 %17, ptr %10, align 1, !tbaa !9
  %18 = zext i1 %4 to i8
  store i8 %18, ptr %11, align 1, !tbaa !9
  %19 = zext i1 %5 to i8
  store i8 %19, ptr %12, align 1, !tbaa !9
  store i32 %6, ptr %13, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #3
  %20 = load i32, ptr %8, align 4, !tbaa !5
  %21 = load i32, ptr %9, align 4, !tbaa !5
  %22 = load i8, ptr %10, align 1, !tbaa !9, !range !11, !noundef !12
  %23 = trunc i8 %22 to i1
  %24 = load i8, ptr %11, align 1, !tbaa !9, !range !11, !noundef !12
  %25 = trunc i8 %24 to i1
  %26 = load i8, ptr %12, align 1, !tbaa !9, !range !11, !noundef !12
  %27 = trunc i8 %26 to i1
  %28 = load i32, ptr %13, align 4, !tbaa !5
  %29 = call i32 @get_tile_attr(ptr noundef byval(%struct.Game) align 8 %0, i32 noundef %20, i32 noundef %21, i1 noundef zeroext %23, i1 noundef zeroext %25, i1 noundef zeroext %27, i32 noundef %28)
  store i32 %29, ptr %14, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #3
  %30 = getelementptr inbounds %struct.Game, ptr %0, i32 0, i32 1
  %31 = load i32, ptr %9, align 4, !tbaa !5
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds [8 x [8 x i16]], ptr %30, i64 0, i64 %32
  %34 = load i32, ptr %8, align 4, !tbaa !5
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds [8 x i16], ptr %33, i64 0, i64 %35
  %37 = load i16, ptr %36, align 2, !tbaa !13
  %38 = sext i16 %37 to i32
  %39 = call i32 @get_piece_type(i32 noundef %38)
  store i32 %39, ptr %15, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 1, ptr %16) #3
  %40 = load i32, ptr %15, align 4, !tbaa !5
  %41 = call signext i8 @get_piece_repr(i32 noundef %40)
  store i8 %41, ptr %16, align 1, !tbaa !15
  %42 = load ptr, ptr @win_board, align 8, !tbaa !16
  %43 = load i32, ptr %14, align 4, !tbaa !5
  %44 = call i32 @wattr_on(ptr noundef %42, i32 noundef %43, ptr noundef null)
  call void @transform_to_win(ptr noundef %8, ptr noundef %9)
  %45 = load ptr, ptr @win_board, align 8, !tbaa !16
  %46 = load i32, ptr %9, align 4, !tbaa !5
  %47 = load i32, ptr %8, align 4, !tbaa !5
  %48 = load i8, ptr %16, align 1, !tbaa !15
  %49 = sext i8 %48 to i32
  %50 = call i32 (ptr, i32, i32, ptr, ...) @mvwprintw(ptr noundef %45, i32 noundef %46, i32 noundef %47, ptr noundef @.str, i32 noundef %49)
  %51 = load ptr, ptr @win_board, align 8, !tbaa !16
  %52 = load i32, ptr %14, align 4, !tbaa !5
  %53 = call i32 @wattr_off(ptr noundef %51, i32 noundef %52, ptr noundef null)
  call void @llvm.lifetime.end.p0(i64 1, ptr %16) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #3
  ret void
}

declare i32 @wattr_on(ptr noundef, i32 noundef, ptr noundef) #2

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

declare i32 @wattr_off(ptr noundef, i32 noundef, 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"_Bool", !7, i64 0}
!11 = !{i8 0, i8 2}
!12 = !{}
!13 = !{!14, !14, i64 0}
!14 = !{!"short", !7, i64 0}
!15 = !{!7, !7, i64 0}
!16 = !{!17, !17, i64 0}
!17 = !{!"any pointer", !7, i64 0}


; 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.Game = type { i32, [8 x [8 x i16]], i32, i32, i32 }

@win_board = external dso_local local_unnamed_addr global ptr, align 8
@.str = external hidden unnamed_addr constant [5 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local i32 @get_piece_type(i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local signext i8 @get_piece_repr(i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local void @transform_to_win(ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local i32 @get_tile_attr(ptr noundef byval(%struct.Game) align 8, i32 noundef, i32 noundef, i1 noundef zeroext, i1 noundef zeroext, i1 noundef zeroext, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @draw_board_tile(ptr noundef byval(%struct.Game) align 8 %0, i32 noundef %1, i32 noundef %2, i1 noundef zeroext %3, i1 noundef zeroext %4, i1 noundef zeroext %5, i32 noundef %6) local_unnamed_addr #0 {
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  store i32 %1, ptr %8, align 4, !tbaa !5
  store i32 %2, ptr %9, align 4, !tbaa !5
  %10 = tail call i32 @get_tile_attr(ptr noundef nonnull byval(%struct.Game) align 8 %0, i32 noundef %1, i32 noundef %2, i1 noundef zeroext %3, i1 noundef zeroext %4, i1 noundef zeroext %5, i32 noundef %6)
  %11 = getelementptr inbounds i8, ptr %0, i64 4
  %12 = sext i32 %2 to i64
  %13 = sext i32 %1 to i64
  %14 = getelementptr inbounds [8 x [8 x i16]], ptr %11, i64 0, i64 %12, i64 %13
  %15 = load i16, ptr %14, align 2, !tbaa !9
  %16 = sext i16 %15 to i32
  %17 = tail call i32 @get_piece_type(i32 noundef %16)
  %18 = tail call signext i8 @get_piece_repr(i32 noundef %17)
  %19 = load ptr, ptr @win_board, align 8, !tbaa !11
  %20 = tail call i32 @wattr_on(ptr noundef %19, i32 noundef %10, ptr noundef null) #2
  call void @transform_to_win(ptr noundef nonnull %8, ptr noundef nonnull %9)
  %21 = load ptr, ptr @win_board, align 8, !tbaa !11
  %22 = load i32, ptr %9, align 4, !tbaa !5
  %23 = load i32, ptr %8, align 4, !tbaa !5
  %24 = sext i8 %18 to i32
  %25 = call i32 (ptr, i32, i32, ptr, ...) @mvwprintw(ptr noundef %21, i32 noundef %22, i32 noundef %23, ptr noundef nonnull @.str, i32 noundef %24) #2
  %26 = load ptr, ptr @win_board, align 8, !tbaa !11
  %27 = call i32 @wattr_off(ptr noundef %26, i32 noundef %10, ptr noundef null) #2
  ret void
}

declare i32 @wattr_on(ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #1

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

declare i32 @wattr_off(ptr noundef, i32 noundef, 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"short", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"any pointer", !7, i64 0}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,SROAPass,TailCallElimPass