; LLVM IR from tangjz/acm-icpc :: projecteuler/448.ll (Z9calc_iphix)

; 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::map" = type { %"class.std::_Rb_tree" }
%"class.std::_Rb_tree" = type { %"struct.std::_Rb_tree<long long, std::pair<const long long, int>, std::_Select1st<std::pair<const long long, int>>, std::less<long long>>::_Rb_tree_impl" }
%"struct.std::_Rb_tree<long long, std::pair<const long long, int>, std::_Select1st<std::pair<const long long, int>>, std::less<long long>>::_Rb_tree_impl" = type { [8 x i8], %"struct.std::_Rb_tree_header" }
%"struct.std::_Rb_tree_header" = type { %"struct.std::_Rb_tree_node_base", i64 }
%"struct.std::_Rb_tree_node_base" = type { i32, ptr, ptr, ptr }

@Hash = external dso_local global %"class.std::map", align 8
@f = external dso_local global [23333333 x i32], align 16

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z9calc_iphix(i64 noundef %0) #0 {
  %2 = alloca i32, align 4
  %3 = alloca i64, align 8
  %4 = alloca i32, align 4
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  store i64 %0, ptr %3, align 8, !tbaa !5
  %8 = load i64, ptr %3, align 8, !tbaa !5
  %9 = icmp slt i64 %8, 23333333
  br i1 %9, label %10, label %16

10:                                               ; preds = %1
  %11 = load i64, ptr %3, align 8, !tbaa !5
  %12 = trunc i64 %11 to i32
  %13 = sext i32 %12 to i64
  %14 = getelementptr inbounds [23333333 x i32], ptr @f, i64 0, i64 %13
  %15 = load i32, ptr %14, align 4, !tbaa !9
  store i32 %15, ptr %2, align 4
  br label %88

16:                                               ; preds = %1
  %17 = call noundef i64 @_ZNKSt3mapIxiSt4lessIxESaISt4pairIKxiEEE5countERS3_(ptr noundef nonnull align 8 dereferenceable(48) @Hash, ptr noundef nonnull align 8 dereferenceable(8) %3)
  %18 = icmp ne i64 %17, 0
  br i1 %18, label %19, label %22

19:                                               ; preds = %16
  %20 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt3mapIxiSt4lessIxESaISt4pairIKxiEEEixERS3_(ptr noundef nonnull align 8 dereferenceable(48) @Hash, ptr noundef nonnull align 8 dereferenceable(8) %3)
  %21 = load i32, ptr %20, align 4, !tbaa !9
  store i32 %21, ptr %2, align 4
  br label %88

22:                                               ; preds = %16
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #2
  %23 = load i64, ptr %3, align 8, !tbaa !5
  %24 = srem i64 %23, 999999017
  %25 = load i64, ptr %3, align 8, !tbaa !5
  %26 = add nsw i64 %25, 1
  %27 = srem i64 %26, 999999017
  %28 = mul nsw i64 %24, %27
  %29 = srem i64 %28, 999999017
  %30 = load i64, ptr %3, align 8, !tbaa !5
  %31 = shl i64 %30, 1
  %32 = add nsw i64 %31, 1
  %33 = srem i64 %32, 999999017
  %34 = mul nsw i64 %29, %33
  %35 = srem i64 %34, 999999017
  %36 = mul nsw i64 %35, 333333006
  %37 = srem i64 %36, 999999017
  %38 = trunc i64 %37 to i32
  store i32 %38, ptr %4, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #2
  store i64 2, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  br label %39

39:                                               ; preds = %72, %22
  %40 = load i64, ptr %5, align 8, !tbaa !5
  %41 = load i64, ptr %3, align 8, !tbaa !5
  %42 = icmp sle i64 %40, %41
  br i1 %42, label %44, label %43

43:                                               ; preds = %39
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #2
  br label %74

44:                                               ; preds = %39
  %45 = load i64, ptr %3, align 8, !tbaa !5
  %46 = load i64, ptr %5, align 8, !tbaa !5
  %47 = sdiv i64 %45, %46
  store i64 %47, ptr %7, align 8, !tbaa !5
  %48 = load i64, ptr %3, align 8, !tbaa !5
  %49 = load i64, ptr %7, align 8, !tbaa !5
  %50 = sdiv i64 %48, %49
  %51 = add nsw i64 %50, 1
  store i64 %51, ptr %6, align 8, !tbaa !5
  %52 = load i32, ptr %4, align 4, !tbaa !9
  %53 = sext i32 %52 to i64
  %54 = load i64, ptr %5, align 8, !tbaa !5
  %55 = load i64, ptr %6, align 8, !tbaa !5
  %56 = add nsw i64 %54, %55
  %57 = sub nsw i64 %56, 1
  %58 = srem i64 %57, 999999017
  %59 = load i64, ptr %6, align 8, !tbaa !5
  %60 = load i64, ptr %5, align 8, !tbaa !5
  %61 = sub nsw i64 %59, %60
  %62 = srem i64 %61, 999999017
  %63 = mul nsw i64 %58, %62
  %64 = srem i64 %63, 999999017
  %65 = load i64, ptr %7, align 8, !tbaa !5
  %66 = call noundef i32 @_Z9calc_iphix(i64 noundef %65)
  %67 = sext i32 %66 to i64
  %68 = mul nsw i64 %64, %67
  %69 = sub nsw i64 %53, %68
  %70 = srem i64 %69, 999999017
  %71 = trunc i64 %70 to i32
  store i32 %71, ptr %4, align 4, !tbaa !9
  br label %72

72:                                               ; preds = %44
  %73 = load i64, ptr %6, align 8, !tbaa !5
  store i64 %73, ptr %5, align 8, !tbaa !5
  br label %39, !llvm.loop !11

74:                                               ; preds = %43
  %75 = load i32, ptr %4, align 4, !tbaa !9
  %76 = sext i32 %75 to i64
  %77 = mul nsw i64 %76, 499999509
  %78 = srem i64 %77, 999999017
  %79 = trunc i64 %78 to i32
  store i32 %79, ptr %4, align 4, !tbaa !9
  %80 = load i32, ptr %4, align 4, !tbaa !9
  %81 = icmp slt i32 %80, 0
  br i1 %81, label %82, label %85

82:                                               ; preds = %74
  %83 = load i32, ptr %4, align 4, !tbaa !9
  %84 = add nsw i32 %83, 999999017
  store i32 %84, ptr %4, align 4, !tbaa !9
  br label %85

85:                                               ; preds = %82, %74
  %86 = load i32, ptr %4, align 4, !tbaa !9
  %87 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt3mapIxiSt4lessIxESaISt4pairIKxiEEEixERS3_(ptr noundef nonnull align 8 dereferenceable(48) @Hash, ptr noundef nonnull align 8 dereferenceable(8) %3)
  store i32 %86, ptr %87, align 4, !tbaa !9
  store i32 %86, ptr %2, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  br label %88

88:                                               ; preds = %85, %19, %10
  %89 = load i32, ptr %2, align 4
  ret i32 %89
}

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

; Function Attrs: mustprogress uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt3mapIxiSt4lessIxESaISt4pairIKxiEEEixERS3_(ptr noundef nonnull align 8 dereferenceable(48), 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 = !{!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::map" = type { %"class.std::_Rb_tree" }
%"class.std::_Rb_tree" = type { %"struct.std::_Rb_tree<long long, std::pair<const long long, int>, std::_Select1st<std::pair<const long long, int>>, std::less<long long>>::_Rb_tree_impl" }
%"struct.std::_Rb_tree<long long, std::pair<const long long, int>, std::_Select1st<std::pair<const long long, int>>, std::less<long long>>::_Rb_tree_impl" = type { [8 x i8], %"struct.std::_Rb_tree_header" }
%"struct.std::_Rb_tree_header" = type { %"struct.std::_Rb_tree_node_base", i64 }
%"struct.std::_Rb_tree_node_base" = type { i32, ptr, ptr, ptr }

@Hash = external dso_local global %"class.std::map", align 8
@f = external dso_local local_unnamed_addr global [23333333 x i32], align 16

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

4:                                                ; preds = %1
  %sext = shl i64 %0, 32
  %5 = ashr exact i64 %sext, 32
  %6 = getelementptr inbounds [23333333 x i32], ptr @f, i64 0, i64 %5
  %7 = load i32, ptr %6, align 4, !tbaa !9
  br label %47

8:                                                ; preds = %1
  %9 = call noundef i64 @_ZNKSt3mapIxiSt4lessIxESaISt4pairIKxiEEE5countERS3_(ptr noundef nonnull align 8 dereferenceable(48) @Hash, ptr noundef nonnull align 8 dereferenceable(8) %2)
  %.not = icmp eq i64 %9, 0
  br i1 %.not, label %13, label %10

10:                                               ; preds = %8
  %11 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt3mapIxiSt4lessIxESaISt4pairIKxiEEEixERS3_(ptr noundef nonnull align 8 dereferenceable(48) @Hash, ptr noundef nonnull align 8 dereferenceable(8) %2)
  %12 = load i32, ptr %11, align 4, !tbaa !9
  br label %47

13:                                               ; preds = %8
  %14 = load i64, ptr %2, align 8, !tbaa !5
  %15 = srem i64 %14, 999999017
  %16 = add nsw i64 %14, 1
  %17 = srem i64 %16, 999999017
  %18 = mul nsw i64 %17, %15
  %19 = srem i64 %18, 999999017
  %20 = shl i64 %14, 1
  %21 = or disjoint i64 %20, 1
  %22 = srem i64 %21, 999999017
  %23 = mul nsw i64 %19, %22
  %24 = srem i64 %23, 999999017
  %25 = mul nsw i64 %24, 333333006
  %.015.in22 = srem i64 %25, 999999017
  %.not2123 = icmp slt i64 %14, 2
  br i1 %.not2123, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %.lr.ph, %13
  %.015.in.lcssa = phi i64 [ %.015.in22, %13 ], [ %.015.in, %.lr.ph ]
  %26 = mul nsw i64 %.015.in.lcssa, 499999509
  %27 = srem i64 %26, 999999017
  %28 = trunc nsw i64 %27 to i32
  %29 = icmp slt i64 %27, 0
  %30 = add nsw i32 %28, 999999017
  %spec.select = select i1 %29, i32 %30, i32 %28
  %31 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt3mapIxiSt4lessIxESaISt4pairIKxiEEEixERS3_(ptr noundef nonnull align 8 dereferenceable(48) @Hash, ptr noundef nonnull align 8 dereferenceable(8) %2)
  store i32 %spec.select, ptr %31, align 4, !tbaa !9
  br label %47

.lr.ph:                                           ; preds = %13, %.lr.ph
  %32 = phi i64 [ %46, %.lr.ph ], [ %14, %13 ]
  %.015.in25 = phi i64 [ %.015.in, %.lr.ph ], [ %.015.in22, %13 ]
  %.01624 = phi i64 [ %35, %.lr.ph ], [ 2, %13 ]
  %33 = udiv i64 %32, %.01624
  %34 = sdiv i64 %32, %33
  %35 = add nuw nsw i64 %34, 1
  %36 = add i64 %34, %.01624
  %37 = urem i64 %36, 999999017
  %38 = sub nsw i64 %35, %.01624
  %39 = srem i64 %38, 999999017
  %40 = mul nsw i64 %39, %37
  %41 = srem i64 %40, 999999017
  %42 = call noundef i32 @_Z9calc_iphix(i64 noundef %33)
  %43 = sext i32 %42 to i64
  %44 = mul nsw i64 %41, %43
  %45 = sub nsw i64 %.015.in25, %44
  %.015.in = srem i64 %45, 999999017
  %46 = load i64, ptr %2, align 8, !tbaa !5
  %.not21.not = icmp slt i64 %34, %46
  br i1 %.not21.not, label %.lr.ph, label %._crit_edge, !llvm.loop !11

47:                                               ; preds = %._crit_edge, %10, %4
  %.0 = phi i32 [ %7, %4 ], [ %12, %10 ], [ %spec.select, %._crit_edge ]
  ret i32 %.0
}

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

; Function Attrs: mustprogress uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt3mapIxiSt4lessIxESaISt4pairIKxiEEEixERS3_(ptr noundef nonnull align 8 dereferenceable(48), 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 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


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