#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 */

/* Variables and functions */
scalar_t__ is_a_number(char);
scalar_t__ malloc(int);
char *get_number(char *text, unsigned *position) {
  char *num = (char *)malloc(20);
  int i = 0;
  while (is_a_number(text[*position])) {
    num[i++] = text[*position];
    (*position)++;
  }
  num[i] = '\0';
  return num;
}


x86 assembly (clang, -O0):
<get_number>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x14,%edi
call   1030 <malloc@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
mov    (%rcx),%ecx
movsbl (%rax,%rcx,1),%edi
call   1040 <is_a_number@plt>
cmp    $0x0,%rax
je     1194 <get_number+0x74>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
mov    (%rcx),%ecx
mov    (%rax,%rcx,1),%dl
mov    -0x18(%rbp),%rax
mov    -0x1c(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x1c(%rbp)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x10(%rbp),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    %ecx,(%rax)
jmp    1145 <get_number+0x25>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_number>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r12
mov    %rdi,%r15
mov    $0x14,%edi
call   1030 <malloc@plt>
mov    %rax,%r14
mov    (%r12),%eax
movsbl (%r15,%rax,1),%edi
call   1040 <is_a_number@plt>
test   %rax,%rax
je     117f <get_number+0x5f>
xor    %ebx,%ebx
mov    (%r12),%eax
movzbl (%r15,%rax,1),%eax
mov    %al,(%r14,%rbx,1)
add    $0x1,%rbx
mov    (%r12),%eax
add    $0x1,%eax
mov    %eax,(%r12)
movsbl (%r15,%rax,1),%edi
call   1040 <is_a_number@plt>
test   %rax,%rax
jne    1150 <get_number+0x30>
mov    %ebx,%eax
jmp    1181 <get_number+0x61>
xor    %eax,%eax
movb   $0x0,(%r14,%rax,1)
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @get_number(i8* %0, i32* %1) {
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i32
store i8* %0, i8** %3
store i32* %1, i32** %4
%7 = call i64 @malloc(i32 20)
%8 = inttoptr i64 %7 to i8*
store i8* %8, i8** %5
store i32 0, i32* %6
br label %9
9: ; preds = %18, %2
%10 = load i8*, i8** %3
%11 = load i32*, i32** %4
%12 = load i32, i32* %11
%13 = zext i32 %12 to i64
%14 = getelementptr inbounds i8, i8* %10, i64 %13
%15 = load i8, i8* %14
%16 = call i64 @is_a_number(i8 signext %15)
%17 = icmp ne i64 %16, 0
br i1 %17, label %18, label %33
18: ; preds = %9
%19 = load i8*, i8** %3
%20 = load i32*, i32** %4
%21 = load i32, i32* %20
%22 = zext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %19, i64 %22
%24 = load i8, i8* %23
%25 = load i8*, i8** %5
%26 = load i32, i32* %6
%27 = add nsw i32 %26, 1
store i32 %27, i32* %6
%28 = sext i32 %26 to i64
%29 = getelementptr inbounds i8, i8* %25, i64 %28
store i8 %24, i8* %29
%30 = load i32*, i32** %4
%31 = load i32, i32* %30
%32 = add i32 %31, 1
store i32 %32, i32* %30
br label %9
33: ; preds = %9
%34 = load i8*, i8** %5
%35 = load i32, i32* %6
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i8, i8* %34, i64 %36
store i8 0, i8* %37
%38 = load i8*, i8** %5
ret i8* %38
}

LLVM IR (-O2):
define i8* @get_number(i8* nocapture %0, i32* nocapture %1) {
%3 = tail call i64 @malloc(i32 20)
%4 = inttoptr i64 %3 to i8*
%5 = load i32, i32* %1
%6 = zext i32 %5 to i64
%7 = getelementptr inbounds i8, i8* %0, i64 %6
%8 = load i8, i8* %7
%9 = tail call i64 @is_a_number(i8 signext %8)
%10 = icmp eq i64 %9, 0
br i1 %10, label %28, label %11
11: ; preds = %2, %11
%12 = phi i64 [ %17, %11 ], [ 0, %2 ]
%13 = load i32, i32* %1
%14 = zext i32 %13 to i64
%15 = getelementptr inbounds i8, i8* %0, i64 %14
%16 = load i8, i8* %15
%17 = add nuw i64 %12, 1
%18 = getelementptr inbounds i8, i8* %4, i64 %12
store i8 %16, i8* %18
%19 = load i32, i32* %1
%20 = add i32 %19, 1
store i32 %20, i32* %1
%21 = zext i32 %20 to i64
%22 = getelementptr inbounds i8, i8* %0, i64 %21
%23 = load i8, i8* %22
%24 = tail call i64 @is_a_number(i8 signext %23)
%25 = icmp eq i64 %24, 0
br i1 %25, label %26, label %11
26: ; preds = %11
%27 = and i64 %17, 4294967295
br label %28
28: ; preds = %26, %2
%29 = phi i64 [ 0, %2 ], [ %27, %26 ]
%30 = getelementptr inbounds i8, i8* %4, i64 %29
store i8 0, i8* %30
ret i8* %4
}