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

; 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
@h = external dso_local global i32, align 4
@a = external dso_local global i32, align 4
@b = external dso_local global i32, align 4
@k = external dso_local global i32, align 4
@.str = external hidden unnamed_addr constant [9 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [14 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [3 x i8], align 1

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #0 {
  %1 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  br label %2

2:                                                ; preds = %49, %0
  %3 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @h, ptr noundef @a, ptr noundef @b, ptr noundef @k)
  %4 = icmp eq i32 %3, 4
  br i1 %4, label %5, label %14

5:                                                ; preds = %2
  %6 = load i32, ptr @h, align 4, !tbaa !5
  %7 = load i32, ptr @a, align 4, !tbaa !5
  %8 = add nsw i32 %6, %7
  %9 = load i32, ptr @b, align 4, !tbaa !5
  %10 = add nsw i32 %8, %9
  %11 = load i32, ptr @k, align 4, !tbaa !5
  %12 = add nsw i32 %10, %11
  %13 = icmp ne i32 %12, 0
  br label %14

14:                                               ; preds = %5, %2
  %15 = phi i1 [ false, %2 ], [ %13, %5 ]
  br i1 %15, label %16, label %54

16:                                               ; preds = %14
  %17 = load i32, ptr @t, align 4, !tbaa !5
  %18 = add nsw i32 %17, 1
  store i32 %18, ptr @t, align 4, !tbaa !5
  %19 = load i32, ptr @h, align 4, !tbaa !5
  %20 = load i32, ptr @a, align 4, !tbaa !5
  %21 = icmp sle i32 %19, %20
  br i1 %21, label %49, label %22

22:                                               ; preds = %16
  %23 = load i32, ptr @h, align 4, !tbaa !5
  %24 = sext i32 %23 to i64
  %25 = load i32, ptr @k, align 4, !tbaa !5
  %26 = sext i32 %25 to i64
  %27 = load i32, ptr @a, align 4, !tbaa !5
  %28 = load i32, ptr @b, align 4, !tbaa !5
  %29 = sub nsw i32 %27, %28
  %30 = sext i32 %29 to i64
  %31 = mul nsw i64 %26, %30
  %32 = sub nsw i64 %24, %31
  %33 = load i32, ptr @b, align 4, !tbaa !5
  %34 = sext i32 %33 to i64
  %35 = sub nsw i64 %32, %34
  %36 = icmp sle i64 %35, 0
  br i1 %36, label %49, label %37

37:                                               ; preds = %22
  %38 = load i32, ptr @k, align 4, !tbaa !5
  %39 = sext i32 %38 to i64
  %40 = load i32, ptr @b, align 4, !tbaa !5
  %41 = load i32, ptr @a, align 4, !tbaa !5
  %42 = sub nsw i32 %40, %41
  %43 = sext i32 %42 to i64
  %44 = mul nsw i64 %39, %43
  %45 = load i32, ptr @b, align 4, !tbaa !5
  %46 = sext i32 %45 to i64
  %47 = add nsw i64 %44, %46
  %48 = icmp slt i64 %47, 0
  br label %49

49:                                               ; preds = %37, %22, %16
  %50 = phi i1 [ true, %22 ], [ true, %16 ], [ %48, %37 ]
  %51 = zext i1 %50 to i64
  %52 = select i1 %50, ptr @.str.2, ptr @.str.3
  %53 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i32 noundef %18, ptr noundef %52)
  br label %2, !llvm.loop !9

54:                                               ; preds = %14
  ret i32 0
}

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

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

!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"}


; 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
@h = external dso_local global i32, align 4
@a = external dso_local global i32, align 4
@b = external dso_local global i32, align 4
@k = external dso_local global i32, align 4
@.str = external hidden unnamed_addr constant [9 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [14 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [3 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 @h, ptr noundef nonnull @a, ptr noundef nonnull @b, ptr noundef nonnull @k)
  %2 = icmp eq i32 %1, 4
  br i1 %2, label %.lr.ph, label %.critedge

.lr.ph:                                           ; preds = %0, %27
  %3 = load i32, ptr @h, align 4, !tbaa !5
  %4 = load i32, ptr @a, align 4, !tbaa !5
  %5 = add nsw i32 %4, %3
  %6 = load i32, ptr @b, align 4, !tbaa !5
  %7 = add nsw i32 %5, %6
  %8 = load i32, ptr @k, align 4, !tbaa !5
  %9 = sub i32 0, %8
  %.not = icmp eq i32 %7, %9
  br i1 %.not, label %.critedge, label %10

10:                                               ; preds = %.lr.ph
  %11 = load i32, ptr @t, align 4, !tbaa !5
  %12 = add nsw i32 %11, 1
  store i32 %12, ptr @t, align 4, !tbaa !5
  %.not2 = icmp sgt i32 %3, %4
  br i1 %.not2, label %13, label %.thread

13:                                               ; preds = %10
  %14 = sext i32 %3 to i64
  %15 = sext i32 %8 to i64
  %16 = sub nsw i32 %4, %6
  %17 = sext i32 %16 to i64
  %18 = mul nsw i64 %15, %17
  %19 = sext i32 %6 to i64
  %20 = add nsw i64 %18, %19
  %.not4 = icmp slt i64 %20, %14
  br i1 %.not4, label %21, label %.thread

21:                                               ; preds = %13
  %22 = sub nsw i32 %6, %4
  %23 = sext i32 %22 to i64
  %24 = mul nsw i64 %15, %23
  %25 = add nsw i64 %24, %19
  %.fr = freeze i64 %25
  %26 = icmp slt i64 %.fr, 0
  br i1 %26, label %.thread, label %27

.thread:                                          ; preds = %10, %13, %21
  br label %27

27:                                               ; preds = %21, %.thread
  %28 = phi ptr [ @.str.2, %.thread ], [ @.str.3, %21 ]
  %29 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %12, ptr noundef nonnull %28)
  %30 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @h, ptr noundef nonnull @a, ptr noundef nonnull @b, ptr noundef nonnull @k)
  %31 = icmp eq i32 %30, 4
  br i1 %31, label %.lr.ph, label %.critedge, !llvm.loop !9

.critedge:                                        ; preds = %.lr.ph, %27, %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 = !{!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"}


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