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

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

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

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

; 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 void @generate_board(i32 noundef %0, ptr noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  store i32 %0, ptr %3, align 4, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !9
  %8 = load ptr, ptr %4, align 8, !tbaa !9
  %9 = getelementptr inbounds %struct.Board, ptr %8, i32 0, i32 2
  store i32 0, ptr %9, align 4, !tbaa !11
  %10 = load ptr, ptr %4, align 8, !tbaa !9
  %11 = getelementptr inbounds %struct.Board, ptr %10, i32 0, i32 0
  %12 = load i32, ptr %11, align 4, !tbaa !14
  %13 = load ptr, ptr %4, align 8, !tbaa !9
  %14 = getelementptr inbounds %struct.Board, ptr %13, i32 0, i32 1
  %15 = load i32, ptr %14, align 4, !tbaa !15
  %16 = mul nsw i32 %12, %15
  %17 = load ptr, ptr %4, align 8, !tbaa !9
  %18 = getelementptr inbounds %struct.Board, ptr %17, i32 0, i32 3
  store i32 %16, ptr %18, align 4, !tbaa !16
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  store i32 0, ptr %5, align 4, !tbaa !5
  br label %19

19:                                               ; preds = %46, %2
  %20 = load i32, ptr %5, align 4, !tbaa !5
  %21 = load ptr, ptr %4, align 8, !tbaa !9
  %22 = getelementptr inbounds %struct.Board, ptr %21, i32 0, i32 0
  %23 = load i32, ptr %22, align 4, !tbaa !14
  %24 = load ptr, ptr %4, align 8, !tbaa !9
  %25 = getelementptr inbounds %struct.Board, ptr %24, i32 0, i32 1
  %26 = load i32, ptr %25, align 4, !tbaa !15
  %27 = mul nsw i32 %23, %26
  %28 = icmp slt i32 %20, %27
  br i1 %28, label %30, label %29

29:                                               ; preds = %19
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  br label %49

30:                                               ; preds = %19
  %31 = load ptr, ptr %4, align 8, !tbaa !9
  %32 = getelementptr inbounds %struct.Board, ptr %31, i32 0, i32 4
  %33 = load i32, ptr %5, align 4, !tbaa !5
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds [1024 x i32], ptr %32, i64 0, i64 %34
  store i32 0, ptr %35, align 4, !tbaa !5
  %36 = load ptr, ptr %4, align 8, !tbaa !9
  %37 = getelementptr inbounds %struct.Board, ptr %36, i32 0, i32 5
  %38 = load i32, ptr %5, align 4, !tbaa !5
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds [1024 x i8], ptr %37, i64 0, i64 %39
  store i8 0, ptr %40, align 1, !tbaa !17
  %41 = load ptr, ptr %4, align 8, !tbaa !9
  %42 = getelementptr inbounds %struct.Board, ptr %41, i32 0, i32 6
  %43 = load i32, ptr %5, align 4, !tbaa !5
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds [1024 x i8], ptr %42, i64 0, i64 %44
  store i8 0, ptr %45, align 1, !tbaa !17
  br label %46

46:                                               ; preds = %30
  %47 = load i32, ptr %5, align 4, !tbaa !5
  %48 = add nsw i32 %47, 1
  store i32 %48, ptr %5, align 4, !tbaa !5
  br label %19, !llvm.loop !18

49:                                               ; preds = %29
  br label %50

50:                                               ; preds = %86, %84, %49
  %51 = load ptr, ptr %4, align 8, !tbaa !9
  %52 = getelementptr inbounds %struct.Board, ptr %51, i32 0, i32 2
  %53 = load i32, ptr %52, align 4, !tbaa !11
  %54 = load i32, ptr %3, align 4, !tbaa !5
  %55 = icmp slt i32 %53, %54
  br i1 %55, label %56, label %87

56:                                               ; preds = %50
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  %57 = call i32 @rand() #3
  %58 = load ptr, ptr %4, align 8, !tbaa !9
  %59 = getelementptr inbounds %struct.Board, ptr %58, i32 0, i32 0
  %60 = load i32, ptr %59, align 4, !tbaa !14
  %61 = load ptr, ptr %4, align 8, !tbaa !9
  %62 = getelementptr inbounds %struct.Board, ptr %61, i32 0, i32 1
  %63 = load i32, ptr %62, align 4, !tbaa !15
  %64 = mul nsw i32 %60, %63
  %65 = srem i32 %57, %64
  store i32 %65, ptr %6, align 4, !tbaa !5
  %66 = load ptr, ptr %4, align 8, !tbaa !9
  %67 = getelementptr inbounds %struct.Board, ptr %66, i32 0, i32 6
  %68 = load i32, ptr %6, align 4, !tbaa !5
  %69 = sext i32 %68 to i64
  %70 = getelementptr inbounds [1024 x i8], ptr %67, i64 0, i64 %69
  %71 = load i8, ptr %70, align 1, !tbaa !17, !range !20, !noundef !21
  %72 = trunc i8 %71 to i1
  br i1 %72, label %73, label %74

73:                                               ; preds = %56
  store i32 5, ptr %7, align 4
  br label %84, !llvm.loop !22

74:                                               ; preds = %56
  %75 = load ptr, ptr %4, align 8, !tbaa !9
  %76 = getelementptr inbounds %struct.Board, ptr %75, i32 0, i32 6
  %77 = load i32, ptr %6, align 4, !tbaa !5
  %78 = sext i32 %77 to i64
  %79 = getelementptr inbounds [1024 x i8], ptr %76, i64 0, i64 %78
  store i8 1, ptr %79, align 1, !tbaa !17
  %80 = load ptr, ptr %4, align 8, !tbaa !9
  %81 = getelementptr inbounds %struct.Board, ptr %80, i32 0, i32 2
  %82 = load i32, ptr %81, align 4, !tbaa !11
  %83 = add nsw i32 %82, 1
  store i32 %83, ptr %81, align 4, !tbaa !11
  store i32 0, ptr %7, align 4
  br label %84

84:                                               ; preds = %74, %73
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  %85 = load i32, ptr %7, align 4
  switch i32 %85, label %89 [
    i32 0, label %86
    i32 5, label %50
  ]

86:                                               ; preds = %84
  br label %50, !llvm.loop !22

87:                                               ; preds = %50
  %88 = load ptr, ptr %4, align 8, !tbaa !9
  call void @calculate_adjacent_mines(ptr noundef %88)
  ret void

89:                                               ; preds = %84
  unreachable
}

; Function Attrs: nounwind
declare i32 @rand() #2

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #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, !6, i64 8}
!12 = !{!"Board", !6, i64 0, !6, i64 4, !6, i64 8, !6, i64 12, !7, i64 16, !7, i64 4112, !7, i64 5136, !13, i64 6160}
!13 = !{!"_Bool", !7, i64 0}
!14 = !{!12, !6, i64 0}
!15 = !{!12, !6, i64 4}
!16 = !{!12, !6, i64 12}
!17 = !{!13, !13, i64 0}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}
!20 = !{i8 0, i8 2}
!21 = !{}
!22 = distinct !{!22, !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"

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

; Function Attrs: nounwind uwtable
define dso_local void @generate_board(i32 noundef %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %1, i64 8
  store i32 0, ptr %3, align 4, !tbaa !5
  %4 = load i32, ptr %1, align 4, !tbaa !11
  %5 = getelementptr inbounds i8, ptr %1, i64 4
  %6 = load i32, ptr %5, align 4, !tbaa !12
  %7 = mul nsw i32 %6, %4
  %8 = getelementptr inbounds i8, ptr %1, i64 12
  store i32 %7, ptr %8, align 4, !tbaa !13
  %9 = icmp sgt i32 %7, 0
  br i1 %9, label %.lr.ph, label %.preheader

.lr.ph:                                           ; preds = %2
  %10 = getelementptr inbounds i8, ptr %1, i64 16
  %11 = getelementptr inbounds i8, ptr %1, i64 4112
  %12 = getelementptr inbounds i8, ptr %1, i64 5136
  %wide.trip.count = zext nneg i32 %7 to i64
  %min.iters.check = icmp ult i32 %7, 4
  br i1 %min.iters.check, label %scalar.ph.preheader, label %vector.ph

scalar.ph.preheader:                              ; preds = %middle.block, %.lr.ph
  %indvars.iv.ph = phi i64 [ 0, %.lr.ph ], [ %n.vec, %middle.block ]
  br label %scalar.ph

vector.ph:                                        ; preds = %.lr.ph
  %n.vec = and i64 %wide.trip.count, 2147483644
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %13 = getelementptr inbounds [1024 x i32], ptr %10, i64 0, i64 %index
  store <4 x i32> zeroinitializer, ptr %13, align 4, !tbaa !14
  %14 = getelementptr inbounds [1024 x i8], ptr %11, i64 0, i64 %index
  store <4 x i8> zeroinitializer, ptr %14, align 1, !tbaa !15
  %15 = getelementptr inbounds [1024 x i8], ptr %12, i64 0, i64 %index
  store <4 x i8> zeroinitializer, ptr %15, align 1, !tbaa !15
  %index.next = add nuw i64 %index, 4
  %16 = icmp eq i64 %index.next, %n.vec
  br i1 %16, label %middle.block, label %vector.body, !llvm.loop !16

middle.block:                                     ; preds = %vector.body
  %cmp.n = icmp eq i64 %n.vec, %wide.trip.count
  br i1 %cmp.n, label %.preheader, label %scalar.ph.preheader

.preheader:                                       ; preds = %scalar.ph, %middle.block, %2
  %17 = icmp sgt i32 %0, 0
  br i1 %17, label %.lr.ph24, label %._crit_edge

.lr.ph24:                                         ; preds = %.preheader
  %18 = getelementptr inbounds i8, ptr %1, i64 5136
  br label %22

scalar.ph:                                        ; preds = %scalar.ph.preheader, %scalar.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %scalar.ph ], [ %indvars.iv.ph, %scalar.ph.preheader ]
  %19 = getelementptr inbounds [1024 x i32], ptr %10, i64 0, i64 %indvars.iv
  store i32 0, ptr %19, align 4, !tbaa !14
  %20 = getelementptr inbounds [1024 x i8], ptr %11, i64 0, i64 %indvars.iv
  store i8 0, ptr %20, align 1, !tbaa !15
  %21 = getelementptr inbounds [1024 x i8], ptr %12, i64 0, i64 %indvars.iv
  store i8 0, ptr %21, align 1, !tbaa !15
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %.preheader, label %scalar.ph, !llvm.loop !20

22:                                               ; preds = %.lr.ph24, %34
  %23 = tail call i32 @rand() #2
  %24 = load i32, ptr %1, align 4, !tbaa !11
  %25 = load i32, ptr %5, align 4, !tbaa !12
  %26 = mul nsw i32 %25, %24
  %27 = srem i32 %23, %26
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds [1024 x i8], ptr %18, i64 0, i64 %28
  %30 = load i8, ptr %29, align 1, !tbaa !15, !range !21, !noundef !22
  %31 = trunc nuw i8 %30 to i1
  %.pre = load i32, ptr %3, align 4, !tbaa !5
  br i1 %31, label %34, label %32, !llvm.loop !23

32:                                               ; preds = %22
  store i8 1, ptr %29, align 1, !tbaa !15
  %33 = add nsw i32 %.pre, 1
  store i32 %33, ptr %3, align 4, !tbaa !5
  br label %34

34:                                               ; preds = %22, %32
  %35 = phi i32 [ %.pre, %22 ], [ %33, %32 ]
  %36 = icmp slt i32 %35, %0
  br i1 %36, label %22, label %._crit_edge

._crit_edge:                                      ; preds = %34, %.preheader
  tail call void @calculate_adjacent_mines(ptr noundef nonnull %1)
  ret void
}

; Function Attrs: nounwind
declare i32 @rand() 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 = { 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 #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, !7, i64 8}
!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 = !{!6, !7, i64 4}
!13 = !{!6, !7, i64 12}
!14 = !{!7, !7, i64 0}
!15 = !{!10, !10, i64 0}
!16 = distinct !{!16, !17, !18, !19}
!17 = !{!"llvm.loop.mustprogress"}
!18 = !{!"llvm.loop.isvectorized", i32 1}
!19 = !{!"llvm.loop.unroll.runtime.disable"}
!20 = distinct !{!20, !17, !19, !18}
!21 = !{i8 0, i8 2}
!22 = !{}
!23 = distinct !{!23, !17}


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