#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 */
char fgetc(int /*<<< orphan*/);
char *reallocMemory(char *, int *);
int /*<<< orphan*/ stdin;
int readPhoneNumber(char **phoneNumber) {
  char *tmpNumber = NULL;
  char c;
  int maxMemory = 0, pNumberLength = 0;
  while (1) {
    if ((c = fgetc(stdin)) < '0' || c > '9') {
      if (c == '\n')
        return -2;
      else if (c == ' ' && pNumberLength > 0)
        break;
      else
        return 0;
    }
    if (pNumberLength + 1 >= maxMemory)
      tmpNumber = reallocMemory(tmpNumber, &maxMemory);
    tmpNumber[pNumberLength++] = c;
    *phoneNumber = tmpNumber;
  }
  tmpNumber[pNumberLength] = '\0';
  *phoneNumber = tmpNumber;
  return 1;
}


x86 assembly (clang, -O0):
<readPhoneNumber>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    0x2e9f(%rip),%rax
mov    (%rax),%edi
call   1030 <fgetc@plt>
mov    %al,-0x19(%rbp)
movsbl %al,%eax
cmp    $0x30,%eax
jl     116c <readPhoneNumber+0x4c>
movsbl -0x19(%rbp),%eax
cmp    $0x39,%eax
jle    11ad <readPhoneNumber+0x8d>
movsbl -0x19(%rbp),%eax
cmp    $0xa,%eax
jne    1185 <readPhoneNumber+0x65>
movl   $0xfffffffe,-0x4(%rbp)
jmp    1213 <readPhoneNumber+0xf3>
movsbl -0x19(%rbp),%eax
cmp    $0x20,%eax
jne    11a1 <readPhoneNumber+0x81>
cmpl   $0x0,-0x24(%rbp)
jle    11a1 <readPhoneNumber+0x81>
jmp    11f5 <readPhoneNumber+0xd5>
movl   $0x0,-0x4(%rbp)
jmp    1213 <readPhoneNumber+0xf3>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
cmp    -0x20(%rbp),%eax
jl     11cd <readPhoneNumber+0xad>
mov    -0x18(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1040 <reallocMemory@plt>
mov    %rax,-0x18(%rbp)
mov    -0x19(%rbp),%dl
mov    -0x18(%rbp),%rax
mov    -0x24(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x24(%rbp)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x18(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
jmp    1142 <readPhoneNumber+0x22>
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readPhoneNumber>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
movl   $0x0,0x4(%rsp)
mov    0x2eab(%rip),%rbp
mov    0x0(%rbp),%edi
call   1030 <fgetc@plt>
mov    %eax,%ebx
add    $0xc6,%al
cmp    $0xf6,%al
jae    1155 <readPhoneNumber+0x35>
xor    %r15d,%r15d
xor    %r13d,%r13d
jmp    11ab <readPhoneNumber+0x8b>
xor    %eax,%eax
lea    0x4(%rsp),%r12
xor    %r13d,%r13d
xor    %r15d,%r15d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
lea    0x1(%r13),%ecx
cmp    %ecx,%eax
jg     1186 <readPhoneNumber+0x66>
mov    %r15,%rdi
mov    %r12,%rsi
call   1040 <reallocMemory@plt>
mov    %rax,%r15
mov    %bl,(%r15,%r13,1)
mov    %r15,(%r14)
mov    0x0(%rbp),%edi
call   1030 <fgetc@plt>
mov    %eax,%ebx
add    $0xc6,%al
cmp    $0xf6,%al
jb     11a7 <readPhoneNumber+0x87>
mov    0x4(%rsp),%eax
add    $0x1,%r13
jmp    1170 <readPhoneNumber+0x50>
add    $0x1,%r13d
mov    $0xfffffffe,%eax
cmp    $0xa,%bl
je     11d1 <readPhoneNumber+0xb1>
xor    %eax,%eax
cmp    $0x20,%bl
jne    11d1 <readPhoneNumber+0xb1>
test   %r13d,%r13d
je     11d1 <readPhoneNumber+0xb1>
mov    %r13d,%eax
movb   $0x0,(%r15,%rax,1)
mov    %r15,(%r14)
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stdin = global i32 0
define i32 @readPhoneNumber(i8** %0) {
%2 = alloca i32
%3 = alloca i8**
%4 = alloca i8*
%5 = alloca i8
%6 = alloca i32
%7 = alloca i32
store i8** %0, i8*** %3
store i8* null, i8** %4
store i32 0, i32* %6
store i32 0, i32* %7
br label %8
8: ; preds = %1, %39
%9 = load i32, i32* @stdin
%10 = call signext i8 @fgetc(i32 %9)
store i8 %10, i8* %5
%11 = sext i8 %10 to i32
%12 = icmp slt i32 %11, 48
br i1 %12, label %17, label %13
13: ; preds = %8
%14 = load i8, i8* %5
%15 = sext i8 %14 to i32
%16 = icmp sgt i32 %15, 57
br i1 %16, label %17, label %31
17: ; preds = %13, %8
%18 = load i8, i8* %5
%19 = sext i8 %18 to i32
%20 = icmp eq i32 %19, 10
br i1 %20, label %21, label %22
21: ; preds = %17
store i32 -2, i32* %2
br label %55
22: ; preds = %17
%23 = load i8, i8* %5
%24 = sext i8 %23 to i32
%25 = icmp eq i32 %24, 32
br i1 %25, label %26, label %30
26: ; preds = %22
%27 = load i32, i32* %7
%28 = icmp sgt i32 %27, 0
br i1 %28, label %29, label %30
29: ; preds = %26
br label %48
30: ; preds = %26, %22
store i32 0, i32* %2
br label %55
31: ; preds = %13
%32 = load i32, i32* %7
%33 = add nsw i32 %32, 1
%34 = load i32, i32* %6
%35 = icmp sge i32 %33, %34
br i1 %35, label %36, label %39
36: ; preds = %31
%37 = load i8*, i8** %4
%38 = call i8* @reallocMemory(i8* %37, i32* %6)
store i8* %38, i8** %4
br label %39
39: ; preds = %36, %31
%40 = load i8, i8* %5
%41 = load i8*, i8** %4
%42 = load i32, i32* %7
%43 = add nsw i32 %42, 1
store i32 %43, i32* %7
%44 = sext i32 %42 to i64
%45 = getelementptr inbounds i8, i8* %41, i64 %44
store i8 %40, i8* %45
%46 = load i8*, i8** %4
%47 = load i8**, i8*** %3
store i8* %46, i8** %47
br label %8
48: ; preds = %29
%49 = load i8*, i8** %4
%50 = load i32, i32* %7
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds i8, i8* %49, i64 %51
store i8 0, i8* %52
%53 = load i8*, i8** %4
%54 = load i8**, i8*** %3
store i8* %53, i8** %54
store i32 1, i32* %2
br label %55
55: ; preds = %48, %30, %21
%56 = load i32, i32* %2
ret i32 %56
}

LLVM IR (-O2):
@stdin = global i32 0
define i32 @readPhoneNumber(i8** nocapture writeonly %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
store i32 0, i32* %2
%4 = load i32, i32* @stdin
%5 = call signext i8 @fgetc(i32 %4)
%6 = add i8 %5, -58
%7 = icmp ult i8 %6, -10
br i1 %7, label %10, label %19
8: ; preds = %29
%9 = trunc i64 %24 to i32
br label %10
10: ; preds = %8, %1
%11 = phi i8* [ null, %1 ], [ %30, %8 ]
%12 = phi i32 [ 0, %1 ], [ %9, %8 ]
%13 = phi i8 [ %5, %1 ], [ %33, %8 ]
%14 = icmp eq i8 %13, 10
br i1 %14, label %41, label %15
15: ; preds = %10
%16 = icmp eq i8 %13, 32
%17 = icmp ne i32 %12, 0
%18 = select i1 %16, i1 %17, i1 false
br i1 %18, label %38, label %41
19: ; preds = %1, %36
%20 = phi i32 [ %37, %36 ], [ 0, %1 ]
%21 = phi i64 [ %24, %36 ], [ 0, %1 ]
%22 = phi i8 [ %33, %36 ], [ %5, %1 ]
%23 = phi i8* [ %30, %36 ], [ null, %1 ]
%24 = add nuw i64 %21, 1
%25 = trunc i64 %24 to i32
%26 = icmp sgt i32 %20, %25
br i1 %26, label %29, label %27
27: ; preds = %19
%28 = call i8* @reallocMemory(i8* %23, i32* %2)
br label %29
29: ; preds = %27, %19
%30 = phi i8* [ %28, %27 ], [ %23, %19 ]
%31 = getelementptr inbounds i8, i8* %30, i64 %21
store i8 %22, i8* %31
store i8* %30, i8** %0
%32 = load i32, i32* @stdin
%33 = call signext i8 @fgetc(i32 %32)
%34 = add i8 %33, -58
%35 = icmp ult i8 %34, -10
br i1 %35, label %8, label %36
36: ; preds = %29
%37 = load i32, i32* %2
br label %19
38: ; preds = %15
%39 = zext i32 %12 to i64
%40 = getelementptr inbounds i8, i8* %11, i64 %39
store i8 0, i8* %40
store i8* %11, i8** %0
br label %41
41: ; preds = %15, %10, %38
%42 = phi i32 [ 1, %38 ], [ -2, %10 ], [ 0, %15 ]
ret i32 %42
}