; LLVM IR from tangjz/acm-icpc :: loj/2563.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"

@_ZZ11pollard_rhoxE3seq = external hidden global [10000001 x i64], align 16

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

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

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

; 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 i32, align 4
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i64, align 8
  %11 = alloca i64, align 8
  %12 = alloca i32, align 4
  store i64 %0, ptr %3, align 8, !tbaa !5
  br label %13

13:                                               ; preds = %102, %1
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  store i32 0, ptr %4, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  %14 = call i32 @rand() #4
  %15 = sext i32 %14 to i64
  %16 = load i64, ptr %3, align 8, !tbaa !5
  %17 = srem i64 %15, %16
  store i64 %17, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  %18 = load i64, ptr %5, align 8, !tbaa !5
  store i64 %18, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %19 = call i32 @rand() #4
  %20 = sext i32 %19 to i64
  %21 = load i64, ptr %3, align 8, !tbaa !5
  %22 = srem i64 %20, %21
  store i64 %22, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  store ptr @_ZZ11pollard_rhoxE3seq, ptr %8, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  store ptr @_ZZ11pollard_rhoxE3seq, ptr %9, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  store i64 1, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  br label %23

23:                                               ; preds = %82, %13
  br label %24

24:                                               ; preds = %23
  %25 = load i64, ptr %6, align 8, !tbaa !5
  %26 = load i64, ptr %6, align 8, !tbaa !5
  %27 = load i64, ptr %3, align 8, !tbaa !5
  %28 = call noundef i64 @_Z7mod_mulxxx(i64 noundef %25, i64 noundef %26, i64 noundef %27)
  %29 = load i64, ptr %7, align 8, !tbaa !5
  %30 = load i64, ptr %3, align 8, !tbaa !5
  %31 = call noundef i64 @_Z7mod_addxxx(i64 noundef %28, i64 noundef %29, i64 noundef %30)
  store i64 %31, ptr %6, align 8, !tbaa !5
  %32 = load ptr, ptr %9, align 8, !tbaa !11
  %33 = getelementptr inbounds i64, ptr %32, i32 1
  store ptr %33, ptr %9, align 8, !tbaa !11
  store i64 %31, ptr %32, align 8, !tbaa !5
  %34 = load i64, ptr %6, align 8, !tbaa !5
  %35 = load i64, ptr %6, align 8, !tbaa !5
  %36 = load i64, ptr %3, align 8, !tbaa !5
  %37 = call noundef i64 @_Z7mod_mulxxx(i64 noundef %34, i64 noundef %35, i64 noundef %36)
  %38 = load i64, ptr %7, align 8, !tbaa !5
  %39 = load i64, ptr %3, align 8, !tbaa !5
  %40 = call noundef i64 @_Z7mod_addxxx(i64 noundef %37, i64 noundef %38, i64 noundef %39)
  store i64 %40, ptr %6, align 8, !tbaa !5
  %41 = load ptr, ptr %9, align 8, !tbaa !11
  %42 = getelementptr inbounds i64, ptr %41, i32 1
  store ptr %42, ptr %9, align 8, !tbaa !11
  store i64 %40, ptr %41, align 8, !tbaa !5
  %43 = load ptr, ptr %8, align 8, !tbaa !11
  %44 = getelementptr inbounds i64, ptr %43, i32 1
  store ptr %44, ptr %8, align 8, !tbaa !11
  %45 = load i64, ptr %43, align 8, !tbaa !5
  store i64 %45, ptr %5, align 8, !tbaa !5
  %46 = load i64, ptr %5, align 8, !tbaa !5
  %47 = load i64, ptr %6, align 8, !tbaa !5
  %48 = icmp eq i64 %46, %47
  br i1 %48, label %49, label %50

49:                                               ; preds = %24
  br label %83

50:                                               ; preds = %24
  %51 = load i64, ptr %10, align 8, !tbaa !5
  store i64 %51, ptr %11, align 8, !tbaa !5
  %52 = load i64, ptr %10, align 8, !tbaa !5
  %53 = load i64, ptr %6, align 8, !tbaa !5
  %54 = load i64, ptr %5, align 8, !tbaa !5
  %55 = sub nsw i64 %53, %54
  %56 = call noundef i64 @_ZSt3absx(i64 noundef %55)
  %57 = load i64, ptr %3, align 8, !tbaa !5
  %58 = call noundef i64 @_Z7mod_mulxxx(i64 noundef %52, i64 noundef %56, i64 noundef %57)
  store i64 %58, ptr %10, align 8, !tbaa !5
  %59 = load i64, ptr %10, align 8, !tbaa !5
  %60 = icmp ne i64 %59, 0
  br i1 %60, label %65, label %61

61:                                               ; preds = %50
  %62 = load i64, ptr %11, align 8, !tbaa !5
  %63 = load i64, ptr %3, align 8, !tbaa !5
  %64 = call noundef i64 @_Z3gcdxx(i64 noundef %62, i64 noundef %63)
  store i64 %64, ptr %2, align 8
  store i32 1, ptr %12, align 4
  br label %100

65:                                               ; preds = %50
  %66 = load i32, ptr %4, align 4, !tbaa !9
  %67 = add nsw i32 %66, 1
  store i32 %67, ptr %4, align 4, !tbaa !9
  %68 = icmp eq i32 %67, 61
  br i1 %68, label %69, label %82

69:                                               ; preds = %65
  %70 = load i64, ptr %10, align 8, !tbaa !5
  %71 = load i64, ptr %3, align 8, !tbaa !5
  %72 = call noundef i64 @_Z3gcdxx(i64 noundef %70, i64 noundef %71)
  store i64 %72, ptr %10, align 8, !tbaa !5
  %73 = load i64, ptr %10, align 8, !tbaa !5
  %74 = icmp sgt i64 %73, 1
  br i1 %74, label %75, label %81

75:                                               ; preds = %69
  %76 = load i64, ptr %10, align 8, !tbaa !5
  %77 = load i64, ptr %3, align 8, !tbaa !5
  %78 = icmp slt i64 %76, %77
  br i1 %78, label %79, label %81

79:                                               ; preds = %75
  %80 = load i64, ptr %10, align 8, !tbaa !5
  store i64 %80, ptr %2, align 8
  store i32 1, ptr %12, align 4
  br label %100

81:                                               ; preds = %75, %69
  store i32 0, ptr %4, align 4, !tbaa !9
  br label %82

82:                                               ; preds = %81, %65
  br label %23, !llvm.loop !13

83:                                               ; preds = %49
  %84 = load i32, ptr %4, align 4, !tbaa !9
  %85 = icmp ne i32 %84, 0
  br i1 %85, label %86, label %99

86:                                               ; preds = %83
  %87 = load i64, ptr %10, align 8, !tbaa !5
  %88 = load i64, ptr %3, align 8, !tbaa !5
  %89 = call noundef i64 @_Z3gcdxx(i64 noundef %87, i64 noundef %88)
  store i64 %89, ptr %10, align 8, !tbaa !5
  %90 = load i64, ptr %10, align 8, !tbaa !5
  %91 = icmp sgt i64 %90, 1
  br i1 %91, label %92, label %98

92:                                               ; preds = %86
  %93 = load i64, ptr %10, align 8, !tbaa !5
  %94 = load i64, ptr %3, align 8, !tbaa !5
  %95 = icmp slt i64 %93, %94
  br i1 %95, label %96, label %98

96:                                               ; preds = %92
  %97 = load i64, ptr %10, align 8, !tbaa !5
  store i64 %97, ptr %2, align 8
  store i32 1, ptr %12, align 4
  br label %100

98:                                               ; preds = %92, %86
  br label %99

99:                                               ; preds = %98, %83
  store i32 0, ptr %12, align 4
  br label %100

100:                                              ; preds = %99, %96, %79, %61
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  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 4, ptr %4) #4
  %101 = load i32, ptr %12, align 4
  switch i32 %101, label %105 [
    i32 0, label %102
    i32 1, label %103
  ]

102:                                              ; preds = %100
  br label %13, !llvm.loop !15

103:                                              ; preds = %100
  %104 = load i64, ptr %2, align 8
  ret i64 %104

105:                                              ; preds = %100
  unreachable
}

; Function Attrs: nounwind
declare i32 @rand() #3

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

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

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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" }
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 = { 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 #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 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"any pointer", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !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"

@_ZZ11pollard_rhoxE3seq = external hidden local_unnamed_addr global [10000001 x i64], align 16

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i64 @_Z11pollard_rhox(i64 noundef %0) local_unnamed_addr #1 {
  br label %2

2:                                                ; preds = %.backedge86, %1
  %3 = tail call i32 @rand() #3
  %4 = sext i32 %3 to i64
  %5 = srem i64 %4, %0
  %6 = tail call i32 @rand() #3
  %7 = sext i32 %6 to i64
  %8 = srem i64 %7, %0
  br label %9

9:                                                ; preds = %.backedge, %2
  %.048 = phi i64 [ %5, %2 ], [ %14, %.backedge ]
  %.046 = phi i32 [ 0, %2 ], [ %.046.be, %.backedge ]
  %.045 = phi ptr [ @_ZZ11pollard_rhoxE3seq, %2 ], [ %16, %.backedge ]
  %.044 = phi ptr [ @_ZZ11pollard_rhoxE3seq, %2 ], [ %15, %.backedge ]
  %.042 = phi i64 [ 1, %2 ], [ %.042.be, %.backedge ]
  %10 = tail call noundef i64 @_Z7mod_mulxxx(i64 noundef %.048, i64 noundef %.048, i64 noundef %0)
  %11 = tail call noundef i64 @_Z7mod_addxxx(i64 noundef %10, i64 noundef %8, i64 noundef %0)
  %12 = getelementptr inbounds i8, ptr %.044, i64 8
  store i64 %11, ptr %.044, align 8, !tbaa !5
  %13 = tail call noundef i64 @_Z7mod_mulxxx(i64 noundef %11, i64 noundef %11, i64 noundef %0)
  %14 = tail call noundef i64 @_Z7mod_addxxx(i64 noundef %13, i64 noundef %8, i64 noundef %0)
  %15 = getelementptr inbounds i8, ptr %.044, i64 16
  store i64 %14, ptr %12, align 8, !tbaa !5
  %16 = getelementptr inbounds i8, ptr %.045, i64 8
  %17 = load i64, ptr %.045, align 8, !tbaa !5
  %18 = icmp eq i64 %17, %14
  br i1 %18, label %32, label %19

19:                                               ; preds = %9
  %20 = sub nsw i64 %14, %17
  %21 = tail call noundef i64 @_ZSt3absx(i64 noundef %20)
  %22 = tail call noundef i64 @_Z7mod_mulxxx(i64 noundef %.042, i64 noundef %21, i64 noundef %0)
  %.not = icmp eq i64 %22, 0
  br i1 %.not, label %23, label %25

23:                                               ; preds = %19
  %24 = tail call noundef i64 @_Z3gcdxx(i64 noundef %.042, i64 noundef %0)
  br label %.loopexit

25:                                               ; preds = %19
  %26 = add nsw i32 %.046, 1
  %27 = icmp eq i32 %26, 61
  br i1 %27, label %28, label %.backedge

28:                                               ; preds = %25
  %29 = tail call noundef i64 @_Z3gcdxx(i64 noundef %22, i64 noundef %0)
  %30 = icmp sgt i64 %29, 1
  %31 = icmp slt i64 %29, %0
  %or.cond = and i1 %30, %31
  br i1 %or.cond, label %.loopexit, label %.backedge

.backedge:                                        ; preds = %28, %25
  %.046.be = phi i32 [ 0, %28 ], [ %26, %25 ]
  %.042.be = phi i64 [ %29, %28 ], [ %22, %25 ]
  br label %9, !llvm.loop !9

32:                                               ; preds = %9
  %.not55 = icmp eq i32 %.046, 0
  br i1 %.not55, label %.backedge86, label %33

.backedge86:                                      ; preds = %32, %33
  br label %2

33:                                               ; preds = %32
  %34 = tail call noundef i64 @_Z3gcdxx(i64 noundef %.042, i64 noundef %0)
  %35 = icmp sgt i64 %34, 1
  %36 = icmp slt i64 %34, %0
  %or.cond56 = and i1 %35, %36
  br i1 %or.cond56, label %.loopexit, label %.backedge86

.loopexit:                                        ; preds = %33, %28, %23
  %.1.ph = phi i64 [ %24, %23 ], [ %29, %28 ], [ %34, %33 ]
  ret i64 %.1.ph
}

; Function Attrs: nounwind
declare i32 @rand() local_unnamed_addr #2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i64 @_Z7mod_addxxx(i64 noundef, 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 #0

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

attributes #0 = { 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 #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 = { 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 #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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass