; LLVM IR from tangjz/acm-icpc :: projecteuler/432.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::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 }

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

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z1Fx(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 @s, i64 0, i64 %13
  %15 = load i32, ptr %14, align 4, !tbaa !9
  store i32 %15, ptr %2, align 4
  br label %84

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 %84

22:                                               ; preds = %16
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #2
  %23 = load i64, ptr %3, align 8, !tbaa !5
  %24 = and i64 %23, 1
  %25 = icmp ne i64 %24, 0
  br i1 %25, label %26, label %35

26:                                               ; preds = %22
  %27 = load i64, ptr %3, align 8, !tbaa !5
  %28 = srem i64 %27, 1000000000
  %29 = load i64, ptr %3, align 8, !tbaa !5
  %30 = add nsw i64 %29, 1
  %31 = ashr i64 %30, 1
  %32 = srem i64 %31, 1000000000
  %33 = mul nsw i64 %28, %32
  %34 = srem i64 %33, 1000000000
  br label %44

35:                                               ; preds = %22
  %36 = load i64, ptr %3, align 8, !tbaa !5
  %37 = ashr i64 %36, 1
  %38 = srem i64 %37, 1000000000
  %39 = load i64, ptr %3, align 8, !tbaa !5
  %40 = add nsw i64 %39, 1
  %41 = srem i64 %40, 1000000000
  %42 = mul nsw i64 %38, %41
  %43 = srem i64 %42, 1000000000
  br label %44

44:                                               ; preds = %35, %26
  %45 = phi i64 [ %34, %26 ], [ %43, %35 ]
  %46 = trunc i64 %45 to i32
  store i32 %46, 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 %47

47:                                               ; preds = %73, %44
  %48 = load i64, ptr %5, align 8, !tbaa !5
  %49 = load i64, ptr %3, align 8, !tbaa !5
  %50 = icmp sle i64 %48, %49
  br i1 %50, label %52, label %51

51:                                               ; preds = %47
  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 %75

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

73:                                               ; preds = %52
  %74 = load i64, ptr %6, align 8, !tbaa !5
  store i64 %74, ptr %5, align 8, !tbaa !5
  br label %47, !llvm.loop !11

75:                                               ; preds = %51
  %76 = load i32, ptr %4, align 4, !tbaa !9
  %77 = icmp slt i32 %76, 0
  br i1 %77, label %78, label %81

78:                                               ; preds = %75
  %79 = load i32, ptr %4, align 4, !tbaa !9
  %80 = add nsw i32 %79, 1000000000
  store i32 %80, ptr %4, align 4, !tbaa !9
  br label %81

81:                                               ; preds = %78, %75
  %82 = load i32, ptr %4, align 4, !tbaa !9
  %83 = 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 %82, ptr %83, align 4, !tbaa !9
  store i32 %82, ptr %2, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  br label %84

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

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

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

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z1Fx(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 @s, i64 0, i64 %5
  %7 = load i32, ptr %6, align 4, !tbaa !9
  br label %43

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 %43

13:                                               ; preds = %8
  %14 = load i64, ptr %2, align 8, !tbaa !5
  %15 = and i64 %14, 1
  %.not16 = icmp eq i64 %15, 0
  br i1 %.not16, label %22, label %16

16:                                               ; preds = %13
  %17 = srem i64 %14, 1000000000
  %18 = add nsw i64 %14, 1
  %19 = ashr exact i64 %18, 1
  %20 = srem i64 %19, 1000000000
  %21 = mul nsw i64 %20, %17
  br label %28

22:                                               ; preds = %13
  %23 = ashr exact i64 %14, 1
  %24 = srem i64 %23, 1000000000
  %25 = or disjoint i64 %14, 1
  %26 = srem i64 %25, 1000000000
  %27 = mul nsw i64 %24, %26
  br label %28

28:                                               ; preds = %22, %16
  %.in = phi i64 [ %21, %16 ], [ %27, %22 ]
  %.012.in18 = srem i64 %.in, 1000000000
  %.not1719 = icmp slt i64 %14, 2
  br i1 %.not1719, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %.lr.ph, %28
  %.012.in.lcssa = phi i64 [ %.012.in18, %28 ], [ %.012.in, %.lr.ph ]
  %.012 = trunc nsw i64 %.012.in.lcssa to i32
  %29 = icmp slt i64 %.012.in.lcssa, 0
  %30 = add nsw i32 %.012, 1000000000
  %spec.select = select i1 %29, i32 %30, i32 %.012
  %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 %43

.lr.ph:                                           ; preds = %28, %.lr.ph
  %32 = phi i64 [ %42, %.lr.ph ], [ %14, %28 ]
  %.012.in21 = phi i64 [ %.012.in, %.lr.ph ], [ %.012.in18, %28 ]
  %.01320 = phi i64 [ %35, %.lr.ph ], [ 2, %28 ]
  %33 = udiv i64 %32, %.01320
  %34 = sdiv i64 %32, %33
  %35 = add nuw nsw i64 %34, 1
  %36 = sub nsw i64 %35, %.01320
  %37 = srem i64 %36, 1000000000
  %38 = call noundef i32 @_Z1Fx(i64 noundef %33)
  %39 = sext i32 %38 to i64
  %40 = mul nsw i64 %37, %39
  %41 = sub nsw i64 %.012.in21, %40
  %.012.in = srem i64 %41, 1000000000
  %42 = load i64, ptr %2, align 8, !tbaa !5
  %.not17.not = icmp slt i64 %34, %42
  br i1 %.not17.not, label %.lr.ph, label %._crit_edge, !llvm.loop !11

43:                                               ; 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