; LLVM IR from tangjz/acm-icpc :: 51nod (1548)

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

@c = external dso_local global i64, align 8
@hr = external dso_local global i64, align 8
@hb = external dso_local global i64, align 8
@wr = external dso_local global i64, align 8
@wb = external dso_local global i64, align 8
@ans = external dso_local global i64, align 8
@.str = external hidden unnamed_addr constant [26 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [7 x i8], align 1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z4swapRxS_(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(8)) #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 nounwind uwtable
declare dso_local void @_Z3updRxx(ptr noundef nonnull align 8 dereferenceable(8), i64 noundef) #0

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #2 {
  %1 = alloca i32, align 4
  %2 = alloca i64, align 8
  %3 = alloca i64, align 8
  store i32 0, ptr %1, align 4
  %4 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @c, ptr noundef @hr, ptr noundef @hb, ptr noundef @wr, ptr noundef @wb)
  %5 = load i64, ptr @wr, align 8, !tbaa !5
  %6 = load i64, ptr @wb, align 8, !tbaa !5
  %7 = icmp sgt i64 %5, %6
  br i1 %7, label %8, label %9

8:                                                ; preds = %0
  call void @_Z4swapRxS_(ptr noundef nonnull align 8 dereferenceable(8) @wr, ptr noundef nonnull align 8 dereferenceable(8) @wb)
  call void @_Z4swapRxS_(ptr noundef nonnull align 8 dereferenceable(8) @hr, ptr noundef nonnull align 8 dereferenceable(8) @hb)
  br label %9

9:                                                ; preds = %8, %0
  %10 = load i64, ptr @wb, align 8, !tbaa !5
  %11 = icmp sge i64 %10, 100000
  br i1 %11, label %12, label %38

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

13:                                               ; preds = %34, %12
  %14 = load i64, ptr %2, align 8, !tbaa !5
  %15 = load i64, ptr @wb, align 8, !tbaa !5
  %16 = mul nsw i64 %14, %15
  %17 = load i64, ptr @c, align 8, !tbaa !5
  %18 = icmp sle i64 %16, %17
  br i1 %18, label %20, label %19

19:                                               ; preds = %13
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #4
  br label %37

20:                                               ; preds = %13
  %21 = load i64, ptr %2, align 8, !tbaa !5
  %22 = load i64, ptr @hb, align 8, !tbaa !5
  %23 = mul nsw i64 %21, %22
  %24 = load i64, ptr @c, align 8, !tbaa !5
  %25 = load i64, ptr %2, align 8, !tbaa !5
  %26 = load i64, ptr @wb, align 8, !tbaa !5
  %27 = mul nsw i64 %25, %26
  %28 = sub nsw i64 %24, %27
  %29 = load i64, ptr @wr, align 8, !tbaa !5
  %30 = sdiv i64 %28, %29
  %31 = load i64, ptr @hr, align 8, !tbaa !5
  %32 = mul nsw i64 %30, %31
  %33 = add nsw i64 %23, %32
  call void @_Z3updRxx(ptr noundef nonnull align 8 dereferenceable(8) @ans, i64 noundef %33)
  br label %34

34:                                               ; preds = %20
  %35 = load i64, ptr %2, align 8, !tbaa !5
  %36 = add nsw i64 %35, 1
  store i64 %36, ptr %2, align 8, !tbaa !5
  br label %13, !llvm.loop !9

37:                                               ; preds = %19
  br label %79

38:                                               ; preds = %9
  %39 = load i64, ptr @wb, align 8, !tbaa !5
  %40 = load i64, ptr @hr, align 8, !tbaa !5
  %41 = mul nsw i64 %39, %40
  %42 = load i64, ptr @wr, align 8, !tbaa !5
  %43 = load i64, ptr @hb, align 8, !tbaa !5
  %44 = mul nsw i64 %42, %43
  %45 = icmp sgt i64 %41, %44
  br i1 %45, label %46, label %47

46:                                               ; preds = %38
  call void @_Z4swapRxS_(ptr noundef nonnull align 8 dereferenceable(8) @wr, ptr noundef nonnull align 8 dereferenceable(8) @wb)
  call void @_Z4swapRxS_(ptr noundef nonnull align 8 dereferenceable(8) @hr, ptr noundef nonnull align 8 dereferenceable(8) @hb)
  br label %47

47:                                               ; preds = %46, %38
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #4
  store i64 0, ptr %3, align 8, !tbaa !5
  br label %48

48:                                               ; preds = %75, %47
  %49 = load i64, ptr %3, align 8, !tbaa !5
  %50 = load i64, ptr @wb, align 8, !tbaa !5
  %51 = icmp sle i64 %49, %50
  br i1 %51, label %52, label %58

52:                                               ; preds = %48
  %53 = load i64, ptr %3, align 8, !tbaa !5
  %54 = load i64, ptr @wr, align 8, !tbaa !5
  %55 = mul nsw i64 %53, %54
  %56 = load i64, ptr @c, align 8, !tbaa !5
  %57 = icmp sle i64 %55, %56
  br label %58

58:                                               ; preds = %52, %48
  %59 = phi i1 [ false, %48 ], [ %57, %52 ]
  br i1 %59, label %61, label %60

60:                                               ; preds = %58
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  br label %78

61:                                               ; preds = %58
  %62 = load i64, ptr %3, align 8, !tbaa !5
  %63 = load i64, ptr @hr, align 8, !tbaa !5
  %64 = mul nsw i64 %62, %63
  %65 = load i64, ptr @c, align 8, !tbaa !5
  %66 = load i64, ptr %3, align 8, !tbaa !5
  %67 = load i64, ptr @wr, align 8, !tbaa !5
  %68 = mul nsw i64 %66, %67
  %69 = sub nsw i64 %65, %68
  %70 = load i64, ptr @wb, align 8, !tbaa !5
  %71 = sdiv i64 %69, %70
  %72 = load i64, ptr @hb, align 8, !tbaa !5
  %73 = mul nsw i64 %71, %72
  %74 = add nsw i64 %64, %73
  call void @_Z3updRxx(ptr noundef nonnull align 8 dereferenceable(8) @ans, i64 noundef %74)
  br label %75

75:                                               ; preds = %61
  %76 = load i64, ptr %3, align 8, !tbaa !5
  %77 = add nsw i64 %76, 1
  store i64 %77, ptr %3, align 8, !tbaa !5
  br label %48, !llvm.loop !11

78:                                               ; preds = %60
  br label %79

79:                                               ; preds = %78, %37
  %80 = load i64, ptr @ans, align 8, !tbaa !5
  %81 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i64 noundef %80)
  ret i32 0
}

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

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

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 = { 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 = !{!"long long", !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}


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

@c = external dso_local global i64, align 8
@hr = external dso_local global i64, align 8
@hb = external dso_local global i64, align 8
@wr = external dso_local global i64, align 8
@wb = external dso_local global i64, align 8
@ans = external dso_local global i64, align 8
@.str = external hidden unnamed_addr constant [26 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [7 x i8], align 1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z4swapRxS_(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z3updRxx(ptr noundef nonnull align 8 dereferenceable(8), 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 @c, ptr noundef nonnull @hr, ptr noundef nonnull @hb, ptr noundef nonnull @wr, ptr noundef nonnull @wb)
  %2 = load i64, ptr @wr, align 8, !tbaa !5
  %3 = load i64, ptr @wb, align 8, !tbaa !5
  %4 = icmp sgt i64 %2, %3
  br i1 %4, label %5, label %6

5:                                                ; preds = %0
  tail call void @_Z4swapRxS_(ptr noundef nonnull align 8 dereferenceable(8) @wr, ptr noundef nonnull align 8 dereferenceable(8) @wb)
  tail call void @_Z4swapRxS_(ptr noundef nonnull align 8 dereferenceable(8) @hr, ptr noundef nonnull align 8 dereferenceable(8) @hb)
  %.pr = load i64, ptr @wb, align 8, !tbaa !5
  br label %6

6:                                                ; preds = %5, %0
  %7 = phi i64 [ %.pr, %5 ], [ %3, %0 ]
  %8 = icmp sgt i64 %7, 99999
  br i1 %8, label %.preheader, label %24

.preheader:                                       ; preds = %6
  %9 = load i64, ptr @c, align 8, !tbaa !5
  %.not1722 = icmp slt i64 %9, 0
  br i1 %.not1722, label %.critedge, label %.lr.ph24

.lr.ph24:                                         ; preds = %.preheader, %.lr.ph24
  %10 = phi i64 [ %23, %.lr.ph24 ], [ %9, %.preheader ]
  %11 = phi i64 [ %22, %.lr.ph24 ], [ 0, %.preheader ]
  %.0923 = phi i64 [ %20, %.lr.ph24 ], [ 0, %.preheader ]
  %12 = load i64, ptr @hb, align 8, !tbaa !5
  %13 = mul nsw i64 %12, %.0923
  %14 = sub nsw i64 %10, %11
  %15 = load i64, ptr @wr, align 8, !tbaa !5
  %16 = sdiv i64 %14, %15
  %17 = load i64, ptr @hr, align 8, !tbaa !5
  %18 = mul nsw i64 %17, %16
  %19 = add nsw i64 %18, %13
  tail call void @_Z3updRxx(ptr noundef nonnull align 8 dereferenceable(8) @ans, i64 noundef %19)
  %20 = add nuw nsw i64 %.0923, 1
  %21 = load i64, ptr @wb, align 8, !tbaa !5
  %22 = mul nsw i64 %21, %20
  %23 = load i64, ptr @c, align 8, !tbaa !5
  %.not17 = icmp sgt i64 %22, %23
  br i1 %.not17, label %.critedge, label %.lr.ph24, !llvm.loop !9

24:                                               ; preds = %6
  %25 = load i64, ptr @hr, align 8, !tbaa !5
  %26 = mul nsw i64 %25, %7
  %27 = load i64, ptr @wr, align 8, !tbaa !5
  %28 = load i64, ptr @hb, align 8, !tbaa !5
  %29 = mul nsw i64 %28, %27
  %30 = icmp sgt i64 %26, %29
  br i1 %30, label %31, label %32

31:                                               ; preds = %24
  tail call void @_Z4swapRxS_(ptr noundef nonnull align 8 dereferenceable(8) @wr, ptr noundef nonnull align 8 dereferenceable(8) @wb)
  tail call void @_Z4swapRxS_(ptr noundef nonnull align 8 dereferenceable(8) @hr, ptr noundef nonnull align 8 dereferenceable(8) @hb)
  %.pre = load i64, ptr @wb, align 8, !tbaa !5
  br label %32

32:                                               ; preds = %31, %24
  %33 = phi i64 [ %.pre, %31 ], [ %7, %24 ]
  %.not19 = icmp slt i64 %33, 0
  br i1 %.not19, label %.critedge, label %.lr.ph

.lr.ph:                                           ; preds = %32, %38
  %34 = phi i64 [ %47, %38 ], [ %33, %32 ]
  %.020 = phi i64 [ %46, %38 ], [ 0, %32 ]
  %35 = load i64, ptr @wr, align 8, !tbaa !5
  %36 = mul nsw i64 %35, %.020
  %37 = load i64, ptr @c, align 8, !tbaa !5
  %.not16 = icmp sgt i64 %36, %37
  br i1 %.not16, label %.critedge, label %38

38:                                               ; preds = %.lr.ph
  %39 = load i64, ptr @hr, align 8, !tbaa !5
  %40 = mul nsw i64 %39, %.020
  %41 = sub nsw i64 %37, %36
  %42 = sdiv i64 %41, %34
  %43 = load i64, ptr @hb, align 8, !tbaa !5
  %44 = mul nsw i64 %43, %42
  %45 = add nsw i64 %44, %40
  tail call void @_Z3updRxx(ptr noundef nonnull align 8 dereferenceable(8) @ans, i64 noundef %45)
  %46 = add nuw nsw i64 %.020, 1
  %47 = load i64, ptr @wb, align 8, !tbaa !5
  %.not.not = icmp slt i64 %.020, %47
  br i1 %.not.not, label %.lr.ph, label %.critedge, !llvm.loop !11

.critedge:                                        ; preds = %38, %.lr.ph, %.lr.ph24, %32, %.preheader
  %48 = load i64, ptr @ans, align 8, !tbaa !5
  %49 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i64 noundef %48)
  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 = !{!"long long", !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,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass