program main 
 implicit none
 integer*8 N,i,j,tmp
 read(*,*) N
 tmp = N - 1
 j = N/2
 do i=1,N/2
  if(mod(N,i)==0) then
   if(i-1+N/i-1 < tmp) then
    tmp = i-1+N/i-1
   end if
  end if
  j = min(j,N/i+1)
  if(j < i) exit
 end do
 write(*,*) tmp
end program main
  
; ModuleID = 'FIRModule'
source_filename = "FIRModule"
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-pc-linux-gnu"

@_QQcl.a055d478542a3282209c5bfd871b1b52 = linkonce constant [73 x i8] c"/home/ubuntu/Downloads/TheStack_IR/Collated/Fortran/Source_3068/source.f\00"
@_QQEnvironmentDefaults = local_unnamed_addr constant ptr null

define void @_QQmain() local_unnamed_addr {
  %1 = alloca i64, align 8
  %2 = tail call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.a055d478542a3282209c5bfd871b1b52, i32 4)
  %3 = call i1 @_FortranAioInputInteger(ptr %2, ptr nonnull %1, i32 8)
  %4 = call i32 @_FortranAioEndIoStatement(ptr %2)
  %5 = load i64, ptr %1, align 8, !tbaa !3
  %6 = add i64 %5, -1
  %7 = icmp sgt i64 %5, 1
  br i1 %7, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %0
  %8 = lshr i64 %5, 1
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph._crit_edge, %.lr.ph.preheader
  %.020 = phi i64 [ %6, %.lr.ph.preheader ], [ %.1, %.lr.ph._crit_edge ]
  %.01219 = phi i64 [ %8, %.lr.ph.preheader ], [ %16, %.lr.ph._crit_edge ]
  %.01318 = phi i64 [ 1, %.lr.ph.preheader ], [ %18, %.lr.ph._crit_edge ]
  %9 = srem i64 %5, %.01318
  %10 = icmp eq i64 %9, 0
  %11 = sdiv i64 %5, %.01318
  br i1 %10, label %12, label %.lr.ph._crit_edge

12:                                               ; preds = %.lr.ph
  %13 = add nsw i64 %.01318, -2
  %14 = add i64 %13, %11
  %spec.select = call i64 @llvm.smin.i64(i64 %14, i64 %.020)
  br label %.lr.ph._crit_edge

.lr.ph._crit_edge:                                ; preds = %.lr.ph, %12
  %.1 = phi i64 [ %spec.select, %12 ], [ %.020, %.lr.ph ]
  %15 = add i64 %11, 1
  %16 = call i64 @llvm.smin.i64(i64 %.01219, i64 %15)
  %17 = icmp slt i64 %16, %.01318
  %18 = add nuw nsw i64 %.01318, 1
  %exitcond.not = icmp eq i64 %.01318, %8
  %or.cond = select i1 %17, i1 true, i1 %exitcond.not
  br i1 %or.cond, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %.lr.ph._crit_edge, %0
  %.2 = phi i64 [ %6, %0 ], [ %.1, %.lr.ph._crit_edge ]
  %19 = call ptr @_FortranAioBeginExternalListOutput(i32 -1, ptr nonnull @_QQcl.a055d478542a3282209c5bfd871b1b52, i32 16)
  %20 = call i1 @_FortranAioOutputInteger64(ptr %19, i64 %.2)
  %21 = call i32 @_FortranAioEndIoStatement(ptr %19)
  ret void
}

declare ptr @_FortranAioBeginExternalListInput(i32, ptr, i32) local_unnamed_addr

declare i1 @_FortranAioInputInteger(ptr, ptr, i32) local_unnamed_addr

declare i32 @_FortranAioEndIoStatement(ptr) local_unnamed_addr

declare ptr @_FortranAioBeginExternalListOutput(i32, ptr, i32) local_unnamed_addr

declare i1 @_FortranAioOutputInteger64(ptr, i64) local_unnamed_addr

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.smin.i64(i64, i64) #0

attributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }

!llvm.module.flags = !{!0, !1, !2}

!0 = !{i32 2, !"Debug Info Version", i32 3}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{!4, !4, i64 0}
!4 = !{!"any data access", !5, i64 0}
!5 = !{!"any access", !6, i64 0}
!6 = !{!"Flang Type TBAA Root"}
