; LLVM IR from tangjz/acm-icpc :: codeforces (698E)

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

@ss = external dso_local global i32, align 4
@mm = external dso_local global i32, align 4
@hh = external dso_local global i32, align 4
@wk = external dso_local global i32, align 4
@dd = external dso_local global i32, align 4
@mt = external dso_local global i32, align 4
@t = external dso_local global i32, align 4
@val = external dso_local global i64, align 8
@.str = external hidden unnamed_addr constant [15 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [7 x i8], align 1

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z8val_initv() #0

; 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

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z8val_calcv() #0

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z5solvev() #0

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #2 {
  %1 = alloca i32, align 4
  %2 = alloca i8, align 1
  %3 = alloca i32, align 4
  %4 = alloca i64, align 8
  store i32 0, ptr %1, align 4
  %5 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @ss, ptr noundef @mm, ptr noundef @hh, ptr noundef @wk, ptr noundef @dd, ptr noundef @mt, ptr noundef @t)
  br label %6

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

10:                                               ; preds = %6
  %11 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef @val)
  call void @_Z8val_initv()
  call void @llvm.lifetime.start.p0(i64 1, ptr %2) #4
  %12 = load i32, ptr @wk, align 4, !tbaa !5
  %13 = icmp eq i32 %12, -1
  br i1 %13, label %17, label %14

14:                                               ; preds = %10
  %15 = load i32, ptr @dd, align 4, !tbaa !5
  %16 = icmp eq i32 %15, -1
  br label %17

17:                                               ; preds = %14, %10
  %18 = phi i1 [ true, %10 ], [ %16, %14 ]
  %19 = zext i1 %18 to i8
  store i8 %19, ptr %2, align 1, !tbaa !9
  %20 = load i8, ptr %2, align 1, !tbaa !9, !range !11, !noundef !12
  %21 = trunc i8 %20 to i1
  br i1 %21, label %22, label %23

22:                                               ; preds = %17
  call void @_Z5solvev()
  call void @_Z8val_calcv()
  br label %35

23:                                               ; preds = %17
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  %24 = load i32, ptr @wk, align 4, !tbaa !5
  store i32 %24, ptr %3, align 4, !tbaa !5
  store i32 -1, ptr @wk, align 4, !tbaa !5
  call void @_Z5solvev()
  %25 = load i32, ptr %3, align 4, !tbaa !5
  store i32 %25, ptr @wk, align 4, !tbaa !5
  call void @_Z8val_calcv()
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  %26 = load i64, ptr @val, align 8, !tbaa !13
  store i64 %26, ptr %4, align 8, !tbaa !13
  %27 = load i32, ptr @dd, align 4, !tbaa !5
  store i32 %27, ptr %3, align 4, !tbaa !5
  store i32 -1, ptr @dd, align 4, !tbaa !5
  call void @_Z5solvev()
  %28 = load i32, ptr %3, align 4, !tbaa !5
  store i32 %28, ptr @dd, align 4, !tbaa !5
  call void @_Z8val_calcv()
  %29 = load i64, ptr %4, align 8, !tbaa !13
  %30 = load i64, ptr @val, align 8, !tbaa !13
  %31 = icmp slt i64 %29, %30
  br i1 %31, label %32, label %34

32:                                               ; preds = %23
  %33 = load i64, ptr %4, align 8, !tbaa !13
  store i64 %33, ptr @val, align 8, !tbaa !13
  br label %34

34:                                               ; preds = %32, %23
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  br label %35

35:                                               ; preds = %34, %22
  %36 = load i64, ptr @val, align 8, !tbaa !13
  %37 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i64 noundef %36)
  call void @llvm.lifetime.end.p0(i64 1, ptr %2) #4
  br label %6, !llvm.loop !15

38:                                               ; preds = %6
  ret i32 0
}

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

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

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 = { 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 #3 = { "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 #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 = !{!"bool", !7, i64 0}
!11 = !{i8 0, i8 2}
!12 = !{}
!13 = !{!14, !14, i64 0}
!14 = !{!"long long", !7, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}


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

@ss = external dso_local global i32, align 4
@mm = external dso_local global i32, align 4
@hh = external dso_local global i32, align 4
@wk = external dso_local global i32, align 4
@dd = external dso_local global i32, align 4
@mt = external dso_local global i32, align 4
@t = external dso_local global i32, align 4
@val = external dso_local global i64, align 8
@.str = external hidden unnamed_addr constant [15 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [7 x i8], align 1

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z8val_initv() local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z8val_calcv() local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z5solvev() local_unnamed_addr #0

; Function Attrs: mustprogress norecurse 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 @ss, ptr noundef nonnull @mm, ptr noundef nonnull @hh, ptr noundef nonnull @wk, ptr noundef nonnull @dd, ptr noundef nonnull @mt, ptr noundef nonnull @t)
  %2 = load i32, ptr @t, align 4, !tbaa !5
  %3 = add nsw i32 %2, -1
  store i32 %3, ptr @t, align 4, !tbaa !5
  %.not6 = icmp eq i32 %2, 0
  br i1 %.not6, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %0, %17
  %4 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull @val)
  tail call void @_Z8val_initv()
  %5 = load i32, ptr @wk, align 4, !tbaa !5
  %6 = icmp eq i32 %5, -1
  %7 = load i32, ptr @dd, align 4
  %8 = icmp eq i32 %7, -1
  %9 = select i1 %6, i1 true, i1 %8
  br i1 %9, label %10, label %11

10:                                               ; preds = %.lr.ph
  tail call void @_Z5solvev()
  tail call void @_Z8val_calcv()
  %.pre = load i64, ptr @val, align 8, !tbaa !9
  br label %17

11:                                               ; preds = %.lr.ph
  store i32 -1, ptr @wk, align 4, !tbaa !5
  tail call void @_Z5solvev()
  store i32 %5, ptr @wk, align 4, !tbaa !5
  tail call void @_Z8val_calcv()
  %12 = load i64, ptr @val, align 8, !tbaa !9
  %13 = load i32, ptr @dd, align 4, !tbaa !5
  store i32 -1, ptr @dd, align 4, !tbaa !5
  tail call void @_Z5solvev()
  store i32 %13, ptr @dd, align 4, !tbaa !5
  tail call void @_Z8val_calcv()
  %14 = load i64, ptr @val, align 8, !tbaa !9
  %15 = icmp slt i64 %12, %14
  br i1 %15, label %16, label %17

16:                                               ; preds = %11
  store i64 %12, ptr @val, align 8, !tbaa !9
  br label %17

17:                                               ; preds = %11, %16, %10
  %18 = phi i64 [ %14, %11 ], [ %12, %16 ], [ %.pre, %10 ]
  %19 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i64 noundef %18)
  %20 = load i32, ptr @t, align 4, !tbaa !5
  %21 = add nsw i32 %20, -1
  store i32 %21, ptr @t, align 4, !tbaa !5
  %.not = icmp eq i32 %20, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !11

._crit_edge:                                      ; preds = %17, %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 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 = { 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 = !{!10, !10, i64 0}
!10 = !{!"long long", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass