; LLVM IR from kazunetakahashi/atcoder :: 2017/0930_tenka1-2017 (C)

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

%"class.std::basic_istream" = type { ptr, i64, %"class.std::basic_ios" }
%"class.std::basic_ios" = type { %"class.std::ios_base", ptr, i8, i8, ptr, ptr, ptr, ptr }
%"class.std::ios_base" = type { ptr, i64, i64, i32, i32, i32, ptr, %"struct.std::ios_base::_Words", [8 x %"struct.std::ios_base::_Words"], i32, ptr, %"class.std::locale" }
%"struct.std::ios_base::_Words" = type { ptr, i64 }
%"class.std::locale" = type { ptr }
%"class.std::basic_ostream" = type { ptr, %"class.std::basic_ios" }

@N = external dso_local global i64, align 8
@_ZSt3cin = external global %"class.std::basic_istream", align 8
@_ZSt4cout = external global %"class.std::basic_ostream", align 8
@.str = external hidden unnamed_addr constant [2 x i8], align 1

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #0 {
  %1 = alloca i32, align 4
  %2 = alloca i64, align 8
  %3 = alloca i32, align 4
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  store i32 0, ptr %1, align 4
  %7 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERx(ptr noundef nonnull align 8 dereferenceable(16) @_ZSt3cin, ptr noundef nonnull align 8 dereferenceable(8) @N)
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #4
  store i64 1, ptr %2, align 8, !tbaa !5
  br label %8

8:                                                ; preds = %93, %0
  %9 = load i64, ptr %2, align 8, !tbaa !5
  %10 = icmp sle i64 %9, 3500
  br i1 %10, label %12, label %11

11:                                               ; preds = %8
  store i32 2, ptr %3, align 4
  br label %96

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

13:                                               ; preds = %87, %12
  %14 = load i64, ptr %4, align 8, !tbaa !5
  %15 = icmp sle i64 %14, 3500
  br i1 %15, label %17, label %16

16:                                               ; preds = %13
  store i32 5, ptr %3, align 4
  br label %90

17:                                               ; preds = %13
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  %18 = load i64, ptr %2, align 8, !tbaa !5
  %19 = mul nsw i64 4, %18
  %20 = load i64, ptr %4, align 8, !tbaa !5
  %21 = mul nsw i64 %19, %20
  %22 = load i64, ptr @N, align 8, !tbaa !5
  %23 = load i64, ptr %4, align 8, !tbaa !5
  %24 = mul nsw i64 %22, %23
  %25 = sub nsw i64 %21, %24
  %26 = load i64, ptr @N, align 8, !tbaa !5
  %27 = load i64, ptr %2, align 8, !tbaa !5
  %28 = mul nsw i64 %26, %27
  %29 = sub nsw i64 %25, %28
  store i64 %29, ptr %5, align 8, !tbaa !5
  %30 = load i64, ptr %5, align 8, !tbaa !5
  %31 = icmp sle i64 %30, 0
  br i1 %31, label %32, label %33

32:                                               ; preds = %17
  store i32 7, ptr %3, align 4
  br label %84

33:                                               ; preds = %17
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  %34 = load i64, ptr @N, align 8, !tbaa !5
  %35 = load i64, ptr %2, align 8, !tbaa !5
  %36 = mul nsw i64 %34, %35
  %37 = load i64, ptr %4, align 8, !tbaa !5
  %38 = mul nsw i64 %36, %37
  %39 = load i64, ptr %2, align 8, !tbaa !5
  %40 = mul nsw i64 4, %39
  %41 = load i64, ptr %4, align 8, !tbaa !5
  %42 = mul nsw i64 %40, %41
  %43 = load i64, ptr @N, align 8, !tbaa !5
  %44 = load i64, ptr %4, align 8, !tbaa !5
  %45 = mul nsw i64 %43, %44
  %46 = sub nsw i64 %42, %45
  %47 = load i64, ptr @N, align 8, !tbaa !5
  %48 = load i64, ptr %2, align 8, !tbaa !5
  %49 = mul nsw i64 %47, %48
  %50 = sub nsw i64 %46, %49
  %51 = sdiv i64 %38, %50
  store i64 %51, ptr %6, align 8, !tbaa !5
  %52 = load i64, ptr %2, align 8, !tbaa !5
  %53 = mul nsw i64 4, %52
  %54 = load i64, ptr %4, align 8, !tbaa !5
  %55 = mul nsw i64 %53, %54
  %56 = load i64, ptr %6, align 8, !tbaa !5
  %57 = mul nsw i64 %55, %56
  %58 = load i64, ptr @N, align 8, !tbaa !5
  %59 = load i64, ptr %2, align 8, !tbaa !5
  %60 = load i64, ptr %4, align 8, !tbaa !5
  %61 = mul nsw i64 %59, %60
  %62 = load i64, ptr %4, align 8, !tbaa !5
  %63 = load i64, ptr %6, align 8, !tbaa !5
  %64 = mul nsw i64 %62, %63
  %65 = add nsw i64 %61, %64
  %66 = load i64, ptr %6, align 8, !tbaa !5
  %67 = load i64, ptr %2, align 8, !tbaa !5
  %68 = mul nsw i64 %66, %67
  %69 = add nsw i64 %65, %68
  %70 = mul nsw i64 %58, %69
  %71 = icmp eq i64 %57, %70
  br i1 %71, label %72, label %82

72:                                               ; preds = %33
  %73 = load i64, ptr %2, align 8, !tbaa !5
  %74 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEx(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, i64 noundef %73)
  %75 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc(ptr noundef nonnull align 8 dereferenceable(8) %74, ptr noundef @.str)
  %76 = load i64, ptr %4, align 8, !tbaa !5
  %77 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEx(ptr noundef nonnull align 8 dereferenceable(8) %75, i64 noundef %76)
  %78 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc(ptr noundef nonnull align 8 dereferenceable(8) %77, ptr noundef @.str)
  %79 = load i64, ptr %6, align 8, !tbaa !5
  %80 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEx(ptr noundef nonnull align 8 dereferenceable(8) %78, i64 noundef %79)
  %81 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEPFRSoS_E(ptr noundef nonnull align 8 dereferenceable(8) %80, ptr noundef @_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_)
  store i32 0, ptr %1, align 4
  store i32 1, ptr %3, align 4
  br label %83

82:                                               ; preds = %33
  store i32 0, ptr %3, align 4
  br label %83

83:                                               ; preds = %82, %72
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  br label %84

84:                                               ; preds = %83, %32
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  %85 = load i32, ptr %3, align 4
  switch i32 %85, label %90 [
    i32 0, label %86
    i32 7, label %87
  ]

86:                                               ; preds = %84
  br label %87

87:                                               ; preds = %86, %84
  %88 = load i64, ptr %4, align 8, !tbaa !5
  %89 = add nsw i64 %88, 1
  store i64 %89, ptr %4, align 8, !tbaa !5
  br label %13, !llvm.loop !9

90:                                               ; preds = %84, %16
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  %91 = load i32, ptr %3, align 4
  switch i32 %91, label %96 [
    i32 5, label %92
  ]

92:                                               ; preds = %90
  br label %93

93:                                               ; preds = %92
  %94 = load i64, ptr %2, align 8, !tbaa !5
  %95 = add nsw i64 %94, 1
  store i64 %95, ptr %2, align 8, !tbaa !5
  br label %8, !llvm.loop !11

96:                                               ; preds = %90, %11
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #4
  %97 = load i32, ptr %3, align 4
  switch i32 %97, label %100 [
    i32 2, label %98
    i32 1, label %98
  ]

98:                                               ; preds = %96, %96
  %99 = load i32, ptr %1, align 4
  ret i32 %99

100:                                              ; preds = %96
  unreachable
}

; Function Attrs: mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERx(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 8 dereferenceable(8)) #1 align 2

; 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 noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef) #3

; Function Attrs: mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEx(ptr noundef nonnull align 8 dereferenceable(8), i64 noundef) #1 align 2

; Function Attrs: mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEPFRSoS_E(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef) #1 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(8) ptr @_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_(ptr noundef nonnull align 8 dereferenceable(8)) #3

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

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 = { 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 = { 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"

%"class.std::basic_istream" = type { ptr, i64, %"class.std::basic_ios" }
%"class.std::basic_ios" = type { %"class.std::ios_base", ptr, i8, i8, ptr, ptr, ptr, ptr }
%"class.std::ios_base" = type { ptr, i64, i64, i32, i32, i32, ptr, %"struct.std::ios_base::_Words", [8 x %"struct.std::ios_base::_Words"], i32, ptr, %"class.std::locale" }
%"struct.std::ios_base::_Words" = type { ptr, i64 }
%"class.std::locale" = type { ptr }
%"class.std::basic_ostream" = type { ptr, %"class.std::basic_ios" }

@N = external dso_local global i64, align 8
@_ZSt3cin = external global %"class.std::basic_istream", align 8
@_ZSt4cout = external global %"class.std::basic_ostream", align 8
@.str = external hidden unnamed_addr constant [2 x i8], align 1

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = tail call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERx(ptr noundef nonnull align 8 dereferenceable(16) @_ZSt3cin, ptr noundef nonnull align 8 dereferenceable(8) @N)
  %2 = load i64, ptr @N, align 8, !tbaa !5
  br label %.preheader

.preheader:                                       ; preds = %0, %.critedge
  %.03040 = phi i64 [ 1, %0 ], [ %30, %.critedge ]
  %3 = shl nuw nsw i64 %.03040, 2
  %4 = sub i64 %3, %2
  %5 = mul nsw i64 %2, %.03040
  br label %6

6:                                                ; preds = %.preheader, %21
  %.03139 = phi i64 [ 1, %.preheader ], [ %22, %21 ]
  %7 = mul i64 %4, %.03139
  %8 = sub nsw i64 %7, %5
  %9 = icmp slt i64 %8, 1
  br i1 %9, label %21, label %10

10:                                               ; preds = %6
  %11 = mul nuw nsw i64 %.03139, %3
  %12 = mul nsw i64 %5, %.03139
  %13 = sdiv i64 %12, %8
  %14 = mul nsw i64 %11, %13
  %15 = add i64 %13, %.03040
  %16 = mul i64 %15, %.03139
  %17 = mul nsw i64 %13, %.03040
  %18 = add nsw i64 %16, %17
  %19 = mul nsw i64 %18, %2
  %20 = icmp eq i64 %14, %19
  br i1 %20, label %23, label %21

21:                                               ; preds = %6, %10
  %22 = add nuw nsw i64 %.03139, 1
  %exitcond = icmp eq i64 %22, 3501
  br i1 %exitcond, label %.critedge, label %6, !llvm.loop !9

23:                                               ; preds = %10
  %24 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEx(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, i64 noundef %.03040)
  %25 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc(ptr noundef nonnull align 8 dereferenceable(8) %24, ptr noundef nonnull @.str)
  %26 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEx(ptr noundef nonnull align 8 dereferenceable(8) %25, i64 noundef %.03139)
  %27 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc(ptr noundef nonnull align 8 dereferenceable(8) %26, ptr noundef nonnull @.str)
  %28 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEx(ptr noundef nonnull align 8 dereferenceable(8) %27, i64 noundef %13)
  %29 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEPFRSoS_E(ptr noundef nonnull align 8 dereferenceable(8) %28, ptr noundef nonnull @_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_)
  br label %.loopexit

.critedge:                                        ; preds = %21
  %30 = add nuw nsw i64 %.03040, 1
  %exitcond43.not = icmp eq i64 %30, 3501
  br i1 %exitcond43.not, label %.loopexit, label %.preheader, !llvm.loop !11

.loopexit:                                        ; preds = %.critedge, %23
  ret i32 0
}

; Function Attrs: mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERx(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #1 align 2

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

; Function Attrs: mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEx(ptr noundef nonnull align 8 dereferenceable(8), i64 noundef) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEPFRSoS_E(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef) local_unnamed_addr #1 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(8) ptr @_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_(ptr noundef nonnull align 8 dereferenceable(8)) #2

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

!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,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass