; LLVM IR from VastoLorde95/Competitive-Programming :: Codeforces/346 Division 2/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"

%"class.std::basic_ostream" = type { ptr, %"class.std::basic_ios" }
%"class.std::basic_ios" = type { %"class.std::ios_base", ptr, i8, i8, ptr, ptr, ptr, ptr }
%"class.std::ios_base" = type { ptr, i64, i64, i32, i32, i32, ptr, %"struct.std::ios_base::_Words", [8 x %"struct.std::ios_base::_Words"], i32, ptr, %"class.std::locale" }
%"struct.std::ios_base::_Words" = type { ptr, i64 }
%"class.std::locale" = type { ptr }

@_ZSt4cout = external global %"class.std::basic_ostream", align 8
@.str = external hidden unnamed_addr constant [7 x i8], align 1

; Function Attrs: mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEPFRSoS_E(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef) #0 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(8) ptr @_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_(ptr noundef nonnull align 8 dereferenceable(8)) #1

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #2 {
  %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
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #5
  %7 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %2, ptr noundef %3, ptr noundef %4)
  %8 = load i32, ptr %4, align 4, !tbaa !5
  %9 = icmp slt i32 %8, 0
  br i1 %9, label %10, label %26

10:                                               ; preds = %0
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #5
  %11 = load i32, ptr %4, align 4, !tbaa !5
  %12 = sub nsw i32 0, %11
  store i32 %12, ptr %5, align 4, !tbaa !5
  br label %13

13:                                               ; preds = %24, %10
  %14 = load i32, ptr %5, align 4, !tbaa !5
  %15 = add nsw i32 %14, -1
  store i32 %15, ptr %5, align 4, !tbaa !5
  %16 = icmp ne i32 %14, 0
  br i1 %16, label %17, label %25

17:                                               ; preds = %13
  %18 = load i32, ptr %3, align 4, !tbaa !5
  %19 = add nsw i32 %18, -1
  store i32 %19, ptr %3, align 4, !tbaa !5
  %20 = load i32, ptr %3, align 4, !tbaa !5
  %21 = icmp eq i32 %20, 0
  br i1 %21, label %22, label %24

22:                                               ; preds = %17
  %23 = load i32, ptr %2, align 4, !tbaa !5
  store i32 %23, ptr %3, align 4, !tbaa !5
  br label %24

24:                                               ; preds = %22, %17
  br label %13, !llvm.loop !9

25:                                               ; preds = %13
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #5
  br label %41

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

28:                                               ; preds = %39, %26
  %29 = load i32, ptr %6, align 4, !tbaa !5
  %30 = add nsw i32 %29, -1
  store i32 %30, ptr %6, align 4, !tbaa !5
  %31 = icmp ne i32 %29, 0
  br i1 %31, label %32, label %40

32:                                               ; preds = %28
  %33 = load i32, ptr %3, align 4, !tbaa !5
  %34 = add nsw i32 %33, 1
  store i32 %34, ptr %3, align 4, !tbaa !5
  %35 = load i32, ptr %3, align 4, !tbaa !5
  %36 = load i32, ptr %2, align 4, !tbaa !5
  %37 = icmp sgt i32 %35, %36
  br i1 %37, label %38, label %39

38:                                               ; preds = %32
  store i32 1, ptr %3, align 4, !tbaa !5
  br label %39

39:                                               ; preds = %38, %32
  br label %28, !llvm.loop !11

40:                                               ; preds = %28
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #5
  br label %41

41:                                               ; preds = %40, %25
  %42 = load i32, ptr %3, align 4, !tbaa !5
  %43 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEi(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, i32 noundef %42)
  %44 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEPFRSoS_E(ptr noundef nonnull align 8 dereferenceable(8) %43, ptr noundef @_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_)
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #5
  ret i32 0
}

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

declare i32 @__isoc99_scanf(ptr noundef, ...) #4

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

declare noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEi(ptr noundef nonnull align 8 dereferenceable(8), i32 noundef) #4

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 = { inlinehint 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 #2 = { 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 #3 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { "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 #5 = { 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}


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

%"class.std::basic_ostream" = type { ptr, %"class.std::basic_ios" }
%"class.std::basic_ios" = type { %"class.std::ios_base", ptr, i8, i8, ptr, ptr, ptr, ptr }
%"class.std::ios_base" = type { ptr, i64, i64, i32, i32, i32, ptr, %"struct.std::ios_base::_Words", [8 x %"struct.std::ios_base::_Words"], i32, ptr, %"class.std::locale" }
%"struct.std::ios_base::_Words" = type { ptr, i64 }
%"class.std::locale" = type { ptr }

@_ZSt4cout = external global %"class.std::basic_ostream", align 8
@.str = external hidden unnamed_addr constant [7 x i8], align 1

; Function Attrs: mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEPFRSoS_E(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef) local_unnamed_addr #0 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(8) ptr @_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_(ptr noundef nonnull align 8 dereferenceable(8)) #1

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() local_unnamed_addr #2 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %3) #6
  %4 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %1, ptr noundef nonnull %2, ptr noundef nonnull %3)
  %5 = load i32, ptr %3, align 4, !tbaa !5
  %6 = icmp slt i32 %5, 0
  br i1 %6, label %11, label %.preheader

.preheader:                                       ; preds = %0
  %.not8 = icmp eq i32 %5, 0
  %.pre = load i32, ptr %2, align 4
  br i1 %.not8, label %.loopexit6, label %.lr.ph

.lr.ph:                                           ; preds = %.preheader
  %7 = load i32, ptr %1, align 4, !tbaa !5
  %xtraiter = and i32 %5, 3
  %lcmp.mod.not = icmp eq i32 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.prol.loopexit, label %.prol.preheader

.prol.preheader:                                  ; preds = %.lr.ph, %.prol.preheader
  %.010.prol = phi i32 [ %8, %.prol.preheader ], [ %5, %.lr.ph ]
  %spec.store.select79.prol = phi i32 [ %spec.store.select.prol, %.prol.preheader ], [ %.pre, %.lr.ph ]
  %prol.iter = phi i32 [ %prol.iter.next, %.prol.preheader ], [ 0, %.lr.ph ]
  %8 = add nsw i32 %.010.prol, -1
  %9 = add nsw i32 %spec.store.select79.prol, 1
  %.not4.prol = icmp slt i32 %spec.store.select79.prol, %7
  %spec.store.select.prol = select i1 %.not4.prol, i32 %9, i32 1
  %prol.iter.next = add i32 %prol.iter, 1
  %prol.iter.cmp.not = icmp eq i32 %prol.iter.next, %xtraiter
  br i1 %prol.iter.cmp.not, label %.prol.loopexit, label %.prol.preheader, !llvm.loop !9

.prol.loopexit:                                   ; preds = %.prol.preheader, %.lr.ph
  %spec.store.select.lcssa.unr = phi i32 [ poison, %.lr.ph ], [ %spec.store.select.prol, %.prol.preheader ]
  %.010.unr = phi i32 [ %5, %.lr.ph ], [ %8, %.prol.preheader ]
  %spec.store.select79.unr = phi i32 [ %.pre, %.lr.ph ], [ %spec.store.select.prol, %.prol.preheader ]
  %10 = icmp ult i32 %5, 4
  br i1 %10, label %..loopexit6_crit_edge, label %.lr.ph.new

11:                                               ; preds = %0
  %.promoted11 = load i32, ptr %2, align 4, !tbaa !5
  %12 = xor i32 %5, -1
  %13 = load i32, ptr %1, align 4
  %14 = sub i32 0, %5
  %xtraiter14 = and i32 %14, 3
  %lcmp.mod15.not = icmp eq i32 %xtraiter14, 0
  br i1 %lcmp.mod15.not, label %.prol.loopexit13, label %.prol.preheader12

.prol.preheader12:                                ; preds = %11, %.prol.preheader12
  %15 = phi i32 [ %19, %.prol.preheader12 ], [ %12, %11 ]
  %16 = phi i32 [ %spec.select.prol, %.prol.preheader12 ], [ %.promoted11, %11 ]
  %prol.iter16 = phi i32 [ %prol.iter16.next, %.prol.preheader12 ], [ 0, %11 ]
  %17 = add nsw i32 %16, -1
  %18 = icmp eq i32 %17, 0
  %spec.select.prol = select i1 %18, i32 %13, i32 %17
  %19 = add nsw i32 %15, -1
  %prol.iter16.next = add i32 %prol.iter16, 1
  %prol.iter16.cmp.not = icmp eq i32 %prol.iter16.next, %xtraiter14
  br i1 %prol.iter16.cmp.not, label %.prol.loopexit13, label %.prol.preheader12, !llvm.loop !11

.prol.loopexit13:                                 ; preds = %.prol.preheader12, %11
  %spec.select.lcssa.unr = phi i32 [ poison, %11 ], [ %spec.select.prol, %.prol.preheader12 ]
  %.unr = phi i32 [ %12, %11 ], [ %19, %.prol.preheader12 ]
  %.unr17 = phi i32 [ %.promoted11, %11 ], [ %spec.select.prol, %.prol.preheader12 ]
  %20 = icmp ugt i32 %5, -4
  br i1 %20, label %.loopexit, label %.new

.new:                                             ; preds = %.prol.loopexit13, %.new
  %21 = phi i32 [ %31, %.new ], [ %.unr, %.prol.loopexit13 ]
  %22 = phi i32 [ %spec.select.3, %.new ], [ %.unr17, %.prol.loopexit13 ]
  %23 = add nsw i32 %22, -1
  %24 = icmp eq i32 %23, 0
  %spec.select = select i1 %24, i32 %13, i32 %23
  %25 = add nsw i32 %spec.select, -1
  %26 = icmp eq i32 %25, 0
  %spec.select.1 = select i1 %26, i32 %13, i32 %25
  %27 = add nsw i32 %spec.select.1, -1
  %28 = icmp eq i32 %27, 0
  %spec.select.2 = select i1 %28, i32 %13, i32 %27
  %29 = add nsw i32 %spec.select.2, -1
  %30 = icmp eq i32 %29, 0
  %spec.select.3 = select i1 %30, i32 %13, i32 %29
  %31 = add nsw i32 %21, -4
  %.not5.3 = icmp eq i32 %21, 3
  br i1 %.not5.3, label %.loopexit, label %.new, !llvm.loop !12

.lr.ph.new:                                       ; preds = %.prol.loopexit, %.lr.ph.new
  %.010 = phi i32 [ %35, %.lr.ph.new ], [ %.010.unr, %.prol.loopexit ]
  %spec.store.select79 = phi i32 [ %spec.store.select.3, %.lr.ph.new ], [ %spec.store.select79.unr, %.prol.loopexit ]
  %32 = add nsw i32 %spec.store.select79, 1
  %.not4 = icmp slt i32 %spec.store.select79, %7
  %spec.store.select = select i1 %.not4, i32 %32, i32 1
  %33 = add nsw i32 %spec.store.select, 1
  %.not4.1 = icmp slt i32 %spec.store.select, %7
  %spec.store.select.1 = select i1 %.not4.1, i32 %33, i32 1
  %34 = add nsw i32 %spec.store.select.1, 1
  %.not4.2 = icmp slt i32 %spec.store.select.1, %7
  %spec.store.select.2 = select i1 %.not4.2, i32 %34, i32 1
  %35 = add nsw i32 %.010, -4
  %36 = add nsw i32 %spec.store.select.2, 1
  %.not4.3 = icmp slt i32 %spec.store.select.2, %7
  %spec.store.select.3 = select i1 %.not4.3, i32 %36, i32 1
  %.not.3 = icmp eq i32 %35, 0
  br i1 %.not.3, label %..loopexit6_crit_edge, label %.lr.ph.new, !llvm.loop !14

.loopexit:                                        ; preds = %.new, %.prol.loopexit13
  %spec.select.lcssa = phi i32 [ %spec.select.lcssa.unr, %.prol.loopexit13 ], [ %spec.select.3, %.new ]
  store i32 %spec.select.lcssa, ptr %2, align 4, !tbaa !5
  br label %.loopexit6

..loopexit6_crit_edge:                            ; preds = %.lr.ph.new, %.prol.loopexit
  %spec.store.select.lcssa = phi i32 [ %spec.store.select.lcssa.unr, %.prol.loopexit ], [ %spec.store.select.3, %.lr.ph.new ]
  store i32 %spec.store.select.lcssa, ptr %2, align 4
  br label %.loopexit6

.loopexit6:                                       ; preds = %.preheader, %..loopexit6_crit_edge, %.loopexit
  %37 = phi i32 [ %spec.store.select.lcssa, %..loopexit6_crit_edge ], [ %spec.select.lcssa, %.loopexit ], [ %.pre, %.preheader ]
  %38 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEi(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, i32 noundef %37)
  %39 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEPFRSoS_E(ptr noundef nonnull align 8 dereferenceable(8) %38, ptr noundef nonnull @_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_)
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #6
  ret i32 0
}

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

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

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

declare noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEi(ptr noundef nonnull align 8 dereferenceable(8), i32 noundef) local_unnamed_addr #5

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 = { inlinehint 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 #2 = { 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 #3 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { 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 #5 = { "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 #6 = { 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.unroll.disable"}
!11 = distinct !{!11, !10}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = distinct !{!14, !13}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass