; LLVM IR from kazunetakahashi/atcoder :: 2019/1005_AGC039/E.ll (Z5flushv)

; 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
@N = external dso_local global i32, align 4

; 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 uwtable
declare dso_local noundef zeroext i1 @_Z11connectableii(i32 noundef, i32 noundef) #0

; Function Attrs: mustprogress uwtable
define dso_local void @_Z5flushv() #0 {
  %1 = alloca i64, align 8
  %2 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 8, ptr %1) #3
  store i64 0, ptr %1, align 8, !tbaa !5
  %3 = load i32, ptr @N, align 4, !tbaa !9
  %4 = icmp sge i32 %3, 2
  br i1 %4, label %5, label %32

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

6:                                                ; preds = %28, %5
  %7 = load i32, ptr %2, align 4, !tbaa !9
  %8 = load i32, ptr @N, align 4, !tbaa !9
  %9 = mul nsw i32 2, %8
  %10 = sub nsw i32 %9, 2
  %11 = icmp sle i32 %7, %10
  br i1 %11, label %13, label %12

12:                                               ; preds = %6
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #3
  br label %31

13:                                               ; preds = %6
  %14 = load i32, ptr %2, align 4, !tbaa !9
  %15 = call noundef zeroext i1 @_Z11connectableii(i32 noundef 0, i32 noundef %14)
  br i1 %15, label %16, label %27

16:                                               ; preds = %13
  %17 = load i32, ptr %2, align 4, !tbaa !9
  %18 = sub nsw i32 %17, 1
  %19 = load i32, ptr %2, align 4, !tbaa !9
  %20 = add nsw i32 %19, 1
  %21 = load i32, ptr @N, align 4, !tbaa !9
  %22 = mul nsw i32 2, %21
  %23 = sub nsw i32 %22, 1
  %24 = call noundef i64 @_Z4calciiii(i32 noundef 1, i32 noundef %18, i32 noundef %20, i32 noundef %23)
  %25 = load i64, ptr %1, align 8, !tbaa !5
  %26 = add nsw i64 %25, %24
  store i64 %26, ptr %1, align 8, !tbaa !5
  br label %27

27:                                               ; preds = %16, %13
  br label %28

28:                                               ; preds = %27
  %29 = load i32, ptr %2, align 4, !tbaa !9
  %30 = add nsw i32 %29, 1
  store i32 %30, ptr %2, align 4, !tbaa !9
  br label %6, !llvm.loop !11

31:                                               ; preds = %12
  br label %37

32:                                               ; preds = %0
  %33 = call noundef zeroext i1 @_Z11connectableii(i32 noundef 0, i32 noundef 1)
  br i1 %33, label %34, label %35

34:                                               ; preds = %32
  store i64 1, ptr %1, align 8, !tbaa !5
  br label %36

35:                                               ; preds = %32
  store i64 0, ptr %1, align 8, !tbaa !5
  br label %36

36:                                               ; preds = %35, %34
  br label %37

37:                                               ; preds = %36, %31
  %38 = load i64, ptr %1, align 8, !tbaa !5
  %39 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEx(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, i64 noundef %38)
  %40 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEPFRSoS_E(ptr noundef nonnull align 8 dereferenceable(8) %39, ptr noundef @_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_)
  call void @llvm.lifetime.end.p0(i64 8, ptr %1) #3
  ret void
}

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

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

; 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) #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 = { 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!"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"}


; 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
@N = external dso_local local_unnamed_addr global i32, align 4

; 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 uwtable
declare dso_local noundef zeroext i1 @_Z11connectableii(i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local void @_Z5flushv() local_unnamed_addr #0 {
  %1 = load i32, ptr @N, align 4, !tbaa !5
  %2 = icmp sgt i32 %1, 1
  br i1 %2, label %.lr.ph, label %16

.lr.ph:                                           ; preds = %0, %12
  %.010 = phi i32 [ %.pre-phi, %12 ], [ 2, %0 ]
  %.079 = phi i64 [ %.1, %12 ], [ 0, %0 ]
  %3 = tail call noundef zeroext i1 @_Z11connectableii(i32 noundef 0, i32 noundef %.010)
  br i1 %3, label %4, label %.lr.ph._crit_edge

.lr.ph._crit_edge:                                ; preds = %.lr.ph
  %.pre = add nuw nsw i32 %.010, 1
  br label %12

4:                                                ; preds = %.lr.ph
  %5 = add nsw i32 %.010, -1
  %6 = add nuw nsw i32 %.010, 1
  %7 = load i32, ptr @N, align 4, !tbaa !5
  %8 = shl nsw i32 %7, 1
  %9 = add nsw i32 %8, -1
  %10 = tail call noundef i64 @_Z4calciiii(i32 noundef 1, i32 noundef %5, i32 noundef %6, i32 noundef %9)
  %11 = add nsw i64 %10, %.079
  br label %12

12:                                               ; preds = %.lr.ph._crit_edge, %4
  %.pre-phi = phi i32 [ %.pre, %.lr.ph._crit_edge ], [ %6, %4 ]
  %.1 = phi i64 [ %.079, %.lr.ph._crit_edge ], [ %11, %4 ]
  %13 = load i32, ptr @N, align 4, !tbaa !5
  %14 = shl nsw i32 %13, 1
  %15 = add nsw i32 %14, -2
  %.not.not = icmp slt i32 %.010, %15
  br i1 %.not.not, label %.lr.ph, label %.loopexit, !llvm.loop !9

16:                                               ; preds = %0
  %17 = tail call noundef zeroext i1 @_Z11connectableii(i32 noundef 0, i32 noundef 1)
  %. = zext i1 %17 to i64
  br label %.loopexit

.loopexit:                                        ; preds = %12, %16
  %.2 = phi i64 [ %., %16 ], [ %.1, %12 ]
  %18 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEx(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, i64 noundef %.2)
  %19 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEPFRSoS_E(ptr noundef nonnull align 8 dereferenceable(8) %18, ptr noundef nonnull @_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_)
  ret void
}

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

; 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 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


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