; LLVM IR from Shah-Shishir/Codeforces-Solutions :: 263A. Beautiful Matrix (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"

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

8:                                                ; preds = %27, %0
  %9 = load i32, ptr %2, align 4, !tbaa !5
  %10 = icmp sle i32 %9, 5
  br i1 %10, label %11, label %30

11:                                               ; preds = %8
  store i32 1, ptr %3, align 4, !tbaa !5
  br label %12

12:                                               ; preds = %23, %11
  %13 = load i32, ptr %3, align 4, !tbaa !5
  %14 = icmp sle i32 %13, 5
  br i1 %14, label %15, label %26

15:                                               ; preds = %12
  %16 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %6)
  %17 = load i32, ptr %6, align 4, !tbaa !5
  %18 = icmp eq i32 %17, 1
  br i1 %18, label %19, label %22

19:                                               ; preds = %15
  %20 = load i32, ptr %2, align 4, !tbaa !5
  store i32 %20, ptr %4, align 4, !tbaa !5
  %21 = load i32, ptr %3, align 4, !tbaa !5
  store i32 %21, ptr %5, align 4, !tbaa !5
  br label %22

22:                                               ; preds = %19, %15
  br label %23

23:                                               ; preds = %22
  %24 = load i32, ptr %3, align 4, !tbaa !5
  %25 = add nsw i32 %24, 1
  store i32 %25, ptr %3, align 4, !tbaa !5
  br label %12, !llvm.loop !9

26:                                               ; preds = %12
  br label %27

27:                                               ; preds = %26
  %28 = load i32, ptr %2, align 4, !tbaa !5
  %29 = add nsw i32 %28, 1
  store i32 %29, ptr %2, align 4, !tbaa !5
  br label %8, !llvm.loop !11

30:                                               ; preds = %8
  %31 = load i32, ptr %4, align 4, !tbaa !5
  %32 = sub nsw i32 3, %31
  %33 = call i32 @llvm.abs.i32(i32 %32, i1 true)
  %34 = load i32, ptr %5, align 4, !tbaa !5
  %35 = sub nsw i32 3, %34
  %36 = call i32 @llvm.abs.i32(i32 %35, i1 true)
  %37 = add nsw i32 %33, %36
  store i32 %37, ptr %7, align 4, !tbaa !5
  %38 = load i32, ptr %7, align 4, !tbaa !5
  %39 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i32 noundef %38)
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #4
  ret i32 0
}

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

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.abs.i32(i32, i1 immarg) #3

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

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { 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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !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"

@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = 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 {
.preheader:
  %0 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %0) #4
  %1 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %0)
  %2 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %0)
  %3 = load i32, ptr %0, align 4, !tbaa !5
  %4 = icmp eq i32 %3, 1
  %5 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %0)
  %6 = load i32, ptr %0, align 4, !tbaa !5
  %7 = icmp eq i32 %6, 1
  %8 = select i1 %4, i32 1, i32 2
  %9 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %0)
  %10 = load i32, ptr %0, align 4, !tbaa !5
  %11 = icmp eq i32 %10, 1
  %12 = select i1 %7, i32 0, i32 %8
  %13 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %0)
  %14 = load i32, ptr %0, align 4, !tbaa !5
  %15 = icmp eq i32 %14, 1
  %16 = select i1 %11, i32 -1, i32 %12
  %17 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %0)
  %18 = load i32, ptr %0, align 4, !tbaa !5
  %19 = icmp eq i32 %18, 1
  %20 = select i1 %15, i32 -2, i32 %16
  %21 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %0)
  %22 = load i32, ptr %0, align 4, !tbaa !5
  %23 = icmp eq i32 %22, 1
  %24 = select i1 %19, i32 2, i32 %20
  %25 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %0)
  %26 = load i32, ptr %0, align 4, !tbaa !5
  %27 = icmp eq i32 %26, 1
  %28 = select i1 %23, i32 1, i32 %24
  %29 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %0)
  %30 = load i32, ptr %0, align 4, !tbaa !5
  %31 = icmp eq i32 %30, 1
  %32 = select i1 %27, i32 0, i32 %28
  %33 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %0)
  %34 = load i32, ptr %0, align 4, !tbaa !5
  %35 = icmp eq i32 %34, 1
  %36 = select i1 %35, i1 true, i1 %31
  %37 = select i1 %36, i1 true, i1 %27
  %38 = select i1 %37, i1 true, i1 %23
  %39 = select i1 %38, i1 true, i1 %19
  %40 = select i1 %31, i32 -1, i32 %32
  %41 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %0)
  %42 = load i32, ptr %0, align 4, !tbaa !5
  %43 = icmp eq i32 %42, 1
  %44 = select i1 %35, i32 -2, i32 %40
  %45 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %0)
  %46 = load i32, ptr %0, align 4, !tbaa !5
  %47 = icmp eq i32 %46, 1
  %48 = select i1 %43, i32 2, i32 %44
  %49 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %0)
  %50 = load i32, ptr %0, align 4, !tbaa !5
  %51 = icmp eq i32 %50, 1
  %52 = select i1 %47, i32 1, i32 %48
  %53 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %0)
  %54 = load i32, ptr %0, align 4, !tbaa !5
  %55 = icmp eq i32 %54, 1
  %56 = select i1 %51, i32 0, i32 %52
  %57 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %0)
  %58 = load i32, ptr %0, align 4, !tbaa !5
  %59 = icmp eq i32 %58, 1
  %60 = select i1 %59, i1 true, i1 %55
  %61 = select i1 %60, i1 true, i1 %51
  %62 = select i1 %61, i1 true, i1 %47
  %63 = select i1 %62, i1 true, i1 %43
  %64 = select i1 %39, i32 1, i32 2
  %65 = select i1 %55, i32 -1, i32 %56
  %66 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %0)
  %67 = load i32, ptr %0, align 4, !tbaa !5
  %68 = icmp eq i32 %67, 1
  %69 = select i1 %59, i32 -2, i32 %65
  %70 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %0)
  %71 = load i32, ptr %0, align 4, !tbaa !5
  %72 = icmp eq i32 %71, 1
  %73 = select i1 %68, i32 2, i32 %69
  %74 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %0)
  %75 = load i32, ptr %0, align 4, !tbaa !5
  %76 = icmp eq i32 %75, 1
  %77 = select i1 %72, i32 1, i32 %73
  %78 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %0)
  %79 = load i32, ptr %0, align 4, !tbaa !5
  %80 = icmp eq i32 %79, 1
  %81 = select i1 %76, i32 0, i32 %77
  %82 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %0)
  %83 = load i32, ptr %0, align 4, !tbaa !5
  %84 = icmp eq i32 %83, 1
  %85 = select i1 %84, i1 true, i1 %80
  %86 = select i1 %85, i1 true, i1 %76
  %87 = select i1 %86, i1 true, i1 %72
  %88 = select i1 %87, i1 true, i1 %68
  %89 = select i1 %63, i32 0, i32 %64
  %90 = select i1 %80, i32 -1, i32 %81
  %91 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %0)
  %92 = load i32, ptr %0, align 4, !tbaa !5
  %93 = icmp eq i32 %92, 1
  %94 = select i1 %84, i32 -2, i32 %90
  %95 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %0)
  %96 = load i32, ptr %0, align 4, !tbaa !5
  %97 = icmp eq i32 %96, 1
  %98 = select i1 %93, i32 2, i32 %94
  %99 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %0)
  %100 = load i32, ptr %0, align 4, !tbaa !5
  %101 = icmp eq i32 %100, 1
  %102 = select i1 %97, i32 1, i32 %98
  %103 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %0)
  %104 = load i32, ptr %0, align 4, !tbaa !5
  %105 = icmp eq i32 %104, 1
  %106 = select i1 %101, i32 0, i32 %102
  %107 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %0)
  %108 = load i32, ptr %0, align 4, !tbaa !5
  %109 = icmp eq i32 %108, 1
  %110 = select i1 %109, i1 true, i1 %105
  %111 = select i1 %110, i1 true, i1 %101
  %112 = select i1 %111, i1 true, i1 %97
  %113 = select i1 %112, i1 true, i1 %93
  %114 = select i1 %88, i32 -1, i32 %89
  %115 = select i1 %105, i32 -1, i32 %106
  %116 = select i1 %113, i32 -2, i32 %114
  %117 = call i32 @llvm.abs.i32(i32 %116, i1 true)
  %118 = select i1 %109, i32 -2, i32 %115
  %119 = call i32 @llvm.abs.i32(i32 %118, i1 true)
  %120 = add nuw nsw i32 %119, %117
  %121 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %120)
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %0) #4
  ret i32 0
}

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

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

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.abs.i32(i32, i1 immarg) #3

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) 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

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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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" }
attributes #3 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}


; Effective O3 passes: GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass