; LLVM IR from kazunetakahashi/atcoder :: 2018/0325_ARC093/E2.ll (Z1fx)

; 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::vector.7" = type { %"struct.std::_Vector_base.8" }
%"struct.std::_Vector_base.8" = type { %"struct.std::_Vector_base<long long, std::allocator<long long>>::_Vector_impl" }
%"struct.std::_Vector_base<long long, std::allocator<long long>>::_Vector_impl" = type { %"struct.std::_Vector_base<long long, std::allocator<long long>>::_Vector_impl_data" }
%"struct.std::_Vector_base<long long, std::allocator<long long>>::_Vector_impl_data" = type { ptr, ptr, ptr }

@M = external dso_local global i32, align 4
@S = external dso_local global %"class.std::vector.7", align 8

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

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

; Function Attrs: mustprogress uwtable
declare dso_local noundef i64 @_Z5powerxx(i64 noundef, i64 noundef) #1

; Function Attrs: mustprogress uwtable
define dso_local noundef i64 @_Z1fx(i64 noundef %0) #1 {
  %2 = alloca i64, align 8
  %3 = alloca i64, align 8
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  %8 = alloca i32, align 4
  store i64 %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  %9 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24) @S, i64 noundef 0) #3
  %10 = load i64, ptr %9, align 8, !tbaa !5
  %11 = load i64, ptr %3, align 8, !tbaa !5
  %12 = icmp sgt i64 %10, %11
  br i1 %12, label %13, label %14

13:                                               ; preds = %1
  store i64 0, ptr %4, align 8, !tbaa !5
  br label %38

14:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  store i64 0, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %15 = call noundef i64 @_ZNKSt6vectorIxSaIxEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) @S) #3
  store i64 %15, ptr %6, align 8, !tbaa !5
  br label %16

16:                                               ; preds = %35, %14
  %17 = load i64, ptr %6, align 8, !tbaa !5
  %18 = load i64, ptr %5, align 8, !tbaa !5
  %19 = sub nsw i64 %17, %18
  %20 = icmp sgt i64 %19, 1
  br i1 %20, label %21, label %36

21:                                               ; preds = %16
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %22 = load i64, ptr %6, align 8, !tbaa !5
  %23 = load i64, ptr %5, align 8, !tbaa !5
  %24 = add nsw i64 %22, %23
  %25 = sdiv i64 %24, 2
  store i64 %25, ptr %7, align 8, !tbaa !5
  %26 = load i64, ptr %7, align 8, !tbaa !5
  %27 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24) @S, i64 noundef %26) #3
  %28 = load i64, ptr %27, align 8, !tbaa !5
  %29 = load i64, ptr %3, align 8, !tbaa !5
  %30 = icmp sgt i64 %28, %29
  br i1 %30, label %31, label %33

31:                                               ; preds = %21
  %32 = load i64, ptr %7, align 8, !tbaa !5
  store i64 %32, ptr %6, align 8, !tbaa !5
  br label %35

33:                                               ; preds = %21
  %34 = load i64, ptr %7, align 8, !tbaa !5
  store i64 %34, ptr %5, align 8, !tbaa !5
  br label %35

35:                                               ; preds = %33, %31
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  br label %16, !llvm.loop !9

36:                                               ; preds = %16
  %37 = load i64, ptr %6, align 8, !tbaa !5
  store i64 %37, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  br label %38

38:                                               ; preds = %36, %13
  %39 = load i64, ptr %4, align 8, !tbaa !5
  %40 = icmp eq i64 %39, 0
  br i1 %40, label %41, label %45

41:                                               ; preds = %38
  %42 = load i32, ptr @M, align 4, !tbaa !11
  %43 = sext i32 %42 to i64
  %44 = call noundef i64 @_Z5powerxx(i64 noundef 2, i64 noundef %43)
  store i64 %44, ptr %2, align 8
  store i32 1, ptr %8, align 4
  br label %52

45:                                               ; preds = %38
  %46 = load i32, ptr @M, align 4, !tbaa !11
  %47 = sext i32 %46 to i64
  %48 = load i64, ptr %4, align 8, !tbaa !5
  %49 = sub nsw i64 %47, %48
  %50 = add nsw i64 %49, 1
  %51 = call noundef i64 @_Z5powerxx(i64 noundef 2, i64 noundef %50)
  store i64 %51, ptr %2, align 8
  store i32 1, ptr %8, align 4
  br label %52

52:                                               ; preds = %45, %41
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  %53 = load i64, ptr %2, align 8
  ret i64 %53
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) #2 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZNKSt6vectorIxSaIxEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24)) #2 align 2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 #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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}


; 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::vector.7" = type { %"struct.std::_Vector_base.8" }
%"struct.std::_Vector_base.8" = type { %"struct.std::_Vector_base<long long, std::allocator<long long>>::_Vector_impl" }
%"struct.std::_Vector_base<long long, std::allocator<long long>>::_Vector_impl" = type { %"struct.std::_Vector_base<long long, std::allocator<long long>>::_Vector_impl_data" }
%"struct.std::_Vector_base<long long, std::allocator<long long>>::_Vector_impl_data" = type { ptr, ptr, ptr }

@M = external dso_local local_unnamed_addr global i32, align 4
@S = external dso_local global %"class.std::vector.7", align 8

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

; Function Attrs: mustprogress uwtable
define dso_local noundef i64 @_Z1fx(i64 noundef %0) local_unnamed_addr #0 {
  %2 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24) @S, i64 noundef 0) #2
  %3 = load i64, ptr %2, align 8, !tbaa !5
  %4 = icmp sgt i64 %3, %0
  br i1 %4, label %.thread, label %5

5:                                                ; preds = %1
  %6 = tail call noundef i64 @_ZNKSt6vectorIxSaIxEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) @S) #2
  %7 = icmp sgt i64 %6, 1
  br i1 %7, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %5, %.lr.ph
  %.01320 = phi i64 [ %..013, %.lr.ph ], [ %6, %5 ]
  %.01419 = phi i64 [ %.014., %.lr.ph ], [ 0, %5 ]
  %8 = add nsw i64 %.01320, %.01419
  %9 = sdiv i64 %8, 2
  %10 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24) @S, i64 noundef %9) #2
  %11 = load i64, ptr %10, align 8, !tbaa !5
  %12 = icmp sgt i64 %11, %0
  %.014. = select i1 %12, i64 %.01419, i64 %9
  %..013 = select i1 %12, i64 %9, i64 %.01320
  %13 = sub nsw i64 %..013, %.014.
  %14 = icmp sgt i64 %13, 1
  br i1 %14, label %.lr.ph, label %._crit_edge, !llvm.loop !9

._crit_edge:                                      ; preds = %.lr.ph, %5
  %.013.lcssa = phi i64 [ %6, %5 ], [ %..013, %.lr.ph ]
  %15 = icmp eq i64 %.013.lcssa, 0
  br i1 %15, label %.thread, label %18

.thread:                                          ; preds = %1, %._crit_edge
  %16 = load i32, ptr @M, align 4, !tbaa !11
  %17 = sext i32 %16 to i64
  br label %22

18:                                               ; preds = %._crit_edge
  %19 = load i32, ptr @M, align 4, !tbaa !11
  %20 = sext i32 %19 to i64
  %reass.sub = sub i64 %20, %.013.lcssa
  %21 = add i64 %reass.sub, 1
  br label %22

22:                                               ; preds = %18, %.thread
  %.sink = phi i64 [ %21, %18 ], [ %17, %.thread ]
  %23 = tail call noundef i64 @_Z5powerxx(i64 noundef 2, i64 noundef %.sink)
  ret i64 %23
}

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZNKSt6vectorIxSaIxEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24)) local_unnamed_addr #1 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 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 #2 = { 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"}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}


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