; LLVM IR from abeaumont/competitive-programming :: cses/1146.ll (Z1cy)

; 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::unordered_map" = type { %"class.std::_Hashtable" }
%"class.std::_Hashtable" = type { ptr, i64, %"struct.std::__detail::_Hash_node_base", i64, %"struct.std::__detail::_Prime_rehash_policy", ptr }
%"struct.std::__detail::_Hash_node_base" = type { ptr }
%"struct.std::__detail::_Prime_rehash_policy" = type { float, i64 }

@cache = external dso_local global %"class.std::unordered_map", align 8

; Function Attrs: mustprogress uwtable
define dso_local noundef i64 @_Z1cy(i64 noundef %0) #0 {
  %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
  store i64 %0, ptr %3, align 8, !tbaa !5
  %7 = load i64, ptr %3, align 8, !tbaa !5
  %8 = icmp eq i64 %7, 0
  br i1 %8, label %9, label %10

9:                                                ; preds = %1
  store i64 0, ptr %2, align 8
  br label %43

10:                                               ; preds = %1
  %11 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt13unordered_mapIyySt4hashIyESt8equal_toIyESaISt4pairIKyyEEEixERS5_(ptr noundef nonnull align 8 dereferenceable(56) @cache, ptr noundef nonnull align 8 dereferenceable(8) %3)
  %12 = load i64, ptr %11, align 8, !tbaa !5
  %13 = icmp ne i64 %12, 0
  br i1 %13, label %14, label %17

14:                                               ; preds = %10
  %15 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt13unordered_mapIyySt4hashIyESt8equal_toIyESaISt4pairIKyyEEEixERS5_(ptr noundef nonnull align 8 dereferenceable(56) @cache, ptr noundef nonnull align 8 dereferenceable(8) %3)
  %16 = load i64, ptr %15, align 8, !tbaa !5
  store i64 %16, ptr %2, align 8
  br label %43

17:                                               ; preds = %10
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #2
  %18 = load i64, ptr %3, align 8, !tbaa !5
  store i64 %18, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #2
  store i64 1, ptr %5, align 8, !tbaa !5
  br label %19

19:                                               ; preds = %23, %17
  %20 = load i64, ptr %4, align 8, !tbaa !5
  %21 = lshr i64 %20, 1
  store i64 %21, ptr %4, align 8, !tbaa !5
  %22 = icmp ne i64 %21, 0
  br i1 %22, label %23, label %26

23:                                               ; preds = %19
  %24 = load i64, ptr %5, align 8, !tbaa !5
  %25 = shl i64 %24, 1
  store i64 %25, ptr %5, align 8, !tbaa !5
  br label %19, !llvm.loop !9

26:                                               ; preds = %19
  %27 = load i64, ptr %5, align 8, !tbaa !5
  %28 = sub i64 %27, 1
  store i64 %28, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #2
  %29 = load i64, ptr %3, align 8, !tbaa !5
  %30 = load i64, ptr %5, align 8, !tbaa !5
  %31 = sub i64 %29, %30
  store i64 %31, ptr %6, align 8, !tbaa !5
  %32 = load i64, ptr %5, align 8, !tbaa !5
  %33 = call noundef i64 @_Z1cy(i64 noundef %32)
  %34 = load i64, ptr %6, align 8, !tbaa !5
  %35 = add i64 %33, %34
  %36 = load i64, ptr %6, align 8, !tbaa !5
  %37 = sub i64 %36, 1
  %38 = call noundef i64 @_Z1cy(i64 noundef %37)
  %39 = add i64 %35, %38
  %40 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt13unordered_mapIyySt4hashIyESt8equal_toIyESaISt4pairIKyyEEEixERS5_(ptr noundef nonnull align 8 dereferenceable(56) @cache, ptr noundef nonnull align 8 dereferenceable(8) %3)
  store i64 %39, ptr %40, align 8, !tbaa !5
  %41 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt13unordered_mapIyySt4hashIyESt8equal_toIyESaISt4pairIKyyEEEixERS5_(ptr noundef nonnull align 8 dereferenceable(56) @cache, ptr noundef nonnull align 8 dereferenceable(8) %3)
  %42 = load i64, ptr %41, align 8, !tbaa !5
  store i64 %42, ptr %2, align 8
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #2
  br label %43

43:                                               ; preds = %26, %14, %9
  %44 = load i64, ptr %2, align 8
  ret i64 %44
}

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

; 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

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 = { 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::unordered_map" = type { %"class.std::_Hashtable" }
%"class.std::_Hashtable" = type { ptr, i64, %"struct.std::__detail::_Hash_node_base", i64, %"struct.std::__detail::_Prime_rehash_policy", ptr }
%"struct.std::__detail::_Hash_node_base" = type { ptr }
%"struct.std::__detail::_Prime_rehash_policy" = type { float, i64 }

@cache = external dso_local global %"class.std::unordered_map", align 8

; Function Attrs: mustprogress uwtable
define dso_local noundef i64 @_Z1cy(i64 noundef %0) local_unnamed_addr #0 {
  %2 = alloca i64, align 8
  store i64 %0, ptr %2, align 8, !tbaa !5
  %3 = icmp eq i64 %0, 0
  br i1 %3, label %21, label %4

4:                                                ; preds = %1
  %5 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt13unordered_mapIyySt4hashIyESt8equal_toIyESaISt4pairIKyyEEEixERS5_(ptr noundef nonnull align 8 dereferenceable(56) @cache, ptr noundef nonnull align 8 dereferenceable(8) %2)
  %6 = load i64, ptr %5, align 8, !tbaa !5
  %.not = icmp eq i64 %6, 0
  br i1 %.not, label %7, label %.sink.split

7:                                                ; preds = %4
  %8 = load i64, ptr %2, align 8, !tbaa !5
  %.not1112 = icmp ult i64 %8, 2
  br i1 %.not1112, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %7, %.lr.ph
  %.0814 = phi i64 [ %10, %.lr.ph ], [ 1, %7 ]
  %.0913 = phi i64 [ %9, %.lr.ph ], [ %8, %7 ]
  %9 = lshr i64 %.0913, 1
  %10 = shl i64 %.0814, 1
  %.not11 = icmp ult i64 %.0913, 4
  br i1 %.not11, label %._crit_edge.loopexit, label %.lr.ph, !llvm.loop !9

._crit_edge.loopexit:                             ; preds = %.lr.ph
  %11 = add i64 %10, -1
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %7
  %.08.lcssa = phi i64 [ 0, %7 ], [ %11, %._crit_edge.loopexit ]
  %12 = sub i64 %8, %.08.lcssa
  %13 = call noundef i64 @_Z1cy(i64 noundef %.08.lcssa)
  %14 = add i64 %13, %12
  %15 = add i64 %12, -1
  %16 = call noundef i64 @_Z1cy(i64 noundef %15)
  %17 = add i64 %14, %16
  %18 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt13unordered_mapIyySt4hashIyESt8equal_toIyESaISt4pairIKyyEEEixERS5_(ptr noundef nonnull align 8 dereferenceable(56) @cache, ptr noundef nonnull align 8 dereferenceable(8) %2)
  store i64 %17, ptr %18, align 8, !tbaa !5
  br label %.sink.split

.sink.split:                                      ; preds = %4, %._crit_edge
  %19 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt13unordered_mapIyySt4hashIyESt8equal_toIyESaISt4pairIKyyEEEixERS5_(ptr noundef nonnull align 8 dereferenceable(56) @cache, ptr noundef nonnull align 8 dereferenceable(8) %2)
  %20 = load i64, ptr %19, align 8, !tbaa !5
  br label %21

21:                                               ; preds = %.sink.split, %1
  %.0 = phi i64 [ 0, %1 ], [ %20, %.sink.split ]
  ret i64 %.0
}

; Function Attrs: mustprogress uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt13unordered_mapIyySt4hashIyESt8equal_toIyESaISt4pairIKyyEEEixERS5_(ptr noundef nonnull align 8 dereferenceable(56), ptr noundef nonnull align 8 dereferenceable(8)) 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" }

!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,InstSimplifyPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass