; LLVM IR from kazunetakahashi/atcoder :: 2017/1115_ABC062/C.ll (Z5solvev)

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

@H = external dso_local global i64, align 8
@W = external dso_local global i64, align 8

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_Z3twoxxi(i64 noundef, i64 noundef, i32 noundef) #0

; Function Attrs: mustprogress uwtable
define dso_local noundef i64 @_Z5solvev() #1 {
  %1 = alloca i64, align 8
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca [3 x i64], align 16
  %6 = alloca i64, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %1) #5
  %7 = load i64, ptr @H, align 8, !tbaa !5
  %8 = load i64, ptr @W, align 8, !tbaa !5
  %9 = mul nsw i64 %7, %8
  store i64 %9, ptr %1, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #5
  store i32 1, ptr %2, align 4, !tbaa !9
  br label %10

10:                                               ; preds = %59, %0
  %11 = load i32, ptr %2, align 4, !tbaa !9
  %12 = sext i32 %11 to i64
  %13 = load i64, ptr @H, align 8, !tbaa !5
  %14 = icmp slt i64 %12, %13
  br i1 %14, label %16, label %15

15:                                               ; preds = %10
  store i32 2, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #5
  br label %62

16:                                               ; preds = %10
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #5
  store i32 0, ptr %4, align 4, !tbaa !9
  br label %17

17:                                               ; preds = %55, %16
  %18 = load i32, ptr %4, align 4, !tbaa !9
  %19 = icmp slt i32 %18, 2
  br i1 %19, label %21, label %20

20:                                               ; preds = %17
  store i32 5, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #5
  br label %58

21:                                               ; preds = %17
  call void @llvm.lifetime.start.p0(i64 24, ptr %5) #5
  %22 = load i32, ptr %2, align 4, !tbaa !9
  %23 = sext i32 %22 to i64
  %24 = load i64, ptr @W, align 8, !tbaa !5
  %25 = mul nsw i64 %23, %24
  %26 = getelementptr inbounds [3 x i64], ptr %5, i64 0, i64 0
  store i64 %25, ptr %26, align 16, !tbaa !5
  %27 = load i64, ptr @H, align 8, !tbaa !5
  %28 = load i32, ptr %2, align 4, !tbaa !9
  %29 = sext i32 %28 to i64
  %30 = sub nsw i64 %27, %29
  %31 = load i64, ptr @W, align 8, !tbaa !5
  %32 = load i32, ptr %4, align 4, !tbaa !9
  %33 = call noundef i64 @_Z3twoxxi(i64 noundef %30, i64 noundef %31, i32 noundef %32)
  %34 = getelementptr inbounds [3 x i64], ptr %5, i64 0, i64 1
  store i64 %33, ptr %34, align 8, !tbaa !5
  %35 = load i64, ptr @H, align 8, !tbaa !5
  %36 = load i32, ptr %2, align 4, !tbaa !9
  %37 = sext i32 %36 to i64
  %38 = sub nsw i64 %35, %37
  %39 = load i64, ptr @W, align 8, !tbaa !5
  %40 = mul nsw i64 %38, %39
  %41 = getelementptr inbounds [3 x i64], ptr %5, i64 0, i64 1
  %42 = load i64, ptr %41, align 8, !tbaa !5
  %43 = sub nsw i64 %40, %42
  %44 = getelementptr inbounds [3 x i64], ptr %5, i64 0, i64 2
  store i64 %43, ptr %44, align 16, !tbaa !5
  %45 = getelementptr inbounds [3 x i64], ptr %5, i64 0, i64 0
  %46 = getelementptr inbounds [3 x i64], ptr %5, i64 0, i64 0
  %47 = getelementptr inbounds i64, ptr %46, i64 3
  call void @_ZSt4sortIPxEvT_S1_(ptr noundef %45, ptr noundef %47)
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #5
  %48 = getelementptr inbounds [3 x i64], ptr %5, i64 0, i64 2
  %49 = load i64, ptr %48, align 16, !tbaa !5
  %50 = getelementptr inbounds [3 x i64], ptr %5, i64 0, i64 0
  %51 = load i64, ptr %50, align 16, !tbaa !5
  %52 = sub nsw i64 %49, %51
  store i64 %52, ptr %6, align 8, !tbaa !5
  %53 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3minIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) %1, ptr noundef nonnull align 8 dereferenceable(8) %6)
  %54 = load i64, ptr %53, align 8, !tbaa !5
  store i64 %54, ptr %1, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #5
  call void @llvm.lifetime.end.p0(i64 24, ptr %5) #5
  br label %55

55:                                               ; preds = %21
  %56 = load i32, ptr %4, align 4, !tbaa !9
  %57 = add nsw i32 %56, 1
  store i32 %57, ptr %4, align 4, !tbaa !9
  br label %17, !llvm.loop !11

58:                                               ; preds = %20
  br label %59

59:                                               ; preds = %58
  %60 = load i32, ptr %2, align 4, !tbaa !9
  %61 = add nsw i32 %60, 1
  store i32 %61, ptr %2, align 4, !tbaa !9
  br label %10, !llvm.loop !13

62:                                               ; preds = %15
  %63 = load i64, ptr %1, align 8, !tbaa !5
  store i32 1, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %1) #5
  ret i64 %63
}

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

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZSt4sortIPxEvT_S1_(ptr noundef, ptr noundef) #3

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3minIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(8)) #4

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { inlinehint 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 #4 = { inlinehint 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 #5 = { 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 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !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"

@H = external dso_local local_unnamed_addr global i64, align 8
@W = external dso_local local_unnamed_addr global i64, align 8

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_Z3twoxxi(i64 noundef, i64 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local noundef i64 @_Z5solvev() local_unnamed_addr #1 {
  %1 = alloca i64, align 8
  %2 = alloca [3 x i64], align 16
  %3 = alloca i64, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %1) #5
  %4 = load i64, ptr @H, align 8, !tbaa !5
  %5 = load i64, ptr @W, align 8, !tbaa !5
  %6 = mul nsw i64 %5, %4
  store i64 %6, ptr %1, align 8, !tbaa !5
  %7 = icmp sgt i64 %4, 1
  br i1 %7, label %.preheader.lr.ph, label %._crit_edge

.preheader.lr.ph:                                 ; preds = %0
  %8 = getelementptr inbounds i8, ptr %2, i64 8
  %9 = getelementptr inbounds i8, ptr %2, i64 16
  %10 = getelementptr inbounds i8, ptr %2, i64 24
  br label %.preheader

.preheader:                                       ; preds = %.preheader.lr.ph, %.preheader
  %11 = phi i64 [ %4, %.preheader.lr.ph ], [ %41, %.preheader ]
  %indvars.iv = phi i64 [ 1, %.preheader.lr.ph ], [ %indvars.iv.next, %.preheader ]
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %2) #5
  %12 = load i64, ptr @W, align 8, !tbaa !5
  %13 = mul nsw i64 %12, %indvars.iv
  store i64 %13, ptr %2, align 16, !tbaa !5
  %14 = sub nsw i64 %11, %indvars.iv
  %15 = call noundef i64 @_Z3twoxxi(i64 noundef %14, i64 noundef %12, i32 noundef 0)
  store i64 %15, ptr %8, align 8, !tbaa !5
  %16 = load i64, ptr @H, align 8, !tbaa !5
  %17 = sub nsw i64 %16, %indvars.iv
  %18 = load i64, ptr @W, align 8, !tbaa !5
  %19 = mul nsw i64 %17, %18
  %20 = sub nsw i64 %19, %15
  store i64 %20, ptr %9, align 16, !tbaa !5
  call void @_ZSt4sortIPxEvT_S1_(ptr noundef nonnull %2, ptr noundef nonnull %10)
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #5
  %21 = load i64, ptr %9, align 16, !tbaa !5
  %22 = load i64, ptr %2, align 16, !tbaa !5
  %23 = sub nsw i64 %21, %22
  store i64 %23, ptr %3, align 8, !tbaa !5
  %24 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3minIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) %1, ptr noundef nonnull align 8 dereferenceable(8) %3)
  %25 = load i64, ptr %24, align 8, !tbaa !5
  store i64 %25, ptr %1, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #5
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %2) #5
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %2) #5
  %26 = load i64, ptr @W, align 8, !tbaa !5
  %27 = mul nsw i64 %26, %indvars.iv
  store i64 %27, ptr %2, align 16, !tbaa !5
  %28 = load i64, ptr @H, align 8, !tbaa !5
  %29 = sub nsw i64 %28, %indvars.iv
  %30 = call noundef i64 @_Z3twoxxi(i64 noundef %29, i64 noundef %26, i32 noundef 1)
  store i64 %30, ptr %8, align 8, !tbaa !5
  %31 = load i64, ptr @H, align 8, !tbaa !5
  %32 = sub nsw i64 %31, %indvars.iv
  %33 = load i64, ptr @W, align 8, !tbaa !5
  %34 = mul nsw i64 %32, %33
  %35 = sub nsw i64 %34, %30
  store i64 %35, ptr %9, align 16, !tbaa !5
  call void @_ZSt4sortIPxEvT_S1_(ptr noundef nonnull %2, ptr noundef nonnull %10)
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #5
  %36 = load i64, ptr %9, align 16, !tbaa !5
  %37 = load i64, ptr %2, align 16, !tbaa !5
  %38 = sub nsw i64 %36, %37
  store i64 %38, ptr %3, align 8, !tbaa !5
  %39 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3minIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) %1, ptr noundef nonnull align 8 dereferenceable(8) %3)
  %40 = load i64, ptr %39, align 8, !tbaa !5
  store i64 %40, ptr %1, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #5
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %2) #5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %41 = load i64, ptr @H, align 8, !tbaa !5
  %42 = icmp sgt i64 %41, %indvars.iv.next
  br i1 %42, label %.preheader, label %._crit_edge, !llvm.loop !9

._crit_edge:                                      ; preds = %.preheader, %0
  %43 = phi i64 [ %6, %0 ], [ %40, %.preheader ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %1) #5
  ret i64 %43
}

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

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZSt4sortIPxEvT_S1_(ptr noundef, ptr noundef) local_unnamed_addr #3

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3minIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #4

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { inlinehint 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 #4 = { inlinehint 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 #5 = { 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"}


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