; LLVM IR from VastoLorde95/Competitive-Programming :: Hackerrank/Random/String Transmission (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"

@c = external dso_local global [1010 x [1010 x i32]], align 16
@.str.3 = external hidden unnamed_addr constant [3 x i8], align 1

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z5solvev() #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

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #3 {
  %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
  store i32 0, ptr %1, align 4
  store i32 1, ptr @c, align 16, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #4
  store i32 1, ptr %2, align 4, !tbaa !5
  br label %6

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

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

10:                                               ; preds = %6
  %11 = load i32, ptr %2, align 4, !tbaa !5
  %12 = sext i32 %11 to i64
  %13 = getelementptr inbounds [1010 x [1010 x i32]], ptr @c, i64 0, i64 %12
  %14 = load i32, ptr %2, align 4, !tbaa !5
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds [1010 x i32], ptr %13, i64 0, i64 %15
  store i32 1, ptr %16, align 4, !tbaa !5
  %17 = load i32, ptr %2, align 4, !tbaa !5
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds [1010 x [1010 x i32]], ptr @c, i64 0, i64 %18
  %20 = getelementptr inbounds [1010 x i32], ptr %19, i64 0, i64 0
  store i32 1, ptr %20, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  store i32 1, ptr %4, align 4, !tbaa !5
  br label %21

21:                                               ; preds = %69, %10
  %22 = load i32, ptr %4, align 4, !tbaa !5
  %23 = load i32, ptr %2, align 4, !tbaa !5
  %24 = icmp slt i32 %22, %23
  br i1 %24, label %26, label %25

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

26:                                               ; preds = %21
  %27 = load i32, ptr %2, align 4, !tbaa !5
  %28 = sub nsw i32 %27, 1
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds [1010 x [1010 x i32]], ptr @c, i64 0, i64 %29
  %31 = load i32, ptr %4, align 4, !tbaa !5
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds [1010 x i32], ptr %30, i64 0, i64 %32
  %34 = load i32, ptr %33, align 4, !tbaa !5
  %35 = load i32, ptr %2, align 4, !tbaa !5
  %36 = sub nsw i32 %35, 1
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds [1010 x [1010 x i32]], ptr @c, i64 0, i64 %37
  %39 = load i32, ptr %4, align 4, !tbaa !5
  %40 = sub nsw i32 %39, 1
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds [1010 x i32], ptr %38, i64 0, i64 %41
  %43 = load i32, ptr %42, align 4, !tbaa !5
  %44 = add nsw i32 %34, %43
  %45 = load i32, ptr %2, align 4, !tbaa !5
  %46 = sext i32 %45 to i64
  %47 = getelementptr inbounds [1010 x [1010 x i32]], ptr @c, i64 0, i64 %46
  %48 = load i32, ptr %4, align 4, !tbaa !5
  %49 = sext i32 %48 to i64
  %50 = getelementptr inbounds [1010 x i32], ptr %47, i64 0, i64 %49
  store i32 %44, ptr %50, align 4, !tbaa !5
  %51 = load i32, ptr %2, align 4, !tbaa !5
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds [1010 x [1010 x i32]], ptr @c, i64 0, i64 %52
  %54 = load i32, ptr %4, align 4, !tbaa !5
  %55 = sext i32 %54 to i64
  %56 = getelementptr inbounds [1010 x i32], ptr %53, i64 0, i64 %55
  %57 = load i32, ptr %56, align 4, !tbaa !5
  %58 = icmp sge i32 %57, 1000000007
  br i1 %58, label %59, label %68

59:                                               ; preds = %26
  %60 = load i32, ptr %2, align 4, !tbaa !5
  %61 = sext i32 %60 to i64
  %62 = getelementptr inbounds [1010 x [1010 x i32]], ptr @c, i64 0, i64 %61
  %63 = load i32, ptr %4, align 4, !tbaa !5
  %64 = sext i32 %63 to i64
  %65 = getelementptr inbounds [1010 x i32], ptr %62, i64 0, i64 %64
  %66 = load i32, ptr %65, align 4, !tbaa !5
  %67 = sub nsw i32 %66, 1000000007
  store i32 %67, ptr %65, align 4, !tbaa !5
  br label %68

68:                                               ; preds = %59, %26
  br label %69

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

72:                                               ; preds = %25
  br label %73

73:                                               ; preds = %72
  %74 = load i32, ptr %2, align 4, !tbaa !5
  %75 = add nsw i32 %74, 1
  store i32 %75, ptr %2, align 4, !tbaa !5
  br label %6, !llvm.loop !11

76:                                               ; preds = %9
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  %77 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.3, ptr noundef %5)
  br label %78

78:                                               ; preds = %82, %76
  %79 = load i32, ptr %5, align 4, !tbaa !5
  %80 = add nsw i32 %79, -1
  store i32 %80, ptr %5, align 4, !tbaa !5
  %81 = icmp ne i32 %79, 0
  br i1 %81, label %82, label %83

82:                                               ; preds = %78
  call void @_Z5solvev()
  br label %78, !llvm.loop !12

83:                                               ; preds = %78
  store i32 0, ptr %1, align 4
  store i32 1, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  %84 = load i32, ptr %1, align 4
  ret i32 %84
}

attributes #0 = { mustprogress 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 = { 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 #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}
!12 = distinct !{!12, !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"

@c = external dso_local local_unnamed_addr global [1010 x [1010 x i32]], align 16
@.str.3 = external hidden unnamed_addr constant [3 x i8], align 1

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z5solvev() local_unnamed_addr #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 willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() local_unnamed_addr #3 {
  %1 = alloca i32, align 4
  store i32 1, ptr @c, align 16, !tbaa !5
  br label %6

2:                                                ; preds = %._crit_edge
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #4
  %3 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.3, ptr noundef nonnull %1)
  %4 = load i32, ptr %1, align 4, !tbaa !5
  %5 = add nsw i32 %4, -1
  store i32 %5, ptr %1, align 4, !tbaa !5
  %.not23 = icmp eq i32 %4, 0
  br i1 %.not23, label %._crit_edge26, label %.lr.ph25

6:                                                ; preds = %0, %._crit_edge
  %indvar = phi i64 [ 0, %0 ], [ %indvar.next, %._crit_edge ]
  %indvars.iv28 = phi i64 [ 1, %0 ], [ %indvars.iv.next29, %._crit_edge ]
  %7 = getelementptr inbounds [1010 x [1010 x i32]], ptr @c, i64 0, i64 %indvars.iv28
  %8 = getelementptr inbounds [1010 x [1010 x i32]], ptr @c, i64 0, i64 %indvars.iv28, i64 %indvars.iv28
  store i32 1, ptr %8, align 4, !tbaa !5
  store i32 1, ptr %7, align 8, !tbaa !5
  %9 = icmp ugt i64 %indvars.iv28, 1
  br i1 %9, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %6
  %10 = add nsw i64 %indvars.iv28, -1
  %.phi.trans.insert = getelementptr inbounds [1010 x [1010 x i32]], ptr @c, i64 0, i64 %10, i64 0
  %.pre = load i32, ptr %.phi.trans.insert, align 8, !tbaa !5
  %min.iters.check = icmp ult i64 %indvar, 8
  br i1 %min.iters.check, label %scalar.ph.preheader, label %vector.ph

scalar.ph.preheader:                              ; preds = %middle.block, %.lr.ph
  %.ph = phi i32 [ %.pre, %.lr.ph ], [ %vector.recur.extract, %middle.block ]
  %indvars.iv.ph = phi i64 [ 1, %.lr.ph ], [ %ind.end, %middle.block ]
  br label %scalar.ph

vector.ph:                                        ; preds = %.lr.ph
  %n.vec = and i64 %indvar, -8
  %ind.end = or disjoint i64 %n.vec, 1
  %vector.recur.init = insertelement <4 x i32> poison, i32 %.pre, i64 3
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %vector.recur = phi <4 x i32> [ %vector.recur.init, %vector.ph ], [ %wide.load32, %vector.body ]
  %offset.idx = or disjoint i64 %index, 1
  %11 = getelementptr inbounds [1010 x [1010 x i32]], ptr @c, i64 0, i64 %10, i64 %offset.idx
  %12 = getelementptr inbounds i8, ptr %11, i64 16
  %wide.load = load <4 x i32>, ptr %11, align 4, !tbaa !5
  %wide.load32 = load <4 x i32>, ptr %12, align 4, !tbaa !5
  %13 = shufflevector <4 x i32> %vector.recur, <4 x i32> %wide.load, <4 x i32> <i32 3, i32 4, i32 5, i32 6>
  %14 = shufflevector <4 x i32> %wide.load, <4 x i32> %wide.load32, <4 x i32> <i32 3, i32 4, i32 5, i32 6>
  %15 = add nsw <4 x i32> %13, %wide.load
  %16 = add nsw <4 x i32> %14, %wide.load32
  %17 = getelementptr inbounds [1010 x [1010 x i32]], ptr @c, i64 0, i64 %indvars.iv28, i64 %offset.idx
  %18 = icmp sgt <4 x i32> %15, <i32 1000000006, i32 1000000006, i32 1000000006, i32 1000000006>
  %19 = icmp sgt <4 x i32> %16, <i32 1000000006, i32 1000000006, i32 1000000006, i32 1000000006>
  %20 = add nsw <4 x i32> %15, <i32 -1000000007, i32 -1000000007, i32 -1000000007, i32 -1000000007>
  %21 = add nsw <4 x i32> %16, <i32 -1000000007, i32 -1000000007, i32 -1000000007, i32 -1000000007>
  %22 = select <4 x i1> %18, <4 x i32> %20, <4 x i32> %15
  %23 = select <4 x i1> %19, <4 x i32> %21, <4 x i32> %16
  %24 = getelementptr inbounds i8, ptr %17, i64 16
  store <4 x i32> %22, ptr %17, align 4, !tbaa !5
  store <4 x i32> %23, ptr %24, align 4, !tbaa !5
  %index.next = add nuw i64 %index, 8
  %25 = icmp eq i64 %index.next, %n.vec
  br i1 %25, label %middle.block, label %vector.body, !llvm.loop !9

middle.block:                                     ; preds = %vector.body
  %vector.recur.extract = extractelement <4 x i32> %wide.load32, i64 3
  %cmp.n = icmp eq i64 %indvar, %n.vec
  br i1 %cmp.n, label %._crit_edge, label %scalar.ph.preheader

._crit_edge:                                      ; preds = %scalar.ph, %middle.block, %6
  %indvars.iv.next29 = add nuw nsw i64 %indvars.iv28, 1
  %exitcond31.not = icmp eq i64 %indvars.iv.next29, 1010
  %indvar.next = add i64 %indvar, 1
  br i1 %exitcond31.not, label %2, label %6, !llvm.loop !13

scalar.ph:                                        ; preds = %scalar.ph.preheader, %scalar.ph
  %26 = phi i32 [ %28, %scalar.ph ], [ %.ph, %scalar.ph.preheader ]
  %indvars.iv = phi i64 [ %indvars.iv.next, %scalar.ph ], [ %indvars.iv.ph, %scalar.ph.preheader ]
  %27 = getelementptr inbounds [1010 x [1010 x i32]], ptr @c, i64 0, i64 %10, i64 %indvars.iv
  %28 = load i32, ptr %27, align 4, !tbaa !5
  %29 = add nsw i32 %26, %28
  %30 = getelementptr inbounds [1010 x [1010 x i32]], ptr @c, i64 0, i64 %indvars.iv28, i64 %indvars.iv
  %31 = icmp sgt i32 %29, 1000000006
  %32 = add nsw i32 %29, -1000000007
  %spec.select = select i1 %31, i32 %32, i32 %29
  store i32 %spec.select, ptr %30, align 4, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %indvars.iv28
  br i1 %exitcond.not, label %._crit_edge, label %scalar.ph, !llvm.loop !14

.lr.ph25:                                         ; preds = %2, %.lr.ph25
  call void @_Z5solvev()
  %33 = load i32, ptr %1, align 4, !tbaa !5
  %34 = add nsw i32 %33, -1
  store i32 %34, ptr %1, align 4, !tbaa !5
  %.not = icmp eq i32 %33, 0
  br i1 %.not, label %._crit_edge26, label %.lr.ph25, !llvm.loop !15

._crit_edge26:                                    ; preds = %.lr.ph25, %2
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #4
  ret i32 0
}

attributes #0 = { mustprogress 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 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 #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, !11, !12}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!"llvm.loop.isvectorized", i32 1}
!12 = !{!"llvm.loop.unroll.runtime.disable"}
!13 = distinct !{!13, !10}
!14 = distinct !{!14, !10, !12, !11}
!15 = distinct !{!15, !10}


; Effective O3 passes: BDCEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopLoadEliminationPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,LoopVectorizePass,ReassociatePass,SROAPass,SimplifyCFGPass