; LLVM IR from tangjz/acm-icpc :: codeforces/complete (535C)

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

@q = external dso_local global i32, align 4
@l = external dso_local global i32, align 4
@t = external dso_local global i32, align 4
@m = external dso_local global i32, align 4
@a = external dso_local global i64, align 8
@b = external dso_local global i64, align 8
@.str = external hidden unnamed_addr constant [13 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [7 x i8], align 1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_Z1fx(i64 noundef) #0

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

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #1 {
  %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 @a, ptr noundef @b, ptr noundef @q)
  br label %6

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

10:                                               ; preds = %6
  %11 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef @l, ptr noundef @t, ptr noundef @m)
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #4
  %12 = load i32, ptr @l, align 4, !tbaa !5
  %13 = sub nsw i32 %12, 1
  %14 = sext i32 %13 to i64
  store i64 %14, ptr %2, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #4
  store i64 3000000, ptr %3, align 8, !tbaa !9
  br label %15

15:                                               ; preds = %46, %10
  %16 = load i64, ptr %2, align 8, !tbaa !9
  %17 = load i64, ptr %3, align 8, !tbaa !9
  %18 = icmp slt i64 %16, %17
  br i1 %18, label %19, label %47

19:                                               ; preds = %15
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  %20 = load i64, ptr %2, align 8, !tbaa !9
  %21 = load i64, ptr %3, align 8, !tbaa !9
  %22 = add nsw i64 %20, %21
  %23 = add nsw i64 %22, 1
  %24 = ashr i64 %23, 1
  store i64 %24, ptr %4, align 8, !tbaa !9
  %25 = load i64, ptr %4, align 8, !tbaa !9
  %26 = call noundef i64 @_Z1fx(i64 noundef %25)
  %27 = load i32, ptr @t, align 4, !tbaa !5
  %28 = sext i32 %27 to i64
  %29 = icmp sgt i64 %26, %28
  br i1 %29, label %41, label %30

30:                                               ; preds = %19
  %31 = load i32, ptr @l, align 4, !tbaa !5
  %32 = sext i32 %31 to i64
  %33 = load i64, ptr %4, align 8, !tbaa !9
  %34 = call noundef i64 @_Z1sxx(i64 noundef %32, i64 noundef %33)
  %35 = load i32, ptr @t, align 4, !tbaa !5
  %36 = sext i32 %35 to i64
  %37 = load i32, ptr @m, align 4, !tbaa !5
  %38 = sext i32 %37 to i64
  %39 = mul nsw i64 %36, %38
  %40 = icmp sgt i64 %34, %39
  br i1 %40, label %41, label %44

41:                                               ; preds = %30, %19
  %42 = load i64, ptr %4, align 8, !tbaa !9
  %43 = sub nsw i64 %42, 1
  store i64 %43, ptr %3, align 8, !tbaa !9
  br label %46

44:                                               ; preds = %30
  %45 = load i64, ptr %4, align 8, !tbaa !9
  store i64 %45, ptr %2, align 8, !tbaa !9
  br label %46

46:                                               ; preds = %44, %41
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  br label %15, !llvm.loop !11

47:                                               ; preds = %15
  %48 = load i64, ptr %2, align 8, !tbaa !9
  %49 = load i32, ptr @l, align 4, !tbaa !5
  %50 = sext i32 %49 to i64
  %51 = icmp slt i64 %48, %50
  br i1 %51, label %52, label %53

52:                                               ; preds = %47
  br label %55

53:                                               ; preds = %47
  %54 = load i64, ptr %2, align 8, !tbaa !9
  br label %55

55:                                               ; preds = %53, %52
  %56 = phi i64 [ -1, %52 ], [ %54, %53 ]
  %57 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i64 noundef %56)
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #4
  br label %6, !llvm.loop !13

58:                                               ; preds = %6
  ret i32 0
}

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

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

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

declare i32 @printf(ptr noundef, ...) #2

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 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 #2 = { "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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!"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"

@q = external dso_local global i32, align 4
@l = external dso_local global i32, align 4
@t = external dso_local global i32, align 4
@m = external dso_local global i32, align 4
@a = external dso_local global i64, align 8
@b = external dso_local global i64, align 8
@.str = external hidden unnamed_addr constant [13 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [7 x i8], align 1

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

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

; Function Attrs: mustprogress norecurse nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #1 {
  %1 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @a, ptr noundef nonnull @b, ptr noundef nonnull @q)
  %2 = load i32, ptr @q, align 4, !tbaa !5
  %3 = add nsw i32 %2, -1
  store i32 %3, ptr @q, align 4, !tbaa !5
  %.not14 = icmp eq i32 %2, 0
  br i1 %.not14, label %._crit_edge17, label %.lr.ph16

.lr.ph16:                                         ; preds = %0, %._crit_edge
  %4 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull @l, ptr noundef nonnull @t, ptr noundef nonnull @m)
  %5 = load i32, ptr @l, align 4, !tbaa !5
  %6 = add nsw i32 %5, -1
  %7 = sext i32 %6 to i64
  %8 = icmp slt i32 %5, 3000001
  br i1 %8, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %.lr.ph16, %28
  %.013 = phi i64 [ %.1, %28 ], [ %7, %.lr.ph16 ]
  %.01012 = phi i64 [ %.111, %28 ], [ 3000000, %.lr.ph16 ]
  %9 = add i64 %.01012, 1
  %10 = add i64 %9, %.013
  %11 = ashr i64 %10, 1
  %12 = tail call noundef i64 @_Z1fx(i64 noundef %11)
  %13 = load i32, ptr @t, align 4, !tbaa !5
  %14 = sext i32 %13 to i64
  %15 = icmp sgt i64 %12, %14
  br i1 %15, label %26, label %16

16:                                               ; preds = %.lr.ph
  %17 = load i32, ptr @l, align 4, !tbaa !5
  %18 = sext i32 %17 to i64
  %19 = tail call noundef i64 @_Z1sxx(i64 noundef %18, i64 noundef %11)
  %20 = load i32, ptr @t, align 4, !tbaa !5
  %21 = sext i32 %20 to i64
  %22 = load i32, ptr @m, align 4, !tbaa !5
  %23 = sext i32 %22 to i64
  %24 = mul nsw i64 %23, %21
  %25 = icmp sgt i64 %19, %24
  br i1 %25, label %26, label %28

26:                                               ; preds = %16, %.lr.ph
  %27 = add nsw i64 %11, -1
  br label %28

28:                                               ; preds = %16, %26
  %.111 = phi i64 [ %27, %26 ], [ %.01012, %16 ]
  %.1 = phi i64 [ %.013, %26 ], [ %11, %16 ]
  %29 = icmp slt i64 %.1, %.111
  br i1 %29, label %.lr.ph, label %._crit_edge.loopexit, !llvm.loop !9

._crit_edge.loopexit:                             ; preds = %28
  %.pre = load i32, ptr @l, align 4, !tbaa !5
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %.lr.ph16
  %30 = phi i32 [ %5, %.lr.ph16 ], [ %.pre, %._crit_edge.loopexit ]
  %.0.lcssa = phi i64 [ %7, %.lr.ph16 ], [ %.1, %._crit_edge.loopexit ]
  %31 = sext i32 %30 to i64
  %32 = icmp slt i64 %.0.lcssa, %31
  %33 = select i1 %32, i64 -1, i64 %.0.lcssa
  %34 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i64 noundef %33)
  %35 = load i32, ptr @q, align 4, !tbaa !5
  %36 = add nsw i32 %35, -1
  store i32 %36, ptr @q, align 4, !tbaa !5
  %.not = icmp eq i32 %35, 0
  br i1 %.not, label %._crit_edge17, label %.lr.ph16, !llvm.loop !11

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

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

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

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