#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 */
struct token {
  int dummy;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ free(char *);
char getc(int /*<<< orphan*/ *);
scalar_t__ is_part_of_a_number(char);
char *malloc(int);
int /*<<< orphan*/ strncat(char *, char *, int);
int /*<<< orphan*/ ungetc(char, int /*<<< orphan*/ *);
int /*<<< orphan*/ update_token(struct token *, int, char *, char *,
                                int /*<<< orphan*/, int);
void parse_number(struct token *token, char character, FILE *file) {
  char *value = malloc(512 * sizeof(char));
  value[0] = character;
  value[1] = '\0';
  char next_char = getc(file);
  while (is_part_of_a_number(next_char)) {
    strncat(value, &next_char, sizeof(char));
    next_char = getc(file);
  }
  ungetc(next_char, file);
  update_token(token, 904, "\x1b[31m", value, 0, 1);
  free(value);
}


x86 assembly (clang, -O0):
<parse_number>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %sil,%al
mov    %rdi,-0x8(%rbp)
mov    %al,-0x9(%rbp)
mov    %rdx,-0x18(%rbp)
mov    $0x200,%edi
call   1060 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x9(%rbp),%cl
mov    -0x20(%rbp),%rax
mov    %cl,(%rax)
mov    -0x20(%rbp),%rax
movb   $0x0,0x1(%rax)
mov    -0x18(%rbp),%rdi
call   1090 <getc@plt>
mov    %al,-0x21(%rbp)
movsbl -0x21(%rbp),%edi
call   1080 <is_part_of_a_number@plt>
cmp    $0x0,%rax
je     11e7 <parse_number+0x77>
mov    -0x20(%rbp),%rdi
lea    -0x21(%rbp),%rsi
mov    $0x1,%edx
call   1040 <strncat@plt>
mov    -0x18(%rbp),%rdi
call   1090 <getc@plt>
mov    %al,-0x21(%rbp)
jmp    11b1 <parse_number+0x41>
mov    -0x21(%rbp),%al
mov    -0x18(%rbp),%rsi
movsbl %al,%edi
call   1070 <ungetc@plt>
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rcx
mov    $0x388,%esi
lea    0xdf6(%rip),%rdx
xor    %r8d,%r8d
mov    $0x1,%r9d
call   1050 <update_token@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_number>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rdx,%rbx
mov    %esi,%ebp
mov    %rdi,%r14
mov    $0x200,%edi
call   1060 <malloc@plt>
mov    %rax,%r15
mov    %bpl,(%rax)
movb   $0x0,0x1(%rax)
mov    %rbx,%rdi
call   1090 <getc@plt>
mov    %eax,%ebp
mov    %al,0xf(%rsp)
movsbl %al,%edi
call   1080 <is_part_of_a_number@plt>
test   %rax,%rax
je     11ee <parse_number+0x7e>
lea    0xf(%rsp),%r12
nopl   0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    %r12,%rsi
mov    $0x1,%edx
call   1040 <strncat@plt>
mov    %rbx,%rdi
call   1090 <getc@plt>
mov    %al,0xf(%rsp)
movsbl %al,%edi
call   1080 <is_part_of_a_number@plt>
test   %rax,%rax
jne    11c0 <parse_number+0x50>
mov    0xf(%rsp),%bpl
movsbl %bpl,%edi
mov    %rbx,%rsi
call   1070 <ungetc@plt>
lea    0xdff(%rip),%rdx
mov    %r14,%rdi
mov    $0x388,%esi
mov    %r15,%rcx
xor    %r8d,%r8d
mov    $0x1,%r9d
call   1050 <update_token@plt>
mov    %r15,%rdi
call   1030 <free@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.token = type { i32 }
@.str = [6 x i8] c"\1B[31m\00"
define void @parse_number(%struct.token* %0, i8 signext %1, i32* %2) {
%4 = alloca %struct.token*
%5 = alloca i8
%6 = alloca i32*
%7 = alloca i8*
%8 = alloca i8
store %struct.token* %0, %struct.token** %4
store i8 %1, i8* %5
store i32* %2, i32** %6
%9 = call i8* @malloc(i32 512)
store i8* %9, i8** %7
%10 = load i8, i8* %5
%11 = load i8*, i8** %7
%12 = getelementptr inbounds i8, i8* %11, i64 0
store i8 %10, i8* %12
%13 = load i8*, i8** %7
%14 = getelementptr inbounds i8, i8* %13, i64 1
store i8 0, i8* %14
%15 = load i32*, i32** %6
%16 = call signext i8 @getc(i32* %15)
store i8 %16, i8* %8
br label %17
17: ; preds = %21, %3
%18 = load i8, i8* %8
%19 = call i64 @is_part_of_a_number(i8 signext %18)
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %26
21: ; preds = %17
%22 = load i8*, i8** %7
%23 = call i32 @strncat(i8* %22, i8* %8, i32 1)
%24 = load i32*, i32** %6
%25 = call signext i8 @getc(i32* %24)
store i8 %25, i8* %8
br label %17
26: ; preds = %17
%27 = load i8, i8* %8
%28 = load i32*, i32** %6
%29 = call i32 @ungetc(i8 signext %27, i32* %28)
%30 = load %struct.token*, %struct.token** %4
%31 = load i8*, i8** %7
%32 = call i32 @update_token(%struct.token* %30, i32 904, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %31, i32 0, i32 1)
%33 = load i8*, i8** %7
%34 = call i32 @free(i8* %33)
ret void
}

LLVM IR (-O2):
%struct.token = type { i32 }
@.str = [6 x i8] c"\1B[31m\00"
define void @parse_number(%struct.token* %0, i8 signext %1, i32* nocapture %2) {
%4 = alloca i8
%5 = tail call dereferenceable_or_null(512) i8* @malloc(i32 512)
store i8 %1, i8* %5
%6 = getelementptr inbounds i8, i8* %5, i64 1
store i8 0, i8* %6
%7 = tail call signext i8 @getc(i32* %2)
store i8 %7, i8* %4
%8 = call i64 @is_part_of_a_number(i8 signext %7)
%9 = icmp eq i64 %8, 0
br i1 %9, label %17, label %10
10: ; preds = %3, %10
%11 = call i32 @strncat(i8* %5, i8* %4, i32 1)
%12 = call signext i8 @getc(i32* %2)
store i8 %12, i8* %4
%13 = call i64 @is_part_of_a_number(i8 signext %12)
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %10
15: ; preds = %10
%16 = load i8, i8* %4
br label %17
17: ; preds = %15, %3
%18 = phi i8 [ %16, %15 ], [ %7, %3 ]
%19 = call i32 @ungetc(i8 signext %18, i32* %2)
%20 = call i32 @update_token(%struct.token* %0, i32 904, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %5, i32 0, i32 1)
%21 = call i32 @free(i8* %5)
ret void
}