; LLVM IR from VastoLorde95/Competitive-Programming :: Codeforces/369 Division 2/Problem A (A)

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

@n = external dso_local global i32, align 4
@grid = external dso_local global [1100 x [10 x i8]], align 16
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #0 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i8, align 1
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  %7 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n)
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #3
  store i32 0, ptr %2, align 4, !tbaa !5
  br label %8

8:                                                ; preds = %19, %0
  %9 = load i32, ptr %2, align 4, !tbaa !5
  %10 = load i32, ptr @n, align 4, !tbaa !5
  %11 = icmp slt i32 %9, %10
  br i1 %11, label %13, label %12

12:                                               ; preds = %8
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #3
  br label %22

13:                                               ; preds = %8
  %14 = load i32, ptr %2, align 4, !tbaa !5
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds [1100 x [10 x i8]], ptr @grid, i64 0, i64 %15
  %17 = getelementptr inbounds [10 x i8], ptr %16, i64 0, i64 0
  %18 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef %17)
  br label %19

19:                                               ; preds = %13
  %20 = load i32, ptr %2, align 4, !tbaa !5
  %21 = add nsw i32 %20, 1
  store i32 %21, ptr %2, align 4, !tbaa !5
  br label %8, !llvm.loop !9

22:                                               ; preds = %12
  call void @llvm.lifetime.start.p0(i64 1, ptr %3) #3
  store i8 0, ptr %3, align 1, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  store i32 0, ptr %4, align 4, !tbaa !5
  br label %23

23:                                               ; preds = %84, %22
  %24 = load i32, ptr %4, align 4, !tbaa !5
  %25 = load i32, ptr @n, align 4, !tbaa !5
  %26 = icmp slt i32 %24, %25
  br i1 %26, label %28, label %27

27:                                               ; preds = %23
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  br label %87

28:                                               ; preds = %23
  %29 = load i8, ptr %3, align 1, !tbaa !11, !range !13, !noundef !14
  %30 = trunc i8 %29 to i1
  br i1 %30, label %83, label %31

31:                                               ; preds = %28
  %32 = load i32, ptr %4, align 4, !tbaa !5
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds [1100 x [10 x i8]], ptr @grid, i64 0, i64 %33
  %35 = getelementptr inbounds [10 x i8], ptr %34, i64 0, i64 0
  %36 = load i8, ptr %35, align 2, !tbaa !15
  %37 = sext i8 %36 to i32
  %38 = icmp eq i32 %37, 79
  br i1 %38, label %39, label %56

39:                                               ; preds = %31
  %40 = load i32, ptr %4, align 4, !tbaa !5
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds [1100 x [10 x i8]], ptr @grid, i64 0, i64 %41
  %43 = getelementptr inbounds [10 x i8], ptr %42, i64 0, i64 1
  %44 = load i8, ptr %43, align 1, !tbaa !15
  %45 = sext i8 %44 to i32
  %46 = icmp eq i32 %45, 79
  br i1 %46, label %47, label %56

47:                                               ; preds = %39
  store i8 1, ptr %3, align 1, !tbaa !11
  %48 = load i32, ptr %4, align 4, !tbaa !5
  %49 = sext i32 %48 to i64
  %50 = getelementptr inbounds [1100 x [10 x i8]], ptr @grid, i64 0, i64 %49
  %51 = getelementptr inbounds [10 x i8], ptr %50, i64 0, i64 1
  store i8 43, ptr %51, align 1, !tbaa !15
  %52 = load i32, ptr %4, align 4, !tbaa !5
  %53 = sext i32 %52 to i64
  %54 = getelementptr inbounds [1100 x [10 x i8]], ptr @grid, i64 0, i64 %53
  %55 = getelementptr inbounds [10 x i8], ptr %54, i64 0, i64 0
  store i8 43, ptr %55, align 2, !tbaa !15
  br label %82

56:                                               ; preds = %39, %31
  %57 = load i32, ptr %4, align 4, !tbaa !5
  %58 = sext i32 %57 to i64
  %59 = getelementptr inbounds [1100 x [10 x i8]], ptr @grid, i64 0, i64 %58
  %60 = getelementptr inbounds [10 x i8], ptr %59, i64 0, i64 3
  %61 = load i8, ptr %60, align 1, !tbaa !15
  %62 = sext i8 %61 to i32
  %63 = icmp eq i32 %62, 79
  br i1 %63, label %64, label %81

64:                                               ; preds = %56
  %65 = load i32, ptr %4, align 4, !tbaa !5
  %66 = sext i32 %65 to i64
  %67 = getelementptr inbounds [1100 x [10 x i8]], ptr @grid, i64 0, i64 %66
  %68 = getelementptr inbounds [10 x i8], ptr %67, i64 0, i64 4
  %69 = load i8, ptr %68, align 2, !tbaa !15
  %70 = sext i8 %69 to i32
  %71 = icmp eq i32 %70, 79
  br i1 %71, label %72, label %81

72:                                               ; preds = %64
  store i8 1, ptr %3, align 1, !tbaa !11
  %73 = load i32, ptr %4, align 4, !tbaa !5
  %74 = sext i32 %73 to i64
  %75 = getelementptr inbounds [1100 x [10 x i8]], ptr @grid, i64 0, i64 %74
  %76 = getelementptr inbounds [10 x i8], ptr %75, i64 0, i64 4
  store i8 43, ptr %76, align 2, !tbaa !15
  %77 = load i32, ptr %4, align 4, !tbaa !5
  %78 = sext i32 %77 to i64
  %79 = getelementptr inbounds [1100 x [10 x i8]], ptr @grid, i64 0, i64 %78
  %80 = getelementptr inbounds [10 x i8], ptr %79, i64 0, i64 3
  store i8 43, ptr %80, align 1, !tbaa !15
  br label %81

81:                                               ; preds = %72, %64, %56
  br label %82

82:                                               ; preds = %81, %47
  br label %83

83:                                               ; preds = %82, %28
  br label %84

84:                                               ; preds = %83
  %85 = load i32, ptr %4, align 4, !tbaa !5
  %86 = add nsw i32 %85, 1
  store i32 %86, ptr %4, align 4, !tbaa !5
  br label %23, !llvm.loop !16

87:                                               ; preds = %27
  %88 = load i8, ptr %3, align 1, !tbaa !11, !range !13, !noundef !14
  %89 = trunc i8 %88 to i1
  br i1 %89, label %92, label %90

90:                                               ; preds = %87
  %91 = call i32 @puts(ptr noundef @.str.2)
  store i32 0, ptr %1, align 4
  store i32 1, ptr %5, align 4
  br label %109

92:                                               ; preds = %87
  %93 = call i32 @puts(ptr noundef @.str.3)
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  store i32 0, ptr %6, align 4, !tbaa !5
  br label %94

94:                                               ; preds = %105, %92
  %95 = load i32, ptr %6, align 4, !tbaa !5
  %96 = load i32, ptr @n, align 4, !tbaa !5
  %97 = icmp slt i32 %95, %96
  br i1 %97, label %99, label %98

98:                                               ; preds = %94
  store i32 8, ptr %5, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  br label %108

99:                                               ; preds = %94
  %100 = load i32, ptr %6, align 4, !tbaa !5
  %101 = sext i32 %100 to i64
  %102 = getelementptr inbounds [1100 x [10 x i8]], ptr @grid, i64 0, i64 %101
  %103 = getelementptr inbounds [10 x i8], ptr %102, i64 0, i64 0
  %104 = call i32 (ptr, ...) @printf(ptr noundef @.str.4, ptr noundef %103)
  br label %105

105:                                              ; preds = %99
  %106 = load i32, ptr %6, align 4, !tbaa !5
  %107 = add nsw i32 %106, 1
  store i32 %107, ptr %6, align 4, !tbaa !5
  br label %94, !llvm.loop !17

108:                                              ; preds = %98
  store i32 0, ptr %1, align 4
  store i32 1, ptr %5, align 4
  br label %109

109:                                              ; preds = %108, %90
  call void @llvm.lifetime.end.p0(i64 1, ptr %3) #3
  %110 = load i32, ptr %1, align 4
  ret i32 %110
}

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

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

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

declare i32 @puts(ptr noundef) #1

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

attributes #0 = { mustprogress norecurse 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!12, !12, i64 0}
!12 = !{!"bool", !7, i64 0}
!13 = !{i8 0, i8 2}
!14 = !{}
!15 = !{!7, !7, i64 0}
!16 = distinct !{!16, !10}
!17 = distinct !{!17, !10}


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

@n = external dso_local global i32, align 4
@grid = external dso_local global [1100 x [10 x i8]], align 16
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: mustprogress nofree norecurse nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n)
  %2 = load i32, ptr @n, align 4, !tbaa !5
  %3 = icmp sgt i32 %2, 0
  br i1 %3, label %.lr.ph, label %._crit_edge.thread

.preheader:                                       ; preds = %.lr.ph
  %4 = icmp sgt i32 %7, 0
  br i1 %4, label %.lr.ph26.preheader, label %._crit_edge.thread

.lr.ph26.preheader:                               ; preds = %.preheader
  %wide.trip.count = zext nneg i32 %7 to i64
  br label %.lr.ph26

.lr.ph:                                           ; preds = %0, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %0 ]
  %5 = getelementptr inbounds [1100 x [10 x i8]], ptr @grid, i64 0, i64 %indvars.iv
  %6 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %5)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %7 = load i32, ptr @n, align 4, !tbaa !5
  %8 = sext i32 %7 to i64
  %9 = icmp slt i64 %indvars.iv.next, %8
  br i1 %9, label %.lr.ph, label %.preheader, !llvm.loop !9

._crit_edge:                                      ; preds = %30
  %10 = trunc nuw i8 %.1 to i1
  br i1 %10, label %32, label %._crit_edge.thread

.lr.ph26:                                         ; preds = %.lr.ph26.preheader, %30
  %indvars.iv33 = phi i64 [ 0, %.lr.ph26.preheader ], [ %indvars.iv.next34, %30 ]
  %.02024 = phi i8 [ 0, %.lr.ph26.preheader ], [ %.1, %30 ]
  %11 = trunc nuw i8 %.02024 to i1
  br i1 %11, label %30, label %12

12:                                               ; preds = %.lr.ph26
  %13 = getelementptr inbounds [1100 x [10 x i8]], ptr @grid, i64 0, i64 %indvars.iv33
  %14 = load i8, ptr %13, align 2, !tbaa !11
  %15 = icmp eq i8 %14, 79
  br i1 %15, label %16, label %21

16:                                               ; preds = %12
  %17 = getelementptr inbounds i8, ptr %13, i64 1
  %18 = load i8, ptr %17, align 1, !tbaa !11
  %19 = icmp eq i8 %18, 79
  br i1 %19, label %20, label %21

20:                                               ; preds = %16
  store i8 43, ptr %17, align 1, !tbaa !11
  store i8 43, ptr %13, align 2, !tbaa !11
  br label %30

21:                                               ; preds = %16, %12
  %22 = getelementptr inbounds i8, ptr %13, i64 3
  %23 = load i8, ptr %22, align 1, !tbaa !11
  %24 = icmp eq i8 %23, 79
  br i1 %24, label %25, label %30

25:                                               ; preds = %21
  %26 = getelementptr inbounds i8, ptr %13, i64 4
  %27 = load i8, ptr %26, align 2, !tbaa !11
  %28 = icmp eq i8 %27, 79
  br i1 %28, label %29, label %30

29:                                               ; preds = %25
  store i8 43, ptr %26, align 2, !tbaa !11
  store i8 43, ptr %22, align 1, !tbaa !11
  br label %30

30:                                               ; preds = %.lr.ph26, %21, %25, %29, %20
  %.1 = phi i8 [ %.02024, %.lr.ph26 ], [ 1, %20 ], [ 1, %29 ], [ %.02024, %25 ], [ %.02024, %21 ]
  %indvars.iv.next34 = add nuw nsw i64 %indvars.iv33, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next34, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph26, !llvm.loop !12

._crit_edge.thread:                               ; preds = %0, %.preheader, %._crit_edge
  %31 = tail call i32 @puts(ptr noundef nonnull dereferenceable(1) @.str.2)
  br label %.loopexit

32:                                               ; preds = %._crit_edge
  %33 = tail call i32 @puts(ptr noundef nonnull dereferenceable(1) @.str.3)
  %34 = load i32, ptr @n, align 4, !tbaa !5
  %35 = icmp sgt i32 %34, 0
  br i1 %35, label %.lr.ph30, label %.loopexit

.lr.ph30:                                         ; preds = %32, %.lr.ph30
  %indvars.iv35 = phi i64 [ %indvars.iv.next36, %.lr.ph30 ], [ 0, %32 ]
  %36 = getelementptr inbounds [1100 x [10 x i8]], ptr @grid, i64 0, i64 %indvars.iv35
  %37 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.4, ptr noundef nonnull %36)
  %indvars.iv.next36 = add nuw nsw i64 %indvars.iv35, 1
  %38 = load i32, ptr @n, align 4, !tbaa !5
  %39 = sext i32 %38 to i64
  %40 = icmp slt i64 %indvars.iv.next36, %39
  br i1 %40, label %.lr.ph30, label %.loopexit, !llvm.loop !13

.loopexit:                                        ; preds = %.lr.ph30, %32, %._crit_edge.thread
  ret i32 0
}

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

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

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

attributes #0 = { mustprogress nofree norecurse 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, !6, i64 0}
!6 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!7, !7, i64 0}
!12 = distinct !{!12, !10}
!13 = distinct !{!13, !10}


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