; LLVM IR from tangjz/acm-icpc :: lydsy (3858)

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

@t = external dso_local global i32, align 4
@x = external dso_local global i64, align 8
@k = external dso_local global i64, align 8
@.str = external hidden unnamed_addr constant [9 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [16 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 i32, align 4
  %4 = alloca i64, align 8
  store i32 0, ptr %1, align 4
  br label %5

5:                                                ; preds = %45, %0
  %6 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @x, ptr noundef @k)
  %7 = icmp eq i32 %6, 2
  br i1 %7, label %8, label %13

8:                                                ; preds = %5
  %9 = load i64, ptr @x, align 8, !tbaa !5
  %10 = load i64, ptr @k, align 8, !tbaa !5
  %11 = add nsw i64 %9, %10
  %12 = icmp ne i64 %11, 0
  br label %13

13:                                               ; preds = %8, %5
  %14 = phi i1 [ false, %5 ], [ %12, %8 ]
  br i1 %14, label %15, label %50

15:                                               ; preds = %13
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #3
  store i64 2, ptr %2, align 8, !tbaa !5
  br label %16

16:                                               ; preds = %41, %15
  %17 = load i64, ptr %2, align 8, !tbaa !5
  %18 = load i64, ptr @k, align 8, !tbaa !5
  %19 = icmp sle i64 %17, %18
  br i1 %19, label %21, label %20

20:                                               ; preds = %16
  store i32 4, ptr %3, align 4
  br label %44

21:                                               ; preds = %16
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  %22 = load i64, ptr @x, align 8, !tbaa !5
  %23 = sub nsw i64 %22, 1
  %24 = load i64, ptr %2, align 8, !tbaa !5
  %25 = sdiv i64 %23, %24
  %26 = add nsw i64 %25, 1
  store i64 %26, ptr %4, align 8, !tbaa !5
  %27 = load i64, ptr %4, align 8, !tbaa !5
  %28 = load i64, ptr %2, align 8, !tbaa !5
  %29 = icmp sle i64 %27, %28
  br i1 %29, label %30, label %34

30:                                               ; preds = %21
  %31 = load i64, ptr %4, align 8, !tbaa !5
  %32 = load i64, ptr @k, align 8, !tbaa !5
  %33 = mul nsw i64 %31, %32
  store i64 %33, ptr @x, align 8, !tbaa !5
  store i32 4, ptr %3, align 4
  br label %38

34:                                               ; preds = %21
  %35 = load i64, ptr %4, align 8, !tbaa !5
  %36 = load i64, ptr %2, align 8, !tbaa !5
  %37 = mul nsw i64 %35, %36
  store i64 %37, ptr @x, align 8, !tbaa !5
  store i32 0, ptr %3, align 4
  br label %38

38:                                               ; preds = %34, %30
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  %39 = load i32, ptr %3, align 4
  switch i32 %39, label %44 [
    i32 0, label %40
  ]

40:                                               ; preds = %38
  br label %41

41:                                               ; preds = %40
  %42 = load i64, ptr %2, align 8, !tbaa !5
  %43 = add nsw i64 %42, 1
  store i64 %43, ptr %2, align 8, !tbaa !5
  br label %16, !llvm.loop !9

44:                                               ; preds = %38, %20
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #3
  br label %45

45:                                               ; preds = %44
  %46 = load i32, ptr @t, align 4, !tbaa !11
  %47 = add nsw i32 %46, 1
  store i32 %47, ptr @t, align 4, !tbaa !11
  %48 = load i64, ptr @x, align 8, !tbaa !5
  %49 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i32 noundef %47, i64 noundef %48)
  br label %5, !llvm.loop !13

50:                                               ; preds = %13
  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

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

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

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 = !{!"long long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = distinct !{!13, !10}


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

@t = external dso_local local_unnamed_addr global i32, align 4
@x = external dso_local global i64, align 8
@k = external dso_local global i64, align 8
@.str = external hidden unnamed_addr constant [9 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [16 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 @x, ptr noundef nonnull @k)
  %2 = icmp eq i32 %1, 2
  %3 = load i64, ptr @x, align 8
  %4 = load i64, ptr @k, align 8
  %5 = sub i64 0, %4
  %6 = icmp ne i64 %3, %5
  %7 = select i1 %2, i1 %6, i1 false
  br i1 %7, label %.preheader, label %._crit_edge19

.preheader:                                       ; preds = %0, %13
  %x.promoted = phi i64 [ %20, %13 ], [ %3, %0 ]
  %8 = phi i64 [ %21, %13 ], [ %4, %0 ]
  %.not14 = icmp slt i64 %8, 2
  br i1 %.not14, label %13, label %.lr.ph

.lr.ph:                                           ; preds = %.preheader, %.lr.ph
  %.016 = phi i64 [ %12, %.lr.ph ], [ 2, %.preheader ]
  %storemerge1315 = phi i64 [ %storemerge, %.lr.ph ], [ %x.promoted, %.preheader ]
  %9 = add nsw i64 %storemerge1315, -1
  %10 = sdiv i64 %9, %.016
  %11 = add nsw i64 %10, 1
  %.not12.not.not = icmp slt i64 %10, %.016
  %..0 = select i1 %.not12.not.not, i64 %8, i64 %.016
  %storemerge = mul nsw i64 %..0, %11
  %12 = add nuw i64 %.016, 1
  %exitcond.not = icmp eq i64 %.016, %8
  %or.cond = or i1 %.not12.not.not, %exitcond.not
  br i1 %or.cond, label %.sink.split, label %.lr.ph, !llvm.loop !5

.sink.split:                                      ; preds = %.lr.ph
  store i64 %storemerge, ptr @x, align 8, !tbaa !7
  br label %13

13:                                               ; preds = %.sink.split, %.preheader
  %14 = phi i64 [ %x.promoted, %.preheader ], [ %storemerge, %.sink.split ]
  %15 = load i32, ptr @t, align 4, !tbaa !11
  %16 = add nsw i32 %15, 1
  store i32 %16, ptr @t, align 4, !tbaa !11
  %17 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %16, i64 noundef %14)
  %18 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @x, ptr noundef nonnull @k)
  %19 = icmp eq i32 %18, 2
  %20 = load i64, ptr @x, align 8
  %21 = load i64, ptr @k, align 8
  %22 = sub i64 0, %21
  %23 = icmp ne i64 %20, %22
  %24 = select i1 %19, i1 %23, i1 false
  br i1 %24, label %.preheader, label %._crit_edge19, !llvm.loop !13

._crit_edge19:                                    ; preds = %13, %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 @printf(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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = !{!8, !8, i64 0}
!8 = !{!"long long", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !9, i64 0}
!13 = distinct !{!13, !6}


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