#import <stdio.h>

int main(){
    char a[20] = {'\0'};
    int N=0;
    char c = getchar();
    while(c>='0' && c<='9'){
        a[N]=c;
        N++;
        c = getchar();
    }
    for(int i=0;i<N;i++){
        if (a[i] == '9') {
            continue;
        } else if (a[i] == '0' || i>0) {
            a[i-1]--;
            for (int j=i;j<N;j++){
                a[j] = '9';
            }
        } else if (i<N-1) {
            int nineOnly = 1;
            for(int j=i+1;j<N;j++){
                if(a[j] !=
                   '9'){
                    nineOnly = 0;
                    a[j] = '9';
                }
            }
            if(!nineOnly){
                a[i]--;
            }
        } else if (N>1) {
            a[i] = '9';
            a[i-1]--;
        }
    }
    int sum = 0;
    for(int i=0;i<N;i++){
        sum += a[i] - '0';
    }
    printf("%d", sum);
}

; ModuleID = '/data/TheStack_IR/OJ_Samples/Collated/ObjectiveC/Source_591/source.m'
source_filename = "/data/TheStack_IR/OJ_Samples/Collated/ObjectiveC/Source_591/source.m"
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"

@.str = private unnamed_addr constant [3 x i8] c"%d\00", align 1
@stdin = external local_unnamed_addr global ptr, align 8

; Function Attrs: nofree nounwind uwtable
define dso_local i32 @main() local_unnamed_addr #0 {
entry:
  %a = alloca [20 x i8], align 16
  call void @llvm.lifetime.start.p0(i64 20, ptr nonnull %a) #5
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(20) %a, i8 0, i64 20, i1 false)
  %0 = load ptr, ptr @stdin, align 8, !tbaa !5
  %call.i = tail call i32 @getc(ptr noundef %0)
  %sext121 = shl i32 %call.i, 24
  %1 = add i32 %sext121, -788529153
  %2 = icmp ult i32 %1, 184549375
  br i1 %2, label %while.body, label %for.cond.cleanup81

for.cond.preheader:                               ; preds = %while.body
  %3 = trunc i64 %indvars.iv.next to i32
  %cmp8130.not = icmp eq i32 %3, 0
  br i1 %cmp8130.not, label %for.cond.cleanup81, label %for.body.lr.ph

for.body.lr.ph:                                   ; preds = %for.cond.preheader
  %sub34 = add i32 %3, -1
  %cmp61.not137 = icmp eq i32 %3, 1
  %arrayidx68 = getelementptr inbounds [20 x i8], ptr %a, i64 0, i64 -1
  %4 = and i64 %indvars.iv.next, 4294967295
  br i1 %cmp61.not137, label %for.body, label %for.body.us.preheader

for.body.us.preheader:                            ; preds = %for.body.lr.ph
  %cmp35.us = icmp sgt i32 %sub34, 0
  %5 = add nsw i64 %4, -1
  %min.iters.check = icmp ult i64 %5, 8
  %n.vec = and i64 %5, -8
  %ind.end = or i64 %n.vec, 1
  %cmp.n = icmp eq i64 %5, %n.vec
  br label %for.body.us

for.body.us:                                      ; preds = %for.body.us.preheader, %for.inc74.us
  %indvar = phi i64 [ 0, %for.body.us.preheader ], [ %indvar.next, %for.inc74.us ]
  %scevgep = getelementptr i8, ptr %a, i64 %indvar
  %6 = trunc i64 %indvar to i32
  %7 = sub i32 %sub34, %6
  %8 = zext i32 %7 to i64
  %9 = add nuw nsw i64 %8, 1
  %10 = load i8, ptr %scevgep, align 1, !tbaa !9
  %cmp13.us = icmp eq i8 %10, 57
  br i1 %cmp13.us, label %for.inc74.us, label %if.else.us

if.else.us:                                       ; preds = %for.body.us
  %cmp18.us = icmp eq i8 %10, 48
  %cmp20.us = icmp ne i64 %indvar, 0
  %or.cond.us = or i1 %cmp20.us, %cmp18.us
  br i1 %or.cond.us, label %for.body29.us.preheader, label %if.else33.us

if.else33.us:                                     ; preds = %if.else.us
  br i1 %cmp35.us, label %for.body43.us.preheader, label %if.then63.us

for.body43.us.preheader:                          ; preds = %if.else33.us
  br i1 %min.iters.check, label %for.body43.us.preheader199, label %vector.body

vector.body:                                      ; preds = %for.body43.us.preheader, %vector.body
  %index = phi i64 [ %index.next, %vector.body ], [ 0, %for.body43.us.preheader ]
  %vec.phi = phi <4 x i32> [ %15, %vector.body ], [ <i32 1, i32 1, i32 1, i32 1>, %for.body43.us.preheader ]
  %vec.phi176 = phi <4 x i32> [ %16, %vector.body ], [ <i32 1, i32 1, i32 1, i32 1>, %for.body43.us.preheader ]
  %offset.idx = or i64 %index, 1
  %11 = getelementptr inbounds [20 x i8], ptr %a, i64 0, i64 %offset.idx
  %wide.load = load <4 x i8>, ptr %11, align 1, !tbaa !9
  %12 = getelementptr inbounds i8, ptr %11, i64 4
  %wide.load177 = load <4 x i8>, ptr %12, align 1, !tbaa !9
  %13 = icmp eq <4 x i8> %wide.load, <i8 57, i8 57, i8 57, i8 57>
  %14 = icmp eq <4 x i8> %wide.load177, <i8 57, i8 57, i8 57, i8 57>
  store <4 x i8> <i8 57, i8 57, i8 57, i8 57>, ptr %11, align 1
  store <4 x i8> <i8 57, i8 57, i8 57, i8 57>, ptr %12, align 1
  %15 = select <4 x i1> %13, <4 x i32> %vec.phi, <4 x i32> zeroinitializer
  %16 = select <4 x i1> %14, <4 x i32> %vec.phi176, <4 x i32> zeroinitializer
  %index.next = add nuw i64 %index, 8
  %17 = icmp eq i64 %index.next, %n.vec
  br i1 %17, label %middle.block, label %vector.body, !llvm.loop !10

middle.block:                                     ; preds = %vector.body
  %rdx.select.cmp.not = icmp ne <4 x i32> %15, <i32 1, i32 1, i32 1, i32 1>
  %rdx.select.cmp178196 = icmp ne <4 x i32> %16, <i32 1, i32 1, i32 1, i32 1>
  %rdx.select.cmp178 = select <4 x i1> %rdx.select.cmp.not, <4 x i1> <i1 true, i1 true, i1 true, i1 true>, <4 x i1> %rdx.select.cmp178196
  %18 = bitcast <4 x i1> %rdx.select.cmp178 to i4
  %.not = icmp eq i4 %18, 0
  %rdx.select179 = zext i1 %.not to i32
  br i1 %cmp.n, label %for.cond39.for.cond.cleanup42_crit_edge.us, label %for.body43.us.preheader199

for.body43.us.preheader199:                       ; preds = %for.body43.us.preheader, %middle.block
  %indvars.iv140.ph = phi i64 [ 1, %for.body43.us.preheader ], [ %ind.end, %middle.block ]
  %nineOnly.0125.us.ph = phi i32 [ 1, %for.body43.us.preheader ], [ %rdx.select179, %middle.block ]
  br label %for.body43.us

if.then63.us:                                     ; preds = %if.else33.us
  store i8 57, ptr %scevgep, align 1, !tbaa !9
  %19 = load i8, ptr %arrayidx68, align 1, !tbaa !9
  %dec69.us = add i8 %19, -1
  store i8 %dec69.us, ptr %arrayidx68, align 1, !tbaa !9
  br label %for.inc74.us

if.then55.us:                                     ; preds = %for.cond39.for.cond.cleanup42_crit_edge.us
  %20 = load i8, ptr %scevgep, align 1, !tbaa !9
  %dec58.us = add i8 %20, -1
  store i8 %dec58.us, ptr %scevgep, align 1, !tbaa !9
  br label %for.inc74.us

for.body43.us:                                    ; preds = %for.body43.us.preheader199, %for.body43.us
  %indvars.iv140 = phi i64 [ %indvars.iv.next141, %for.body43.us ], [ %indvars.iv140.ph, %for.body43.us.preheader199 ]
  %nineOnly.0125.us = phi i32 [ %spec.select.us, %for.body43.us ], [ %nineOnly.0125.us.ph, %for.body43.us.preheader199 ]
  %arrayidx45.us = getelementptr inbounds [20 x i8], ptr %a, i64 0, i64 %indvars.iv140
  %21 = load i8, ptr %arrayidx45.us, align 1, !tbaa !9
  %cmp47.not.us = icmp eq i8 %21, 57
  store i8 57, ptr %arrayidx45.us, align 1
  %spec.select.us = select i1 %cmp47.not.us, i32 %nineOnly.0125.us, i32 0
  %indvars.iv.next141 = add nuw nsw i64 %indvars.iv140, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next141, %4
  br i1 %exitcond.not, label %for.cond39.for.cond.cleanup42_crit_edge.us, label %for.body43.us, !llvm.loop !13

for.body29.us.preheader:                          ; preds = %if.else.us
  %22 = add nsw i64 %indvar, -1
  %arrayidx24.us = getelementptr inbounds [20 x i8], ptr %a, i64 0, i64 %22
  %23 = load i8, ptr %arrayidx24.us, align 1, !tbaa !9
  %dec.us = add i8 %23, -1
  store i8 %dec.us, ptr %arrayidx24.us, align 1, !tbaa !9
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 1 dereferenceable(1) %scevgep, i8 57, i64 %9, i1 false), !tbaa !9
  br label %for.inc74.us

for.inc74.us:                                     ; preds = %for.body29.us.preheader, %if.then55.us, %for.cond39.for.cond.cleanup42_crit_edge.us, %if.then63.us, %for.body.us
  %indvar.next = add nuw nsw i64 %indvar, 1
  %exitcond149.not = icmp eq i64 %indvar.next, %4
  br i1 %exitcond149.not, label %for.cond78.preheader, label %for.body.us

for.cond39.for.cond.cleanup42_crit_edge.us:       ; preds = %for.body43.us, %middle.block
  %spec.select.us.lcssa = phi i32 [ %rdx.select179, %middle.block ], [ %spec.select.us, %for.body43.us ]
  %tobool.not.us = icmp eq i32 %spec.select.us.lcssa, 0
  br i1 %tobool.not.us, label %if.then55.us, label %for.inc74.us

while.body:                                       ; preds = %entry, %while.body
  %indvars.iv = phi i64 [ %indvars.iv.next, %while.body ], [ 0, %entry ]
  %c.0.in123 = phi i32 [ %call.i120, %while.body ], [ %call.i, %entry ]
  %c.0 = trunc i32 %c.0.in123 to i8
  %arrayidx = getelementptr inbounds [20 x i8], ptr %a, i64 0, i64 %indvars.iv
  store i8 %c.0, ptr %arrayidx, align 1, !tbaa !9
  %indvars.iv.next = add i64 %indvars.iv, 1
  %24 = load ptr, ptr @stdin, align 8, !tbaa !5
  %call.i120 = tail call i32 @getc(ptr noundef %24)
  %sext = shl i32 %call.i120, 24
  %25 = add i32 %sext, -788529153
  %26 = icmp ult i32 %25, 184549375
  br i1 %26, label %while.body, label %for.cond.preheader

for.cond78.preheader:                             ; preds = %for.inc74.us
  br i1 %cmp8130.not, label %for.cond.cleanup81, label %for.body82.preheader

for.body82.preheader:                             ; preds = %for.body, %for.body29.preheader, %for.cond78.preheader
  %N.0.lcssa167171 = phi i64 [ %indvars.iv.next, %for.cond78.preheader ], [ 1, %for.body29.preheader ], [ 1, %for.body ]
  %wide.trip.count163 = and i64 %N.0.lcssa167171, 4294967295
  %min.iters.check182 = icmp ult i64 %wide.trip.count163, 8
  br i1 %min.iters.check182, label %for.body82.preheader197, label %vector.ph183

vector.ph183:                                     ; preds = %for.body82.preheader
  %n.mod.vf184 = and i64 %N.0.lcssa167171, 7
  %n.vec185 = sub nsw i64 %wide.trip.count163, %n.mod.vf184
  br label %vector.body188

vector.body188:                                   ; preds = %vector.body188, %vector.ph183
  %index189 = phi i64 [ 0, %vector.ph183 ], [ %index.next194, %vector.body188 ]
  %vec.phi190 = phi <4 x i32> [ zeroinitializer, %vector.ph183 ], [ %33, %vector.body188 ]
  %vec.phi191 = phi <4 x i32> [ zeroinitializer, %vector.ph183 ], [ %34, %vector.body188 ]
  %27 = getelementptr inbounds [20 x i8], ptr %a, i64 0, i64 %index189
  %wide.load192 = load <4 x i8>, ptr %27, align 8, !tbaa !9
  %28 = getelementptr inbounds i8, ptr %27, i64 4
  %wide.load193 = load <4 x i8>, ptr %28, align 4, !tbaa !9
  %29 = sext <4 x i8> %wide.load192 to <4 x i32>
  %30 = sext <4 x i8> %wide.load193 to <4 x i32>
  %31 = add <4 x i32> %vec.phi190, <i32 -48, i32 -48, i32 -48, i32 -48>
  %32 = add <4 x i32> %vec.phi191, <i32 -48, i32 -48, i32 -48, i32 -48>
  %33 = add <4 x i32> %31, %29
  %34 = add <4 x i32> %32, %30
  %index.next194 = add nuw i64 %index189, 8
  %35 = icmp eq i64 %index.next194, %n.vec185
  br i1 %35, label %middle.block180, label %vector.body188, !llvm.loop !14

middle.block180:                                  ; preds = %vector.body188
  %bin.rdx = add <4 x i32> %34, %33
  %36 = tail call i32 @llvm.vector.reduce.add.v4i32(<4 x i32> %bin.rdx)
  %cmp.n187 = icmp eq i64 %n.mod.vf184, 0
  br i1 %cmp.n187, label %for.cond.cleanup81, label %for.body82.preheader197

for.body82.preheader197:                          ; preds = %for.body82.preheader, %middle.block180
  %indvars.iv160.ph = phi i64 [ 0, %for.body82.preheader ], [ %n.vec185, %middle.block180 ]
  %sum.0134.ph = phi i32 [ 0, %for.body82.preheader ], [ %36, %middle.block180 ]
  br label %for.body82

for.body:                                         ; preds = %for.body.lr.ph
  %37 = load i8, ptr %a, align 16, !tbaa !9
  %cond = icmp eq i8 %37, 48
  br i1 %cond, label %for.body29.preheader, label %for.body82.preheader

for.body29.preheader:                             ; preds = %for.body
  call void @llvm.memset.p0.i64(ptr nonnull align 16 %a, i8 57, i64 %4, i1 false), !tbaa !9
  br label %for.body82.preheader

for.cond.cleanup81:                               ; preds = %for.body82, %middle.block180, %entry, %for.cond.preheader, %for.cond78.preheader
  %sum.0.lcssa = phi i32 [ 0, %for.cond78.preheader ], [ 0, %for.cond.preheader ], [ 0, %entry ], [ %36, %middle.block180 ], [ %add87, %for.body82 ]
  %call91 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, i32 noundef %sum.0.lcssa)
  call void @llvm.lifetime.end.p0(i64 20, ptr nonnull %a) #5
  ret i32 0

for.body82:                                       ; preds = %for.body82.preheader197, %for.body82
  %indvars.iv160 = phi i64 [ %indvars.iv.next161, %for.body82 ], [ %indvars.iv160.ph, %for.body82.preheader197 ]
  %sum.0134 = phi i32 [ %add87, %for.body82 ], [ %sum.0134.ph, %for.body82.preheader197 ]
  %arrayidx84 = getelementptr inbounds [20 x i8], ptr %a, i64 0, i64 %indvars.iv160
  %38 = load i8, ptr %arrayidx84, align 1, !tbaa !9
  %conv85 = sext i8 %38 to i32
  %sub86 = add i32 %sum.0134, -48
  %add87 = add i32 %sub86, %conv85
  %indvars.iv.next161 = add nuw nsw i64 %indvars.iv160, 1
  %exitcond164.not = icmp eq i64 %indvars.iv.next161, %wide.trip.count163
  br i1 %exitcond164.not, label %for.cond.cleanup81, label %for.body82, !llvm.loop !15
}

; 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 nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

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

; Function Attrs: nofree nounwind
declare noundef i32 @getc(ptr nocapture noundef) local_unnamed_addr #3

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.vector.reduce.add.v4i32(<4 x i32>) #4

attributes #0 = { nofree 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 nocallback nofree nounwind willreturn memory(argmem: write) }
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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #5 = { nounwind }

!llvm.linker.options = !{}
!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 = !{!"Ubuntu clang version 18.0.0 (++20231007042255+8abb2ace888b-1~exp1~20231007042414.1230)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!7, !7, i64 0}
!10 = distinct !{!10, !11, !12}
!11 = !{!"llvm.loop.isvectorized", i32 1}
!12 = !{!"llvm.loop.unroll.runtime.disable"}
!13 = distinct !{!13, !12, !11}
!14 = distinct !{!14, !11, !12}
!15 = distinct !{!15, !12, !11}
