; LLVM IR from tangjz/acm-icpc :: codeforces/complete (492D)

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

@n = external dso_local global i32, align 4
@x = external dso_local global i32, align 4
@y = external dso_local global i32, align 4
@a = external dso_local global i32, align 4
@.str = external hidden unnamed_addr constant [7 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [5 x i8], align 1

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #0 {
  %1 = alloca i32, align 4
  %2 = alloca i64, align 8
  %3 = alloca i64, align 8
  %4 = alloca i64, align 8
  store i32 0, ptr %1, align 4
  %5 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n, ptr noundef @x, ptr noundef @y)
  br label %6

6:                                                ; preds = %62, %0
  %7 = load i32, ptr @n, align 4, !tbaa !5
  %8 = add nsw i32 %7, -1
  store i32 %8, ptr @n, align 4, !tbaa !5
  %9 = icmp ne i32 %7, 0
  br i1 %9, label %10, label %63

10:                                               ; preds = %6
  %11 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef @a)
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #3
  store i64 0, ptr %2, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  store i64 1000000000000000, ptr %3, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  br label %12

12:                                               ; preds = %38, %10
  %13 = load i64, ptr %2, align 8, !tbaa !9
  %14 = load i64, ptr %3, align 8, !tbaa !9
  %15 = icmp slt i64 %13, %14
  br i1 %15, label %16, label %39

16:                                               ; preds = %12
  %17 = load i64, ptr %2, align 8, !tbaa !9
  %18 = load i64, ptr %3, align 8, !tbaa !9
  %19 = add nsw i64 %17, %18
  %20 = ashr i64 %19, 1
  store i64 %20, ptr %4, align 8, !tbaa !9
  %21 = load i64, ptr %4, align 8, !tbaa !9
  %22 = load i32, ptr @x, align 4, !tbaa !5
  %23 = sext i32 %22 to i64
  %24 = sdiv i64 %21, %23
  %25 = load i64, ptr %4, align 8, !tbaa !9
  %26 = load i32, ptr @y, align 4, !tbaa !5
  %27 = sext i32 %26 to i64
  %28 = sdiv i64 %25, %27
  %29 = add nsw i64 %24, %28
  %30 = load i32, ptr @a, align 4, !tbaa !5
  %31 = sext i32 %30 to i64
  %32 = icmp slt i64 %29, %31
  br i1 %32, label %33, label %36

33:                                               ; preds = %16
  %34 = load i64, ptr %4, align 8, !tbaa !9
  %35 = add nsw i64 %34, 1
  store i64 %35, ptr %2, align 8, !tbaa !9
  br label %38

36:                                               ; preds = %16
  %37 = load i64, ptr %4, align 8, !tbaa !9
  store i64 %37, ptr %3, align 8, !tbaa !9
  br label %38

38:                                               ; preds = %36, %33
  br label %12, !llvm.loop !11

39:                                               ; preds = %12
  %40 = load i64, ptr %2, align 8, !tbaa !9
  %41 = load i32, ptr @x, align 4, !tbaa !5
  %42 = sext i32 %41 to i64
  %43 = srem i64 %40, %42
  %44 = icmp eq i64 %43, 0
  br i1 %44, label %45, label %53

45:                                               ; preds = %39
  %46 = load i64, ptr %2, align 8, !tbaa !9
  %47 = load i32, ptr @y, align 4, !tbaa !5
  %48 = sext i32 %47 to i64
  %49 = srem i64 %46, %48
  %50 = icmp eq i64 %49, 0
  br i1 %50, label %51, label %53

51:                                               ; preds = %45
  %52 = call i32 @puts(ptr noundef @.str.2)
  br label %62

53:                                               ; preds = %45, %39
  %54 = load i64, ptr %2, align 8, !tbaa !9
  %55 = load i32, ptr @y, align 4, !tbaa !5
  %56 = sext i32 %55 to i64
  %57 = srem i64 %54, %56
  %58 = icmp eq i64 %57, 0
  %59 = zext i1 %58 to i64
  %60 = select i1 %58, ptr @.str.3, ptr @.str.4
  %61 = call i32 @puts(ptr noundef %60)
  br label %62

62:                                               ; preds = %53, %51
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #3
  br label %6, !llvm.loop !13

63:                                               ; preds = %6
  ret i32 0
}

declare i32 @__isoc99_scanf(ptr noundef, ...) #1

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

declare i32 @puts(ptr noundef) #1

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

attributes #0 = { mustprogress norecurse 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 = { "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 = { 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}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}


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

@n = external dso_local global i32, align 4
@x = external dso_local global i32, align 4
@y = external dso_local global i32, align 4
@a = external dso_local global i32, align 4
@.str = external hidden unnamed_addr constant [7 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [5 x i8], align 1

; Function Attrs: mustprogress nofree norecurse nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n, ptr noundef nonnull @x, ptr noundef nonnull @y)
  %2 = load i32, ptr @n, align 4, !tbaa !5
  %3 = add nsw i32 %2, -1
  store i32 %3, ptr @n, align 4, !tbaa !5
  %.not15 = icmp eq i32 %2, 0
  br i1 %.not15, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %0, %20
  %4 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull @a)
  %5 = load i32, ptr @x, align 4, !tbaa !5
  %6 = sext i32 %5 to i64
  %7 = load i32, ptr @y, align 4, !tbaa !5
  %8 = sext i32 %7 to i64
  %9 = load i32, ptr @a, align 4, !tbaa !5
  %10 = sext i32 %9 to i64
  br label %11

11:                                               ; preds = %.lr.ph, %11
  %.014 = phi i64 [ 0, %.lr.ph ], [ %.1, %11 ]
  %.01113 = phi i64 [ 1000000000000000, %.lr.ph ], [ %.112, %11 ]
  %12 = add nsw i64 %.014, %.01113
  %13 = ashr i64 %12, 1
  %14 = sdiv i64 %13, %6
  %15 = sdiv i64 %13, %8
  %16 = add nsw i64 %15, %14
  %17 = icmp slt i64 %16, %10
  %18 = add nsw i64 %13, 1
  %.112 = select i1 %17, i64 %.01113, i64 %13
  %.1 = select i1 %17, i64 %18, i64 %.014
  %19 = icmp slt i64 %.1, %.112
  br i1 %19, label %11, label %20, !llvm.loop !9

20:                                               ; preds = %11
  %21 = srem i64 %.1, %6
  %22 = srem i64 %.1, %8
  %23 = or i64 %21, %22
  %or.cond = icmp eq i64 %23, 0
  %24 = icmp eq i64 %22, 0
  %25 = select i1 %24, ptr @.str.3, ptr @.str.4
  %.sink = select i1 %or.cond, ptr @.str.2, ptr %25
  %26 = tail call i32 @puts(ptr noundef nonnull dereferenceable(1) %.sink)
  %27 = load i32, ptr @n, align 4, !tbaa !5
  %28 = add nsw i32 %27, -1
  store i32 %28, ptr @n, align 4, !tbaa !5
  %.not = icmp eq i32 %27, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !11

._crit_edge:                                      ; preds = %20, %0
  ret i32 0
}

; Function Attrs: nofree nounwind
declare noundef i32 @__isoc99_scanf(ptr nocapture noundef readonly, ...) local_unnamed_addr #1

; Function Attrs: nofree nounwind
declare noundef i32 @puts(ptr nocapture noundef readonly) local_unnamed_addr #1

attributes #0 = { mustprogress nofree norecurse 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 = { nofree 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" }

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


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass