; LLVM IR from tangjz/acm-icpc :: 51nod (1162)

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

@.str.2 = external hidden unnamed_addr constant [3 x i8], align 1

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z4readRn(ptr noundef nonnull align 16 dereferenceable(16)) #0

; 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

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z5writenc(i64 noundef, i64 noundef, i8 noundef signext) #0

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z9factorizeRnRiPn(ptr noundef nonnull align 16 dereferenceable(16), ptr noundef nonnull align 4 dereferenceable(4), ptr noundef) #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z11euler_sieveRnRiPn(ptr noundef nonnull align 16 dereferenceable(16), ptr noundef nonnull align 4 dereferenceable(4), ptr noundef) #2

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #3 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i128, align 16
  %4 = alloca [97 x i128], align 16
  %5 = alloca i32, align 4
  %6 = alloca i128, align 16
  %7 = alloca i128, align 16
  store i32 0, ptr %1, align 4
  %8 = call i64 @time(ptr noundef null) #6
  %9 = trunc i64 %8 to i32
  call void @srand(i32 noundef %9) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #6
  store i32 0, ptr %2, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 16, ptr %3) #6
  call void @llvm.lifetime.start.p0(i64 1552, ptr %4) #6
  call void @_Z4readRn(ptr noundef nonnull align 16 dereferenceable(16) %3)
  %10 = getelementptr inbounds [97 x i128], ptr %4, i64 0, i64 0
  call void @_Z11euler_sieveRnRiPn(ptr noundef nonnull align 16 dereferenceable(16) %3, ptr noundef nonnull align 4 dereferenceable(4) %2, ptr noundef %10)
  %11 = getelementptr inbounds [97 x i128], ptr %4, i64 0, i64 0
  call void @_Z9factorizeRnRiPn(ptr noundef nonnull align 16 dereferenceable(16) %3, ptr noundef nonnull align 4 dereferenceable(4) %2, ptr noundef %11)
  %12 = getelementptr inbounds [97 x i128], ptr %4, i64 0, i64 0
  %13 = getelementptr inbounds [97 x i128], ptr %4, i64 0, i64 0
  %14 = load i32, ptr %2, align 4, !tbaa !5
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds i128, ptr %13, i64 %15
  call void @_ZSt4sortIPnEvT_S1_(ptr noundef %12, ptr noundef %16)
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #6
  store i32 0, ptr %5, align 4, !tbaa !5
  br label %17

17:                                               ; preds = %38, %0
  %18 = load i32, ptr %5, align 4, !tbaa !5
  %19 = load i32, ptr %2, align 4, !tbaa !5
  %20 = icmp slt i32 %18, %19
  br i1 %20, label %22, label %21

21:                                               ; preds = %17
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #6
  br label %41

22:                                               ; preds = %17
  %23 = load i32, ptr %5, align 4, !tbaa !5
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds [97 x i128], ptr %4, i64 0, i64 %24
  %26 = load i128, ptr %25, align 16, !tbaa !9
  %27 = load i32, ptr %5, align 4, !tbaa !5
  %28 = load i32, ptr %2, align 4, !tbaa !5
  %29 = sub nsw i32 %28, 1
  %30 = icmp eq i32 %27, %29
  %31 = zext i1 %30 to i64
  %32 = getelementptr inbounds [3 x i8], ptr @.str.2, i64 0, i64 %31
  %33 = load i8, ptr %32, align 1, !tbaa !11
  store i128 %26, ptr %6, align 16, !tbaa !9
  %34 = getelementptr inbounds { i64, i64 }, ptr %6, i32 0, i32 0
  %35 = load i64, ptr %34, align 16
  %36 = getelementptr inbounds { i64, i64 }, ptr %6, i32 0, i32 1
  %37 = load i64, ptr %36, align 8
  call void @_Z5writenc(i64 noundef %35, i64 noundef %37, i8 noundef signext %33)
  br label %38

38:                                               ; preds = %22
  %39 = load i32, ptr %5, align 4, !tbaa !5
  %40 = add nsw i32 %39, 1
  store i32 %40, ptr %5, align 4, !tbaa !5
  br label %17, !llvm.loop !12

41:                                               ; preds = %21
  %42 = load i128, ptr %3, align 16, !tbaa !9
  %43 = icmp sgt i128 %42, 1
  br i1 %43, label %44, label %50

44:                                               ; preds = %41
  %45 = load i128, ptr %3, align 16, !tbaa !9
  store i128 %45, ptr %7, align 16, !tbaa !9
  %46 = getelementptr inbounds { i64, i64 }, ptr %7, i32 0, i32 0
  %47 = load i64, ptr %46, align 16
  %48 = getelementptr inbounds { i64, i64 }, ptr %7, i32 0, i32 1
  %49 = load i64, ptr %48, align 8
  call void @_Z5writenc(i64 noundef %47, i64 noundef %49, i8 noundef signext 10)
  br label %50

50:                                               ; preds = %44, %41
  call void @llvm.lifetime.end.p0(i64 1552, ptr %4) #6
  call void @llvm.lifetime.end.p0(i64 16, ptr %3) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #6
  ret i32 0
}

; Function Attrs: nounwind
declare void @srand(i32 noundef) #4

; Function Attrs: nounwind
declare i64 @time(ptr noundef) #4

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZSt4sortIPnEvT_S1_(ptr noundef, ptr noundef) #5

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 = { 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 = { mustprogress norecurse 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 #4 = { nounwind "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 #5 = { 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 #6 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"__int128", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"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"

@.str.2 = external hidden unnamed_addr constant [3 x i8], align 1

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z4readRn(ptr noundef nonnull align 16 dereferenceable(16)) local_unnamed_addr #0

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

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z5writenc(i64 noundef, i64 noundef, i8 noundef signext) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z9factorizeRnRiPn(ptr noundef nonnull align 16 dereferenceable(16), ptr noundef nonnull align 4 dereferenceable(4), ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z11euler_sieveRnRiPn(ptr noundef nonnull align 16 dereferenceable(16), ptr noundef nonnull align 4 dereferenceable(4), ptr noundef) local_unnamed_addr #2

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() local_unnamed_addr #3 {
  %1 = alloca i32, align 4
  %2 = alloca i128, align 16
  %3 = alloca [97 x i128], align 16
  %4 = tail call i64 @time(ptr noundef null) #6
  %5 = trunc i64 %4 to i32
  tail call void @srand(i32 noundef %5) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #6
  store i32 0, ptr %1, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %2) #6
  call void @llvm.lifetime.start.p0(i64 1552, ptr nonnull %3) #6
  call void @_Z4readRn(ptr noundef nonnull align 16 dereferenceable(16) %2)
  call void @_Z11euler_sieveRnRiPn(ptr noundef nonnull align 16 dereferenceable(16) %2, ptr noundef nonnull align 4 dereferenceable(4) %1, ptr noundef nonnull %3)
  call void @_Z9factorizeRnRiPn(ptr noundef nonnull align 16 dereferenceable(16) %2, ptr noundef nonnull align 4 dereferenceable(4) %1, ptr noundef nonnull %3)
  %6 = load i32, ptr %1, align 4, !tbaa !5
  %7 = sext i32 %6 to i64
  %8 = getelementptr inbounds i128, ptr %3, i64 %7
  call void @_ZSt4sortIPnEvT_S1_(ptr noundef nonnull %3, ptr noundef nonnull %8)
  %9 = load i32, ptr %1, align 4, !tbaa !5
  %10 = icmp sgt i32 %9, 0
  br i1 %10, label %.lr.ph, label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph, %0
  %11 = load i128, ptr %2, align 16, !tbaa !9
  %12 = icmp sgt i128 %11, 1
  br i1 %12, label %25, label %26

.lr.ph:                                           ; preds = %0, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %0 ]
  %13 = phi i32 [ %22, %.lr.ph ], [ %9, %0 ]
  %14 = getelementptr inbounds [97 x i128], ptr %3, i64 0, i64 %indvars.iv
  %15 = load i128, ptr %14, align 16, !tbaa !9
  %16 = add nsw i32 %13, -1
  %17 = zext i32 %16 to i64
  %18 = icmp eq i64 %indvars.iv, %17
  %19 = zext i1 %18 to i64
  %20 = getelementptr inbounds [3 x i8], ptr @.str.2, i64 0, i64 %19
  %21 = load i8, ptr %20, align 1, !tbaa !11
  %.sroa.01.0.extract.trunc = trunc i128 %15 to i64
  %.sroa.22.0.extract.shift = lshr i128 %15, 64
  %.sroa.22.0.extract.trunc = trunc nuw i128 %.sroa.22.0.extract.shift to i64
  call void @_Z5writenc(i64 noundef %.sroa.01.0.extract.trunc, i64 noundef %.sroa.22.0.extract.trunc, i8 noundef signext %21)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %22 = load i32, ptr %1, align 4, !tbaa !5
  %23 = sext i32 %22 to i64
  %24 = icmp slt i64 %indvars.iv.next, %23
  br i1 %24, label %.lr.ph, label %._crit_edge, !llvm.loop !12

25:                                               ; preds = %._crit_edge
  %.sroa.0.0.extract.trunc = trunc i128 %11 to i64
  %.sroa.2.0.extract.shift = lshr i128 %11, 64
  %.sroa.2.0.extract.trunc = trunc nuw nsw i128 %.sroa.2.0.extract.shift to i64
  call void @_Z5writenc(i64 noundef %.sroa.0.0.extract.trunc, i64 noundef %.sroa.2.0.extract.trunc, i8 noundef signext 10)
  br label %26

26:                                               ; preds = %25, %._crit_edge
  call void @llvm.lifetime.end.p0(i64 1552, ptr nonnull %3) #6
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %2) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #6
  ret i32 0
}

; Function Attrs: nounwind
declare void @srand(i32 noundef) local_unnamed_addr #4

; Function Attrs: nounwind
declare i64 @time(ptr noundef) local_unnamed_addr #4

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZSt4sortIPnEvT_S1_(ptr noundef, ptr noundef) local_unnamed_addr #5

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 nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { mustprogress norecurse 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 #4 = { nounwind "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 #5 = { 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 #6 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"__int128", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass