; LLVM IR from VastoLorde95/Competitive-Programming :: Codeforces/275 Division 2/Problem B/B.ll (Z5checkx)

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

@cnt1 = external dso_local global i64, align 8
@cnt2 = external dso_local global i64, align 8
@x = external dso_local global i64, align 8
@y = external dso_local global i64, align 8

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_Z5checkx(i64 noundef %0) #0 {
  %2 = alloca i1, align 1
  %3 = alloca i64, align 8
  %4 = alloca i64, align 8
  %5 = alloca i32, align 4
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  store i64 %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  %8 = load i64, ptr %3, align 8, !tbaa !5
  %9 = load i64, ptr %3, align 8, !tbaa !5
  %10 = load i64, ptr @x, align 8, !tbaa !5
  %11 = load i64, ptr @y, align 8, !tbaa !5
  %12 = mul nsw i64 %10, %11
  %13 = sdiv i64 %9, %12
  %14 = add nsw i64 %8, %13
  %15 = load i64, ptr %3, align 8, !tbaa !5
  %16 = load i64, ptr @x, align 8, !tbaa !5
  %17 = sdiv i64 %15, %16
  %18 = sub nsw i64 %14, %17
  %19 = load i64, ptr %3, align 8, !tbaa !5
  %20 = load i64, ptr @y, align 8, !tbaa !5
  %21 = sdiv i64 %19, %20
  %22 = sub nsw i64 %18, %21
  store i64 %22, ptr %4, align 8, !tbaa !5
  %23 = load i64, ptr %3, align 8, !tbaa !5
  %24 = load i64, ptr %3, align 8, !tbaa !5
  %25 = load i64, ptr @x, align 8, !tbaa !5
  %26 = load i64, ptr @y, align 8, !tbaa !5
  %27 = mul nsw i64 %25, %26
  %28 = sdiv i64 %24, %27
  %29 = sub nsw i64 %23, %28
  %30 = load i64, ptr @cnt1, align 8, !tbaa !5
  %31 = load i64, ptr @cnt2, align 8, !tbaa !5
  %32 = add nsw i64 %30, %31
  %33 = icmp slt i64 %29, %32
  br i1 %33, label %34, label %35

34:                                               ; preds = %1
  store i1 false, ptr %2, align 1
  store i32 1, ptr %5, align 4
  br label %81

35:                                               ; preds = %1
  %36 = load i64, ptr %4, align 8, !tbaa !5
  %37 = load i64, ptr %3, align 8, !tbaa !5
  %38 = load i64, ptr @y, align 8, !tbaa !5
  %39 = sdiv i64 %37, %38
  %40 = add nsw i64 %36, %39
  %41 = load i64, ptr %3, align 8, !tbaa !5
  %42 = load i64, ptr @x, align 8, !tbaa !5
  %43 = load i64, ptr @y, align 8, !tbaa !5
  %44 = mul nsw i64 %42, %43
  %45 = sdiv i64 %41, %44
  %46 = sub nsw i64 %40, %45
  %47 = load i64, ptr @cnt1, align 8, !tbaa !5
  %48 = icmp slt i64 %46, %47
  br i1 %48, label %49, label %50

49:                                               ; preds = %35
  store i1 false, ptr %2, align 1
  store i32 1, ptr %5, align 4
  br label %81

50:                                               ; preds = %35
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %51 = load i64, ptr @cnt1, align 8, !tbaa !5
  %52 = load i64, ptr %3, align 8, !tbaa !5
  %53 = load i64, ptr @y, align 8, !tbaa !5
  %54 = sdiv i64 %52, %53
  %55 = sub nsw i64 %51, %54
  %56 = load i64, ptr %3, align 8, !tbaa !5
  %57 = load i64, ptr @x, align 8, !tbaa !5
  %58 = load i64, ptr @y, align 8, !tbaa !5
  %59 = mul nsw i64 %57, %58
  %60 = sdiv i64 %56, %59
  %61 = add nsw i64 %55, %60
  store i64 %61, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  store i64 0, ptr %7, align 8, !tbaa !5
  %62 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3maxIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) %6, ptr noundef nonnull align 8 dereferenceable(8) %7)
  %63 = load i64, ptr %62, align 8, !tbaa !5
  %64 = load i64, ptr %4, align 8, !tbaa !5
  %65 = sub nsw i64 %64, %63
  store i64 %65, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  %66 = load i64, ptr %4, align 8, !tbaa !5
  %67 = load i64, ptr %3, align 8, !tbaa !5
  %68 = load i64, ptr @x, align 8, !tbaa !5
  %69 = sdiv i64 %67, %68
  %70 = add nsw i64 %66, %69
  %71 = load i64, ptr %3, align 8, !tbaa !5
  %72 = load i64, ptr @x, align 8, !tbaa !5
  %73 = load i64, ptr @y, align 8, !tbaa !5
  %74 = mul nsw i64 %72, %73
  %75 = sdiv i64 %71, %74
  %76 = sub nsw i64 %70, %75
  %77 = load i64, ptr @cnt2, align 8, !tbaa !5
  %78 = icmp slt i64 %76, %77
  br i1 %78, label %79, label %80

79:                                               ; preds = %50
  store i1 false, ptr %2, align 1
  store i32 1, ptr %5, align 4
  br label %81

80:                                               ; preds = %50
  store i1 true, ptr %2, align 1
  store i32 1, ptr %5, align 4
  br label %81

81:                                               ; preds = %80, %79, %49, %34
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  %82 = load i1, ptr %2, align 1
  ret i1 %82
}

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3maxIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(8)) #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 = { 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 #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"}


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

@cnt1 = external dso_local local_unnamed_addr global i64, align 8
@cnt2 = external dso_local local_unnamed_addr global i64, align 8
@x = external dso_local local_unnamed_addr global i64, align 8
@y = external dso_local local_unnamed_addr global i64, align 8

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef zeroext i1 @_Z5checkx(i64 noundef %0) local_unnamed_addr #0 {
  %2 = alloca i64, align 8
  %3 = alloca i64, align 8
  %4 = load i64, ptr @x, align 8, !tbaa !5
  %5 = load i64, ptr @y, align 8, !tbaa !5
  %6 = mul nsw i64 %5, %4
  %7 = sdiv i64 %0, %6
  %8 = add nsw i64 %7, %0
  %9 = sdiv i64 %0, %4
  %10 = sub i64 %8, %9
  %11 = sub nsw i64 %0, %7
  %12 = load i64, ptr @cnt1, align 8, !tbaa !5
  %13 = load i64, ptr @cnt2, align 8, !tbaa !5
  %14 = add nsw i64 %13, %12
  %15 = icmp slt i64 %11, %14
  %16 = sub nsw i64 %10, %7
  %17 = icmp slt i64 %16, %12
  %or.cond = select i1 %15, i1 true, i1 %17
  br i1 %or.cond, label %35, label %18

18:                                               ; preds = %1
  %19 = sdiv i64 %0, %5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #3
  %20 = add i64 %12, %7
  %21 = sub i64 %20, %19
  store i64 %21, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #3
  store i64 0, ptr %3, align 8, !tbaa !5
  %22 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3maxIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) %2, ptr noundef nonnull align 8 dereferenceable(8) %3)
  %23 = load i64, ptr %22, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #3
  %24 = load i64, ptr @x, align 8, !tbaa !5
  %25 = sdiv i64 %0, %24
  %26 = load i64, ptr @y, align 8, !tbaa !5
  %27 = mul nsw i64 %26, %24
  %28 = sdiv i64 %0, %27
  %29 = add i64 %19, %23
  %30 = add i64 %10, %25
  %31 = add i64 %29, %28
  %32 = sub i64 %30, %31
  %33 = load i64, ptr @cnt2, align 8, !tbaa !5
  %34 = icmp sge i64 %32, %33
  br label %35

35:                                               ; preds = %18, %1
  %.0 = phi i1 [ false, %1 ], [ %34, %18 ]
  ret i1 %.0
}

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3maxIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #2

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #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"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass