; LLVM IR from Shah-Shishir/Codeforces-Solutions :: 204A. Little Elephant and Interval (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"

@.str = external hidden unnamed_addr constant [6 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [6 x i8], align 1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_Z8strtolldPc(ptr noundef) #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 noundef zeroext i1 @_Z8isLargerx(i64 noundef) #0

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #2 {
  %1 = alloca i32, align 4
  %2 = alloca [22 x i8], align 16
  %3 = alloca [22 x i8], align 16
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 22, ptr %2) #6
  call void @llvm.lifetime.start.p0(i64 22, ptr %3) #6
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #6
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #6
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #6
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #6
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #6
  br label %9

9:                                                ; preds = %70, %0
  %10 = getelementptr inbounds [22 x i8], ptr %2, i64 0, i64 0
  %11 = getelementptr inbounds [22 x i8], ptr %3, i64 0, i64 0
  %12 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %10, ptr noundef %11)
  %13 = icmp ne i32 %12, -1
  br i1 %13, label %14, label %75

14:                                               ; preds = %9
  %15 = getelementptr inbounds [22 x i8], ptr %2, i64 0, i64 0
  %16 = call noundef i64 @_Z8strtolldPc(ptr noundef %15)
  %17 = sub nsw i64 %16, 1
  store i64 %17, ptr %5, align 8, !tbaa !5
  %18 = getelementptr inbounds [22 x i8], ptr %3, i64 0, i64 0
  %19 = call noundef i64 @_Z8strtolldPc(ptr noundef %18)
  store i64 %19, ptr %6, align 8, !tbaa !5
  %20 = load i64, ptr %5, align 8, !tbaa !5
  %21 = icmp eq i64 %20, 0
  br i1 %21, label %22, label %23

22:                                               ; preds = %14
  store i64 0, ptr %7, align 8, !tbaa !5
  br label %38

23:                                               ; preds = %14
  %24 = load i64, ptr %5, align 8, !tbaa !5
  %25 = call noundef double @_ZSt5log10IxEN9__gnu_cxx11__enable_ifIXsr12__is_integerIT_EE7__valueEdE6__typeES2_(i64 noundef %24)
  %26 = call double @llvm.floor.f64(double %25)
  %27 = fadd double %26, 1.000000e+00
  %28 = fptosi double %27 to i64
  store i64 %28, ptr %4, align 8, !tbaa !5
  %29 = load i64, ptr %4, align 8, !tbaa !5
  %30 = icmp eq i64 %29, 1
  br i1 %30, label %31, label %33

31:                                               ; preds = %23
  %32 = load i64, ptr %5, align 8, !tbaa !5
  store i64 %32, ptr %7, align 8, !tbaa !5
  br label %37

33:                                               ; preds = %23
  %34 = load i64, ptr %5, align 8, !tbaa !5
  %35 = sdiv i64 %34, 10
  %36 = add nsw i64 %35, 9
  store i64 %36, ptr %7, align 8, !tbaa !5
  br label %37

37:                                               ; preds = %33, %31
  br label %38

38:                                               ; preds = %37, %22
  %39 = load i64, ptr %6, align 8, !tbaa !5
  %40 = call noundef double @_ZSt5log10IxEN9__gnu_cxx11__enable_ifIXsr12__is_integerIT_EE7__valueEdE6__typeES2_(i64 noundef %39)
  %41 = call double @llvm.floor.f64(double %40)
  %42 = fadd double %41, 1.000000e+00
  %43 = fptosi double %42 to i64
  store i64 %43, ptr %4, align 8, !tbaa !5
  %44 = load i64, ptr %4, align 8, !tbaa !5
  %45 = icmp eq i64 %44, 1
  br i1 %45, label %46, label %48

46:                                               ; preds = %38
  %47 = load i64, ptr %6, align 8, !tbaa !5
  store i64 %47, ptr %8, align 8, !tbaa !5
  br label %52

48:                                               ; preds = %38
  %49 = load i64, ptr %6, align 8, !tbaa !5
  %50 = sdiv i64 %49, 10
  %51 = add nsw i64 %50, 9
  store i64 %51, ptr %8, align 8, !tbaa !5
  br label %52

52:                                               ; preds = %48, %46
  %53 = load i64, ptr %5, align 8, !tbaa !5
  %54 = call noundef zeroext i1 @_Z8isLargerx(i64 noundef %53)
  br i1 %54, label %55, label %61

55:                                               ; preds = %52
  %56 = load i64, ptr %7, align 8, !tbaa !5
  %57 = icmp sgt i64 %56, 0
  br i1 %57, label %58, label %61

58:                                               ; preds = %55
  %59 = load i64, ptr %7, align 8, !tbaa !5
  %60 = add nsw i64 %59, -1
  store i64 %60, ptr %7, align 8, !tbaa !5
  br label %61

61:                                               ; preds = %58, %55, %52
  %62 = load i64, ptr %6, align 8, !tbaa !5
  %63 = call noundef zeroext i1 @_Z8isLargerx(i64 noundef %62)
  br i1 %63, label %64, label %70

64:                                               ; preds = %61
  %65 = load i64, ptr %8, align 8, !tbaa !5
  %66 = icmp sgt i64 %65, 0
  br i1 %66, label %67, label %70

67:                                               ; preds = %64
  %68 = load i64, ptr %8, align 8, !tbaa !5
  %69 = add nsw i64 %68, -1
  store i64 %69, ptr %8, align 8, !tbaa !5
  br label %70

70:                                               ; preds = %67, %64, %61
  %71 = load i64, ptr %8, align 8, !tbaa !5
  %72 = load i64, ptr %7, align 8, !tbaa !5
  %73 = sub nsw i64 %71, %72
  %74 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i64 noundef %73)
  br label %9, !llvm.loop !9

75:                                               ; preds = %9
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #6
  call void @llvm.lifetime.end.p0(i64 22, ptr %3) #6
  call void @llvm.lifetime.end.p0(i64 22, ptr %2) #6
  ret i32 0
}

declare i32 @__isoc99_scanf(ptr noundef, ...) #3

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef double @_ZSt5log10IxEN9__gnu_cxx11__enable_ifIXsr12__is_integerIT_EE7__valueEdE6__typeES2_(i64 noundef) #4

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.floor.f64(double) #5

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 = { 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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #6 = { 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"}


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

@.str = external hidden unnamed_addr constant [6 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [6 x i8], align 1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_Z8strtolldPc(ptr noundef) local_unnamed_addr #0

; 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 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 noundef zeroext i1 @_Z8isLargerx(i64 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress norecurse nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #2 {
  %1 = alloca [22 x i8], align 16
  %2 = alloca [22 x i8], align 16
  call void @llvm.lifetime.start.p0(i64 22, ptr nonnull %1) #6
  call void @llvm.lifetime.start.p0(i64 22, ptr nonnull %2) #6
  %3 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %1, ptr noundef nonnull %2)
  %.not23 = icmp eq i32 %3, -1
  br i1 %.not23, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %0, %26
  %4 = call noundef i64 @_Z8strtolldPc(ptr noundef nonnull %1)
  %5 = add nsw i64 %4, -1
  %6 = call noundef i64 @_Z8strtolldPc(ptr noundef nonnull %2)
  %7 = icmp eq i64 %5, 0
  br i1 %7, label %17, label %8

8:                                                ; preds = %.lr.ph
  %9 = call noundef double @_ZSt5log10IxEN9__gnu_cxx11__enable_ifIXsr12__is_integerIT_EE7__valueEdE6__typeES2_(i64 noundef %5)
  %10 = call double @llvm.floor.f64(double %9)
  %11 = fadd double %10, 1.000000e+00
  %12 = fptosi double %11 to i64
  %13 = icmp eq i64 %12, 1
  br i1 %13, label %17, label %14

14:                                               ; preds = %8
  %15 = sdiv i64 %5, 10
  %16 = add nsw i64 %15, 9
  br label %17

17:                                               ; preds = %8, %.lr.ph, %14
  %.020 = phi i64 [ %16, %14 ], [ 0, %.lr.ph ], [ %5, %8 ]
  %18 = call noundef double @_ZSt5log10IxEN9__gnu_cxx11__enable_ifIXsr12__is_integerIT_EE7__valueEdE6__typeES2_(i64 noundef %6)
  %19 = call double @llvm.floor.f64(double %18)
  %20 = fadd double %19, 1.000000e+00
  %21 = fptosi double %20 to i64
  %22 = icmp eq i64 %21, 1
  br i1 %22, label %26, label %23

23:                                               ; preds = %17
  %24 = sdiv i64 %6, 10
  %25 = add nsw i64 %24, 9
  br label %26

26:                                               ; preds = %17, %23
  %.0 = phi i64 [ %25, %23 ], [ %6, %17 ]
  %27 = call noundef zeroext i1 @_Z8isLargerx(i64 noundef %5)
  %28 = icmp sgt i64 %.020, 0
  %or.cond = select i1 %27, i1 %28, i1 false
  %.neg24 = zext i1 %or.cond to i64
  %29 = call noundef zeroext i1 @_Z8isLargerx(i64 noundef %6)
  %30 = icmp sgt i64 %.0, 0
  %or.cond3 = select i1 %29, i1 %30, i1 false
  %31 = sext i1 %or.cond3 to i64
  %spec.select.neg = sub i64 %.0, %.020
  %.1 = add i64 %spec.select.neg, %.neg24
  %32 = add i64 %.1, %31
  %33 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i64 noundef %32)
  %34 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %1, ptr noundef nonnull %2)
  %.not = icmp eq i32 %34, -1
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !5

._crit_edge:                                      ; preds = %26, %0
  call void @llvm.lifetime.end.p0(i64 22, ptr nonnull %2) #6
  call void @llvm.lifetime.end.p0(i64 22, ptr nonnull %1) #6
  ret i32 0
}

; Function Attrs: nofree nounwind
declare noundef i32 @__isoc99_scanf(ptr nocapture noundef readonly, ...) local_unnamed_addr #3

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef double @_ZSt5log10IxEN9__gnu_cxx11__enable_ifIXsr12__is_integerIT_EE7__valueEdE6__typeES2_(i64 noundef) local_unnamed_addr #4

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.floor.f64(double) #5

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #3 = { 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" }
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 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #6 = { 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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}


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