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

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

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

7:                                                ; preds = %28, %0
  %8 = load i32, ptr %2, align 4, !tbaa !5
  %9 = icmp slt i32 %8, 3
  br i1 %9, label %11, label %10

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

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

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

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

16:                                               ; preds = %12
  %17 = load i32, ptr %2, align 4, !tbaa !5
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds [3 x [3 x i32]], ptr @m, i64 0, i64 %18
  %20 = load i32, ptr %4, align 4, !tbaa !5
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds [3 x i32], ptr %19, i64 0, i64 %21
  %23 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %22)
  br label %24

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

27:                                               ; preds = %15
  br label %28

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

31:                                               ; preds = %10
  %32 = load i32, ptr @m, align 16, !tbaa !5
  %33 = load i32, ptr getelementptr inbounds ([3 x i32], ptr @m, i64 0, i64 1), align 4, !tbaa !5
  %34 = add nsw i32 %32, %33
  %35 = load i32, ptr getelementptr inbounds ([3 x i32], ptr @m, i64 0, i64 2), align 8, !tbaa !5
  %36 = add nsw i32 %34, %35
  store i32 %36, ptr @s1, align 4, !tbaa !5
  %37 = load i32, ptr getelementptr inbounds ([3 x [3 x i32]], ptr @m, i64 0, i64 1), align 4, !tbaa !5
  %38 = load i32, ptr getelementptr inbounds ([3 x i32], ptr getelementptr inbounds ([3 x [3 x i32]], ptr @m, i64 0, i64 1), i64 0, i64 1), align 4, !tbaa !5
  %39 = add nsw i32 %37, %38
  %40 = load i32, ptr getelementptr inbounds ([3 x i32], ptr getelementptr inbounds ([3 x [3 x i32]], ptr @m, i64 0, i64 1), i64 0, i64 2), align 4, !tbaa !5
  %41 = add nsw i32 %39, %40
  store i32 %41, ptr @s2, align 4, !tbaa !5
  %42 = load i32, ptr getelementptr inbounds ([3 x [3 x i32]], ptr @m, i64 0, i64 2), align 8, !tbaa !5
  %43 = load i32, ptr getelementptr inbounds ([3 x i32], ptr getelementptr inbounds ([3 x [3 x i32]], ptr @m, i64 0, i64 2), i64 0, i64 1), align 4, !tbaa !5
  %44 = add nsw i32 %42, %43
  %45 = load i32, ptr getelementptr inbounds ([3 x i32], ptr getelementptr inbounds ([3 x [3 x i32]], ptr @m, i64 0, i64 2), i64 0, i64 2), align 8, !tbaa !5
  %46 = add nsw i32 %44, %45
  store i32 %46, ptr @s3, align 4, !tbaa !5
  %47 = load i32, ptr @s1, align 4, !tbaa !5
  %48 = load i32, ptr @s2, align 4, !tbaa !5
  %49 = add nsw i32 %47, %48
  %50 = load i32, ptr @s3, align 4, !tbaa !5
  %51 = add nsw i32 %49, %50
  %52 = sdiv i32 %51, 2
  %53 = load i32, ptr @s1, align 4, !tbaa !5
  %54 = sub nsw i32 %52, %53
  store i32 %54, ptr @m, align 16, !tbaa !5
  %55 = load i32, ptr @s1, align 4, !tbaa !5
  %56 = load i32, ptr @s2, align 4, !tbaa !5
  %57 = add nsw i32 %55, %56
  %58 = load i32, ptr @s3, align 4, !tbaa !5
  %59 = add nsw i32 %57, %58
  %60 = sdiv i32 %59, 2
  %61 = load i32, ptr @s2, align 4, !tbaa !5
  %62 = sub nsw i32 %60, %61
  store i32 %62, ptr getelementptr inbounds ([3 x i32], ptr getelementptr inbounds ([3 x [3 x i32]], ptr @m, i64 0, i64 1), i64 0, i64 1), align 4, !tbaa !5
  %63 = load i32, ptr @s1, align 4, !tbaa !5
  %64 = load i32, ptr @s2, align 4, !tbaa !5
  %65 = add nsw i32 %63, %64
  %66 = load i32, ptr @s3, align 4, !tbaa !5
  %67 = add nsw i32 %65, %66
  %68 = sdiv i32 %67, 2
  %69 = load i32, ptr @s3, align 4, !tbaa !5
  %70 = sub nsw i32 %68, %69
  store i32 %70, ptr getelementptr inbounds ([3 x i32], ptr getelementptr inbounds ([3 x [3 x i32]], ptr @m, i64 0, i64 2), i64 0, i64 2), align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  store i32 0, ptr %5, align 4, !tbaa !5
  br label %71

71:                                               ; preds = %94, %31
  %72 = load i32, ptr %5, align 4, !tbaa !5
  %73 = icmp slt i32 %72, 3
  br i1 %73, label %75, label %74

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

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

76:                                               ; preds = %89, %75
  %77 = load i32, ptr %6, align 4, !tbaa !5
  %78 = icmp slt i32 %77, 3
  br i1 %78, label %80, label %79

79:                                               ; preds = %76
  store i32 11, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  br label %92

80:                                               ; preds = %76
  %81 = load i32, ptr %5, align 4, !tbaa !5
  %82 = sext i32 %81 to i64
  %83 = getelementptr inbounds [3 x [3 x i32]], ptr @m, i64 0, i64 %82
  %84 = load i32, ptr %6, align 4, !tbaa !5
  %85 = sext i32 %84 to i64
  %86 = getelementptr inbounds [3 x i32], ptr %83, i64 0, i64 %85
  %87 = load i32, ptr %86, align 4, !tbaa !5
  %88 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i32 noundef %87)
  br label %89

