; 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

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

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

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

; Function Attrs: nounwind uwtable
define dso_local zeroext i1 @move(ptr noundef %0, i32 noundef %1, i1 noundef zeroext %2) #0 {
  %4 = alloca i1, align 1
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i8, align 1
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca [8 x i32], align 16
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !9
  %13 = zext i1 %2 to i8
  store i8 %13, ptr %7, align 1, !tbaa !11
  %14 = load ptr, ptr %5, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.Board, ptr %14, i32 0, i32 5
  %16 = load i32, ptr %6, align 4, !tbaa !9
  %17 = sext i32 %16 to i64
  %18 = getelementptr inbounds [1024 x i8], ptr %15, i64 0, i64 %17
  %19 = load i8, ptr %18, align 1, !tbaa !11, !range !13, !noundef !14
  %20 = trunc i8 %19 to i1
  br i1 %20, label %21, label %22

21:                                               ; preds = %3
  store i1 true, ptr %4, align 1
  br label %110

22:                                               ; preds = %3
  %23 = load ptr, ptr %5, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.Board, ptr %23, i32 0, i32 6
  %25 = load i32, ptr %6, align 4, !tbaa !9
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds [1024 x i8], ptr %24, i64 0, i64 %26
  %28 = load i8, ptr %27, align 1, !tbaa !11, !range !13, !noundef !14
  %29 = trunc i8 %28 to i1
  br i1 %29, label %30, label %71

30:                                               ; preds = %22
  %31 = load i8, ptr %7, align 1, !tbaa !11, !range !13, !noundef !14
  %32 = trunc i8 %31 to i1
  br i1 %32, label %33, label %70

33:                                               ; preds = %30
  br label %34

34:                                               ; preds = %58, %33
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  %35 = call i32 @rand() #4
  %36 = load ptr, ptr %5, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.Board, ptr %36, i32 0, i32 0
  %38 = load i32, ptr %37, align 4, !tbaa !15
  %39 = load ptr, ptr %5, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.Board, ptr %39, i32 0, i32 1
  %41 = load i32, ptr %40, align 4, !tbaa !17
  %42 = mul nsw i32 %38, %41
  %43 = srem i32 %35, %42
  store i32 %43, ptr %8, align 4, !tbaa !9
  %44 = load ptr, ptr %5, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.Board, ptr %44, i32 0, i32 6
  %46 = load i32, ptr %8, align 4, !tbaa !9
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds [1024 x i8], ptr %45, i64 0, i64 %47
  %49 = load i8, ptr %48, align 1, !tbaa !11, !range !13, !noundef !14
  %50 = trunc i8 %49 to i1
  br i1 %50, label %51, label %52

51:                                               ; preds = %34
  store i32 2, ptr %9, align 4
  br label %58

52:                                               ; preds = %34
  %53 = load ptr, ptr %5, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.Board, ptr %53, i32 0, i32 6
  %55 = load i32, ptr %8, align 4, !tbaa !9
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds [1024 x i8], ptr %54, i64 0, i64 %56
  store i8 1, ptr %57, align 1, !tbaa !11
  store i32 3, ptr %9, align 4
  br label %58

58:                                               ; preds = %52, %51
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  %59 = load i32, ptr %9, align 4
  switch i32 %59, label %112 [
    i32 2, label %34
    i32 3, label %60
  ]

60:                                               ; preds = %58
  %61 = load ptr, ptr %5, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.Board, ptr %61, i32 0, i32 6
  %63 = load i32, ptr %6, align 4, !tbaa !9
  %64 = sext i32 %63 to i64
  %65 = getelementptr inbounds [1024 x i8], ptr %62, i64 0, i64 %64
  store i8 0, ptr %65, align 1, !tbaa !11
  %66 = load ptr, ptr %5, align 8, !tbaa !5
  call void @calculate_adjacent_mines(ptr noundef %66)
  %67 = load ptr, ptr %5, align 8, !tbaa !5
  %68 = load i32, ptr %6, align 4, !tbaa !9
  %69 = call zeroext i1 @move(ptr noundef %67, i32 noundef %68, i1 noundef zeroext false)
  store i1 %69, ptr %4, align 1
  br label %110

70:                                               ; preds = %30
  store i1 false, ptr %4, align 1
  br label %110

71:                                               ; preds = %22
  %72 = load ptr, ptr %5, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct.Board, ptr %72, i32 0, i32 5
  %74 = load i32, ptr %6, align 4, !tbaa !9
  %75 = sext i32 %74 to i64
  %76 = getelementptr inbounds [1024 x i8], ptr %73, i64 0, i64 %75
  store i8 1, ptr %76, align 1, !tbaa !11
  %77 = load ptr, ptr %5, align 8, !tbaa !5
  %78 = getelementptr inbounds %struct.Board, ptr %77, i32 0, i32 3
  %79 = load i32, ptr %78, align 4, !tbaa !18
  %80 = sub nsw i32 %79, 1
  store i32 %80, ptr %78, align 4, !tbaa !18
  %81 = load ptr, ptr %5, align 8, !tbaa !5
  %82 = getelementptr inbounds %struct.Board, ptr %81, i32 0, i32 4
  %83 = load i32, ptr %6, align 4, !tbaa !9
  %84 = sext i32 %83 to i64
  %85 = getelementptr inbounds [1024 x i32], ptr %82, i64 0, i64 %84
  %86 = load i32, ptr %85, align 4, !tbaa !9
  %87 = icmp eq i32 %86, 0
  br i1 %87, label %88, label %109

88:                                               ; preds = %71
  call void @llvm.lifetime.start.p0(i64 32, ptr %10) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #4
  %89 = load ptr, ptr %5, align 8, !tbaa !5
  %90 = load i32, ptr %6, align 4, !tbaa !9
  %91 = getelementptr inbounds [8 x i32], ptr %10, i64 0, i64 0
  %92 = call i32 @get_adjacent(ptr noundef %89, i32 noundef %90, ptr noundef %91)
  store i32 %92, ptr %11, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #4
  store i32 0, ptr %12, align 4, !tbaa !9
  br label %93

93:                                               ; preds = %105, %88
  %94 = load i32, ptr %12, align 4, !tbaa !9
  %95 = load i32, ptr %11, align 4, !tbaa !9
  %96 = icmp slt i32 %94, %95
  br i1 %96, label %98, label %97

97:                                               ; preds = %93
  store i32 4, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #4
  br label %108

98:                                               ; preds = %93
  %99 = load ptr, ptr %5, align 8, !tbaa !5
  %100 = load i32, ptr %12, align 4, !tbaa !9
  %101 = sext i32 %100 to i64
  %102 = getelementptr inbounds [8 x i32], ptr %10, i64 0, i64 %101
  %103 = load i32, ptr %102, align 4, !tbaa !9
  %104 = call zeroext i1 @move(ptr noundef %99, i32 noundef %103, i1 noundef zeroext false)
  br label %105

105:                                              ; preds = %98
  %106 = load i32, ptr %12, align 4, !tbaa !9
  %107 = add nsw i32 %106, 1
  store i32 %107, ptr %12, align 4, !tbaa !9
  br label %93, !llvm.loop !19

108:                                              ; preds = %97
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 32, ptr %10) #4
  br label %109

109:                                              ; preds = %108, %71
  store i1 true, ptr %4, align 1
  br label %110

110:                                              ; preds = %109, %70, %60, %21
  %111 = load i1, ptr %4, align 1
  ret i1 %111

112:                                              ; preds = %58
  unreachable
}

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 = { "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 "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 #4 = { 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, !12, i64 0}
!12 = !{!"_Bool", !7, i64 0}
!13 = !{i8 0, i8 2}
!14 = !{}
!15 = !{!16, !10, i64 0}
!16 = !{!"Board", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !7, i64 16, !7, i64 4112, !7, i64 5136, !12, i64 6160}
!17 = !{!16, !10, i64 4}
!18 = !{!16, !10, i64 12}
!19 = distinct !{!19, !20}
!20 = !{!"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"

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

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

declare i32 @get_adjacent(ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #2

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

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

; Function Attrs: nounwind uwtable
define dso_local noundef zeroext i1 @move(ptr noundef %0, i32 noundef %1, i1 noundef zeroext %2) local_unnamed_addr #0 {
  %4 = alloca [8 x i32], align 16
  %5 = getelementptr inbounds i8, ptr %0, i64 4112
  %6 = sext i32 %1 to i64
  %7 = getelementptr inbounds [1024 x i8], ptr %5, i64 0, i64 %6
  %8 = load i8, ptr %7, align 1, !tbaa !5, !range !9, !noundef !10
  %9 = trunc nuw i8 %8 to i1
  br i1 %9, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %3
  %10 = getelementptr inbounds i8, ptr %0, i64 5136
  %11 = getelementptr inbounds [1024 x i8], ptr %10, i64 0, i64 %6
  %12 = getelementptr inbounds i8, ptr %0, i64 4
  br label %13

13:                                               ; preds = %.lr.ph, %tailrecurse
  %.tr3542 = phi i1 [ %2, %.lr.ph ], [ false, %tailrecurse ]
  %14 = load i8, ptr %11, align 1, !tbaa !5, !range !9, !noundef !10
  %15 = trunc nuw i8 %14 to i1
  br i1 %15, label %16, label %29

16:                                               ; preds = %13
  br i1 %.tr3542, label %.preheader, label %.loopexit

.preheader:                                       ; preds = %16, %.preheader
  %17 = tail call i32 @rand() #4
  %18 = load i32, ptr %0, align 4, !tbaa !11
  %19 = load i32, ptr %12, align 4, !tbaa !14
  %20 = mul nsw i32 %19, %18
  %21 = srem i32 %17, %20
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [1024 x i8], ptr %10, i64 0, i64 %22
  %24 = load i8, ptr %23, align 1, !tbaa !5, !range !9, !noundef !10
  %25 = trunc nuw i8 %24 to i1
  br i1 %25, label %.preheader, label %tailrecurse

tailrecurse:                                      ; preds = %.preheader
  %26 = getelementptr inbounds [1024 x i8], ptr %10, i64 0, i64 %22
  store i8 1, ptr %26, align 1, !tbaa !5
  store i8 0, ptr %11, align 1, !tbaa !5
  tail call void @calculate_adjacent_mines(ptr noundef nonnull %0)
  %27 = load i8, ptr %7, align 1, !tbaa !5, !range !9, !noundef !10
  %28 = trunc nuw i8 %27 to i1
  br i1 %28, label %.loopexit, label %13

29:                                               ; preds = %13
  store i8 1, ptr %7, align 1, !tbaa !5
  %30 = getelementptr inbounds i8, ptr %0, i64 12
  %31 = load i32, ptr %30, align 4, !tbaa !15
  %32 = add nsw i32 %31, -1
  store i32 %32, ptr %30, align 4, !tbaa !15
  %33 = getelementptr inbounds i8, ptr %0, i64 16
  %34 = getelementptr inbounds [1024 x i32], ptr %33, i64 0, i64 %6
  %35 = load i32, ptr %34, align 4, !tbaa !16
  %36 = icmp eq i32 %35, 0
  br i1 %36, label %37, label %.loopexit

37:                                               ; preds = %29
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %4) #4
  %38 = call i32 @get_adjacent(ptr noundef nonnull %0, i32 noundef %1, ptr noundef nonnull %4) #4
  %39 = icmp sgt i32 %38, 0
  br i1 %39, label %.lr.ph45.preheader, label %._crit_edge

.lr.ph45.preheader:                               ; preds = %37
  %wide.trip.count = zext nneg i32 %38 to i64
  br label %.lr.ph45

._crit_edge:                                      ; preds = %.lr.ph45, %37
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %4) #4
  br label %.loopexit

.lr.ph45:                                         ; preds = %.lr.ph45.preheader, %.lr.ph45
  %indvars.iv = phi i64 [ 0, %.lr.ph45.preheader ], [ %indvars.iv.next, %.lr.ph45 ]
  %40 = getelementptr inbounds [8 x i32], ptr %4, i64 0, i64 %indvars.iv
  %41 = load i32, ptr %40, align 4, !tbaa !16
  %42 = call zeroext i1 @move(ptr noundef %0, i32 noundef %41, i1 noundef zeroext false)
  %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 %._crit_edge, label %.lr.ph45, !llvm.loop !17

.loopexit:                                        ; preds = %tailrecurse, %16, %3, %29, %._crit_edge
  %.029 = phi i1 [ true, %._crit_edge ], [ true, %29 ], [ true, %3 ], [ %.tr3542, %tailrecurse ], [ false, %16 ]
  ret i1 %.029
}

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


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