program probC
    implicit none
    integer(16)::X, K, D, ans, c
    integer::i, j
    read(*,*) X, K, D
    X = abs(X)
    c = X/D
    if(c >= K)then 
    	write(*,*) X - K*D
    else
        K = K - c
        if(mod(K,2) == 0)then 
        	write(*,*) X - c*D
        else 
            write(*,*) abs(X - (c+1)*D)
        end if
    end if
    stop
end program
; 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.41eb13d3d0ca063bdfd45cc9dc46b440 = linkonce constant [72 x i8] c"/home/ubuntu/Downloads/TheStack_IR/Collated/Fortran/Source_810/source.f\00"
@_QQEnvironmentDefaults = local_unnamed_addr constant ptr null

; Function Attrs: noreturn
define void @_QQmain() local_unnamed_addr #0 {
  %1 = alloca i128, align 8
  %2 = alloca i128, align 8
  %3 = alloca i128, align 8
  %4 = tail call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.41eb13d3d0ca063bdfd45cc9dc46b440, i32 5)
  %5 = call i1 @_FortranAioInputInteger(ptr %4, ptr nonnull %3, i32 16)
  %6 = call i1 @_FortranAioInputInteger(ptr %4, ptr nonnull %2, i32 16)
  %7 = call i1 @_FortranAioInputInteger(ptr %4, ptr nonnull %1, i32 16)
  %8 = call i32 @_FortranAioEndIoStatement(ptr %4)
  %9 = load i128, ptr %3, align 8, !tbaa !3
  %10 = call i128 @llvm.abs.i128(i128 %9, i1 false)
  store i128 %10, ptr %3, align 8, !tbaa !3
  %11 = load i128, ptr %1, align 8, !tbaa !3
  %12 = sdiv i128 %10, %11
  %13 = load i128, ptr %2, align 8, !tbaa !3
  %.not = icmp sgt i128 %13, %12
  br i1 %.not, label %21, label %14

14:                                               ; preds = %0
  %15 = call ptr @_FortranAioBeginExternalListOutput(i32 -1, ptr nonnull @_QQcl.41eb13d3d0ca063bdfd45cc9dc46b440, i32 9)
  %16 = load i128, ptr %3, align 8, !tbaa !3
  %17 = load i128, ptr %2, align 8, !tbaa !3
  %18 = load i128, ptr %1, align 8, !tbaa !3
  %19 = mul i128 %18, %17
  %20 = sub i128 %16, %19
  br label %37

21:                                               ; preds = %0
  %22 = sub i128 %13, %12
  store i128 %22, ptr %2, align 8, !tbaa !3
  %23 = and i128 %22, 1
  %24 = icmp eq i128 %23, 0
  br i1 %24, label %25, label %31

25:                                               ; preds = %21
  %26 = call ptr @_FortranAioBeginExternalListOutput(i32 -1, ptr nonnull @_QQcl.41eb13d3d0ca063bdfd45cc9dc46b440, i32 13)
  %27 = load i128, ptr %3, align 8, !tbaa !3
  %28 = load i128, ptr %1, align 8, !tbaa !3
  %29 = mul i128 %28, %12
  %30 = sub i128 %27, %29
  br label %37

31:                                               ; preds = %21
  %32 = call ptr @_FortranAioBeginExternalListOutput(i32 -1, ptr nonnull @_QQcl.41eb13d3d0ca063bdfd45cc9dc46b440, i32 15)
  %33 = load i128, ptr %3, align 8, !tbaa !3
  %.neg = xor i128 %12, -1
  %34 = load i128, ptr %1, align 8, !tbaa !3
  %.neg5 = mul i128 %34, %.neg
  %35 = add i128 %.neg5, %33
  %36 = call i128 @llvm.abs.i128(i128 %35, i1 false)
  br label %37

37:                                               ; preds = %14, %25, %31
  %.sink7 = phi i128 [ %20, %14 ], [ %30, %25 ], [ %36, %31 ]
  %.sink6 = phi ptr [ %15, %14 ], [ %26, %25 ], [ %32, %31 ]
  %38 = call i1 @_FortranAioOutputInteger128(ptr %.sink6, i128 %.sink7)
  %39 = call i32 @_FortranAioEndIoStatement(ptr %.sink6)
  %40 = call {} @_FortranAStopStatement(i32 0, i1 false, i1 false)
  unreachable
}

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 @_FortranAioOutputInteger128(ptr, i128) local_unnamed_addr

declare {} @_FortranAStopStatement(i32, i1, i1) local_unnamed_addr

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i128 @llvm.abs.i128(i128, i1 immarg) #1

attributes #0 = { noreturn }
attributes #1 = { 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"}
