; LLVM IR from tangjz/acm-icpc :: 51nod/1404.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"

@.str.1 = external hidden unnamed_addr constant [64 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [18 x i8], align 1
@__PRETTY_FUNCTION__._Z1Fx = external hidden unnamed_addr constant [9 x i8], align 1
@_ZL4fact = external hidden constant [4781 x i64], align 16

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

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #1

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

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

; Function Attrs: mustprogress uwtable
define dso_local noundef i64 @_Z1Fx(i64 noundef %0) #0 {
  %2 = alloca i64, align 8
  %3 = alloca i64, align 8
  %4 = alloca i64, align 8
  store i64 %0, ptr %2, align 8, !tbaa !5
  %5 = load i64, ptr %2, align 8, !tbaa !5
  %6 = icmp sle i64 0, %5
  br i1 %6, label %7, label %10

7:                                                ; preds = %1
  %8 = load i64, ptr %2, align 8, !tbaa !5
  %9 = icmp slt i64 %8, 9560518619
  br label %10

10:                                               ; preds = %7, %1
  %11 = phi i1 [ false, %1 ], [ %9, %7 ]
  br i1 %11, label %12, label %13

12:                                               ; preds = %10
  br label %15

13:                                               ; preds = %10
  call void @__assert_fail(ptr noundef @.str.3, ptr noundef @.str.1, i32 noundef 36, ptr noundef @__PRETTY_FUNCTION__._Z1Fx) #3
  unreachable

14:                                               ; No predecessors!
  br label %15

15:                                               ; preds = %14, %12
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #4
  %16 = load i64, ptr %2, align 8, !tbaa !5
  %17 = sdiv i64 %16, 2000000
  %18 = getelementptr inbounds [4781 x i64], ptr @_ZL4fact, i64 0, i64 %17
  %19 = load i64, ptr %18, align 8, !tbaa !5
  store i64 %19, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  %20 = load i64, ptr %2, align 8, !tbaa !5
  %21 = sdiv i64 %20, 2000000
  %22 = mul nsw i64 %21, 2000000
  %23 = add nsw i64 %22, 1
  store i64 %23, ptr %4, align 8, !tbaa !5
  br label %24

24:                                               ; preds = %33, %15
  %25 = load i64, ptr %4, align 8, !tbaa !5
  %26 = load i64, ptr %2, align 8, !tbaa !5
  %27 = icmp sle i64 %25, %26
  br i1 %27, label %29, label %28

28:                                               ; preds = %24
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  br label %36

29:                                               ; preds = %24
  %30 = load i64, ptr %3, align 8, !tbaa !5
  %31 = load i64, ptr %4, align 8, !tbaa !5
  %32 = call noundef i64 @_Z7mod_mulxx(i64 noundef %30, i64 noundef %31)
  store i64 %32, ptr %3, align 8, !tbaa !5
  br label %33

33:                                               ; preds = %29
  %34 = load i64, ptr %4, align 8, !tbaa !5
  %35 = add nsw i64 %34, 1
  store i64 %35, ptr %4, align 8, !tbaa !5
  br label %24, !llvm.loop !9

36:                                               ; preds = %28
  %37 = load i64, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  ret i64 %37
}

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 = { noreturn 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 #2 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { noreturn nounwind }
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 = distinct !{!9, !10}
!10 = !{!"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.1 = external hidden unnamed_addr constant [64 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [18 x i8], align 1
@__PRETTY_FUNCTION__._Z1Fx = external hidden unnamed_addr constant [9 x i8], align 1
@_ZL4fact = external hidden local_unnamed_addr constant [4781 x i64], align 16

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

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
define dso_local noundef i64 @_Z1Fx(i64 noundef %0) local_unnamed_addr #0 {
  %2 = icmp ult i64 %0, 9560518619
  br i1 %2, label %4, label %3

3:                                                ; preds = %1
  tail call void @__assert_fail(ptr noundef nonnull @.str.3, ptr noundef nonnull @.str.1, i32 noundef 36, ptr noundef nonnull @__PRETTY_FUNCTION__._Z1Fx) #2
  unreachable

4:                                                ; preds = %1
  %5 = udiv i64 %0, 2000000
  %6 = getelementptr inbounds [4781 x i64], ptr @_ZL4fact, i64 0, i64 %5
  %7 = load i64, ptr %6, align 8, !tbaa !5
  %8 = mul nuw nsw i64 %5, 2000000
  %.not12.not = icmp ult i64 %8, %0
  br i1 %.not12.not, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %4
  %9 = or disjoint i64 %8, 1
  br label %.lr.ph

._crit_edge:                                      ; preds = %.lr.ph, %4
  %.010.lcssa = phi i64 [ %7, %4 ], [ %10, %.lr.ph ]
  ret i64 %.010.lcssa

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %.014 = phi i64 [ %11, %.lr.ph ], [ %9, %.lr.ph.preheader ]
  %.01013 = phi i64 [ %10, %.lr.ph ], [ %7, %.lr.ph.preheader ]
  %10 = tail call noundef i64 @_Z7mod_mulxx(i64 noundef %.01013, i64 noundef %.014)
  %11 = add i64 %.014, 1
  %exitcond.not = icmp eq i64 %.014, %0
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !9
}

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 = { noreturn 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 #2 = { noreturn 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,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass