#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
typedef int /*<<< orphan*/ token_buf;

/* Variables and functions */
int /*<<< orphan*/ add_token(char *);
scalar_t__ is_digit(char);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
int do_digit(int cur_first_index, char *readbuf) {
  int cur_index;
  char cur_char;
  char token_buf[80];
  char temp[80 + 8];
  cur_index = cur_first_index;
  while (1) {
    cur_char = readbuf[cur_index];
    if (is_digit(cur_char)) {
      cur_index++;
      continue;
    } else
      break;
  }
  memset(token_buf, 0, sizeof(token_buf));
  strncpy(token_buf, &(readbuf[cur_first_index]), cur_index - cur_first_index);
  temp[0] = '<';
  strcpy(temp + 1, token_buf);
  strcpy(temp + strlen(token_buf) + 1, ",NUM>");
  add_token(temp);
  return cur_index;
}


x86 assembly (clang, -O0):
<do_digit>:
push   %rbp
mov    %rsp,%rbp
sub    $0xe0,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x15(%rbp)
movsbl -0x15(%rbp),%edi
call   1070 <is_digit@plt>
cmp    $0x0,%rax
je     11a7 <do_digit+0x47>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1178 <do_digit+0x18>
jmp    11ac <do_digit+0x4c>
lea    -0x70(%rbp),%rdi
xor    %esi,%esi
mov    $0x50,%edx
call   1060 <memset@plt>
lea    -0x70(%rbp),%rdi
mov    -0x10(%rbp),%rsi
movslq -0x4(%rbp),%rax
add    %rax,%rsi
mov    -0x14(%rbp),%edx
sub    -0x4(%rbp),%edx
call   1030 <strncpy@plt>
movb   $0x3c,-0xd0(%rbp)
lea    -0xd0(%rbp),%rdi
add    $0x1,%rdi
lea    -0x70(%rbp),%rsi
call   1040 <strcpy@plt>
lea    -0xd0(%rbp),%rax
mov    %rax,-0xd8(%rbp)
lea    -0x70(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0xd8(%rbp),%rdi
cltq
add    %rax,%rdi
add    $0x1,%rdi
lea    0xde1(%rip),%rsi
call   1040 <strcpy@plt>
lea    -0xd0(%rbp),%rdi
call   1080 <add_token@plt>
mov    -0x14(%rbp),%eax
add    $0xe0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_digit>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xb8,%rsp
mov    %rsi,%r13
movslq %edi,%r12
lea    (%rsi,%r12,1),%rbx
mov    $0xffffffff,%ebp
movsbl (%rbx),%edi
call   1070 <is_digit@plt>
add    $0x1,%ebp
add    $0x1,%rbx
test   %rax,%rax
jne    1180 <do_digit+0x20>
lea    (%r12,%rbp,1),%r14d
lea    0x60(%rsp),%r15
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x50,%edx
call   1060 <memset@plt>
add    %r12,%r13
mov    %r15,%rdi
mov    %r13,%rsi
mov    %ebp,%edx
call   1030 <strncpy@plt>
movb   $0x3c,(%rsp)
lea    0x1(%rsp),%rdi
mov    %r15,%rsi
call   1040 <strcpy@plt>
mov    %r15,%rdi
call   1050 <strlen@plt>
cltq
lea    (%rsp,%rax,1),%rdi
add    $0x1,%rdi
lea    0xe1a(%rip),%rsi
call   1040 <strcpy@plt>
mov    %rsp,%rdi
call   1080 <add_token@plt>
mov    %r14d,%eax
add    $0xb8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [6 x i8] c",NUM>\00"
define i32 @do_digit(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8
%7 = alloca [80 x i8]
%8 = alloca [88 x i8]
store i32 %0, i32* %3
store i8* %1, i8** %4
%9 = load i32, i32* %3
store i32 %9, i32* %5
br label %10
10: ; preds = %2, %19
%11 = load i8*, i8** %4
%12 = load i32, i32* %5
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds i8, i8* %11, i64 %13
%15 = load i8, i8* %14
store i8 %15, i8* %6
%16 = load i8, i8* %6
%17 = call i64 @is_digit(i8 signext %16)
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %22
19: ; preds = %10
%20 = load i32, i32* %5
%21 = add nsw i32 %20, 1
store i32 %21, i32* %5
br label %10
22: ; preds = %10
br label %23
23: ; preds = %22
%24 = getelementptr inbounds [80 x i8], [80 x i8]* %7, i64 0, i64 0
%25 = call i32 @memset(i8* %24, i32 0, i32 80)
%26 = getelementptr inbounds [80 x i8], [80 x i8]* %7, i64 0, i64 0
%27 = load i8*, i8** %4
%28 = load i32, i32* %3
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %27, i64 %29
%31 = load i32, i32* %5
%32 = load i32, i32* %3
%33 = sub nsw i32 %31, %32
%34 = call i32 @strncpy(i8* %26, i8* %30, i32 %33)
%35 = getelementptr inbounds [88 x i8], [88 x i8]* %8, i64 0, i64 0
store i8 60, i8* %35
%36 = getelementptr inbounds [88 x i8], [88 x i8]* %8, i64 0, i64 0
%37 = getelementptr inbounds i8, i8* %36, i64 1
%38 = getelementptr inbounds [80 x i8], [80 x i8]* %7, i64 0, i64 0
%39 = call i32 @strcpy(i8* %37, i8* %38)
%40 = getelementptr inbounds [88 x i8], [88 x i8]* %8, i64 0, i64 0
%41 = getelementptr inbounds [80 x i8], [80 x i8]* %7, i64 0, i64 0
%42 = call i32 @strlen(i8* %41)
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds i8, i8* %40, i64 %43
%45 = getelementptr inbounds i8, i8* %44, i64 1
%46 = call i32 @strcpy(i8* %45, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%47 = getelementptr inbounds [88 x i8], [88 x i8]* %8, i64 0, i64 0
%48 = call i32 @add_token(i8* %47)
%49 = load i32, i32* %5
ret i32 %49
}

LLVM IR (-O2):
@.str = [6 x i8] c",NUM>\00"
define i32 @do_digit(i32 %0, i8* %1) {
%3 = alloca [80 x i8]
%4 = alloca [88 x i8]
%5 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [88 x i8], [88 x i8]* %4, i64 0, i64 0
%7 = sext i32 %0 to i64
br label %8
8: ; preds = %8, %2
%9 = phi i64 [ %14, %8 ], [ %7, %2 ]
%10 = getelementptr inbounds i8, i8* %1, i64 %9
%11 = load i8, i8* %10
%12 = tail call i64 @is_digit(i8 signext %11)
%13 = icmp eq i64 %12, 0
%14 = add i64 %9, 1
br i1 %13, label %15, label %8
15: ; preds = %8
%16 = trunc i64 %9 to i32
%17 = call i32 @memset(i8* %5, i32 0, i32 80)
%18 = getelementptr inbounds i8, i8* %1, i64 %7
%19 = sub nsw i32 %16, %0
%20 = call i32 @strncpy(i8* %5, i8* %18, i32 %19)
store i8 60, i8* %6
%21 = getelementptr inbounds [88 x i8], [88 x i8]* %4, i64 0, i64 1
%22 = call i32 @strcpy(i8* %21, i8* %5)
%23 = call i32 @strlen(i8* %5)
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds [88 x i8], [88 x i8]* %4, i64 0, i64 %24
%26 = getelementptr inbounds i8, i8* %25, i64 1
%27 = call i32 @strcpy(i8* %26, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%28 = call i32 @add_token(i8* %6)
ret i32 %16
}