program c175
 
implicit none
integer(16) :: x, k, d, a, s, l, t
 
read *, x, k, d
 
a = int(abs(x) / d)
s = abs(x) - a * d

!print *, s

if(abs(s) > abs(s-d)) then
 l = abs(s)
 s = abs(s-d)
 t = 1
else
 s = abs(s)
 l = abs(s-d)
 t = 0
end if
 
!print '(3(I5))', a, s, l
 
a = k - int(abs(x) / d) - t
 
if(abs(x) > d * k) then
 print *, abs(x) - d * k
else if(mod(a, 2) == 0) then
 print *, s
else if(mod(a, 2) == 1) then
 print *, l
end if
 
end program c175
; 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.19e00ca4983475c470a11ecf38fd58ce = linkonce constant [72 x i8] c"/home/ubuntu/Downloads/TheStack_IR/Collated/Fortran/Source_815/source.f\00"
@_QQEnvironmentDefaults = local_unnamed_addr constant ptr null

define void @_QQmain() local_unnamed_addr {
  %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.19e00ca4983475c470a11ecf38fd58ce, i32 6)
  %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)
  %11 = load i128, ptr %1, align 8, !tbaa !3
  %12 = sdiv i128 %10, %11
  %13 = shl i128 %12, 96
  %14 = ashr exact i128 %13, 96
  %15 = mul i128 %14, %11
  %16 = sub i128 %10, %15
  %17 = call i128 @llvm.abs.i128(i128 %16, i1 false)
  %18 = sub i128 %16, %11
  %19 = call i128 @llvm.abs.i128(i128 %18, i1 false)
  %20 = icmp sgt i128 %17, %19
  br i1 %20, label %24, label %21

21:                                               ; preds = %0
  %22 = sub i128 %17, %11
  %23 = call i128 @llvm.abs.i128(i128 %22, i1 false)
  br label %24

24:                                               ; preds = %0, %21
  %.012 = phi i128 [ %23, %21 ], [ %17, %0 ]
  %.011 = phi i128 [ %17, %21 ], [ %19, %0 ]
  %.0.neg = phi i128 [ 0, %21 ], [ -1, %0 ]
  %25 = load i128, ptr %2, align 8, !tbaa !3
  %26 = mul i128 %25, %11
  %27 = icmp sgt i128 %10, %26
  br i1 %27, label %28, label %37

28:                                               ; preds = %24
  %29 = call ptr @_FortranAioBeginExternalListOutput(i32 -1, ptr nonnull @_QQcl.19e00ca4983475c470a11ecf38fd58ce, i32 28)
  %30 = load i128, ptr %3, align 8, !tbaa !3
  %31 = call i128 @llvm.abs.i128(i128 %30, i1 false)
  %32 = load i128, ptr %1, align 8, !tbaa !3
  %33 = load i128, ptr %2, align 8, !tbaa !3
  %34 = mul i128 %33, %32
  %35 = sub i128 %31, %34
  %36 = call i1 @_FortranAioOutputInteger128(ptr %29, i128 %35)
  br label %.sink.split

37:                                               ; preds = %24
  %38 = sub nsw i128 %.0.neg, %14
  %39 = add i128 %38, %25
  %40 = srem i128 %39, 2
  switch i128 %40, label %48 [
    i128 0, label %41
    i128 1, label %44
  ]

41:                                               ; preds = %37
  %42 = call ptr @_FortranAioBeginExternalListOutput(i32 -1, ptr nonnull @_QQcl.19e00ca4983475c470a11ecf38fd58ce, i32 30)
  %43 = call i1 @_FortranAioOutputInteger128(ptr %42, i128 %.011)
  br label %.sink.split

44:                                               ; preds = %37
  %45 = call ptr @_FortranAioBeginExternalListOutput(i32 -1, ptr nonnull @_QQcl.19e00ca4983475c470a11ecf38fd58ce, i32 32)
  %46 = call i1 @_FortranAioOutputInteger128(ptr %45, i128 %.012)
  br label %.sink.split

.sink.split:                                      ; preds = %44, %41, %28
  %.sink = phi ptr [ %29, %28 ], [ %42, %41 ], [ %45, %44 ]
  %47 = call i32 @_FortranAioEndIoStatement(ptr %.sink)
  br label %48

48:                                               ; preds = %.sink.split, %37
  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 @_FortranAioOutputInteger128(ptr, i128) local_unnamed_addr

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i128 @llvm.abs.i128(i128, i1 immarg) #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"}
