; LLVM IR from tangjz/acm-icpc :: 51nod/1226.ll (Z4calcx)

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

@tot = external dso_local global i32, align 4
@prime = external dso_local global [227647 x i32], align 16
@_ZL6sprime = external hidden constant [2219 x i64], align 16

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z4calcx(i64 noundef %0) #0 {
  %2 = alloca i64, align 8
  %3 = alloca i32, align 4
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i8, align 1
  %9 = alloca i32, align 4
  store i64 %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  %10 = call noundef ptr @_ZSt11upper_boundIPKxxET_S2_S2_RKT0_(ptr noundef @_ZL6sprime, ptr noundef getelementptr inbounds (i64, ptr @_ZL6sprime, i64 2219), ptr noundef nonnull align 8 dereferenceable(8) %2)
  %11 = ptrtoint ptr %10 to i64
  %12 = sub i64 %11, ptrtoint (ptr @_ZL6sprime to i64)
  %13 = sdiv exact i64 %12, 8
  %14 = sub nsw i64 %13, 1
  %15 = trunc i64 %14 to i32
  store i32 %15, ptr %3, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  %16 = load i32, ptr %3, align 4, !tbaa !9
  %17 = sext i32 %16 to i64
  %18 = getelementptr inbounds [2219 x i64], ptr @_ZL6sprime, i64 0, i64 %17
  %19 = load i64, ptr %18, align 8, !tbaa !5
  store i64 %19, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  %20 = load i32, ptr %3, align 4, !tbaa !9
  %21 = mul nsw i32 %20, 100
  store i32 %21, ptr %3, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  store i32 1, ptr %6, align 4, !tbaa !9
  br label %22

22:                                               ; preds = %88, %1
  %23 = load i32, ptr %6, align 4, !tbaa !9
  %24 = sext i32 %23 to i64
  %25 = load i32, ptr %6, align 4, !tbaa !9
  %26 = sext i32 %25 to i64
  %27 = mul nsw i64 %24, %26
  %28 = load i32, ptr %6, align 4, !tbaa !9
  %29 = sext i32 %28 to i64
  %30 = add nsw i64 %29, 1
  %31 = load i32, ptr %6, align 4, !tbaa !9
  %32 = add nsw i32 %31, 1
  %33 = sext i32 %32 to i64
  %34 = mul nsw i64 %30, %33
  %35 = add nsw i64 %27, %34
  store i64 %35, ptr %5, align 8, !tbaa !5
  %36 = load i64, ptr %2, align 8, !tbaa !5
  %37 = icmp sle i64 %35, %36
  br i1 %37, label %39, label %38

38:                                               ; preds = %22
  store i32 2, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  br label %91

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

43:                                               ; preds = %39
  br label %88

44:                                               ; preds = %39
  call void @llvm.lifetime.start.p0(i64 1, ptr %8) #3
  store i8 1, ptr %8, align 1, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  store i32 0, ptr %9, align 4, !tbaa !9
  br label %45

45:                                               ; preds = %77, %44
  %46 = load i32, ptr %9, align 4, !tbaa !9
  %47 = load i32, ptr @tot, align 4, !tbaa !9
  %48 = icmp slt i32 %46, %47
  br i1 %48, label %49, label %63

49:                                               ; preds = %45
  %50 = load i32, ptr %9, align 4, !tbaa !9
  %51 = sext i32 %50 to i64
  %52 = getelementptr inbounds [227647 x i32], ptr @prime, i64 0, i64 %51
  %53 = load i32, ptr %52, align 4, !tbaa !9
  %54 = sext i32 %53 to i64
  %55 = load i64, ptr %5, align 8, !tbaa !5
  %56 = load i32, ptr %9, align 4, !tbaa !9
  %57 = sext i32 %56 to i64
  %58 = getelementptr inbounds [227647 x i32], ptr @prime, i64 0, i64 %57
  %59 = load i32, ptr %58, align 4, !tbaa !9
  %60 = sext i32 %59 to i64
  %61 = sdiv i64 %55, %60
  %62 = icmp sle i64 %54, %61
  br label %63

63:                                               ; preds = %49, %45
  %64 = phi i1 [ false, %45 ], [ %62, %49 ]
  br i1 %64, label %66, label %65

65:                                               ; preds = %63
  store i32 5, ptr %7, align 4
  br label %80

66:                                               ; preds = %63
  %67 = load i64, ptr %5, align 8, !tbaa !5
  %68 = load i32, ptr %9, align 4, !tbaa !9
  %69 = sext i32 %68 to i64
  %70 = getelementptr inbounds [227647 x i32], ptr @prime, i64 0, i64 %69
  %71 = load i32, ptr %70, align 4, !tbaa !9
  %72 = sext i32 %71 to i64
  %73 = srem i64 %67, %72
  %74 = icmp eq i64 %73, 0
  br i1 %74, label %75, label %76

75:                                               ; preds = %66
  store i8 0, ptr %8, align 1, !tbaa !11
  store i32 5, ptr %7, align 4
  br label %80

76:                                               ; preds = %66
  br label %77

77:                                               ; preds = %76
  %78 = load i32, ptr %9, align 4, !tbaa !9
  %79 = add nsw i32 %78, 1
  store i32 %79, ptr %9, align 4, !tbaa !9
  br label %45, !llvm.loop !13

80:                                               ; preds = %75, %65
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  br label %81

81:                                               ; preds = %80
  %82 = load i8, ptr %8, align 1, !tbaa !11, !range !15, !noundef !16
  %83 = trunc i8 %82 to i1
  br i1 %83, label %84, label %87

84:                                               ; preds = %81
  %85 = load i32, ptr %3, align 4, !tbaa !9
  %86 = add nsw i32 %85, 1
  store i32 %86, ptr %3, align 4, !tbaa !9
  br label %87

87:                                               ; preds = %84, %81
  call void @llvm.lifetime.end.p0(i64 1, ptr %8) #3
  br label %88

88:                                               ; preds = %87, %43
  %89 = load i32, ptr %6, align 4, !tbaa !9
  %90 = add nsw i32 %89, 1
  store i32 %90, ptr %6, align 4, !tbaa !9
  br label %22, !llvm.loop !17

91:                                               ; preds = %38
  %92 = load i32, ptr %3, align 4, !tbaa !9
  store i32 1, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  ret i32 %92
}

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

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

; 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 = { 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 #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 = !{!12, !12, i64 0}
!12 = !{!"bool", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{i8 0, i8 2}
!16 = !{}
!17 = distinct !{!17, !14}


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

@tot = external dso_local local_unnamed_addr global i32, align 4
@prime = external dso_local local_unnamed_addr global [227647 x i32], align 16
@_ZL6sprime = external hidden constant [2219 x i64], align 16

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z4calcx(i64 noundef %0) local_unnamed_addr #0 {
  %2 = alloca i64, align 8
  store i64 %0, ptr %2, align 8, !tbaa !5
  %3 = call noundef ptr @_ZSt11upper_boundIPKxxET_S2_S2_RKT0_(ptr noundef nonnull @_ZL6sprime, ptr noundef nonnull getelementptr inbounds (i8, ptr @_ZL6sprime, i64 17752), ptr noundef nonnull align 8 dereferenceable(8) %2)
  %4 = ptrtoint ptr %3 to i64
  %5 = sub i64 %4, ptrtoint (ptr @_ZL6sprime to i64)
  %6 = lshr exact i64 %5, 3
  %7 = trunc i64 %6 to i32
  %8 = add i32 %7, -1
  %9 = sext i32 %8 to i64
  %10 = getelementptr inbounds [2219 x i64], ptr @_ZL6sprime, i64 0, i64 %9
  %11 = load i64, ptr %10, align 8, !tbaa !5
  %12 = mul nsw i32 %8, 100
  %13 = load i64, ptr %2, align 8, !tbaa !5
  %.not29 = icmp slt i64 %13, 5
  br i1 %.not29, label %._crit_edge33, label %.lr.ph32

.lr.ph32:                                         ; preds = %1
  %14 = load i32, ptr @tot, align 4
  %.fr34 = freeze i32 %14
  %15 = icmp sgt i32 %.fr34, 0
  br i1 %15, label %.lr.ph32.split.us.preheader, label %.lr.ph32.split

.lr.ph32.split.us.preheader:                      ; preds = %.lr.ph32
  %wide.trip.count = zext nneg i32 %.fr34 to i64
  br label %.lr.ph32.split.us

.lr.ph32.split.us:                                ; preds = %.lr.ph32.split.us.preheader, %.critedge.us
  %indvars.iv40 = phi i64 [ 2, %.lr.ph32.split.us.preheader ], [ %27, %.critedge.us ]
  %16 = phi i64 [ 5, %.lr.ph32.split.us.preheader ], [ %29, %.critedge.us ]
  %.02130.us = phi i32 [ %12, %.lr.ph32.split.us.preheader ], [ %.2.us, %.critedge.us ]
  %.not24.us = icmp sgt i64 %16, %11
  br i1 %.not24.us, label %.preheader.us, label %.critedge.us

17:                                               ; preds = %23
  %indvars.iv.next38 = add nuw nsw i64 %indvars.iv37, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next38, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge.us, label %.preheader.us, !llvm.loop !9

.preheader.us:                                    ; preds = %.lr.ph32.split.us, %17
  %indvars.iv37 = phi i64 [ %indvars.iv.next38, %17 ], [ 0, %.lr.ph32.split.us ]
  %18 = getelementptr inbounds [227647 x i32], ptr @prime, i64 0, i64 %indvars.iv37
  %19 = load i32, ptr %18, align 4, !tbaa !11
  %20 = sext i32 %19 to i64
  %21 = sdiv i64 %16, %20
  %22 = srem i64 %16, %20
  %.not25.us = icmp slt i64 %21, %20
  br i1 %.not25.us, label %._crit_edge.us, label %23

23:                                               ; preds = %.preheader.us
  %24 = icmp eq i64 %22, 0
  br i1 %24, label %.critedge.us, label %17

._crit_edge.us:                                   ; preds = %.preheader.us, %17
  %25 = add nsw i32 %.02130.us, 1
  br label %.critedge.us

.critedge.us:                                     ; preds = %23, %._crit_edge.us, %.lr.ph32.split.us
  %.2.us = phi i32 [ %.02130.us, %.lr.ph32.split.us ], [ %25, %._crit_edge.us ], [ %.02130.us, %23 ]
  %26 = mul nuw nsw i64 %indvars.iv40, %indvars.iv40
  %27 = add nuw nsw i64 %indvars.iv40, 1
  %28 = mul nuw nsw i64 %27, %27
  %29 = add nuw nsw i64 %28, %26
  %.not.us = icmp sgt i64 %29, %13
  br i1 %.not.us, label %._crit_edge33, label %.lr.ph32.split.us, !llvm.loop !13

._crit_edge33:                                    ; preds = %.lr.ph32.split, %.critedge.us, %1
  %.021.lcssa = phi i32 [ %12, %1 ], [ %.2.us, %.critedge.us ], [ %spec.select, %.lr.ph32.split ]
  ret i32 %.021.lcssa

.lr.ph32.split:                                   ; preds = %.lr.ph32, %.lr.ph32.split
  %indvars.iv = phi i64 [ %33, %.lr.ph32.split ], [ 2, %.lr.ph32 ]
  %30 = phi i64 [ %35, %.lr.ph32.split ], [ 5, %.lr.ph32 ]
  %.02130 = phi i32 [ %spec.select, %.lr.ph32.split ], [ %12, %.lr.ph32 ]
  %.not24 = icmp sgt i64 %30, %11
  %31 = zext i1 %.not24 to i32
  %spec.select = add nsw i32 %.02130, %31
  %32 = mul nuw nsw i64 %indvars.iv, %indvars.iv
  %33 = add nuw nsw i64 %indvars.iv, 1
  %34 = mul nuw nsw i64 %33, %33
  %35 = add nuw nsw i64 %34, %32
  %.not = icmp sgt i64 %35, %13
  br i1 %.not, label %._crit_edge33, label %.lr.ph32.split, !llvm.loop !13
}

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef ptr @_ZSt11upper_boundIPKxxET_S2_S2_RKT0_(ptr noundef, ptr noundef, ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #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 = { 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 = !{!"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}
!13 = distinct !{!13, !10}


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