; LLVM IR from tangjz/acm-icpc :: self_training/2015-04-30 (J)

; 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
@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 [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [26 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [17 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 i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  store i32 0, ptr %1, align 4
  %6 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @t)
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #4
  store i32 1, ptr %2, align 4, !tbaa !5
  br label %7

7:                                                ; preds = %92, %0
  %8 = load i32, ptr %2, align 4, !tbaa !5
  %9 = load i32, ptr @t, align 4, !tbaa !5
  %10 = icmp sle i32 %8, %9
  br i1 %10, label %12, label %11

11:                                               ; preds = %7
  store i32 2, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #4
  br label %95

12:                                               ; preds = %7
  store i64 0, ptr @ans, align 8, !tbaa !9
  %13 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef @c, ptr noundef @wr, ptr noundef @hr, ptr noundef @wb, ptr noundef @hb)
  %14 = load i64, ptr @wr, align 8, !tbaa !9
  %15 = load i64, ptr @wb, align 8, !tbaa !9
  %16 = icmp sgt i64 %14, %15
  br i1 %16, label %17, label %18

17:                                               ; preds = %12
  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 %18

18:                                               ; preds = %17, %12
  %19 = load i64, ptr @wb, align 8, !tbaa !9
  %20 = icmp sge i64 %19, 100000
  br i1 %20, label %21, label %47

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

22:                                               ; preds = %43, %21
  %23 = load i64, ptr %4, align 8, !tbaa !9
  %24 = load i64, ptr @wb, align 8, !tbaa !9
  %25 = mul nsw i64 %23, %24
  %26 = load i64, ptr @c, align 8, !tbaa !9
  %27 = icmp sle i64 %25, %26
  br i1 %27, label %29, label %28

28:                                               ; preds = %22
  store i32 5, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  br label %46

29:                                               ; preds = %22
  %30 = load i64, ptr %4, align 8, !tbaa !9
  %31 = load i64, ptr @hb, align 8, !tbaa !9
  %32 = mul nsw i64 %30, %31
  %33 = load i64, ptr @c, align 8, !tbaa !9
  %34 = load i64, ptr %4, align 8, !tbaa !9
  %35 = load i64, ptr @wb, align 8, !tbaa !9
  %36 = mul nsw i64 %34, %35
  %37 = sub nsw i64 %33, %36
  %38 = load i64, ptr @wr, align 8, !tbaa !9
  %39 = sdiv i64 %37, %38
  %40 = load i64, ptr @hr, align 8, !tbaa !9
  %41 = mul nsw i64 %39, %40
  %42 = add nsw i64 %32, %41
  call void @_Z3updRxx(ptr noundef nonnull align 8 dereferenceable(8) @ans, i64 noundef %42)
  br label %43

43:                                               ; preds = %29
  %44 = load i64, ptr %4, align 8, !tbaa !9
  %45 = add nsw i64 %44, 1
  store i64 %45, ptr %4, align 8, !tbaa !9
  br label %22, !llvm.loop !11

46:                                               ; preds = %28
  br label %88

47:                                               ; preds = %18
  %48 = load i64, ptr @wb, align 8, !tbaa !9
  %49 = load i64, ptr @hr, align 8, !tbaa !9
  %50 = mul nsw i64 %48, %49
  %51 = load i64, ptr @wr, align 8, !tbaa !9
  %52 = load i64, ptr @hb, align 8, !tbaa !9
  %53 = mul nsw i64 %51, %52
  %54 = icmp sgt i64 %50, %53
  br i1 %54, label %55, label %56

55:                                               ; preds = %47
  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 %56

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

57:                                               ; preds = %84, %56
  %58 = load i64, ptr %5, align 8, !tbaa !9
  %59 = load i64, ptr @wb, align 8, !tbaa !9
  %60 = icmp sle i64 %58, %59
  br i1 %60, label %61, label %67

61:                                               ; preds = %57
  %62 = load i64, ptr %5, align 8, !tbaa !9
  %63 = load i64, ptr @wr, align 8, !tbaa !9
  %64 = mul nsw i64 %62, %63
  %65 = load i64, ptr @c, align 8, !tbaa !9
  %66 = icmp sle i64 %64, %65
  br label %67

67:                                               ; preds = %61, %57
  %68 = phi i1 [ false, %57 ], [ %66, %61 ]
  br i1 %68, label %70, label %69

69:                                               ; preds = %67
  store i32 8, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  br label %87

70:                                               ; preds = %67
  %71 = load i64, ptr %5, align 8, !tbaa !9
  %72 = load i64, ptr @hr, align 8, !tbaa !9
  %73 = mul nsw i64 %71, %72
  %74 = load i64, ptr @c, align 8, !tbaa !9
  %75 = load i64, ptr %5, align 8, !tbaa !9
  %76 = load i64, ptr @wr, align 8, !tbaa !9
  %77 = mul nsw i64 %75, %76
  %78 = sub nsw i64 %74, %77
  %79 = load i64, ptr @wb, align 8, !tbaa !9
  %80 = sdiv i64 %78, %79
  %81 = load i64, ptr @hb, align 8, !tbaa !9
  %82 = mul nsw i64 %80, %81
  %83 = add nsw i64 %73, %82
  call void @_Z3updRxx(ptr noundef nonnull align 8 dereferenceable(8) @ans, i64 noundef %83)
  br label %84

84:                                               ; preds = %70
  %85 = load i64, ptr %5, align 8, !tbaa !9
  %86 = add nsw i64 %85, 1
  store i64 %86, ptr %5, align 8, !tbaa !9
  br label %57, !llvm.loop !13

87:                                               ; preds = %69
  br label %88

88:                                               ; preds = %87, %46
  %89 = load i32, ptr %2, align 4, !tbaa !5
  %90 = load i64, ptr @ans, align 8, !tbaa !9
  %91 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i32 noundef %89, i64 noundef %90)
  br label %92

92:                                               ; preds = %88
  %93 = load i32, ptr %2, align 4, !tbaa !5
  %94 = add nsw i32 %93, 1
  store i32 %94, ptr %2, align 4, !tbaa !5
  br label %7, !llvm.loop !14

95:                                               ; preds = %11
  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 = !{!"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}
!14 = distinct !{!14, !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"

@t = external dso_local global i32, align 4
@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 [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [26 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [17 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 @t)
  %2 = load i32, ptr @t, align 4, !tbaa !5
  %.not30 = icmp slt i32 %2, 1
  br i1 %.not30, label %._crit_edge, label %.lr.ph32

._crit_edge:                                      ; preds = %.critedge, %0
  ret i32 0

.lr.ph32:                                         ; preds = %0, %.critedge
  %.01331 = phi i32 [ %52, %.critedge ], [ 1, %0 ]
  store i64 0, ptr @ans, align 8, !tbaa !9
  %3 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull @c, ptr noundef nonnull @wr, ptr noundef nonnull @hr, ptr noundef nonnull @wb, ptr noundef nonnull @hb)
  %4 = load i64, ptr @wr, align 8, !tbaa !9
  %5 = load i64, ptr @wb, align 8, !tbaa !9
  %6 = icmp sgt i64 %4, %5
  br i1 %6, label %7, label %8

7:                                                ; preds = %.lr.ph32
  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 !9
  br label %8

8:                                                ; preds = %7, %.lr.ph32
  %9 = phi i64 [ %.pr, %7 ], [ %5, %.lr.ph32 ]
  %10 = icmp sgt i64 %9, 99999
  br i1 %10, label %.preheader, label %26

.preheader:                                       ; preds = %8
  %11 = load i64, ptr @c, align 8, !tbaa !9
  %.not2227 = icmp slt i64 %11, 0
  br i1 %.not2227, label %.critedge, label %.lr.ph29

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

26:                                               ; preds = %8
  %27 = load i64, ptr @hr, align 8, !tbaa !9
  %28 = mul nsw i64 %27, %9
  %29 = load i64, ptr @wr, align 8, !tbaa !9
  %30 = load i64, ptr @hb, align 8, !tbaa !9
  %31 = mul nsw i64 %30, %29
  %32 = icmp sgt i64 %28, %31
  br i1 %32, label %33, label %34

33:                                               ; preds = %26
  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 !9
  br label %34

34:                                               ; preds = %33, %26
  %35 = phi i64 [ %.pre, %33 ], [ %9, %26 ]
  %.not2024 = icmp slt i64 %35, 0
  br i1 %.not2024, label %.critedge, label %.lr.ph

.lr.ph:                                           ; preds = %34, %40
  %36 = phi i64 [ %49, %40 ], [ %35, %34 ]
  %.025 = phi i64 [ %48, %40 ], [ 0, %34 ]
  %37 = load i64, ptr @wr, align 8, !tbaa !9
  %38 = mul nsw i64 %37, %.025
  %39 = load i64, ptr @c, align 8, !tbaa !9
  %.not21 = icmp sgt i64 %38, %39
  br i1 %.not21, label %.critedge, label %40

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

.critedge:                                        ; preds = %40, %.lr.ph, %.lr.ph29, %34, %.preheader
  %50 = load i64, ptr @ans, align 8, !tbaa !9
  %51 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i32 noundef %.01331, i64 noundef %50)
  %52 = add nuw nsw i32 %.01331, 1
  %53 = load i32, ptr @t, align 4, !tbaa !5
  %.not.not = icmp slt i32 %.01331, %53
  br i1 %.not.not, label %.lr.ph32, label %._crit_edge, !llvm.loop !14
}

; 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 = !{!10, !10, i64 0}
!10 = !{!"long long", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}
!14 = distinct !{!14, !12}


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