; LLVM IR from tangjz/acm-icpc :: self_training/2015-02-01/E.ll (Z3dfsii)

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

@k = external dso_local global i32, align 4
@a = external dso_local global [12 x i64], align 16
@now = external dso_local global i64, align 8
@M = external dso_local global i64, align 8
@ret = external dso_local global i64, align 8

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

; Function Attrs: mustprogress uwtable
define dso_local void @_Z3dfsii(i32 noundef %0, i32 noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i64, align 8
  store i32 %0, ptr %3, align 4, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !5
  %6 = load i32, ptr %3, align 4, !tbaa !5
  %7 = load i32, ptr @k, align 4, !tbaa !5
  %8 = icmp eq i32 %6, %7
  br i1 %8, label %9, label %32

9:                                                ; preds = %2
  %10 = load i32, ptr %4, align 4, !tbaa !5
  %11 = and i32 %10, 1
  %12 = icmp ne i32 %11, 0
  br i1 %12, label %13, label %22

13:                                               ; preds = %9
  %14 = load i64, ptr @M, align 8, !tbaa !9
  %15 = load i64, ptr @now, align 8, !tbaa !9
  %16 = sdiv i64 %14, %15
  %17 = load i32, ptr %4, align 4, !tbaa !5
  %18 = sext i32 %17 to i64
  %19 = mul nsw i64 %16, %18
  %20 = load i64, ptr @ret, align 8, !tbaa !9
  %21 = add nsw i64 %20, %19
  store i64 %21, ptr @ret, align 8, !tbaa !9
  br label %31

22:                                               ; preds = %9
  %23 = load i64, ptr @M, align 8, !tbaa !9
  %24 = load i64, ptr @now, align 8, !tbaa !9
  %25 = sdiv i64 %23, %24
  %26 = load i32, ptr %4, align 4, !tbaa !5
  %27 = sext i32 %26 to i64
  %28 = mul nsw i64 %25, %27
  %29 = load i64, ptr @ret, align 8, !tbaa !9
  %30 = sub nsw i64 %29, %28
  store i64 %30, ptr @ret, align 8, !tbaa !9
  br label %31

31:                                               ; preds = %22, %13
  br label %77

32:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  %33 = load i64, ptr @now, align 8, !tbaa !9
  %34 = load i32, ptr %3, align 4, !tbaa !5
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds [12 x i64], ptr @a, i64 0, i64 %35
  %37 = load i64, ptr %36, align 8, !tbaa !9
  %38 = call noundef i64 @_Z3gcdxx(i64 noundef %33, i64 noundef %37)
  store i64 %38, ptr %5, align 8, !tbaa !9
  %39 = load i64, ptr @now, align 8, !tbaa !9
  %40 = load i64, ptr %5, align 8, !tbaa !9
  %41 = sdiv i64 %39, %40
  %42 = sitofp i64 %41 to double
  %43 = call double @log10(double noundef %42) #3
  %44 = load i32, ptr %3, align 4, !tbaa !5
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds [12 x i64], ptr @a, i64 0, i64 %45
  %47 = load i64, ptr %46, align 8, !tbaa !9
  %48 = sitofp i64 %47 to double
  %49 = call double @log10(double noundef %48) #3
  %50 = fadd double %43, %49
  %51 = fcmp ole double %50, 1.500000e+01
  br i1 %51, label %52, label %73

52:                                               ; preds = %32
  %53 = load i32, ptr %3, align 4, !tbaa !5
  %54 = sext i32 %53 to i64
  %55 = getelementptr inbounds [12 x i64], ptr @a, i64 0, i64 %54
  %56 = load i64, ptr %55, align 8, !tbaa !9
  %57 = load i64, ptr %5, align 8, !tbaa !9
  %58 = sdiv i64 %56, %57
  %59 = load i64, ptr @now, align 8, !tbaa !9
  %60 = mul nsw i64 %59, %58
  store i64 %60, ptr @now, align 8, !tbaa !9
  %61 = load i32, ptr %3, align 4, !tbaa !5
  %62 = add nsw i32 %61, 1
  %63 = load i32, ptr %4, align 4, !tbaa !5
  %64 = add nsw i32 %63, 1
  call void @_Z3dfsii(i32 noundef %62, i32 noundef %64)
  %65 = load i32, ptr %3, align 4, !tbaa !5
  %66 = sext i32 %65 to i64
  %67 = getelementptr inbounds [12 x i64], ptr @a, i64 0, i64 %66
  %68 = load i64, ptr %67, align 8, !tbaa !9
  %69 = load i64, ptr %5, align 8, !tbaa !9
  %70 = sdiv i64 %68, %69
  %71 = load i64, ptr @now, align 8, !tbaa !9
  %72 = sdiv i64 %71, %70
  store i64 %72, ptr @now, align 8, !tbaa !9
  br label %73

73:                                               ; preds = %52, %32
  %74 = load i32, ptr %3, align 4, !tbaa !5
  %75 = add nsw i32 %74, 1
  %76 = load i32, ptr %4, align 4, !tbaa !5
  call void @_Z3dfsii(i32 noundef %75, i32 noundef %76)
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  br label %77

77:                                               ; preds = %73, %31
  ret void
}

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

; Function Attrs: nounwind
declare double @log10(double noundef) #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 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long long", !7, i64 0}


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

@k = external dso_local local_unnamed_addr global i32, align 4
@a = external dso_local local_unnamed_addr global [12 x i64], align 16
@now = external dso_local local_unnamed_addr global i64, align 8
@M = external dso_local local_unnamed_addr global i64, align 8
@ret = external dso_local local_unnamed_addr global i64, align 8

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

; Function Attrs: mustprogress uwtable
define dso_local void @_Z3dfsii(i32 noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = load i32, ptr @k, align 4, !tbaa !5
  %4 = icmp eq i32 %3, %0
  br i1 %4, label %tailrecurse._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %2
  %5 = add nsw i32 %1, 1
  %6 = sext i32 %0 to i64
  br label %15

tailrecurse._crit_edge:                           ; preds = %tailrecurse, %2
  %7 = and i32 %1, 1
  %.not = icmp eq i32 %7, 0
  %8 = load i64, ptr @M, align 8, !tbaa !9
  %9 = load i64, ptr @now, align 8, !tbaa !9
  %10 = sdiv i64 %8, %9
  %11 = sext i32 %1 to i64
  %12 = mul nsw i64 %10, %11
  %13 = load i64, ptr @ret, align 8, !tbaa !9
  %14 = sub i64 0, %12
  %storemerge.p = select i1 %.not, i64 %14, i64 %12
  %storemerge = add i64 %13, %storemerge.p
  store i64 %storemerge, ptr @ret, align 8, !tbaa !9
  ret void

15:                                               ; preds = %.lr.ph, %tailrecurse
  %indvars.iv = phi i64 [ %6, %.lr.ph ], [ %indvars.iv.next.pre-phi, %tailrecurse ]
  %16 = load i64, ptr @now, align 8, !tbaa !9
  %17 = getelementptr inbounds [12 x i64], ptr @a, i64 0, i64 %indvars.iv
  %18 = load i64, ptr %17, align 8, !tbaa !9
  %19 = tail call noundef i64 @_Z3gcdxx(i64 noundef %16, i64 noundef %18)
  %20 = load i64, ptr @now, align 8, !tbaa !9
  %21 = sdiv i64 %20, %19
  %22 = sitofp i64 %21 to double
  %23 = tail call double @log10(double noundef %22) #2
  %24 = load i64, ptr %17, align 8, !tbaa !9
  %25 = sitofp i64 %24 to double
  %26 = tail call double @log10(double noundef %25) #2
  %27 = fadd double %23, %26
  %28 = fcmp ugt double %27, 1.500000e+01
  br i1 %28, label %.tailrecurse_crit_edge, label %29

.tailrecurse_crit_edge:                           ; preds = %15
  %.pre = add nsw i64 %indvars.iv, 1
  %.pre18 = trunc nsw i64 %.pre to i32
  br label %tailrecurse

29:                                               ; preds = %15
  %30 = load i64, ptr %17, align 8, !tbaa !9
  %31 = sdiv i64 %30, %19
  %32 = load i64, ptr @now, align 8, !tbaa !9
  %33 = mul nsw i64 %32, %31
  store i64 %33, ptr @now, align 8, !tbaa !9
  %34 = add nsw i64 %indvars.iv, 1
  %35 = trunc nsw i64 %34 to i32
  tail call void @_Z3dfsii(i32 noundef %35, i32 noundef %5)
  %36 = load i64, ptr %17, align 8, !tbaa !9
  %37 = sdiv i64 %36, %19
  %38 = load i64, ptr @now, align 8, !tbaa !9
  %39 = sdiv i64 %38, %37
  store i64 %39, ptr @now, align 8, !tbaa !9
  br label %tailrecurse

tailrecurse:                                      ; preds = %.tailrecurse_crit_edge, %29
  %.pre-phi = phi i32 [ %.pre18, %.tailrecurse_crit_edge ], [ %35, %29 ]
  %indvars.iv.next.pre-phi = phi i64 [ %.pre, %.tailrecurse_crit_edge ], [ %34, %29 ]
  %40 = load i32, ptr @k, align 4, !tbaa !5
  %41 = icmp eq i32 %40, %.pre-phi
  br i1 %41, label %tailrecurse._crit_edge, label %15
}

; Function Attrs: mustprogress nofree nounwind willreturn memory(write)
declare double @log10(double noundef) 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 = { mustprogress nofree nounwind willreturn memory(write) "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 }

!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 = !{!"long long", !7, i64 0}


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