; LLVM IR from bqi343/cp-notebook :: Contests/USACO Solutions/2011-12/Mar (12 Mar G1)

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

@M = external dso_local global i64, align 8
@N = external dso_local global i64, align 8
@L = external dso_local global i64, align 8
@H = external dso_local global i64, align 8
@ans = external dso_local global i64, align 8
@_ZSt4cout = external global %"class.std::basic_ostream", align 8

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z4initv() #0

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

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z3getiii(i32 noundef, i32 noundef, i32 noundef) #0

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #2 {
  %1 = alloca i32, align 4
  %2 = alloca i64, align 8
  %3 = alloca i32, align 4
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  store i32 0, ptr %1, align 4
  call void @_Z4initv()
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #5
  store i64 1, ptr %2, align 8, !tbaa !5
  br label %7

7:                                                ; preds = %72, %0
  %8 = load i64, ptr %2, align 8, !tbaa !5
  %9 = load i64, ptr @M, align 8, !tbaa !5
  %10 = icmp sle i64 %8, %9
  br i1 %10, label %12, label %11

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

12:                                               ; preds = %7
  %13 = load i64, ptr %2, align 8, !tbaa !5
  %14 = load i64, ptr %2, align 8, !tbaa !5
  %15 = mul nsw i64 %13, %14
  %16 = load i64, ptr @N, align 8, !tbaa !5
  %17 = load i64, ptr @N, align 8, !tbaa !5
  %18 = mul nsw i64 %16, %17
  %19 = add nsw i64 %15, %18
  %20 = load i64, ptr @L, align 8, !tbaa !5
  %21 = load i64, ptr @L, align 8, !tbaa !5
  %22 = mul nsw i64 %20, %21
  %23 = icmp sge i64 %19, %22
  br i1 %23, label %24, label %71

24:                                               ; preds = %12
  %25 = load i64, ptr %2, align 8, !tbaa !5
  %26 = load i64, ptr @H, align 8, !tbaa !5
  %27 = icmp sle i64 %25, %26
  br i1 %27, label %28, label %71

28:                                               ; preds = %24
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #5
  store i64 1, ptr %4, align 8, !tbaa !5
  %29 = load i64, ptr %2, align 8, !tbaa !5
  %30 = load i64, ptr @L, align 8, !tbaa !5
  %31 = icmp sle i64 %29, %30
  br i1 %31, label %32, label %45

32:                                               ; preds = %28
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #5
  %33 = load i64, ptr @L, align 8, !tbaa !5
  %34 = load i64, ptr @L, align 8, !tbaa !5
  %35 = mul nsw i64 %33, %34
  %36 = load i64, ptr %2, align 8, !tbaa !5
  %37 = load i64, ptr %2, align 8, !tbaa !5
  %38 = mul nsw i64 %36, %37
  %39 = sub nsw i64 %35, %38
  %40 = call noundef double @_ZSt4sqrtIxEN9__gnu_cxx11__enable_ifIXsr12__is_integerIT_EE7__valueEdE6__typeES2_(i64 noundef %39)
  %41 = call double @llvm.ceil.f64(double %40)
  %42 = fptosi double %41 to i64
  store i64 %42, ptr %5, align 8, !tbaa !5
  %43 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3maxIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) %4, ptr noundef nonnull align 8 dereferenceable(8) %5)
  %44 = load i64, ptr %43, align 8, !tbaa !5
  store i64 %44, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #5
  br label %45

45:                                               ; preds = %32, %28
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #5
  %46 = load i64, ptr @H, align 8, !tbaa !5
  %47 = load i64, ptr @H, align 8, !tbaa !5
  %48 = mul nsw i64 %46, %47
  %49 = load i64, ptr %2, align 8, !tbaa !5
  %50 = load i64, ptr %2, align 8, !tbaa !5
  %51 = mul nsw i64 %49, %50
  %52 = sub nsw i64 %48, %51
  %53 = call noundef double @_ZSt4sqrtIxEN9__gnu_cxx11__enable_ifIXsr12__is_integerIT_EE7__valueEdE6__typeES2_(i64 noundef %52)
  %54 = fptosi double %53 to i64
  store i64 %54, ptr %6, align 8, !tbaa !5
  %55 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3minIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) %6, ptr noundef nonnull align 8 dereferenceable(8) @N)
  %56 = load i64, ptr %55, align 8, !tbaa !5
  store i64 %56, ptr %6, align 8, !tbaa !5
  %57 = load i64, ptr %4, align 8, !tbaa !5
  %58 = load i64, ptr %6, align 8, !tbaa !5
  %59 = icmp sgt i64 %57, %58
  br i1 %59, label %60, label %61

60:                                               ; preds = %45
  store i32 4, ptr %3, align 4
  br label %68

61:                                               ; preds = %45
  %62 = load i64, ptr %2, align 8, !tbaa !5
  %63 = trunc i64 %62 to i32
  %64 = load i64, ptr %4, align 8, !tbaa !5
  %65 = trunc i64 %64 to i32
  %66 = load i64, ptr %6, align 8, !tbaa !5
  %67 = trunc i64 %66 to i32
  call void @_Z3getiii(i32 noundef %63, i32 noundef %65, i32 noundef %67)
  store i32 0, ptr %3, align 4
  br label %68

68:                                               ; preds = %61, %60
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #5
  %69 = load i32, ptr %3, align 4
  switch i32 %69, label %79 [
    i32 0, label %70
    i32 4, label %72
  ]

70:                                               ; preds = %68
  br label %71

71:                                               ; preds = %70, %24, %12
  br label %72

72:                                               ; preds = %71, %68
  %73 = load i64, ptr %2, align 8, !tbaa !5
  %74 = add nsw i64 %73, 1
  store i64 %74, ptr %2, align 8, !tbaa !5
  br label %7, !llvm.loop !9

75:                                               ; preds = %11
  %76 = load i64, ptr @ans, align 8, !tbaa !5
  %77 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEx(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, i64 noundef %76)
  %78 = load i32, ptr %1, align 4
  ret i32 %78

79:                                               ; preds = %68
  unreachable
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3maxIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(8)) #3

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef double @_ZSt4sqrtIxEN9__gnu_cxx11__enable_ifIXsr12__is_integerIT_EE7__valueEdE6__typeES2_(i64 noundef) #3

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.ceil.f64(double) #4

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3minIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(8)) #3

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

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


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

@M = external dso_local local_unnamed_addr global i64, align 8
@N = external dso_local global i64, align 8
@L = external dso_local local_unnamed_addr global i64, align 8
@H = external dso_local local_unnamed_addr global i64, align 8
@ans = external dso_local local_unnamed_addr global i64, align 8
@_ZSt4cout = external global %"class.std::basic_ostream", align 8

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z4initv() local_unnamed_addr #0

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

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z3getiii(i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() local_unnamed_addr #2 {
  %1 = alloca i64, align 8
  %2 = alloca i64, align 8
  %3 = alloca i64, align 8
  tail call void @_Z4initv()
  %4 = load i64, ptr @M, align 8, !tbaa !5
  %.not17 = icmp slt i64 %4, 1
  br i1 %.not17, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %38, %0
  %5 = load i64, ptr @ans, align 8, !tbaa !5
  %6 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEx(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, i64 noundef %5)
  ret i32 0

.lr.ph:                                           ; preds = %0, %38
  %7 = phi i64 [ %39, %38 ], [ %4, %0 ]
  %.018 = phi i64 [ %40, %38 ], [ 1, %0 ]
  %8 = mul nuw nsw i64 %.018, %.018
  %9 = load i64, ptr @N, align 8, !tbaa !5
  %10 = mul nsw i64 %9, %9
  %11 = add nuw nsw i64 %10, %8
  %12 = load i64, ptr @L, align 8, !tbaa !5
  %13 = mul nsw i64 %12, %12
  %.not14 = icmp ult i64 %11, %13
  %14 = load i64, ptr @H, align 8
  %.not15 = icmp sgt i64 %.018, %14
  %or.cond = select i1 %.not14, i1 true, i1 %.not15
  br i1 %or.cond, label %38, label %15

15:                                               ; preds = %.lr.ph
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %1) #5
  store i64 1, ptr %1, align 8, !tbaa !5
  %.not16 = icmp sgt i64 %.018, %12
  br i1 %.not16, label %23, label %16

16:                                               ; preds = %15
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #5
  %17 = sub nsw i64 %13, %8
  %18 = call noundef double @_ZSt4sqrtIxEN9__gnu_cxx11__enable_ifIXsr12__is_integerIT_EE7__valueEdE6__typeES2_(i64 noundef %17)
  %19 = call double @llvm.ceil.f64(double %18)
  %20 = fptosi double %19 to i64
  store i64 %20, ptr %2, align 8, !tbaa !5
  %21 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3maxIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) %1, ptr noundef nonnull align 8 dereferenceable(8) %2)
  %22 = load i64, ptr %21, align 8, !tbaa !5
  store i64 %22, ptr %1, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #5
  %.pre = load i64, ptr @H, align 8, !tbaa !5
  br label %23

23:                                               ; preds = %16, %15
  %24 = phi i64 [ %.pre, %16 ], [ %14, %15 ]
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #5
  %25 = mul nsw i64 %24, %24
  %26 = sub nsw i64 %25, %8
  %27 = call noundef double @_ZSt4sqrtIxEN9__gnu_cxx11__enable_ifIXsr12__is_integerIT_EE7__valueEdE6__typeES2_(i64 noundef %26)
  %28 = fptosi double %27 to i64
  store i64 %28, ptr %3, align 8, !tbaa !5
  %29 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3minIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) %3, ptr noundef nonnull align 8 dereferenceable(8) @N)
  %30 = load i64, ptr %29, align 8, !tbaa !5
  store i64 %30, ptr %3, align 8, !tbaa !5
  %31 = load i64, ptr %1, align 8, !tbaa !5
  %32 = icmp sgt i64 %31, %30
  br i1 %32, label %37, label %33

33:                                               ; preds = %23
  %34 = trunc i64 %.018 to i32
  %35 = trunc i64 %31 to i32
  %36 = trunc i64 %30 to i32
  call void @_Z3getiii(i32 noundef %34, i32 noundef %35, i32 noundef %36)
  br label %37

37:                                               ; preds = %23, %33
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %1) #5
  %.pre20 = load i64, ptr @M, align 8, !tbaa !5
  br label %38

38:                                               ; preds = %37, %.lr.ph
  %39 = phi i64 [ %.pre20, %37 ], [ %7, %.lr.ph ]
  %40 = add nuw nsw i64 %.018, 1
  %.not.not = icmp slt i64 %.018, %39
  br i1 %.not.not, label %.lr.ph, label %._crit_edge, !llvm.loop !9
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3maxIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #3

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef double @_ZSt4sqrtIxEN9__gnu_cxx11__enable_ifIXsr12__is_integerIT_EE7__valueEdE6__typeES2_(i64 noundef) local_unnamed_addr #3

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.ceil.f64(double) #4

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3minIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #3

; 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 #0 align 2

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


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass