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

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

@Gcd = external dso_local global [21 x [21 x i32]], align 16
@xUpp = external dso_local global i32, align 4
@yLow = external dso_local global i64, align 8
@yUpp = external dso_local global i64, align 8

; Function Attrs: mustprogress uwtable
define dso_local noundef i64 @_Z3dfsix(i32 noundef %0, i64 noundef %1) #0 {
  %3 = alloca i64, align 8
  %4 = alloca i32, align 4
  %5 = alloca i64, align 8
  %6 = alloca i32, align 4
  store i32 %0, ptr %4, align 4, !tbaa !5
  store i64 %1, ptr %5, align 8, !tbaa !9
  %7 = load i64, ptr %5, align 8, !tbaa !9
  %8 = load i64, ptr @yUpp, align 8, !tbaa !9
  %9 = icmp sgt i64 %7, %8
  br i1 %9, label %10, label %11

10:                                               ; preds = %2
  store i64 0, ptr %3, align 8
  br label %56

11:                                               ; preds = %2
  %12 = load i32, ptr %4, align 4, !tbaa !5
  %13 = load i32, ptr @xUpp, align 4, !tbaa !5
  %14 = icmp eq i32 %12, %13
  br i1 %14, label %15, label %24

15:                                               ; preds = %11
  %16 = load i64, ptr @yUpp, align 8, !tbaa !9
  %17 = load i64, ptr %5, align 8, !tbaa !9
  %18 = sdiv i64 %16, %17
  %19 = load i64, ptr @yLow, align 8, !tbaa !9
  %20 = sub nsw i64 %19, 1
  %21 = load i64, ptr %5, align 8, !tbaa !9
  %22 = sdiv i64 %20, %21
  %23 = sub nsw i64 %18, %22
  store i64 %23, ptr %3, align 8
  br label %56

24:                                               ; preds = %11
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  %25 = load i64, ptr %5, align 8, !tbaa !9
  %26 = load i32, ptr %4, align 4, !tbaa !5
  %27 = sext i32 %26 to i64
  %28 = srem i64 %25, %27
  %29 = trunc i64 %28 to i32
  store i32 %29, ptr %6, align 4, !tbaa !5
  %30 = load i32, ptr %6, align 4, !tbaa !5
  %31 = icmp ne i32 %30, 0
  br i1 %31, label %32, label %53

32:                                               ; preds = %24
  %33 = load i32, ptr %4, align 4, !tbaa !5
  %34 = add nsw i32 %33, 1
  %35 = load i64, ptr %5, align 8, !tbaa !9
  %36 = call noundef i64 @_Z3dfsix(i32 noundef %34, i64 noundef %35)
  %37 = load i32, ptr %4, align 4, !tbaa !5
  %38 = add nsw i32 %37, 1
  %39 = load i64, ptr %5, align 8, !tbaa !9
  %40 = load i32, ptr %4, align 4, !tbaa !5
  %41 = load i32, ptr %6, align 4, !tbaa !5
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds [21 x [21 x i32]], ptr @Gcd, i64 0, i64 %42
  %44 = load i32, ptr %4, align 4, !tbaa !5
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds [21 x i32], ptr %43, i64 0, i64 %45
  %47 = load i32, ptr %46, align 4, !tbaa !5
  %48 = sdiv i32 %40, %47
  %49 = sext i32 %48 to i64
  %50 = mul nsw i64 %39, %49
  %51 = call noundef i64 @_Z3dfsix(i32 noundef %38, i64 noundef %50)
  %52 = sub nsw i64 %36, %51
  br label %54

53:                                               ; preds = %24
  br label %54

54:                                               ; preds = %53, %32
  %55 = phi i64 [ %52, %32 ], [ 0, %53 ]
  store i64 %55, ptr %3, align 8
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  br label %56

56:                                               ; preds = %54, %15, %10
  %57 = load i64, ptr %3, align 8
  ret i64 %57
}

; 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

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 }

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

@Gcd = external dso_local local_unnamed_addr global [21 x [21 x i32]], align 16
@xUpp = external dso_local local_unnamed_addr global i32, align 4
@yLow = external dso_local local_unnamed_addr global i64, align 8
@yUpp = external dso_local local_unnamed_addr global i64, align 8

; Function Attrs: mustprogress nofree nosync nounwind willreturn memory(read, argmem: none, inaccessiblemem: none) uwtable
define dso_local noundef i64 @_Z3dfsix(i32 noundef %0, i64 noundef %1) local_unnamed_addr #0 {
  %3 = load i64, ptr @yUpp, align 8, !tbaa !5
  %4 = icmp slt i64 %3, %1
  br i1 %4, label %common.ret19, label %5

5:                                                ; preds = %2
  %6 = load i32, ptr @xUpp, align 4, !tbaa !9
  %7 = icmp eq i32 %6, %0
  br i1 %7, label %8, label %14

8:                                                ; preds = %5
  %9 = sdiv i64 %3, %1
  %10 = load i64, ptr @yLow, align 8, !tbaa !5
  %11 = add nsw i64 %10, -1
  %12 = sdiv i64 %11, %1
  %13 = sub nsw i64 %9, %12
  br label %common.ret19

14:                                               ; preds = %5
  %15 = sext i32 %0 to i64
  %16 = srem i64 %1, %15
  %.not = icmp eq i64 %16, 0
  br i1 %.not, label %common.ret19, label %17

common.ret19:                                     ; preds = %14, %2, %8, %17
  %common.ret19.op = phi i64 [ %26, %17 ], [ %13, %8 ], [ 0, %2 ], [ 0, %14 ]
  ret i64 %common.ret19.op

17:                                               ; preds = %14
  %18 = add nsw i32 %0, 1
  %19 = tail call noundef i64 @_Z3dfsix(i32 noundef %18, i64 noundef %1)
  %20 = getelementptr inbounds [21 x [21 x i32]], ptr @Gcd, i64 0, i64 %16, i64 %15
  %21 = load i32, ptr %20, align 4, !tbaa !9
  %22 = sdiv i32 %0, %21
  %23 = sext i32 %22 to i64
  %24 = mul nsw i64 %23, %1
  %25 = tail call noundef i64 @_Z3dfsix(i32 noundef %18, i64 noundef %24)
  %26 = sub nsw i64 %19, %25
  br label %common.ret19
}

attributes #0 = { mustprogress nofree nosync nounwind willreturn memory(read, argmem: none, inaccessiblemem: none) 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 = !{!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}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass