; LLVM IR from VastoLorde95/Competitive-Programming :: Codeforces/340 Division 2/Problem E (brute)

; 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
@m = external dso_local global i32, align 4
@k = external dso_local global i32, align 4
@a = external dso_local global [1000 x i32], align 16
@.str = external hidden unnamed_addr constant [7 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.3 = 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
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  %11 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n, ptr noundef @m, ptr noundef @k)
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #3
  store i32 0, ptr %2, align 4, !tbaa !5
  br label %12

12:                                               ; preds = %22, %0
  %13 = load i32, ptr %2, align 4, !tbaa !5
  %14 = load i32, ptr @n, align 4, !tbaa !5
  %15 = icmp slt i32 %13, %14
  br i1 %15, label %17, label %16

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

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

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

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

26:                                               ; preds = %74, %25
  %27 = load i32, ptr %3, align 4, !tbaa !5
  %28 = load i32, ptr @m, align 4, !tbaa !5
  %29 = icmp slt i32 %27, %28
  br i1 %29, label %31, label %30

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

31:                                               ; preds = %26
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  %32 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.2, ptr noundef %5, ptr noundef %6)
  %33 = load i32, ptr %5, align 4, !tbaa !5
  %34 = add nsw i32 %33, -1
  store i32 %34, ptr %5, align 4, !tbaa !5
  %35 = load i32, ptr %6, align 4, !tbaa !5
  %36 = add nsw i32 %35, -1
  store i32 %36, ptr %6, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  store i32 0, ptr %7, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  %37 = load i32, ptr %5, align 4, !tbaa !5
  store i32 %37, ptr %8, align 4, !tbaa !5
  br label %38

38:                                               ; preds = %68, %31
  %39 = load i32, ptr %8, align 4, !tbaa !5
  %40 = load i32, ptr %6, align 4, !tbaa !5
  %41 = icmp sle i32 %39, %40
  br i1 %41, label %43, label %42

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

43:                                               ; preds = %38
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  store i32 0, ptr %9, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  %44 = load i32, ptr %8, align 4, !tbaa !5
  store i32 %44, ptr %10, align 4, !tbaa !5
  br label %45

45:                                               ; preds = %64, %43
  %46 = load i32, ptr %10, align 4, !tbaa !5
  %47 = load i32, ptr %6, align 4, !tbaa !5
  %48 = icmp sle i32 %46, %47
  br i1 %48, label %50, label %49

49:                                               ; preds = %45
  store i32 11, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  br label %67

50:                                               ; preds = %45
  %51 = load i32, ptr %10, align 4, !tbaa !5
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds [1000 x i32], ptr @a, i64 0, i64 %52
  %54 = load i32, ptr %53, align 4, !tbaa !5
  %55 = load i32, ptr %9, align 4, !tbaa !5
  %56 = xor i32 %55, %54
  store i32 %56, ptr %9, align 4, !tbaa !5
  %57 = load i32, ptr %9, align 4, !tbaa !5
  %58 = load i32, ptr @k, align 4, !tbaa !5
  %59 = icmp eq i32 %57, %58
  br i1 %59, label %60, label %63

60:                                               ; preds = %50
  %61 = load i32, ptr %7, align 4, !tbaa !5
  %62 = add nsw i32 %61, 1
  store i32 %62, ptr %7, align 4, !tbaa !5
  br label %63

63:                                               ; preds = %60, %50
  br label %64

64:                                               ; preds = %63
  %65 = load i32, ptr %10, align 4, !tbaa !5
  %66 = add nsw i32 %65, 1
  store i32 %66, ptr %10, align 4, !tbaa !5
  br label %45, !llvm.loop !11

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

68:                                               ; preds = %67
  %69 = load i32, ptr %8, align 4, !tbaa !5
  %70 = add nsw i32 %69, 1
  store i32 %70, ptr %8, align 4, !tbaa !5
  br label %38, !llvm.loop !12

71:                                               ; preds = %42
  %72 = load i32, ptr %7, align 4, !tbaa !5
  %73 = call i32 (ptr, ...) @printf(ptr noundef @.str.3, i32 noundef %72)
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  br label %74

74:                                               ; preds = %71
  %75 = load i32, ptr %3, align 4, !tbaa !5
  %76 = add nsw i32 %75, 1
  store i32 %76, ptr %3, align 4, !tbaa !5
  br label %26, !llvm.loop !13

77:                                               ; preds = %30
  ret i32 0
}

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 @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 = 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"

@n = external dso_local global i32, align 4
@m = external dso_local global i32, align 4
@k = external dso_local global i32, align 4
@a = external dso_local global [1000 x i32], align 16
@.str = external hidden unnamed_addr constant [7 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.3 = 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 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n, ptr noundef nonnull @m, ptr noundef nonnull @k)
  %4 = load i32, ptr @n, align 4, !tbaa !5
  %5 = icmp sgt i32 %4, 0
  br i1 %5, label %.lr.ph, label %.preheader21

.preheader21:                                     ; preds = %.lr.ph, %0
  %6 = load i32, ptr @m, align 4, !tbaa !5
  %7 = icmp sgt i32 %6, 0
  br i1 %7, label %.lr.ph30, label %._crit_edge31

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

._crit_edge31:                                    ; preds = %._crit_edge, %.preheader21
  ret i32 0

.lr.ph30:                                         ; preds = %.preheader21, %._crit_edge
  %.01829 = phi i32 [ %30, %._crit_edge ], [ 0, %.preheader21 ]
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2) #3
  %13 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.2, ptr noundef nonnull %1, ptr noundef nonnull %2)
  %14 = load i32, ptr %1, align 4, !tbaa !5
  %15 = add i32 %14, -1
  store i32 %15, ptr %1, align 4, !tbaa !5
  %16 = load i32, ptr %2, align 4, !tbaa !5
  %17 = add nsw i32 %16, -1
  store i32 %17, ptr %2, align 4, !tbaa !5
  %.not.not26.not = icmp sgt i32 %14, %16
  br i1 %.not.not26.not, label %._crit_edge, label %.preheader.lr.ph

.preheader.lr.ph:                                 ; preds = %.lr.ph30
  %18 = load i32, ptr @k, align 4, !tbaa !5
  %19 = sext i32 %15 to i64
  %20 = sext i32 %16 to i64
  %21 = add i32 %16, 1
  %22 = sub i32 %21, %14
  %xtraiter = and i32 %22, 1
  %23 = icmp eq i32 %16, %14
  br i1 %23, label %._crit_edge.loopexit.unr-lcssa, label %.preheader.lr.ph.new

.preheader.lr.ph.new:                             ; preds = %.preheader.lr.ph
  %unroll_iter = and i32 %22, -2
  br label %.preheader

.preheader:                                       ; preds = %39, %.preheader.lr.ph.new
  %indvars.iv33 = phi i64 [ %19, %.preheader.lr.ph.new ], [ %indvars.iv.next34.1, %39 ]
  %.01727 = phi i32 [ 0, %.preheader.lr.ph.new ], [ %spec.select.1, %39 ]
  %niter = phi i32 [ 0, %.preheader.lr.ph.new ], [ %niter.next.1, %39 ]
  br label %40

._crit_edge.loopexit.unr-lcssa:                   ; preds = %39, %.preheader.lr.ph
  %spec.select.lcssa.lcssa.ph = phi i32 [ poison, %.preheader.lr.ph ], [ %spec.select.1, %39 ]
  %indvars.iv33.unr = phi i64 [ %19, %.preheader.lr.ph ], [ %indvars.iv.next34.1, %39 ]
  %.01727.unr = phi i32 [ 0, %.preheader.lr.ph ], [ %spec.select.1, %39 ]
  %lcmp.mod.not = icmp eq i32 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge, label %.preheader.epil

.preheader.epil:                                  ; preds = %._crit_edge.loopexit.unr-lcssa, %.preheader.epil
  %indvars.iv35.epil = phi i64 [ %indvars.iv.next36.epil, %.preheader.epil ], [ %indvars.iv33.unr, %._crit_edge.loopexit.unr-lcssa ]
  %.01524.epil = phi i32 [ %26, %.preheader.epil ], [ 0, %._crit_edge.loopexit.unr-lcssa ]
  %.123.epil = phi i32 [ %spec.select.epil, %.preheader.epil ], [ %.01727.unr, %._crit_edge.loopexit.unr-lcssa ]
  %24 = getelementptr inbounds [1000 x i32], ptr @a, i64 0, i64 %indvars.iv35.epil
  %25 = load i32, ptr %24, align 4, !tbaa !5
  %26 = xor i32 %25, %.01524.epil
  %27 = icmp eq i32 %26, %18
  %28 = zext i1 %27 to i32
  %spec.select.epil = add nsw i32 %.123.epil, %28
  %indvars.iv.next36.epil = add nsw i64 %indvars.iv35.epil, 1
  %.not20.not.epil = icmp slt i64 %indvars.iv.next36.epil, %20
  br i1 %.not20.not.epil, label %.preheader.epil, label %._crit_edge, !llvm.loop !11

._crit_edge:                                      ; preds = %._crit_edge.loopexit.unr-lcssa, %.preheader.epil, %.lr.ph30
  %.017.lcssa = phi i32 [ 0, %.lr.ph30 ], [ %spec.select.lcssa.lcssa.ph, %._crit_edge.loopexit.unr-lcssa ], [ %spec.select.epil, %.preheader.epil ]
  %29 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3, i32 noundef %.017.lcssa)
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #3
  %30 = add nuw nsw i32 %.01829, 1
  %31 = load i32, ptr @m, align 4, !tbaa !5
  %32 = icmp slt i32 %30, %31
  br i1 %32, label %.lr.ph30, label %._crit_edge31, !llvm.loop !12

.preheader.1:                                     ; preds = %40
  %indvars.iv.next34 = add nsw i64 %indvars.iv33, 1
  br label %33

33:                                               ; preds = %33, %.preheader.1
  %indvars.iv35.1 = phi i64 [ %indvars.iv.next34, %.preheader.1 ], [ %indvars.iv.next36.1, %33 ]
  %.01524.1 = phi i32 [ 0, %.preheader.1 ], [ %36, %33 ]
  %.123.1 = phi i32 [ %spec.select, %.preheader.1 ], [ %spec.select.1, %33 ]
  %34 = getelementptr inbounds [1000 x i32], ptr @a, i64 0, i64 %indvars.iv35.1
  %35 = load i32, ptr %34, align 4, !tbaa !5
  %36 = xor i32 %35, %.01524.1
  %37 = icmp eq i32 %36, %18
  %38 = zext i1 %37 to i32
  %spec.select.1 = add nsw i32 %.123.1, %38
  %indvars.iv.next36.1 = add nsw i64 %indvars.iv35.1, 1
  %.not20.not.1 = icmp slt i64 %indvars.iv.next36.1, %20
  br i1 %.not20.not.1, label %33, label %39, !llvm.loop !11

39:                                               ; preds = %33
  %indvars.iv.next34.1 = add nsw i64 %indvars.iv33, 2
  %niter.next.1 = add i32 %niter, 2
  %niter.ncmp.1.not = icmp eq i32 %niter.next.1, %unroll_iter
  br i1 %niter.ncmp.1.not, label %._crit_edge.loopexit.unr-lcssa, label %.preheader, !llvm.loop !13

40:                                               ; preds = %.preheader, %40
  %indvars.iv35 = phi i64 [ %indvars.iv33, %.preheader ], [ %indvars.iv.next36, %40 ]
  %.01524 = phi i32 [ 0, %.preheader ], [ %43, %40 ]
  %.123 = phi i32 [ %.01727, %.preheader ], [ %spec.select, %40 ]
  %41 = getelementptr inbounds [1000 x i32], ptr @a, i64 0, i64 %indvars.iv35
  %42 = load i32, ptr %41, align 4, !tbaa !5
  %43 = xor i32 %42, %.01524
  %44 = icmp eq i32 %43, %18
  %45 = zext i1 %44 to i32
  %spec.select = add nsw i32 %.123, %45
  %indvars.iv.next36 = add nsw i64 %indvars.iv35, 1
  %.not20.not = icmp slt i64 %indvars.iv.next36, %20
  br i1 %.not20.not, label %40, label %.preheader.1, !llvm.loop !11
}

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

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

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

; 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" }
attributes #2 = { mustprogress 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 = distinct !{!11, !10}
!12 = distinct !{!12, !10}
!13 = distinct !{!13, !10}


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