89:                                               ; preds = %80
  %90 = load i32, ptr %6, align 4, !tbaa !5
  %91 = add nsw i32 %90, 1
  store i32 %91, ptr %6, align 4, !tbaa !5
  br label %76, !llvm.loop !12

92:                                               ; preds = %79
  %93 = call i32 (ptr, ...) @printf(ptr noundef @.str.2)
  br label %94

94:                                               ; preds = %92
  %95 = load i32, ptr %5, align 4, !tbaa !5
  %96 = add nsw i32 %95, 1
  store i32 %96, ptr %5, align 4, !tbaa !5
  br label %71, !llvm.loop !13

97:                                               ; preds = %74
  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 willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

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

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 = { 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}
!12 = distinct !{!12, !10}
!13 = distinct !{!13, !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"

@m = external dso_local global [3 x [3 x i32]], align 16
@s1 = external dso_local local_unnamed_addr global i32, align 4
@s2 = external dso_local local_unnamed_addr global i32, align 4
@s3 = external dso_local local_unnamed_addr global i32, align 4
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [2 x i8], align 1

; Function Attrs: mustprogress nofree norecurse nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
.preheader15:
  %0 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @m)
  %1 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull getelementptr inbounds (i8, ptr @m, i64 4))
  %2 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull getelementptr inbounds (i8, ptr @m, i64 8))
  %3 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull getelementptr inbounds (i8, ptr @m, i64 12))
  %4 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull getelementptr inbounds (i8, ptr @m, i64 16))
  %5 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull getelementptr inbounds (i8, ptr @m, i64 20))
  %6 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull getelementptr inbounds (i8, ptr @m, i64 24))
  %7 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull getelementptr inbounds (i8, ptr @m, i64 28))
  %8 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull getelementptr inbounds (i8, ptr @m, i64 32))
  %9 = load i32, ptr @m, align 16, !tbaa !5
  %10 = load i32, ptr getelementptr inbounds (i8, ptr @m, i64 4), align 4, !tbaa !5
  %11 = add nsw i32 %10, %9
  %12 = load i32, ptr getelementptr inbounds (i8, ptr @m, i64 8), align 8, !tbaa !5
  %13 = add nsw i32 %11, %12
  store i32 %13, ptr @s1, align 4, !tbaa !5
  %14 = load i32, ptr getelementptr inbounds (i8, ptr @m, i64 12), align 4, !tbaa !5
  %15 = load i32, ptr getelementptr inbounds (i8, ptr @m, i64 16), align 16, !tbaa !5
  %16 = add nsw i32 %15, %14
  %17 = load i32, ptr getelementptr inbounds (i8, ptr @m, i64 20), align 4, !tbaa !5
  %18 = add nsw i32 %16, %17
  store i32 %18, ptr @s2, align 4, !tbaa !5
  %19 = load i32, ptr getelementptr inbounds (i8, ptr @m, i64 24), align 8, !tbaa !5
  %20 = load i32, ptr getelementptr inbounds (i8, ptr @m, i64 28), align 4, !tbaa !5
  %21 = add nsw i32 %20, %19
  %22 = load i32, ptr getelementptr inbounds (i8, ptr @m, i64 32), align 16, !tbaa !5
  %23 = add nsw i32 %21, %22
  store i32 %23, ptr @s3, align 4, !tbaa !5
  %24 = add nsw i32 %18, %13
  %25 = add nsw i32 %24, %23
  %26 = sdiv i32 %25, 2
  %27 = sub nsw i32 %26, %13
  store i32 %27, ptr @m, align 16, !tbaa !5
  %28 = sub nsw i32 %26, %18
  store i32 %28, ptr getelementptr inbounds (i8, ptr @m, i64 16), align 16, !tbaa !5
  %29 = sub nsw i32 %26, %23
  store i32 %29, ptr getelementptr inbounds (i8, ptr @m, i64 32), align 16, !tbaa !5
  %30 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %27)
  %31 = load i32, ptr getelementptr inbounds (i8, ptr @m, i64 4), align 4, !tbaa !5
  %32 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %31)
  %33 = load i32, ptr getelementptr inbounds (i8, ptr @m, i64 8), align 8, !tbaa !5
  %34 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %33)
  %35 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2)
  %36 = load i32, ptr getelementptr inbounds (i8, ptr @m, i64 12), align 4, !tbaa !5
  %37 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %36)
  %38 = load i32, ptr getelementptr inbounds (i8, ptr @m, i64 16), align 16, !tbaa !5
  %39 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %38)
  %40 = load i32, ptr getelementptr inbounds (i8, ptr @m, i64 20), align 4, !tbaa !5
  %41 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %40)
  %42 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2)
  %43 = load i32, ptr getelementptr inbounds (i8, ptr @m, i64 24), align 8, !tbaa !5
  %44 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %43)
  %45 = load i32, ptr getelementptr inbounds (i8, ptr @m, i64 28), align 4, !tbaa !5
  %46 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %45)
  %47 = load i32, ptr getelementptr inbounds (i8, ptr @m, i64 32), align 16, !tbaa !5
  %48 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %47)
  %49 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2)
  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 @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"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,LICMPass,LoopRotatePass,LoopSimplifyPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass