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

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

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

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_Z6rand60v() #1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef { i64, i64 } @_Z7mod_mulnnn(i64 noundef, i64 noundef, i64 noundef, i64 noundef, i64 noundef, i64 noundef) #1

; Function Attrs: mustprogress uwtable
define dso_local noundef i64 @_Z11pollard_rhox(i64 noundef %0) #2 {
  %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
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  %9 = alloca i128, align 16
  %10 = alloca i128, align 16
  %11 = alloca i128, align 16
  %12 = alloca i128, align 16
  store i64 %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #4
  %13 = call noundef i64 @_Z6rand60v()
  %14 = load i64, ptr %2, align 8, !tbaa !5
  %15 = srem i64 %13, %14
  store i64 %15, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  %16 = load i64, ptr %3, align 8, !tbaa !5
  store i64 %16, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  %17 = call noundef i64 @_Z6rand60v()
  %18 = load i64, ptr %2, align 8, !tbaa !5
  %19 = srem i64 %17, %18
  store i64 %19, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  store i64 1, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  store i64 2, ptr %8, align 8, !tbaa !5
  br label %20

20:                                               ; preds = %76, %1
  %21 = load i64, ptr %7, align 8, !tbaa !5
  %22 = load i64, ptr %8, align 8, !tbaa !5
  %23 = icmp eq i64 %21, %22
  br i1 %23, label %24, label %28

24:                                               ; preds = %20
  %25 = load i64, ptr %3, align 8, !tbaa !5
  store i64 %25, ptr %4, align 8, !tbaa !5
  %26 = load i64, ptr %8, align 8, !tbaa !5
  %27 = shl i64 %26, 1
  store i64 %27, ptr %8, align 8, !tbaa !5
  br label %28

28:                                               ; preds = %24, %20
  %29 = load i64, ptr %3, align 8, !tbaa !5
  %30 = sext i64 %29 to i128
  %31 = load i64, ptr %3, align 8, !tbaa !5
  %32 = sext i64 %31 to i128
  %33 = load i64, ptr %2, align 8, !tbaa !5
  %34 = sext i64 %33 to i128
  store i128 %30, ptr %9, align 16, !tbaa !9
  %35 = getelementptr inbounds { i64, i64 }, ptr %9, i32 0, i32 0
  %36 = load i64, ptr %35, align 16
  %37 = getelementptr inbounds { i64, i64 }, ptr %9, i32 0, i32 1
  %38 = load i64, ptr %37, align 8
  store i128 %32, ptr %10, align 16, !tbaa !9
  %39 = getelementptr inbounds { i64, i64 }, ptr %10, i32 0, i32 0
  %40 = load i64, ptr %39, align 16
  %41 = getelementptr inbounds { i64, i64 }, ptr %10, i32 0, i32 1
  %42 = load i64, ptr %41, align 8
  store i128 %34, ptr %11, align 16, !tbaa !9
  %43 = getelementptr inbounds { i64, i64 }, ptr %11, i32 0, i32 0
  %44 = load i64, ptr %43, align 16
  %45 = getelementptr inbounds { i64, i64 }, ptr %11, i32 0, i32 1
  %46 = load i64, ptr %45, align 8
  %47 = call noundef { i64, i64 } @_Z7mod_mulnnn(i64 noundef %36, i64 noundef %38, i64 noundef %40, i64 noundef %42, i64 noundef %44, i64 noundef %46)
  %48 = getelementptr inbounds { i64, i64 }, ptr %12, i32 0, i32 0
  %49 = extractvalue { i64, i64 } %47, 0
  store i64 %49, ptr %48, align 16
  %50 = getelementptr inbounds { i64, i64 }, ptr %12, i32 0, i32 1
  %51 = extractvalue { i64, i64 } %47, 1
  store i64 %51, ptr %50, align 8
  %52 = load i128, ptr %12, align 16, !tbaa !9
  %53 = load i64, ptr %5, align 8, !tbaa !5
  %54 = sext i64 %53 to i128
  %55 = add nsw i128 %52, %54
  %56 = trunc i128 %55 to i64
  store i64 %56, ptr %3, align 8, !tbaa !5
  %57 = load i64, ptr %2, align 8, !tbaa !5
  %58 = icmp sge i64 %56, %57
  br i1 %58, label %59, label %64

59:                                               ; preds = %28
  %60 = load i64, ptr %2, align 8, !tbaa !5
  %61 = load i64, ptr %3, align 8, !tbaa !5
  %62 = sub nsw i64 %61, %60
  store i64 %62, ptr %3, align 8, !tbaa !5
  %63 = icmp ne i64 %62, 0
  br label %64

64:                                               ; preds = %59, %28
  %65 = phi i1 [ false, %28 ], [ %63, %59 ]
  %66 = load i64, ptr %3, align 8, !tbaa !5
  %67 = load i64, ptr %4, align 8, !tbaa !5
  %68 = sub nsw i64 %66, %67
  %69 = call noundef i64 @_ZSt3absx(i64 noundef %68)
  %70 = load i64, ptr %2, align 8, !tbaa !5
  %71 = call noundef i64 @_ZSt5__gcdIxET_S0_S0_(i64 noundef %69, i64 noundef %70)
  store i64 %71, ptr %6, align 8, !tbaa !5
  %72 = icmp sgt i64 %71, 1
  br i1 %72, label %73, label %75

73:                                               ; preds = %64
  %74 = load i64, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  ret i64 %74

75:                                               ; preds = %64
  br label %76

76:                                               ; preds = %75
  %77 = load i64, ptr %7, align 8, !tbaa !5
  %78 = add nsw i64 %77, 1
  store i64 %78, ptr %7, align 8, !tbaa !5
  br label %20, !llvm.loop !11
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZSt5__gcdIxET_S0_S0_(i64 noundef, i64 noundef) #1

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZSt3absx(i64 noundef) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { 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 = { inlinehint 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 #4 = { 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 = !{!"__int128", !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"

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_Z6rand60v() local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef { i64, i64 } @_Z7mod_mulnnn(i64 noundef, i64 noundef, i64 noundef, i64 noundef, i64 noundef, i64 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef range(i64 2, -9223372036854775808) i64 @_Z11pollard_rhox(i64 noundef %0) local_unnamed_addr #0 {
  %2 = tail call noundef i64 @_Z6rand60v()
  %3 = srem i64 %2, %0
  %4 = tail call noundef i64 @_Z6rand60v()
  %5 = srem i64 %4, %0
  %6 = ashr i64 %0, 63
  br label %7

7:                                                ; preds = %19, %1
  %.028 = phi i64 [ 2, %1 ], [ %spec.select, %19 ]
  %.027 = phi i64 [ 1, %1 ], [ %21, %19 ]
  %.025 = phi i64 [ %3, %1 ], [ %spec.select34, %19 ]
  %.0 = phi i64 [ %3, %1 ], [ %.1, %19 ]
  %8 = icmp eq i64 %.027, %.028
  %spec.select34 = select i1 %8, i64 %.0, i64 %.025
  %9 = ashr i64 %.0, 63
  %10 = tail call noundef { i64, i64 } @_Z7mod_mulnnn(i64 noundef %.0, i64 noundef %9, i64 noundef %.0, i64 noundef %9, i64 noundef %0, i64 noundef %6)
  %11 = extractvalue { i64, i64 } %10, 0
  %12 = add i64 %11, %5
  %.not = icmp slt i64 %12, %0
  %13 = select i1 %.not, i64 0, i64 %0
  %.1 = sub nsw i64 %12, %13
  %14 = sub nsw i64 %.1, %spec.select34
  %15 = tail call noundef i64 @_ZSt3absx(i64 noundef %14)
  %16 = tail call noundef i64 @_ZSt5__gcdIxET_S0_S0_(i64 noundef %15, i64 noundef %0)
  %17 = icmp sgt i64 %16, 1
  br i1 %17, label %18, label %19

18:                                               ; preds = %7
  ret i64 %16

19:                                               ; preds = %7
  %20 = zext i1 %8 to i64
  %spec.select = shl i64 %.028, %20
  %21 = add nuw nsw i64 %.027, 1
  br label %7, !llvm.loop !5
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZSt5__gcdIxET_S0_S0_(i64 noundef, i64 noundef) local_unnamed_addr #0

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZSt3absx(i64 noundef) local_unnamed_addr #1

attributes #0 = { 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 #1 = { inlinehint 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" }

!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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LICMPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass