; LLVM IR from manishbisht/Competitive-Programming :: Codechef/COOK74 (Lazy Jem)

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

@t = external dso_local global i64, align 8
@n = external dso_local global i64, align 8
@i = external dso_local global i64, align 8
@b = external dso_local global i64, align 8
@m = external dso_local global i64, align 8
@ans = 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
  store i32 0, ptr %1, align 4
  %2 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERx(ptr noundef nonnull align 8 dereferenceable(16) @_ZSt3cin, ptr noundef nonnull align 8 dereferenceable(8) @t)
  store i64 0, ptr @i, align 8, !tbaa !5
  br label %3

3:                                                ; preds = %48, %0
  %4 = load i64, ptr @i, align 8, !tbaa !5
  %5 = load i64, ptr @t, align 8, !tbaa !5
  %6 = icmp slt i64 %4, %5
  br i1 %6, label %7, label %51

7:                                                ; preds = %3
  store i64 0, ptr @ans, align 8, !tbaa !5
  %8 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERx(ptr noundef nonnull align 8 dereferenceable(16) @_ZSt3cin, ptr noundef nonnull align 8 dereferenceable(8) @n)
  %9 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERx(ptr noundef nonnull align 8 dereferenceable(16) %8, ptr noundef nonnull align 8 dereferenceable(8) @b)
  %10 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERx(ptr noundef nonnull align 8 dereferenceable(16) %9, ptr noundef nonnull align 8 dereferenceable(8) @m)
  br label %11

11:                                               ; preds = %33, %7
  %12 = load i64, ptr @n, align 8, !tbaa !5
  %13 = icmp sgt i64 %12, 1
  br i1 %13, label %14, label %41

14:                                               ; preds = %11
  %15 = load i64, ptr @n, align 8, !tbaa !5
  %16 = srem i64 %15, 2
  %17 = icmp eq i64 %16, 0
  br i1 %17, label %18, label %25

18:                                               ; preds = %14
  %19 = load i64, ptr @ans, align 8, !tbaa !5
  %20 = load i64, ptr @n, align 8, !tbaa !5
  %21 = sdiv i64 %20, 2
  %22 = load i64, ptr @m, align 8, !tbaa !5
  %23 = mul nsw i64 %21, %22
  %24 = add nsw i64 %19, %23
  store i64 %24, ptr @ans, align 8, !tbaa !5
  br label %33

25:                                               ; preds = %14
  %26 = load i64, ptr @ans, align 8, !tbaa !5
  %27 = load i64, ptr @n, align 8, !tbaa !5
  %28 = add nsw i64 %27, 1
  %29 = sdiv i64 %28, 2
  %30 = load i64, ptr @m, align 8, !tbaa !5
  %31 = mul nsw i64 %29, %30
  %32 = add nsw i64 %26, %31
  store i64 %32, ptr @ans, align 8, !tbaa !5
  br label %33

33:                                               ; preds = %25, %18
  %34 = load i64, ptr @n, align 8, !tbaa !5
  %35 = sdiv i64 %34, 2
  store i64 %35, ptr @n, align 8, !tbaa !5
  %36 = load i64, ptr @m, align 8, !tbaa !5
  %37 = mul nsw i64 %36, 2
  store i64 %37, ptr @m, align 8, !tbaa !5
  %38 = load i64, ptr @ans, align 8, !tbaa !5
  %39 = load i64, ptr @b, align 8, !tbaa !5
  %40 = add nsw i64 %38, %39
  store i64 %40, ptr @ans, align 8, !tbaa !5
  br label %11, !llvm.loop !9

41:                                               ; preds = %11
  %42 = load i64, ptr @ans, align 8, !tbaa !5
  %43 = load i64, ptr @m, align 8, !tbaa !5
  %44 = add nsw i64 %42, %43
  store i64 %44, ptr @ans, align 8, !tbaa !5
  %45 = load i64, ptr @ans, align 8, !tbaa !5
  %46 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEx(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, i64 noundef %45)
  %47 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEPFRSoS_E(ptr noundef nonnull align 8 dereferenceable(8) %46, ptr noundef @_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_)
  br label %48

48:                                               ; preds = %41
  %49 = load i64, ptr @i, align 8, !tbaa !5
  %50 = add nsw i64 %49, 1
  store i64 %50, ptr @i, align 8, !tbaa !5
  br label %3, !llvm.loop !11

51:                                               ; preds = %3
  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: 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)) #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 = { 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" }

!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}


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

@t = external dso_local global i64, align 8
@n = external dso_local global i64, align 8
@i = external dso_local local_unnamed_addr global i64, align 8
@b = external dso_local global i64, align 8
@m = external dso_local global i64, align 8
@ans = 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) @t)
  store i64 0, ptr @i, align 8, !tbaa !5
  %2 = load i64, ptr @t, align 8, !tbaa !5
  %3 = icmp sgt i64 %2, 0
  br i1 %3, label %.lr.ph7, label %._crit_edge8

.lr.ph7:                                          ; preds = %0, %17
  store i64 0, ptr @ans, align 8, !tbaa !5
  %4 = 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) @n)
  %5 = tail call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERx(ptr noundef nonnull align 8 dereferenceable(16) %4, ptr noundef nonnull align 8 dereferenceable(8) @b)
  %6 = tail call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERx(ptr noundef nonnull align 8 dereferenceable(16) %5, ptr noundef nonnull align 8 dereferenceable(8) @m)
  %n.promoted = load i64, ptr @n, align 8, !tbaa !5
  %7 = icmp sgt i64 %n.promoted, 1
  br i1 %7, label %.lr.ph, label %.lr.ph7._crit_edge

.lr.ph7._crit_edge:                               ; preds = %.lr.ph7
  %.pre = load i64, ptr @ans, align 8, !tbaa !5
  %.pre12 = load i64, ptr @m, align 8, !tbaa !5
  br label %17

.lr.ph:                                           ; preds = %.lr.ph7
  %m.promoted = load i64, ptr @m, align 8, !tbaa !5
  %ans.promoted = load i64, ptr @ans, align 8, !tbaa !5
  %8 = load i64, ptr @b, align 8, !tbaa !5
  br label %9

9:                                                ; preds = %.lr.ph, %9
  %10 = phi i64 [ %n.promoted, %.lr.ph ], [ %13, %9 ]
  %storemerge123 = phi i64 [ %ans.promoted, %.lr.ph ], [ %15, %9 ]
  %11 = phi i64 [ %m.promoted, %.lr.ph ], [ %14, %9 ]
  %12 = and i64 %10, 1
  %spec.select = add nuw i64 %10, %12
  %.pn9 = lshr exact i64 %spec.select, 1
  %.pn = mul nsw i64 %11, %.pn9
  %storemerge1 = add nsw i64 %.pn, %storemerge123
  %13 = lshr i64 %10, 1
  %14 = shl nsw i64 %11, 1
  %15 = add nsw i64 %8, %storemerge1
  %16 = icmp ugt i64 %10, 3
  br i1 %16, label %9, label %._crit_edge, !llvm.loop !9

._crit_edge:                                      ; preds = %9
  store i64 %13, ptr @n, align 8, !tbaa !5
  store i64 %14, ptr @m, align 8, !tbaa !5
  br label %17

17:                                               ; preds = %.lr.ph7._crit_edge, %._crit_edge
  %18 = phi i64 [ %.pre12, %.lr.ph7._crit_edge ], [ %14, %._crit_edge ]
  %19 = phi i64 [ %.pre, %.lr.ph7._crit_edge ], [ %15, %._crit_edge ]
  %20 = add nsw i64 %18, %19
  store i64 %20, ptr @ans, align 8, !tbaa !5
  %21 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEx(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, i64 noundef %20)
  %22 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEPFRSoS_E(ptr noundef nonnull align 8 dereferenceable(8) %21, ptr noundef nonnull @_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_)
  %23 = load i64, ptr @i, align 8, !tbaa !5
  %24 = add nsw i64 %23, 1
  store i64 %24, ptr @i, align 8, !tbaa !5
  %25 = load i64, ptr @t, align 8, !tbaa !5
  %26 = icmp slt i64 %24, %25
  br i1 %26, label %.lr.ph7, label %._crit_edge8, !llvm.loop !11

._crit_edge8:                                     ; preds = %17, %0
  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)) 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

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

!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: CorrelatedValuePropagationPass,DSEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferAlignmentPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass