; LLVM IR from VastoLorde95/Competitive-Programming :: Codeforces/119 Division 2/Problem B (B)

; 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_istream" = type { ptr, i64, %"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 }
%"class.std::basic_ostream" = type { ptr, %"class.std::basic_ios" }

@w = external dso_local global i64, align 8
@h = external dso_local global i64, align 8
@x = external dso_local global i64, align 8
@y = external dso_local global i64, align 8
@res = external dso_local global i64, align 8
@tmp = external dso_local global i64, align 8
@_ZSt3cin = external global %"class.std::basic_istream", align 8
@_ZSt4cout = external global %"class.std::basic_ostream", align 8

; 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
  store i32 0, ptr %1, align 4
  %5 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERx(ptr noundef nonnull align 8 dereferenceable(16) @_ZSt3cin, ptr noundef nonnull align 8 dereferenceable(8) @w)
  %6 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERx(ptr noundef nonnull align 8 dereferenceable(16) %5, ptr noundef nonnull align 8 dereferenceable(8) @h)
  %7 = load i64, ptr @w, align 8, !tbaa !5
  %8 = sdiv i64 %7, 2
  store i64 %8, ptr @x, align 8, !tbaa !5
  %9 = load i64, ptr @h, align 8, !tbaa !5
  %10 = sdiv i64 %9, 2
  store i64 %10, ptr @y, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #4
  store i32 1, ptr %2, align 4, !tbaa !9
  br label %11

11:                                               ; preds = %53, %0
  %12 = load i32, ptr %2, align 4, !tbaa !9
  %13 = sext i32 %12 to i64
  %14 = load i64, ptr @x, align 8, !tbaa !5
  %15 = icmp sle i64 %13, %14
  br i1 %15, label %17, label %16

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

17:                                               ; preds = %11
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  store i32 1, ptr %4, align 4, !tbaa !9
  br label %18

18:                                               ; preds = %49, %17
  %19 = load i32, ptr %4, align 4, !tbaa !9
  %20 = sext i32 %19 to i64
  %21 = load i64, ptr @y, align 8, !tbaa !5
  %22 = icmp sle i64 %20, %21
  br i1 %22, label %24, label %23

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

24:                                               ; preds = %18
  %25 = load i64, ptr @w, align 8, !tbaa !5
  %26 = load i32, ptr %2, align 4, !tbaa !9
  %27 = sext i32 %26 to i64
  %28 = sub nsw i64 %25, %27
  %29 = load i32, ptr %2, align 4, !tbaa !9
  %30 = sext i32 %29 to i64
  %31 = sub nsw i64 %28, %30
  %32 = add nsw i64 %31, 1
  %33 = load i64, ptr @h, align 8, !tbaa !5
  %34 = load i32, ptr %4, align 4, !tbaa !9
  %35 = sext i32 %34 to i64
  %36 = sub nsw i64 %33, %35
  %37 = load i32, ptr %4, align 4, !tbaa !9
  %38 = sext i32 %37 to i64
  %39 = sub nsw i64 %36, %38
  %40 = add nsw i64 %39, 1
  %41 = mul nsw i64 %32, %40
  store i64 %41, ptr @tmp, align 8, !tbaa !5
  %42 = load i64, ptr @tmp, align 8, !tbaa !5
  %43 = icmp sgt i64 %42, 0
  br i1 %43, label %44, label %48

44:                                               ; preds = %24
  %45 = load i64, ptr @tmp, align 8, !tbaa !5
  %46 = load i64, ptr @res, align 8, !tbaa !5
  %47 = add nsw i64 %46, %45
  store i64 %47, ptr @res, align 8, !tbaa !5
  br label %48

48:                                               ; preds = %44, %24
  br label %49

49:                                               ; preds = %48
  %50 = load i32, ptr %4, align 4, !tbaa !9
  %51 = add nsw i32 %50, 1
  store i32 %51, ptr %4, align 4, !tbaa !9
  br label %18, !llvm.loop !11

52:                                               ; preds = %23
  br label %53

53:                                               ; preds = %52
  %54 = load i32, ptr %2, align 4, !tbaa !9
  %55 = add nsw i32 %54, 1
  store i32 %55, ptr %2, align 4, !tbaa !9
  br label %11, !llvm.loop !13

56:                                               ; preds = %16
  %57 = load i64, ptr @res, align 8, !tbaa !5
  %58 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEx(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, i64 noundef %57)
  %59 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEPFRSoS_E(ptr noundef nonnull align 8 dereferenceable(8) %58, ptr noundef @_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_)
  ret i32 0
}

; Function Attrs: mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERx(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 8 dereferenceable(8)) #1 align 2

; 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

; Function Attrs: mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEx(ptr noundef nonnull align 8 dereferenceable(8), i64 noundef) #1 align 2

; Function Attrs: mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEPFRSoS_E(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef) #1 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)) #3

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 = { 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 #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 = !{!"long long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}


; 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_istream" = type { ptr, i64, %"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 }
%"class.std::basic_ostream" = type { ptr, %"class.std::basic_ios" }

@w = external dso_local global i64, align 8
@h = external dso_local global i64, align 8
@x = external dso_local local_unnamed_addr global i64, align 8
@y = external dso_local local_unnamed_addr global i64, align 8
@res = external dso_local local_unnamed_addr global i64, align 8
@tmp = external dso_local local_unnamed_addr global i64, align 8
@_ZSt3cin = external global %"class.std::basic_istream", align 8
@_ZSt4cout = external global %"class.std::basic_ostream", align 8

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = tail call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERx(ptr noundef nonnull align 8 dereferenceable(16) @_ZSt3cin, ptr noundef nonnull align 8 dereferenceable(8) @w)
  %2 = tail call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERx(ptr noundef nonnull align 8 dereferenceable(16) %1, ptr noundef nonnull align 8 dereferenceable(8) @h)
  %3 = load i64, ptr @w, align 8, !tbaa !5
  %4 = sdiv i64 %3, 2
  store i64 %4, ptr @x, align 8, !tbaa !5
  %5 = load i64, ptr @h, align 8, !tbaa !5
  %6 = sdiv i64 %5, 2
  store i64 %6, ptr @y, align 8, !tbaa !5
  %.not21 = icmp slt i64 %3, 2
  %.pre = load i64, ptr @res, align 8, !tbaa !5
  br i1 %.not21, label %._crit_edge24, label %.preheader.lr.ph

.preheader.lr.ph:                                 ; preds = %0
  %.not1214 = icmp slt i64 %5, 2
  %7 = add nuw i64 %3, 1
  %8 = add i64 %5, 1
  br i1 %.not1214, label %._crit_edge24, label %.preheader.preheader

.preheader.preheader:                             ; preds = %.preheader.lr.ph
  %9 = tail call i64 @llvm.smax.i64(i64 %6, i64 1)
  %10 = tail call i64 @llvm.smax.i64(i64 %4, i64 1)
  %xtraiter = and i64 %9, 1
  %11 = icmp slt i64 %5, 4
  %unroll_iter = and i64 %9, 4611686018427387902
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br label %.preheader

.preheader:                                       ; preds = %.preheader.preheader, %._crit_edge
  %indvars.iv27 = phi i64 [ 1, %.preheader.preheader ], [ %indvars.iv.next28, %._crit_edge ]
  %res.promoted2022 = phi i64 [ %.pre, %.preheader.preheader ], [ %res.promoted17.lcssa, %._crit_edge ]
  %12 = shl nuw nsw i64 %indvars.iv27, 1
  %13 = sub i64 %7, %12
  br i1 %11, label %._crit_edge.unr-lcssa, label %.preheader.new

._crit_edge24.split:                              ; preds = %._crit_edge
  store i64 %.lcssa, ptr @tmp, align 8, !tbaa !5
  br label %._crit_edge24

._crit_edge24:                                    ; preds = %0, %.preheader.lr.ph, %._crit_edge24.split
  %14 = phi i64 [ %res.promoted17.lcssa, %._crit_edge24.split ], [ %.pre, %.preheader.lr.ph ], [ %.pre, %0 ]
  %15 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEx(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, i64 noundef %14)
  %16 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEPFRSoS_E(ptr noundef nonnull align 8 dereferenceable(8) %15, ptr noundef nonnull @_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_)
  ret i32 0

._crit_edge.unr-lcssa:                            ; preds = %42, %.preheader
  %res.promoted17.lcssa.ph = phi i64 [ poison, %.preheader ], [ %res.promoted17.1, %42 ]
  %.lcssa.ph = phi i64 [ poison, %.preheader ], [ %32, %42 ]
  %indvars.iv.unr = phi i64 [ 1, %.preheader ], [ %indvars.iv.next.1, %42 ]
  %res.promoted18.unr = phi i64 [ %res.promoted2022, %.preheader ], [ %res.promoted17.1, %42 ]
  %.unr = phi i64 [ %res.promoted2022, %.preheader ], [ %35, %42 ]
  br i1 %lcmp.mod.not, label %._crit_edge, label %.epil.preheader

.epil.preheader:                                  ; preds = %._crit_edge.unr-lcssa
  %17 = shl nuw nsw i64 %indvars.iv.unr, 1
  %18 = sub i64 %8, %17
  %19 = mul nsw i64 %18, %13
  %20 = icmp sgt i64 %19, 0
  br i1 %20, label %21, label %._crit_edge

21:                                               ; preds = %.epil.preheader
  %22 = add nsw i64 %.unr, %19
  store i64 %22, ptr @res, align 8, !tbaa !5
  br label %._crit_edge

._crit_edge:                                      ; preds = %.epil.preheader, %21, %._crit_edge.unr-lcssa
  %res.promoted17.lcssa = phi i64 [ %res.promoted17.lcssa.ph, %._crit_edge.unr-lcssa ], [ %res.promoted18.unr, %.epil.preheader ], [ %22, %21 ]
  %.lcssa = phi i64 [ %.lcssa.ph, %._crit_edge.unr-lcssa ], [ %19, %21 ], [ %19, %.epil.preheader ]
  %indvars.iv.next28 = add nuw nsw i64 %indvars.iv27, 1
  %exitcond31 = icmp eq i64 %indvars.iv27, %10
  br i1 %exitcond31, label %._crit_edge24.split, label %.preheader, !llvm.loop !9

.preheader.new:                                   ; preds = %.preheader, %42
  %indvars.iv = phi i64 [ %indvars.iv.next.1, %42 ], [ 1, %.preheader ]
  %res.promoted18 = phi i64 [ %res.promoted17.1, %42 ], [ %res.promoted2022, %.preheader ]
  %23 = phi i64 [ %35, %42 ], [ %res.promoted2022, %.preheader ]
  %niter = phi i64 [ %niter.next.1, %42 ], [ 0, %.preheader ]
  %24 = shl nuw nsw i64 %indvars.iv, 1
  %25 = sub i64 %8, %24
  %26 = mul nsw i64 %25, %13
  %27 = icmp sgt i64 %26, 0
  %28 = add nsw i64 %23, %26
  %res.promoted17 = select i1 %27, i64 %28, i64 %res.promoted18
  %29 = select i1 %27, i64 %28, i64 %23
  %indvars.iv.next = shl nuw i64 %indvars.iv, 1
  %30 = add i64 %indvars.iv.next, 2
  %31 = sub i64 %8, %30
  %32 = mul nsw i64 %31, %13
  %33 = icmp sgt i64 %32, 0
  %34 = add nsw i64 %29, %32
  %res.promoted17.1 = select i1 %33, i64 %34, i64 %res.promoted17
  %35 = select i1 %33, i64 %34, i64 %29
  %36 = xor i1 %27, true
  %37 = xor i1 %33, true
  %38 = xor i1 %36, true
  %39 = xor i1 %37, true
  %40 = or i1 %38, %39
  br i1 %40, label %41, label %42

41:                                               ; preds = %.preheader.new
  store i64 %res.promoted17.1, ptr @res, align 8, !tbaa !5
  br label %42

42:                                               ; preds = %.preheader.new, %41
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %niter.next.1 = add nuw i64 %niter, 2
  %niter.ncmp.1 = icmp eq i64 %niter.next.1, %unroll_iter
  br i1 %niter.ncmp.1, label %._crit_edge.unr-lcssa, label %.preheader.new, !llvm.loop !11
}

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

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

; 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 #1 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)) #2

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.smax.i64(i64, i64) #3

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 = { 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 = { 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 #3 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }

!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 = !{!"long long", !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}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopInstSimplifyPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass