; LLVM IR from Izaron/ACM-ICPC :: Timus Online Judge/Volume 8/1756. One and a Half Diggers (main)

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

@_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 double, align 8
  %3 = alloca double, align 8
  %4 = alloca double, align 8
  %5 = alloca i64, align 8
  %6 = alloca i32, align 4
  %7 = alloca double, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  %11 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERd(ptr noundef nonnull align 8 dereferenceable(16) @_ZSt3cin, ptr noundef nonnull align 8 dereferenceable(8) %2)
  %12 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERd(ptr noundef nonnull align 8 dereferenceable(16) %11, ptr noundef nonnull align 8 dereferenceable(8) %3)
  %13 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERd(ptr noundef nonnull align 8 dereferenceable(16) %12, ptr noundef nonnull align 8 dereferenceable(8) %4)
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  %14 = load double, ptr %3, align 8, !tbaa !5
  %15 = load double, ptr %2, align 8, !tbaa !5
  %16 = fmul double %14, %15
  %17 = load double, ptr %4, align 8, !tbaa !5
  %18 = fdiv double %16, %17
  %19 = fadd double %18, 1.000000e+00
  %20 = fptosi double %19 to i32
  %21 = sext i32 %20 to i64
  store i64 %21, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  store i32 0, ptr %6, align 4, !tbaa !11
  store i32 0, ptr %6, align 4, !tbaa !11
  br label %22

22:                                               ; preds = %57, %0
  %23 = load i32, ptr %6, align 4, !tbaa !11
  %24 = sitofp i32 %23 to double
  %25 = load double, ptr %4, align 8, !tbaa !5
  %26 = fcmp olt double %24, %25
  br i1 %26, label %27, label %60

27:                                               ; preds = %22
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %28 = load i32, ptr %6, align 4, !tbaa !11
  %29 = sext i32 %28 to i64
  %30 = load i64, ptr %5, align 8, !tbaa !9
  %31 = mul nsw i64 %29, %30
  %32 = sitofp i64 %31 to double
  %33 = load double, ptr %3, align 8, !tbaa !5
  %34 = load double, ptr %2, align 8, !tbaa !5
  %35 = fmul double %33, %34
  %36 = fdiv double %32, %35
  %37 = load double, ptr %4, align 8, !tbaa !5
  %38 = load i32, ptr %6, align 4, !tbaa !11
  %39 = sitofp i32 %38 to double
  %40 = fsub double %37, %39
  %41 = load i64, ptr %5, align 8, !tbaa !9
  %42 = sub nsw i64 %41, 1
  %43 = sitofp i64 %42 to double
  %44 = fmul double %40, %43
  %45 = load double, ptr %3, align 8, !tbaa !5
  %46 = load double, ptr %2, align 8, !tbaa !5
  %47 = fmul double %45, %46
  %48 = fdiv double %44, %47
  %49 = fadd double %36, %48
  store double %49, ptr %7, align 8, !tbaa !5
  %50 = load double, ptr %7, align 8, !tbaa !5
  %51 = fcmp oge double %50, 1.000000e+00
  br i1 %51, label %52, label %53

52:                                               ; preds = %27
  store i32 2, ptr %8, align 4
  br label %54

53:                                               ; preds = %27
  store i32 0, ptr %8, align 4
  br label %54

54:                                               ; preds = %53, %52
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  %55 = load i32, ptr %8, align 4
  switch i32 %55, label %93 [
    i32 0, label %56
    i32 2, label %60
  ]

56:                                               ; preds = %54
  br label %57

57:                                               ; preds = %56
  %58 = load i32, ptr %6, align 4, !tbaa !11
  %59 = add nsw i32 %58, 1
  store i32 %59, ptr %6, align 4, !tbaa !11
  br label %22, !llvm.loop !13

60:                                               ; preds = %54, %22
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  store i32 0, ptr %9, align 4, !tbaa !11
  br label %61

61:                                               ; preds = %70, %60
  %62 = load i32, ptr %9, align 4, !tbaa !11
  %63 = load i32, ptr %6, align 4, !tbaa !11
  %64 = icmp slt i32 %62, %63
  br i1 %64, label %66, label %65

65:                                               ; preds = %61
  store i32 5, ptr %8, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  br label %73

66:                                               ; preds = %61
  %67 = load i64, ptr %5, align 8, !tbaa !9
  %68 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEx(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, i64 noundef %67)
  %69 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc(ptr noundef nonnull align 8 dereferenceable(8) %68, ptr noundef @.str)
  br label %70

70:                                               ; preds = %66
  %71 = load i32, ptr %9, align 4, !tbaa !11
  %72 = add nsw i32 %71, 1
  store i32 %72, ptr %9, align 4, !tbaa !11
  br label %61, !llvm.loop !15

73:                                               ; preds = %65
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  store i32 0, ptr %10, align 4, !tbaa !11
  br label %74

74:                                               ; preds = %88, %73
  %75 = load i32, ptr %10, align 4, !tbaa !11
  %76 = sitofp i32 %75 to double
  %77 = load double, ptr %4, align 8, !tbaa !5
  %78 = load i32, ptr %6, align 4, !tbaa !11
  %79 = sitofp i32 %78 to double
  %80 = fsub double %77, %79
  %81 = fcmp olt double %76, %80
  br i1 %81, label %83, label %82

82:                                               ; preds = %74
  store i32 8, ptr %8, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  br label %91

83:                                               ; preds = %74
  %84 = load i64, ptr %5, align 8, !tbaa !9
  %85 = sub nsw i64 %84, 1
  %86 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEx(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, i64 noundef %85)
  %87 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc(ptr noundef nonnull align 8 dereferenceable(8) %86, ptr noundef @.str)
  br label %88

88:                                               ; preds = %83
  %89 = load i32, ptr %10, align 4, !tbaa !11
  %90 = add nsw i32 %89, 1
  store i32 %90, ptr %10, align 4, !tbaa !11
  br label %74, !llvm.loop !16

91:                                               ; preds = %82
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #4
  %92 = load i32, ptr %1, align 4
  ret i32 %92

93:                                               ; preds = %54
  unreachable
}

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

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

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

; 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) #2 align 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #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 = !{!"double", !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 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}
!16 = distinct !{!16, !14}


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

@_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 = alloca double, align 8
  %2 = alloca double, align 8
  %3 = alloca double, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %1) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #4
  %4 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERd(ptr noundef nonnull align 8 dereferenceable(16) @_ZSt3cin, ptr noundef nonnull align 8 dereferenceable(8) %1)
  %5 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERd(ptr noundef nonnull align 8 dereferenceable(16) %4, ptr noundef nonnull align 8 dereferenceable(8) %2)
  %6 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERd(ptr noundef nonnull align 8 dereferenceable(16) %5, ptr noundef nonnull align 8 dereferenceable(8) %3)
  %7 = load double, ptr %2, align 8, !tbaa !5
  %8 = load double, ptr %1, align 8, !tbaa !5
  %9 = fmul double %7, %8
  %10 = load double, ptr %3, align 8, !tbaa !5
  %11 = fdiv double %9, %10
  %12 = fadd double %11, 1.000000e+00
  %13 = fptosi double %12 to i32
  %14 = sext i32 %13 to i64
  %15 = fcmp ogt double %10, 0.000000e+00
  br i1 %15, label %.lr.ph, label %.preheader

.lr.ph:                                           ; preds = %0
  %16 = add nsw i64 %14, -1
  %17 = sitofp i64 %16 to double
  %18 = insertelement <2 x double> poison, double %9, i64 0
  %19 = shufflevector <2 x double> %18, <2 x double> poison, <2 x i32> zeroinitializer
  br label %20

20:                                               ; preds = %.lr.ph, %32
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %32 ]
  %21 = phi double [ 0.000000e+00, %.lr.ph ], [ %33, %32 ]
  %22 = mul nsw i64 %indvars.iv, %14
  %23 = sitofp i64 %22 to double
  %24 = fsub double %10, %21
  %25 = fmul double %24, %17
  %26 = insertelement <2 x double> poison, double %23, i64 0
  %27 = insertelement <2 x double> %26, double %25, i64 1
  %28 = fdiv <2 x double> %27, %19
  %shift = shufflevector <2 x double> %28, <2 x double> poison, <2 x i32> <i32 1, i32 poison>
  %29 = fadd <2 x double> %28, %shift
  %30 = extractelement <2 x double> %29, i64 0
  %31 = fcmp ult double %30, 1.000000e+00
  br i1 %31, label %32, label %._crit_edge.split.loop.exit37

32:                                               ; preds = %20
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %indvars = trunc i64 %indvars.iv.next to i32
  %33 = uitofp nneg i32 %indvars to double
  %34 = fcmp ogt double %10, %33
  br i1 %34, label %20, label %._crit_edge, !llvm.loop !9

._crit_edge.split.loop.exit37:                    ; preds = %20
  %35 = trunc nuw nsw i64 %indvars.iv to i32
  br label %._crit_edge

._crit_edge:                                      ; preds = %32, %._crit_edge.split.loop.exit37
  %.018.lcssa = phi i32 [ %35, %._crit_edge.split.loop.exit37 ], [ %indvars, %32 ]
  %.lcssa = phi double [ %21, %._crit_edge.split.loop.exit37 ], [ %33, %32 ]
  %.not = icmp eq i32 %.018.lcssa, 0
  br i1 %.not, label %.preheader, label %.lr.ph28

.preheader.loopexit:                              ; preds = %.lr.ph28
  %.pre = load double, ptr %3, align 8, !tbaa !5
  br label %.preheader

.preheader:                                       ; preds = %0, %.preheader.loopexit, %._crit_edge
  %.lcssa36 = phi double [ %.lcssa, %.preheader.loopexit ], [ %.lcssa, %._crit_edge ], [ 0.000000e+00, %0 ]
  %36 = phi double [ %.pre, %.preheader.loopexit ], [ %10, %._crit_edge ], [ %10, %0 ]
  %37 = fcmp ogt double %36, %.lcssa36
  br i1 %37, label %.lr.ph30, label %._crit_edge31

.lr.ph30:                                         ; preds = %.preheader
  %38 = add nsw i64 %14, -1
  br label %42

.lr.ph28:                                         ; preds = %._crit_edge, %.lr.ph28
  %.01626 = phi i32 [ %41, %.lr.ph28 ], [ 0, %._crit_edge ]
  %39 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEx(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, i64 noundef %14)
  %40 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc(ptr noundef nonnull align 8 dereferenceable(8) %39, ptr noundef nonnull @.str)
  %41 = add nuw i32 %.01626, 1
  %exitcond.not = icmp eq i32 %41, %.018.lcssa
  br i1 %exitcond.not, label %.preheader.loopexit, label %.lr.ph28, !llvm.loop !11

._crit_edge31:                                    ; preds = %42, %.preheader
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %1) #4
  ret i32 0

42:                                               ; preds = %.lr.ph30, %42
  %.029 = phi i32 [ 0, %.lr.ph30 ], [ %45, %42 ]
  %43 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEx(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, i64 noundef %38)
  %44 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc(ptr noundef nonnull align 8 dereferenceable(8) %43, ptr noundef nonnull @.str)
  %45 = add nuw nsw i32 %.029, 1
  %46 = uitofp nneg i32 %45 to double
  %47 = load double, ptr %3, align 8, !tbaa !5
  %48 = fsub double %47, %.lcssa36
  %49 = fcmp ogt double %48, %46
  br i1 %49, label %42, label %._crit_edge31, !llvm.loop !12
}

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

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

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

; 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 #3

; 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 #2 align 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 nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #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 = !{!"double", !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}
!12 = distinct !{!12, !10}


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