; LLVM IR from totte174/minesolve :: src (board)

; 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.Board = type { i32, i32, i32, i32, [1024 x i32], [1024 x i8], [1024 x i8], i8 }

@.str = external hidden unnamed_addr constant [2 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [2 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
define dso_local void @print_board(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  store i32 0, ptr %3, align 4, !tbaa !9
  br label %6

6:                                                ; preds = %74, %1
  %7 = load i32, ptr %3, align 4, !tbaa !9
  %8 = load ptr, ptr %2, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.Board, ptr %8, i32 0, i32 1
  %10 = load i32, ptr %9, align 4, !tbaa !11
  %11 = icmp slt i32 %7, %10
  br i1 %11, label %13, label %12

12:                                               ; preds = %6
  store i32 2, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  br label %77

13:                                               ; preds = %6
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  store i32 0, ptr %5, align 4, !tbaa !9
  br label %14

14:                                               ; preds = %69, %13
  %15 = load i32, ptr %5, align 4, !tbaa !9
  %16 = load ptr, ptr %2, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.Board, ptr %16, i32 0, i32 0
  %18 = load i32, ptr %17, align 4, !tbaa !14
  %19 = icmp slt i32 %15, %18
  br i1 %19, label %21, label %20

20:                                               ; preds = %14
  store i32 5, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  br label %72

21:                                               ; preds = %14
  %22 = load ptr, ptr %2, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.Board, ptr %22, i32 0, i32 5
  %24 = load i32, ptr %3, align 4, !tbaa !9
  %25 = load ptr, ptr %2, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.Board, ptr %25, i32 0, i32 0
  %27 = load i32, ptr %26, align 4, !tbaa !14
  %28 = mul nsw i32 %24, %27
  %29 = load i32, ptr %5, align 4, !tbaa !9
  %30 = add nsw i32 %28, %29
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds [1024 x i8], ptr %23, i64 0, i64 %31
  %33 = load i8, ptr %32, align 1, !tbaa !15, !range !16, !noundef !17
  %34 = trunc i8 %33 to i1
  br i1 %34, label %35, label %66

35:                                               ; preds = %21
  %36 = load ptr, ptr %2, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.Board, ptr %36, i32 0, i32 4
  %38 = load i32, ptr %3, align 4, !tbaa !9
  %39 = load ptr, ptr %2, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.Board, ptr %39, i32 0, i32 0
  %41 = load i32, ptr %40, align 4, !tbaa !14
  %42 = mul nsw i32 %38, %41
  %43 = load i32, ptr %5, align 4, !tbaa !9
  %44 = add nsw i32 %42, %43
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds [1024 x i32], ptr %37, i64 0, i64 %45
  %47 = load i32, ptr %46, align 4, !tbaa !9
  %48 = icmp eq i32 %47, 0
  br i1 %48, label %49, label %51

49:                                               ; preds = %35
  %50 = call i32 (ptr, ...) @printf(ptr noundef @.str)
  br label %65

51:                                               ; preds = %35
  %52 = load ptr, ptr %2, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.Board, ptr %52, i32 0, i32 4
  %54 = load i32, ptr %3, align 4, !tbaa !9
  %55 = load ptr, ptr %2, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.Board, ptr %55, i32 0, i32 0
  %57 = load i32, ptr %56, align 4, !tbaa !14
  %58 = mul nsw i32 %54, %57
  %59 = load i32, ptr %5, align 4, !tbaa !9
  %60 = add nsw i32 %58, %59
  %61 = sext i32 %60 to i64
  %62 = getelementptr inbounds [1024 x i32], ptr %53, i64 0, i64 %61
  %63 = load i32, ptr %62, align 4, !tbaa !9
  %64 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i32 noundef %63)
  br label %65

65:                                               ; preds = %51, %49
  br label %68

66:                                               ; preds = %21
  %67 = call i32 (ptr, ...) @printf(ptr noundef @.str.2)
  br label %68

68:                                               ; preds = %66, %65
  br label %69

69:                                               ; preds = %68
  %70 = load i32, ptr %5, align 4, !tbaa !9
  %71 = add nsw i32 %70, 1
  store i32 %71, ptr %5, align 4, !tbaa !9
  br label %14, !llvm.loop !18

72:                                               ; preds = %20
  %73 = call i32 (ptr, ...) @printf(ptr noundef @.str.3)
  br label %74

74:                                               ; preds = %72
  %75 = load i32, ptr %3, align 4, !tbaa !9
  %76 = add nsw i32 %75, 1
  store i32 %76, ptr %3, align 4, !tbaa !9
  br label %6, !llvm.loop !20

77:                                               ; preds = %12
  ret void
}

declare i32 @printf(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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 4}
!12 = !{!"Board", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !7, i64 16, !7, i64 4112, !7, i64 5136, !13, i64 6160}
!13 = !{!"_Bool", !7, i64 0}
!14 = !{!12, !10, i64 0}
!15 = !{!13, !13, i64 0}
!16 = !{i8 0, i8 2}
!17 = !{}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}
!20 = distinct !{!20, !19}


; 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 [2 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [2 x i8], align 1

; Function Attrs: nofree nounwind uwtable
define dso_local void @print_board(ptr nocapture noundef readonly %0) local_unnamed_addr #0 {
  %2 = getelementptr inbounds i8, ptr %0, i64 4
  %3 = load i32, ptr %2, align 4, !tbaa !5
  %4 = icmp sgt i32 %3, 0
  br i1 %4, label %.preheader.lr.ph, label %._crit_edge22

.preheader.lr.ph:                                 ; preds = %1
  %5 = getelementptr inbounds i8, ptr %0, i64 4112
  %6 = getelementptr inbounds i8, ptr %0, i64 16
  br label %.preheader

.preheader:                                       ; preds = %.preheader.lr.ph, %._crit_edge
  %.01721 = phi i32 [ 0, %.preheader.lr.ph ], [ %10, %._crit_edge ]
  %7 = load i32, ptr %0, align 4, !tbaa !11
  %8 = icmp sgt i32 %7, 0
  br i1 %8, label %.lr.ph, label %._crit_edge

._crit_edge22:                                    ; preds = %._crit_edge, %1
  ret void

._crit_edge:                                      ; preds = %30, %.preheader
  %9 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3)
  %10 = add nuw nsw i32 %.01721, 1
  %11 = load i32, ptr %2, align 4, !tbaa !5
  %12 = icmp slt i32 %10, %11
  br i1 %12, label %.preheader, label %._crit_edge22, !llvm.loop !12

.lr.ph:                                           ; preds = %.preheader, %30
  %13 = phi i32 [ %32, %30 ], [ %7, %.preheader ]
  %.020 = phi i32 [ %31, %30 ], [ 0, %.preheader ]
  %14 = mul nsw i32 %13, %.01721
  %15 = add nsw i32 %14, %.020
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds [1024 x i8], ptr %5, i64 0, i64 %16
  %18 = load i8, ptr %17, align 1, !tbaa !14, !range !15, !noundef !16
  %19 = trunc nuw i8 %18 to i1
  br i1 %19, label %20, label %28

20:                                               ; preds = %.lr.ph
  %21 = getelementptr inbounds [1024 x i32], ptr %6, i64 0, i64 %16
  %22 = load i32, ptr %21, align 4, !tbaa !17
  %23 = icmp eq i32 %22, 0
  br i1 %23, label %24, label %26

24:                                               ; preds = %20
  %25 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str)
  br label %30

26:                                               ; preds = %20
  %27 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %22)
  br label %30

28:                                               ; preds = %.lr.ph
  %29 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2)
  br label %30

30:                                               ; preds = %28, %26, %24
  %31 = add nuw nsw i32 %.020, 1
  %32 = load i32, ptr %0, align 4, !tbaa !11
  %33 = icmp slt i32 %31, %32
  br i1 %33, label %.lr.ph, label %._crit_edge, !llvm.loop !18
}

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #1

attributes #0 = { nofree 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 = { nofree 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" }

!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 4}
!6 = !{!"Board", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12, !8, i64 16, !8, i64 4112, !8, i64 5136, !10, i64 6160}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"_Bool", !8, i64 0}
!11 = !{!6, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = !{!10, !10, i64 0}
!15 = !{i8 0, i8 2}
!16 = !{}
!17 = !{!7, !7, i64 0}
!18 = distinct !{!18, !13}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass