; LLVM IR from xirc/cp-algorithm :: atcoder/abc013/C/main.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"

@N = external dso_local global i64, align 8
@H = external dso_local global i64, align 8
@A = external dso_local global i64, align 8
@B = external dso_local global i64, align 8
@C = external dso_local global i64, align 8
@D = external dso_local global i64, align 8
@E = external dso_local global i64, align 8

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

10:                                               ; preds = %61, %0
  %11 = load i64, ptr %3, align 8, !tbaa !5
  %12 = load i64, ptr @N, align 8, !tbaa !5
  %13 = icmp sle i64 %11, %12
  br i1 %13, label %15, label %14

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

15:                                               ; preds = %10
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  %16 = load i64, ptr @B, align 8, !tbaa !5
  %17 = load i64, ptr %3, align 8, !tbaa !5
  %18 = mul nsw i64 %16, %17
  %19 = load i64, ptr @D, align 8, !tbaa !5
  %20 = load i64, ptr @N, align 8, !tbaa !5
  %21 = mul nsw i64 %19, %20
  %22 = add nsw i64 %18, %21
  %23 = load i64, ptr @D, align 8, !tbaa !5
  %24 = load i64, ptr %3, align 8, !tbaa !5
  %25 = mul nsw i64 %23, %24
  %26 = sub nsw i64 %22, %25
  %27 = load i64, ptr @H, align 8, !tbaa !5
  %28 = add nsw i64 %26, %27
  %29 = sub nsw i64 %28, 1
  store i64 %29, ptr %5, align 8, !tbaa !5
  %30 = load i64, ptr %5, align 8, !tbaa !5
  %31 = icmp slt i64 %30, 0
  br i1 %31, label %32, label %33

32:                                               ; preds = %15
  store i32 4, ptr %4, align 4
  br label %58

33:                                               ; preds = %15
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %34 = load i64, ptr %5, align 8, !tbaa !5
  %35 = load i64, ptr @D, align 8, !tbaa !5
  %36 = load i64, ptr @E, align 8, !tbaa !5
  %37 = add nsw i64 %35, %36
  %38 = sdiv i64 %34, %37
  store i64 %38, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %39 = load i64, ptr @N, align 8, !tbaa !5
  %40 = load i64, ptr %3, align 8, !tbaa !5
  %41 = sub nsw i64 %39, %40
  store i64 %41, ptr %7, align 8, !tbaa !5
  %42 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3minIlERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) %6, ptr noundef nonnull align 8 dereferenceable(8) %7)
  %43 = load i64, ptr %42, align 8, !tbaa !5
  store i64 %43, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %44 = load i64, ptr @N, align 8, !tbaa !5
  %45 = load i64, ptr %3, align 8, !tbaa !5
  %46 = sub nsw i64 %44, %45
  %47 = load i64, ptr %6, align 8, !tbaa !5
  %48 = sub nsw i64 %46, %47
  store i64 %48, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  %49 = load i64, ptr @A, align 8, !tbaa !5
  %50 = load i64, ptr %3, align 8, !tbaa !5
  %51 = mul nsw i64 %49, %50
  %52 = load i64, ptr @C, align 8, !tbaa !5
  %53 = load i64, ptr %8, align 8, !tbaa !5
  %54 = mul nsw i64 %52, %53
  %55 = add nsw i64 %51, %54
  store i64 %55, ptr %9, align 8, !tbaa !5
  %56 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3minIlERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) %2, ptr noundef nonnull align 8 dereferenceable(8) %9)
  %57 = load i64, ptr %56, align 8, !tbaa !5
  store i64 %57, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  store i32 0, ptr %4, align 4
  br label %58

58:                                               ; preds = %33, %32
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  %59 = load i32, ptr %4, align 4
  switch i32 %59, label %66 [
    i32 0, label %60
    i32 4, label %61
  ]

60:                                               ; preds = %58
  br label %61

61:                                               ; preds = %60, %58
  %62 = load i64, ptr %3, align 8, !tbaa !5
  %63 = add nsw i64 %62, 1
  store i64 %63, ptr %3, align 8, !tbaa !5
  br label %10, !llvm.loop !9

64:                                               ; preds = %14
  %65 = load i64, ptr %2, align 8, !tbaa !5
  store i32 1, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %1) #3
  ret i64 %65

66:                                               ; preds = %58
  unreachable
}

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

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

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

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 = { 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 #3 = { 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", !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"

@N = external dso_local local_unnamed_addr global i64, align 8
@H = external dso_local local_unnamed_addr global i64, align 8
@A = external dso_local local_unnamed_addr global i64, align 8
@B = external dso_local local_unnamed_addr global i64, align 8
@C = external dso_local local_unnamed_addr global i64, align 8
@D = external dso_local local_unnamed_addr global i64, align 8
@E = external dso_local local_unnamed_addr global i64, align 8

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i64 @_Z5solvev() local_unnamed_addr #0 {
  %1 = alloca i64, align 8
  %2 = alloca i64, align 8
  %3 = alloca i64, align 8
  %4 = alloca i64, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %1) #3
  store i64 1000000000000000000, ptr %1, align 8, !tbaa !5
  %5 = load i64, ptr @N, align 8, !tbaa !5
  %.not14 = icmp slt i64 %5, 0
  br i1 %.not14, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %0
  %.pre16 = load i64, ptr @B, align 8, !tbaa !5
  %.pre18 = load i64, ptr @D, align 8, !tbaa !5
  %.pre20 = load i64, ptr @H, align 8, !tbaa !5
  br label %.lr.ph

._crit_edge:                                      ; preds = %33, %0
  %6 = phi i64 [ 1000000000000000000, %0 ], [ %34, %33 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %1) #3
  ret i64 %6

.lr.ph:                                           ; preds = %.lr.ph.preheader, %33
  %7 = phi i64 [ %34, %33 ], [ 1000000000000000000, %.lr.ph.preheader ]
  %8 = phi i64 [ %35, %33 ], [ %5, %.lr.ph.preheader ]
  %9 = phi i64 [ %36, %33 ], [ %.pre20, %.lr.ph.preheader ]
  %10 = phi i64 [ %37, %33 ], [ %.pre18, %.lr.ph.preheader ]
  %11 = phi i64 [ %38, %33 ], [ %.pre16, %.lr.ph.preheader ]
  %.015 = phi i64 [ %39, %33 ], [ 0, %.lr.ph.preheader ]
  %12 = mul nsw i64 %11, %.015
  %reass.add = sub i64 %8, %.015
  %reass.mul = mul i64 %reass.add, %10
  %13 = add i64 %9, %12
  %14 = add i64 %13, %reass.mul
  %15 = icmp slt i64 %14, 1
  br i1 %15, label %33, label %16

16:                                               ; preds = %.lr.ph
  %17 = add nsw i64 %14, -1
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #3
  %18 = load i64, ptr @E, align 8, !tbaa !5
  %19 = add nsw i64 %18, %10
  %20 = sdiv i64 %17, %19
  store i64 %20, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #3
  store i64 %reass.add, ptr %3, align 8, !tbaa !5
  %21 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3minIlERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) %2, ptr noundef nonnull align 8 dereferenceable(8) %3)
  %22 = load i64, ptr %21, align 8, !tbaa !5
  store i64 %22, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #3
  %23 = load i64, ptr @N, align 8, !tbaa !5
  %24 = add i64 %22, %.015
  %25 = sub i64 %23, %24
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #3
  %26 = load i64, ptr @A, align 8, !tbaa !5
  %27 = mul nsw i64 %26, %.015
  %28 = load i64, ptr @C, align 8, !tbaa !5
  %29 = mul nsw i64 %28, %25
  %30 = add nsw i64 %29, %27
  store i64 %30, ptr %4, align 8, !tbaa !5
  %31 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3minIlERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) %1, ptr noundef nonnull align 8 dereferenceable(8) %4)
  %32 = load i64, ptr %31, align 8, !tbaa !5
  store i64 %32, ptr %1, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #3
  %.pre = load i64, ptr @B, align 8, !tbaa !5
  %.pre17 = load i64, ptr @D, align 8, !tbaa !5
  %.pre19 = load i64, ptr @H, align 8, !tbaa !5
  %.pre21 = load i64, ptr @N, align 8, !tbaa !5
  br label %33

33:                                               ; preds = %.lr.ph, %16
  %34 = phi i64 [ %7, %.lr.ph ], [ %32, %16 ]
  %35 = phi i64 [ %8, %.lr.ph ], [ %.pre21, %16 ]
  %36 = phi i64 [ %9, %.lr.ph ], [ %.pre19, %16 ]
  %37 = phi i64 [ %10, %.lr.ph ], [ %.pre17, %16 ]
  %38 = phi i64 [ %11, %.lr.ph ], [ %.pre, %16 ]
  %39 = add nuw nsw i64 %.015, 1
  %.not.not = icmp slt i64 %.015, %35
  br i1 %.not.not, label %.lr.ph, label %._crit_edge, !llvm.loop !9
}

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

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

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

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 nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #3 = { 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", !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,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass