; LLVM IR from VastoLorde95/Competitive-Programming :: Codeforces/CROC-MBTU 2012, Elimination Round (ACM-ICPC)/Problem D (D)

; 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
@b = external dso_local global [111 x [111 x i32]], align 16
@a = external dso_local global [111 x i32], align 16
@.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
  %7 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  %8 = 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 %9

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

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

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

15:                                               ; preds = %28, %14
  %16 = load i32, ptr %4, align 4, !tbaa !5
  %17 = load i32, ptr @n, align 4, !tbaa !5
  %18 = icmp slt i32 %16, %17
  br i1 %18, label %20, label %19

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

20:                                               ; preds = %15
  %21 = load i32, ptr %2, align 4, !tbaa !5
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [111 x [111 x i32]], ptr @b, i64 0, i64 %22
  %24 = load i32, ptr %4, align 4, !tbaa !5
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds [111 x i32], ptr %23, i64 0, i64 %25
  %27 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %26)
  br label %28

28:                                               ; preds = %20
  %29 = load i32, ptr %4, align 4, !tbaa !5
  %30 = add nsw i32 %29, 1
  store i32 %30, ptr %4, align 4, !tbaa !5
  br label %15, !llvm.loop !9

31:                                               ; preds = %19
  br label %32

32:                                               ; preds = %31
  %33 = load i32, ptr %2, align 4, !tbaa !5
  %34 = add nsw i32 %33, 1
  store i32 %34, ptr %2, align 4, !tbaa !5
  br label %9, !llvm.loop !11

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

36:                                               ; preds = %69, %35
  %37 = load i32, ptr %5, align 4, !tbaa !5
  %38 = load i32, ptr @n, align 4, !tbaa !5
  %39 = icmp slt i32 %37, %38
  br i1 %39, label %41, label %40

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

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

42:                                               ; preds = %65, %41
  %43 = load i32, ptr %6, align 4, !tbaa !5
  %44 = load i32, ptr @n, align 4, !tbaa !5
  %45 = icmp slt i32 %43, %44
  br i1 %45, label %47, label %46

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

47:                                               ; preds = %42
  %48 = load i32, ptr %5, align 4, !tbaa !5
  %49 = load i32, ptr %6, align 4, !tbaa !5
  %50 = icmp eq i32 %48, %49
  br i1 %50, label %51, label %52

51:                                               ; preds = %47
  br label %65

52:                                               ; preds = %47
  %53 = load i32, ptr %5, align 4, !tbaa !5
  %54 = sext i32 %53 to i64
  %55 = getelementptr inbounds [111 x [111 x i32]], ptr @b, i64 0, i64 %54
  %56 = load i32, ptr %6, align 4, !tbaa !5
  %57 = sext i32 %56 to i64
  %58 = getelementptr inbounds [111 x i32], ptr %55, i64 0, i64 %57
  %59 = load i32, ptr %58, align 4, !tbaa !5
  %60 = load i32, ptr %5, align 4, !tbaa !5
  %61 = sext i32 %60 to i64
  %62 = getelementptr inbounds [111 x i32], ptr @a, i64 0, i64 %61
  %63 = load i32, ptr %62, align 4, !tbaa !5
  %64 = or i32 %63, %59
  store i32 %64, ptr %62, align 4, !tbaa !5
  br label %65

65:                                               ; preds = %52, %51
  %66 = load i32, ptr %6, align 4, !tbaa !5
  %67 = add nsw i32 %66, 1
  store i32 %67, ptr %6, align 4, !tbaa !5
  br label %42, !llvm.loop !12

68:                                               ; preds = %46
  br label %69

69:                                               ; preds = %68
  %70 = load i32, ptr %5, align 4, !tbaa !5
  %71 = add nsw i32 %70, 1
  store i32 %71, ptr %5, align 4, !tbaa !5
  br label %36, !llvm.loop !13

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

73:                                               ; preds = %84, %72
  %74 = load i32, ptr %7, align 4, !tbaa !5
  %75 = load i32, ptr @n, align 4, !tbaa !5
  %76 = icmp slt i32 %74, %75
  br i1 %76, label %78, label %77

77:                                               ; preds = %73
  store i32 14, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  br label %87

78:                                               ; preds = %73
  %79 = load i32, ptr %7, align 4, !tbaa !5
  %80 = sext i32 %79 to i64
  %81 = getelementptr inbounds [111 x i32], ptr @a, i64 0, i64 %80
  %82 = load i32, ptr %81, align 4, !tbaa !5
  %83 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i32 noundef %82)
  br label %84

84:                                               ; preds = %78
  %85 = load i32, ptr %7, align 4, !tbaa !5
  %86 = add nsw i32 %85, 1
  store i32 %86, ptr %7, align 4, !tbaa !5
  br label %73, !llvm.loop !14

87:                                               ; preds = %77
  %88 = call i32 (ptr, ...) @printf(ptr noundef @.str.2)
  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}
!14 = distinct !{!14, !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
@b = external dso_local global [111 x [111 x i32]], align 16
@a = external dso_local local_unnamed_addr global [111 x i32], align 16
@.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 {
  %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 %.preheader24, label %._crit_edge33

.preheader24:                                     ; preds = %0, %._crit_edge
  %4 = phi i32 [ %29, %._crit_edge ], [ %2, %0 ]
  %indvars.iv37 = phi i64 [ %indvars.iv.next38, %._crit_edge ], [ 0, %0 ]
  %5 = icmp sgt i32 %4, 0
  br i1 %5, label %.lr.ph, label %.preheader24.._crit_edge_crit_edge

.preheader24.._crit_edge_crit_edge:               ; preds = %.preheader24
  %.pre = sext i32 %4 to i64
  br label %._crit_edge

.preheader23:                                     ; preds = %._crit_edge
  %6 = icmp sgt i32 %29, 0
  br i1 %6, label %.preheader22.us.preheader, label %._crit_edge33

.preheader22.us.preheader:                        ; preds = %.preheader23
  %wide.trip.count46 = zext nneg i32 %29 to i64
  %xtraiter = and i64 %wide.trip.count46, 1
  %7 = icmp eq i32 %29, 1
  %unroll_iter = and i64 %wide.trip.count46, 2147483646
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br label %.preheader22.us

.preheader22.us:                                  ; preds = %.preheader22.us.preheader, %._crit_edge29.us
  %indvars.iv43 = phi i64 [ 0, %.preheader22.us.preheader ], [ %indvars.iv.next44, %._crit_edge29.us ]
  %8 = getelementptr inbounds [111 x i32], ptr @a, i64 0, i64 %indvars.iv43
  br i1 %7, label %._crit_edge29.us.unr-lcssa, label %.preheader22.us.new

.preheader22.us.new:                              ; preds = %.preheader22.us, %22
  %indvars.iv40 = phi i64 [ %indvars.iv.next41.1, %22 ], [ 0, %.preheader22.us ]
  %niter = phi i64 [ %niter.next.1, %22 ], [ 0, %.preheader22.us ]
  %9 = icmp eq i64 %indvars.iv43, %indvars.iv40
  br i1 %9, label %15, label %10

10:                                               ; preds = %.preheader22.us.new
  %11 = getelementptr inbounds [111 x [111 x i32]], ptr @b, i64 0, i64 %indvars.iv43, i64 %indvars.iv40
  %12 = load i32, ptr %11, align 4, !tbaa !5
  %13 = load i32, ptr %8, align 4, !tbaa !5
  %14 = or i32 %13, %12
  store i32 %14, ptr %8, align 4, !tbaa !5
  br label %15

15:                                               ; preds = %10, %.preheader22.us.new
  %indvars.iv.next41 = or disjoint i64 %indvars.iv40, 1
  %16 = icmp eq i64 %indvars.iv43, %indvars.iv.next41
  br i1 %16, label %22, label %17

17:                                               ; preds = %15
  %18 = getelementptr inbounds [111 x [111 x i32]], ptr @b, i64 0, i64 %indvars.iv43, i64 %indvars.iv.next41
  %19 = load i32, ptr %18, align 4, !tbaa !5
  %20 = load i32, ptr %8, align 4, !tbaa !5
  %21 = or i32 %20, %19
  store i32 %21, ptr %8, align 4, !tbaa !5
  br label %22

22:                                               ; preds = %17, %15
  %indvars.iv.next41.1 = add nuw nsw i64 %indvars.iv40, 2
  %niter.next.1 = add i64 %niter, 2
  %niter.ncmp.1 = icmp eq i64 %niter.next.1, %unroll_iter
  br i1 %niter.ncmp.1, label %._crit_edge29.us.unr-lcssa, label %.preheader22.us.new, !llvm.loop !9

._crit_edge29.us.unr-lcssa:                       ; preds = %22, %.preheader22.us
  %indvars.iv40.unr = phi i64 [ 0, %.preheader22.us ], [ %indvars.iv.next41.1, %22 ]
  %23 = icmp eq i64 %indvars.iv43, %indvars.iv40.unr
  %or.cond = select i1 %lcmp.mod.not, i1 true, i1 %23
  br i1 %or.cond, label %._crit_edge29.us, label %24

24:                                               ; preds = %._crit_edge29.us.unr-lcssa
  %25 = getelementptr inbounds [111 x [111 x i32]], ptr @b, i64 0, i64 %indvars.iv43, i64 %indvars.iv40.unr
  %26 = load i32, ptr %25, align 4, !tbaa !5
  %27 = load i32, ptr %8, align 4, !tbaa !5
  %28 = or i32 %27, %26
  store i32 %28, ptr %8, align 4, !tbaa !5
  br label %._crit_edge29.us

._crit_edge29.us:                                 ; preds = %24, %._crit_edge29.us.unr-lcssa
  %indvars.iv.next44 = add nuw nsw i64 %indvars.iv43, 1
  %exitcond47.not = icmp eq i64 %indvars.iv.next44, %wide.trip.count46
  br i1 %exitcond47.not, label %.lr.ph32, label %.preheader22.us, !llvm.loop !11

._crit_edge:                                      ; preds = %.lr.ph, %.preheader24.._crit_edge_crit_edge
  %.pre-phi = phi i64 [ %.pre, %.preheader24.._crit_edge_crit_edge ], [ %34, %.lr.ph ]
  %29 = phi i32 [ %4, %.preheader24.._crit_edge_crit_edge ], [ %33, %.lr.ph ]
  %indvars.iv.next38 = add nuw nsw i64 %indvars.iv37, 1
  %30 = icmp slt i64 %indvars.iv.next38, %.pre-phi
  br i1 %30, label %.preheader24, label %.preheader23, !llvm.loop !12

.lr.ph:                                           ; preds = %.preheader24, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %.preheader24 ]
  %31 = getelementptr inbounds [111 x [111 x i32]], ptr @b, i64 0, i64 %indvars.iv37, i64 %indvars.iv
  %32 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %31)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %33 = load i32, ptr @n, align 4, !tbaa !5
  %34 = sext i32 %33 to i64
  %35 = icmp slt i64 %indvars.iv.next, %34
  br i1 %35, label %.lr.ph, label %._crit_edge, !llvm.loop !14

._crit_edge33:                                    ; preds = %.lr.ph32, %0, %.preheader23
  %36 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2)
  ret i32 0

.lr.ph32:                                         ; preds = %._crit_edge29.us, %.lr.ph32
  %indvars.iv48 = phi i64 [ %indvars.iv.next49, %.lr.ph32 ], [ 0, %._crit_edge29.us ]
  %37 = getelementptr inbounds [111 x i32], ptr @a, i64 0, i64 %indvars.iv48
  %38 = load i32, ptr %37, align 4, !tbaa !5
  %39 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %38)
  %indvars.iv.next49 = add nuw nsw i64 %indvars.iv48, 1
  %40 = load i32, ptr @n, align 4, !tbaa !5
  %41 = sext i32 %40 to i64
  %42 = icmp slt i64 %indvars.iv.next49, %41
  br i1 %42, label %.lr.ph32, label %._crit_edge33, !llvm.loop !15
}

; 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"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}
!12 = distinct !{!12, !10, !13}
!13 = !{!"llvm.loop.unswitch.partial.disable"}
!14 = distinct !{!14, !10}
!15 = distinct !{!15, !10}


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