; LLVM IR from reyadussalahin/problem-solving :: brute_force/loop/uva/F12455 (Solution)

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

@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [6 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 [1024 x i32], align 16
  %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
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 4096, ptr %2) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  %14 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %3)
  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 = %87, %0
  %16 = load i32, ptr %4, align 4, !tbaa !5
  %17 = load i32, ptr %3, align 4, !tbaa !5
  %18 = icmp slt i32 %16, %17
  br i1 %18, label %20, label %19

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

20:                                               ; preds = %15
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  %21 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef %6, ptr noundef %7)
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  store i32 0, ptr %8, align 4, !tbaa !5
  br label %22

22:                                               ; preds = %32, %20
  %23 = load i32, ptr %8, align 4, !tbaa !5
  %24 = load i32, ptr %7, align 4, !tbaa !5
  %25 = icmp slt i32 %23, %24
  br i1 %25, label %27, label %26

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

27:                                               ; preds = %22
  %28 = load i32, ptr %8, align 4, !tbaa !5
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds [1024 x i32], ptr %2, i64 0, i64 %29
  %31 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %30)
  br label %32

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

35:                                               ; preds = %26
  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
  %36 = load i32, ptr %7, align 4, !tbaa !5
  %37 = shl i32 1, %36
  store i32 %37, ptr %10, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  store i32 0, ptr %11, align 4, !tbaa !5
  br label %38

38:                                               ; preds = %75, %35
  %39 = load i32, ptr %11, align 4, !tbaa !5
  %40 = load i32, ptr %10, align 4, !tbaa !5
  %41 = icmp slt i32 %39, %40
  br i1 %41, label %43, label %42

42:                                               ; preds = %38
  store i32 8, ptr %5, align 4
  br label %78

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

44:                                               ; preds = %63, %43
  %45 = load i32, ptr %13, align 4, !tbaa !5
  %46 = load i32, ptr %7, align 4, !tbaa !5
  %47 = icmp slt i32 %45, %46
  br i1 %47, label %49, label %48

48:                                               ; preds = %44
  store i32 11, ptr %5, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #3
  br label %66

49:                                               ; preds = %44
  %50 = load i32, ptr %11, align 4, !tbaa !5
  %51 = load i32, ptr %13, align 4, !tbaa !5
  %52 = shl i32 1, %51
  %53 = and i32 %50, %52
  %54 = icmp ne i32 %53, 0
  br i1 %54, label %55, label %62

55:                                               ; preds = %49
  %56 = load i32, ptr %13, align 4, !tbaa !5
  %57 = sext i32 %56 to i64
  %58 = getelementptr inbounds [1024 x i32], ptr %2, i64 0, i64 %57
  %59 = load i32, ptr %58, align 4, !tbaa !5
  %60 = load i32, ptr %12, align 4, !tbaa !5
  %61 = add nsw i32 %60, %59
  store i32 %61, ptr %12, align 4, !tbaa !5
  br label %62

62:                                               ; preds = %55, %49
  br label %63

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

66:                                               ; preds = %48
  %67 = load i32, ptr %12, align 4, !tbaa !5
  %68 = load i32, ptr %6, align 4, !tbaa !5
  %69 = icmp eq i32 %67, %68
  br i1 %69, label %70, label %71

70:                                               ; preds = %66
  store i32 1, ptr %9, align 4, !tbaa !5
  store i32 8, ptr %5, align 4
  br label %72

71:                                               ; preds = %66
  store i32 0, ptr %5, align 4
  br label %72

72:                                               ; preds = %71, %70
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #3
  %73 = load i32, ptr %5, align 4
  switch i32 %73, label %78 [
    i32 0, label %74
  ]

74:                                               ; preds = %72
  br label %75

75:                                               ; preds = %74
  %76 = load i32, ptr %11, align 4, !tbaa !5
  %77 = add nsw i32 %76, 1
  store i32 %77, ptr %11, align 4, !tbaa !5
  br label %38, !llvm.loop !12

78:                                               ; preds = %72, %42
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  br label %79

79:                                               ; preds = %78
  %80 = load i32, ptr %9, align 4, !tbaa !5
  %81 = icmp ne i32 %80, 0
  br i1 %81, label %82, label %84

82:                                               ; preds = %79
  %83 = call i32 (ptr, ...) @printf(ptr noundef @.str.2)
  br label %86

84:                                               ; preds = %79
  %85 = call i32 (ptr, ...) @printf(ptr noundef @.str.3)
  br label %86

86:                                               ; preds = %84, %82
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  br label %87

87:                                               ; preds = %86
  %88 = load i32, ptr %4, align 4, !tbaa !5
  %89 = add nsw i32 %88, 1
  store i32 %89, ptr %4, align 4, !tbaa !5
  br label %15, !llvm.loop !13

90:                                               ; preds = %19
  store i32 0, ptr %1, align 4
  store i32 1, ptr %5, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  call void @llvm.lifetime.end.p0(i64 4096, ptr %2) #3
  %91 = load i32, ptr %1, align 4
  ret i32 %91
}

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

@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [6 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 [1024 x i32], align 16
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4096, ptr nonnull %1) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2) #3
  %5 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %2)
  %6 = load i32, ptr %2, align 4, !tbaa !5
  %7 = icmp sgt i32 %6, 0
  br i1 %7, label %.lr.ph39, label %._crit_edge40

._crit_edge40:                                    ; preds = %.split.us, %0
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #3
  call void @llvm.lifetime.end.p0(i64 4096, ptr nonnull %1) #3
  ret i32 0

.lr.ph39:                                         ; preds = %0, %.split.us
  %.02437 = phi i32 [ %48, %.split.us ], [ 0, %0 ]
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %3) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %4) #3
  %8 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %3, ptr noundef nonnull %4)
  %9 = load i32, ptr %4, align 4, !tbaa !5
  %10 = icmp sgt i32 %9, 0
  br i1 %10, label %.lr.ph, label %.preheader.lr.ph.thread

.preheader.lr.ph.thread:                          ; preds = %.lr.ph39
  %11 = load i32, ptr %3, align 4, !tbaa !5
  br label %.preheader.lr.ph.split

._crit_edge:                                      ; preds = %.lr.ph
  %12 = shl nuw nsw i32 1, %44
  %.not2835.not = icmp eq i32 %44, 31
  br i1 %.not2835.not, label %.critedge.loopexit, label %.preheader.lr.ph

.preheader.lr.ph:                                 ; preds = %._crit_edge
  %13 = icmp sgt i32 %44, 0
  %14 = load i32, ptr %3, align 4, !tbaa !5
  br i1 %13, label %.preheader.us.preheader, label %.preheader.lr.ph.split

.preheader.us.preheader:                          ; preds = %.preheader.lr.ph
  %wide.trip.count = zext nneg i32 %44 to i64
  %xtraiter = and i64 %wide.trip.count, 1
  %15 = icmp eq i32 %44, 1
  %unroll_iter = and i64 %wide.trip.count, 2147483646
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br label %.preheader.us

.preheader.us:                                    ; preds = %.preheader.us.preheader, %32
  %.01936.us = phi i32 [ %33, %32 ], [ 0, %.preheader.us.preheader ]
  br i1 %15, label %._crit_edge33.us.unr-lcssa, label %.preheader.us.new

.preheader.us.new:                                ; preds = %.preheader.us, %31
  %indvars.iv44 = phi i64 [ %indvars.iv.next45.1, %31 ], [ 0, %.preheader.us ]
  %.01830.us = phi i32 [ %.1.us.1, %31 ], [ 0, %.preheader.us ]
  %niter = phi i64 [ %niter.next.1, %31 ], [ 0, %.preheader.us ]
  %16 = trunc nuw nsw i64 %indvars.iv44 to i32
  %17 = shl nuw i32 1, %16
  %18 = and i32 %17, %.01936.us
  %.not27.us = icmp eq i32 %18, 0
  br i1 %.not27.us, label %23, label %19

19:                                               ; preds = %.preheader.us.new
  %20 = getelementptr inbounds [1024 x i32], ptr %1, i64 0, i64 %indvars.iv44
  %21 = load i32, ptr %20, align 8, !tbaa !5
  %22 = add nsw i32 %21, %.01830.us
  br label %23

23:                                               ; preds = %19, %.preheader.us.new
  %.1.us = phi i32 [ %22, %19 ], [ %.01830.us, %.preheader.us.new ]
  %indvars.iv.next45 = or disjoint i64 %indvars.iv44, 1
  %24 = trunc nuw nsw i64 %indvars.iv.next45 to i32
  %25 = shl nuw i32 1, %24
  %26 = and i32 %25, %.01936.us
  %.not27.us.1 = icmp eq i32 %26, 0
  br i1 %.not27.us.1, label %31, label %27

27:                                               ; preds = %23
  %28 = getelementptr inbounds [1024 x i32], ptr %1, i64 0, i64 %indvars.iv.next45
  %29 = load i32, ptr %28, align 4, !tbaa !5
  %30 = add nsw i32 %29, %.1.us
  br label %31

31:                                               ; preds = %27, %23
  %.1.us.1 = phi i32 [ %30, %27 ], [ %.1.us, %23 ]
  %indvars.iv.next45.1 = add nuw nsw i64 %indvars.iv44, 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_edge33.us.unr-lcssa, label %.preheader.us.new, !llvm.loop !9

32:                                               ; preds = %._crit_edge33.us
  %33 = add nuw nsw i32 %.01936.us, 1
  %exitcond47.not = icmp eq i32 %33, %12
  br i1 %exitcond47.not, label %.critedge.loopexit, label %.preheader.us, !llvm.loop !11

._crit_edge33.us.unr-lcssa:                       ; preds = %31, %.preheader.us
  %.1.us.lcssa.ph = phi i32 [ poison, %.preheader.us ], [ %.1.us.1, %31 ]
  %indvars.iv44.unr = phi i64 [ 0, %.preheader.us ], [ %indvars.iv.next45.1, %31 ]
  %.01830.us.unr = phi i32 [ 0, %.preheader.us ], [ %.1.us.1, %31 ]
  br i1 %lcmp.mod.not, label %._crit_edge33.us, label %.epil.preheader

.epil.preheader:                                  ; preds = %._crit_edge33.us.unr-lcssa
  %34 = trunc nuw nsw i64 %indvars.iv44.unr to i32
  %35 = shl nuw i32 1, %34
  %36 = and i32 %35, %.01936.us
  %.not27.us.epil = icmp eq i32 %36, 0
  br i1 %.not27.us.epil, label %._crit_edge33.us, label %37

37:                                               ; preds = %.epil.preheader
  %38 = getelementptr inbounds [1024 x i32], ptr %1, i64 0, i64 %indvars.iv44.unr
  %39 = load i32, ptr %38, align 4, !tbaa !5
  %40 = add nsw i32 %39, %.01830.us.unr
  br label %._crit_edge33.us

._crit_edge33.us:                                 ; preds = %.epil.preheader, %37, %._crit_edge33.us.unr-lcssa
  %.1.us.lcssa = phi i32 [ %.1.us.lcssa.ph, %._crit_edge33.us.unr-lcssa ], [ %40, %37 ], [ %.01830.us.unr, %.epil.preheader ]
  %.not.us = icmp eq i32 %.1.us.lcssa, %14
  br i1 %.not.us, label %.split.us, label %32

.preheader.lr.ph.split:                           ; preds = %.preheader.lr.ph.thread, %.preheader.lr.ph
  %41 = phi i32 [ %11, %.preheader.lr.ph.thread ], [ %14, %.preheader.lr.ph ]
  %.not = icmp eq i32 %41, 0
  br i1 %.not, label %.split.us, label %.critedge.loopexit

.lr.ph:                                           ; preds = %.lr.ph39, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %.lr.ph39 ]
  %42 = getelementptr inbounds [1024 x i32], ptr %1, i64 0, i64 %indvars.iv
  %43 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %42)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %44 = load i32, ptr %4, align 4, !tbaa !5
  %45 = sext i32 %44 to i64
  %46 = icmp slt i64 %indvars.iv.next, %45
  br i1 %46, label %.lr.ph, label %._crit_edge, !llvm.loop !12

.critedge.loopexit:                               ; preds = %32, %.preheader.lr.ph.split, %._crit_edge
  br label %.split.us

.split.us:                                        ; preds = %._crit_edge33.us, %.preheader.lr.ph.split, %.critedge.loopexit
  %.str.3.sink = phi ptr [ @.str.3, %.critedge.loopexit ], [ @.str.2, %.preheader.lr.ph.split ], [ @.str.2, %._crit_edge33.us ]
  %47 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) %.str.3.sink)
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %4) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #3
  %48 = add nuw nsw i32 %.02437, 1
  %49 = load i32, ptr %2, align 4, !tbaa !5
  %50 = icmp slt i32 %48, %49
  br i1 %50, label %.lr.ph39, label %._crit_edge40, !llvm.loop !13
}

; 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: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #2

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 = { 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 = { 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: ConstraintEliminationPass,CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopInstSimplifyPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass