program example
	implicit none

	integer(8) N,K
    
    read(*,*) N,K

    if(mod(N,K)==0) then
        write(*,*) 0

    else if(mod(N,K)<dble(K)/2.0d0) then
        write(*,*) mod(N,K)

    else
        write(*,*) K-mod(N,K)
    end if


!    do
!    	if(abs(N-K)>=N) then
!        	write(*,*) N
!            exit
!        else
!        	N=abs(N-K)
!        end if
!    end do

end program example

; 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.996fe97664c4c14f30cc8f6dbb58a427 = linkonce constant [73 x i8] c"/home/ubuntu/Downloads/TheStack_IR/Collated/Fortran/Source_1899/source.f\00"
@_QQEnvironmentDefaults = local_unnamed_addr constant ptr null

define void @_QQmain() local_unnamed_addr {
  %1 = alloca i64, align 8
  %2 = alloca i64, align 8
  %3 = tail call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.996fe97664c4c14f30cc8f6dbb58a427, i32 6)
  %4 = call i1 @_FortranAioInputInteger(ptr %3, ptr nonnull %2, i32 8)
  %5 = call i1 @_FortranAioInputInteger(ptr %3, ptr nonnull %1, i32 8)
  %6 = call i32 @_FortranAioEndIoStatement(ptr %3)
  %7 = load i64, ptr %2, align 8, !tbaa !3
  %8 = load i64, ptr %1, align 8, !tbaa !3
  %9 = srem i64 %7, %8
  %10 = icmp eq i64 %9, 0
  br i1 %10, label %11, label %14

11:                                               ; preds = %0
  %12 = call ptr @_FortranAioBeginExternalListOutput(i32 -1, ptr nonnull @_QQcl.996fe97664c4c14f30cc8f6dbb58a427, i32 9)
  %13 = call i1 @_FortranAioOutputInteger32(ptr %12, i32 0)
  br label %32

14:                                               ; preds = %0
  %15 = sitofp i64 %9 to double
  %16 = sitofp i64 %8 to double
  %17 = fmul contract double %16, 5.000000e-01
  %18 = fcmp ogt double %17, %15
  br i1 %18, label %19, label %25

19:                                               ; preds = %14
  %20 = call ptr @_FortranAioBeginExternalListOutput(i32 -1, ptr nonnull @_QQcl.996fe97664c4c14f30cc8f6dbb58a427, i32 12)
  %21 = load i64, ptr %2, align 8, !tbaa !3
  %22 = load i64, ptr %1, align 8, !tbaa !3
  %23 = srem i64 %21, %22
  %24 = call i1 @_FortranAioOutputInteger64(ptr %20, i64 %23)
  br label %32

25:                                               ; preds = %14
  %26 = call ptr @_FortranAioBeginExternalListOutput(i32 -1, ptr nonnull @_QQcl.996fe97664c4c14f30cc8f6dbb58a427, i32 15)
  %27 = load i64, ptr %1, align 8, !tbaa !3
  %28 = load i64, ptr %2, align 8, !tbaa !3
  %29 = srem i64 %28, %27
  %30 = sub i64 %27, %29
  %31 = call i1 @_FortranAioOutputInteger64(ptr %26, i64 %30)
  br label %32

32:                                               ; preds = %11, %19, %25
  %.sink = phi ptr [ %12, %11 ], [ %20, %19 ], [ %26, %25 ]
  %33 = call i32 @_FortranAioEndIoStatement(ptr %.sink)
  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 @_FortranAioOutputInteger32(ptr, i32) local_unnamed_addr

declare i1 @_FortranAioOutputInteger64(ptr, i64) local_unnamed_addr

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