; LLVM IR from VastoLorde95/Competitive-Programming :: CodeChef/SHORT/COOK65/Problem A (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"

@t = external dso_local global i32, align 4
@n = external dso_local global i32, align 4
@a = external dso_local global [50 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

; 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
  store i32 0, ptr %1, align 4
  %9 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @t)
  br label %10

10:                                               ; preds = %69, %0
  %11 = load i32, ptr @t, align 4, !tbaa !5
  %12 = add nsw i32 %11, -1
  store i32 %12, ptr @t, align 4, !tbaa !5
  %13 = icmp ne i32 %11, 0
  br i1 %13, label %14, label %72

14:                                               ; preds = %10
  %15 = 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
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  store i32 0, ptr %3, align 4, !tbaa !5
  br label %16

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

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

21:                                               ; preds = %16
  %22 = load i32, ptr %3, align 4, !tbaa !5
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds [50 x i32], ptr @a, i64 0, i64 %23
  %25 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %24)
  br label %26

26:                                               ; preds = %21
  %27 = load i32, ptr %3, align 4, !tbaa !5
  %28 = add nsw i32 %27, 1
  store i32 %28, ptr %3, align 4, !tbaa !5
  br label %16, !llvm.loop !9

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

30:                                               ; preds = %66, %29
  %31 = load i32, ptr %4, align 4, !tbaa !5
  %32 = load i32, ptr @n, align 4, !tbaa !5
  %33 = icmp slt i32 %31, %32
  br i1 %33, label %35, label %34

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

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

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

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

42:                                               ; preds = %37
  %43 = load i32, ptr %8, align 4, !tbaa !5
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds [50 x i32], ptr @a, i64 0, i64 %44
  %46 = load i32, ptr %45, align 4, !tbaa !5
  %47 = load i32, ptr %6, align 4, !tbaa !5
  %48 = add nsw i32 %47, %46
  store i32 %48, ptr %6, align 4, !tbaa !5
  %49 = load i32, ptr %8, align 4, !tbaa !5
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds [50 x i32], ptr @a, i64 0, i64 %50
  %52 = load i32, ptr %51, align 4, !tbaa !5
  %53 = load i32, ptr %7, align 4, !tbaa !5
  %54 = mul nsw i32 %53, %52
  store i32 %54, ptr %7, align 4, !tbaa !5
  %55 = load i32, ptr %6, align 4, !tbaa !5
  %56 = load i32, ptr %7, align 4, !tbaa !5
  %57 = icmp eq i32 %55, %56
  br i1 %57, label %58, label %61

58:                                               ; preds = %42
  %59 = load i32, ptr %2, align 4, !tbaa !5
  %60 = add nsw i32 %59, 1
  store i32 %60, ptr %2, align 4, !tbaa !5
  br label %61

61:                                               ; preds = %58, %42
  br label %62

62:                                               ; preds = %61
  %63 = load i32, ptr %8, align 4, !tbaa !5
  %64 = add nsw i32 %63, 1
  store i32 %64, ptr %8, align 4, !tbaa !5
  br label %37, !llvm.loop !11

65:                                               ; preds = %41
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  br label %66

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

69:                                               ; preds = %34
  %70 = load i32, ptr %2, align 4, !tbaa !5
  %71 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i32 noundef %70)
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #3
  br label %10, !llvm.loop !13

72:                                               ; preds = %10
  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"

@t = external dso_local global i32, align 4
@n = external dso_local global i32, align 4
@a = external dso_local global [50 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

; 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 @t)
  %2 = load i32, ptr @t, align 4, !tbaa !5
  %3 = add nsw i32 %2, -1
  store i32 %3, ptr @t, align 4, !tbaa !5
  %.not30 = icmp eq i32 %2, 0
  br i1 %.not30, label %._crit_edge33, label %.lr.ph32

.lr.ph32:                                         ; preds = %0, %._crit_edge
  %4 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n)
  %5 = load i32, ptr @n, align 4, !tbaa !5
  %6 = icmp sgt i32 %5, 0
  br i1 %6, label %.lr.ph, label %._crit_edge

.preheader21:                                     ; preds = %.lr.ph
  %7 = icmp sgt i32 %11, 0
  br i1 %7, label %.preheader.preheader, label %._crit_edge

.preheader.preheader:                             ; preds = %.preheader21
  %wide.trip.count42 = zext nneg i32 %11 to i64
  %xtraiter = and i64 %wide.trip.count42, 1
  %8 = icmp eq i32 %11, 1
  br i1 %8, label %._crit_edge.loopexit.unr-lcssa, label %.preheader.preheader.new

.preheader.preheader.new:                         ; preds = %.preheader.preheader
  %unroll_iter = and i64 %wide.trip.count42, 2147483646
  br label %.preheader

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

.preheader:                                       ; preds = %30, %.preheader.preheader.new
  %indvars.iv36 = phi i64 [ 0, %.preheader.preheader.new ], [ %indvars.iv.next37.1, %30 ]
  %.02027 = phi i32 [ 0, %.preheader.preheader.new ], [ %spec.select.1, %30 ]
  %niter = phi i64 [ 0, %.preheader.preheader.new ], [ %niter.next.1, %30 ]
  br label %31

._crit_edge.loopexit.unr-lcssa:                   ; preds = %30, %.preheader.preheader
  %spec.select.lcssa.lcssa.ph = phi i32 [ poison, %.preheader.preheader ], [ %spec.select.1, %30 ]
  %indvars.iv36.unr = phi i64 [ 0, %.preheader.preheader ], [ %indvars.iv.next37.1, %30 ]
  %.02027.unr = phi i32 [ 0, %.preheader.preheader ], [ %spec.select.1, %30 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge, label %.preheader.epil

.preheader.epil:                                  ; preds = %._crit_edge.loopexit.unr-lcssa, %.preheader.epil
  %indvars.iv38.epil = phi i64 [ %indvars.iv.next39.epil, %.preheader.epil ], [ %indvars.iv36.unr, %._crit_edge.loopexit.unr-lcssa ]
  %.01625.epil = phi i32 [ %17, %.preheader.epil ], [ 1, %._crit_edge.loopexit.unr-lcssa ]
  %.01724.epil = phi i32 [ %16, %.preheader.epil ], [ 0, %._crit_edge.loopexit.unr-lcssa ]
  %.123.epil = phi i32 [ %spec.select.epil, %.preheader.epil ], [ %.02027.unr, %._crit_edge.loopexit.unr-lcssa ]
  %14 = getelementptr inbounds [50 x i32], ptr @a, i64 0, i64 %indvars.iv38.epil
  %15 = load i32, ptr %14, align 4, !tbaa !5
  %16 = add nsw i32 %15, %.01724.epil
  %17 = mul nsw i32 %15, %.01625.epil
  %18 = icmp eq i32 %16, %17
  %19 = zext i1 %18 to i32
  %spec.select.epil = add nsw i32 %.123.epil, %19
  %indvars.iv.next39.epil = add nuw nsw i64 %indvars.iv38.epil, 1
  %exitcond.not.epil = icmp eq i64 %indvars.iv.next39.epil, %wide.trip.count42
  br i1 %exitcond.not.epil, label %._crit_edge, label %.preheader.epil, !llvm.loop !11

._crit_edge:                                      ; preds = %._crit_edge.loopexit.unr-lcssa, %.preheader.epil, %.lr.ph32, %.preheader21
  %.020.lcssa = phi i32 [ 0, %.preheader21 ], [ 0, %.lr.ph32 ], [ %spec.select.lcssa.lcssa.ph, %._crit_edge.loopexit.unr-lcssa ], [ %spec.select.epil, %.preheader.epil ]
  %20 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %.020.lcssa)
  %21 = load i32, ptr @t, align 4, !tbaa !5
  %22 = add nsw i32 %21, -1
  store i32 %22, ptr @t, align 4, !tbaa !5
  %.not = icmp eq i32 %21, 0
  br i1 %.not, label %._crit_edge33, label %.lr.ph32, !llvm.loop !12

.preheader.1:                                     ; preds = %31
  %indvars.iv.next37 = or disjoint i64 %indvars.iv36, 1
  br label %23

23:                                               ; preds = %23, %.preheader.1
  %indvars.iv38.1 = phi i64 [ %indvars.iv.next37, %.preheader.1 ], [ %indvars.iv.next39.1, %23 ]
  %.01625.1 = phi i32 [ 1, %.preheader.1 ], [ %27, %23 ]
  %.01724.1 = phi i32 [ 0, %.preheader.1 ], [ %26, %23 ]
  %.123.1 = phi i32 [ %spec.select, %.preheader.1 ], [ %spec.select.1, %23 ]
  %24 = getelementptr inbounds [50 x i32], ptr @a, i64 0, i64 %indvars.iv38.1
  %25 = load i32, ptr %24, align 4, !tbaa !5
  %26 = add nsw i32 %25, %.01724.1
  %27 = mul nsw i32 %25, %.01625.1
  %28 = icmp eq i32 %26, %27
  %29 = zext i1 %28 to i32
  %spec.select.1 = add nsw i32 %.123.1, %29
  %indvars.iv.next39.1 = add nuw nsw i64 %indvars.iv38.1, 1
  %exitcond.not.1 = icmp eq i64 %indvars.iv.next39.1, %wide.trip.count42
  br i1 %exitcond.not.1, label %30, label %23, !llvm.loop !11

30:                                               ; preds = %23
  %indvars.iv.next37.1 = add nuw nsw i64 %indvars.iv36, 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_edge.loopexit.unr-lcssa, label %.preheader, !llvm.loop !13

31:                                               ; preds = %.preheader, %31
  %indvars.iv38 = phi i64 [ %indvars.iv36, %.preheader ], [ %indvars.iv.next39, %31 ]
  %.01625 = phi i32 [ 1, %.preheader ], [ %35, %31 ]
  %.01724 = phi i32 [ 0, %.preheader ], [ %34, %31 ]
  %.123 = phi i32 [ %.02027, %.preheader ], [ %spec.select, %31 ]
  %32 = getelementptr inbounds [50 x i32], ptr @a, i64 0, i64 %indvars.iv38
  %33 = load i32, ptr %32, align 4, !tbaa !5
  %34 = add nsw i32 %33, %.01724
  %35 = mul nsw i32 %33, %.01625
  %36 = icmp eq i32 %34, %35
  %37 = zext i1 %36 to i32
  %spec.select = add nsw i32 %.123, %37
  %indvars.iv.next39 = add nuw nsw i64 %indvars.iv38, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next39, %wide.trip.count42
  br i1 %exitcond.not, label %.preheader.1, label %31, !llvm.loop !11

._crit_edge33:                                    ; preds = %._crit_edge, %0
  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"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}
!12 = distinct !{!12, !10}
!13 = distinct !{!13, !10}


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