#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 */
int /*<<< orphan*/ assert(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ stderr;
char strip_whitespace(char *);
scalar_t__ strtol(char, char **, int);
int /*<<< orphan*/ valid_numeral_first_char(char);
int tokenizer_next_udp_number(char *input_p) {
  int number;
  char *word, *input;
  assert(input_p != NULL);
  word = input = input_p;
  if (*input == 0)
    return -1;
  if (!valid_numeral_first_char(*input)) {
    fprintf(stderr, "Number expected\n");
    return -1;
  }
  while (*++input != 0) {
    if (*input == ';' || *input == ',') {
      *input = 0;
      *input = strip_whitespace(input + 1);
      break;
    }
    if (!valid_numeral_first_char(*input)) {
      fprintf(stderr, "Invalid character\n");
      return -1;
    }
  }
  number = (int)strtol(*input_p, &input, 10);
  input_p = input;
  return number;
}


x86 assembly (clang, -O0):
<tokenizer_next_udp_number>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    %rax,-0x20(%rbp)
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    1196 <tokenizer_next_udp_number+0x46>
movl   $0xffffffff,-0x4(%rbp)
jmp    128f <tokenizer_next_udp_number+0x13f>
mov    -0x28(%rbp),%rax
movsbl (%rax),%edi
call   1070 <valid_numeral_first_char@plt>
cmp    $0x0,%eax
jne    11cc <tokenizer_next_udp_number+0x7c>
mov    0x2e2e(%rip),%rax
mov    (%rax),%edi
lea    0xe45(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    128f <tokenizer_next_udp_number+0x13f>
jmp    11d1 <tokenizer_next_udp_number+0x81>
mov    -0x28(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x28(%rbp)
movsbl 0x1(%rax),%eax
cmp    $0x0,%eax
je     1269 <tokenizer_next_udp_number+0x119>
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x3b,%eax
je     120d <tokenizer_next_udp_number+0xbd>
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2c,%eax
jne    122e <tokenizer_next_udp_number+0xde>
mov    -0x28(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x28(%rbp),%rdi
add    $0x1,%rdi
call   1030 <strip_whitespace@plt>
mov    %al,%cl
mov    -0x28(%rbp),%rax
mov    %cl,(%rax)
jmp    1269 <tokenizer_next_udp_number+0x119>
mov    -0x28(%rbp),%rax
movsbl (%rax),%edi
call   1070 <valid_numeral_first_char@plt>
cmp    $0x0,%eax
jne    1264 <tokenizer_next_udp_number+0x114>
mov    0x2d96(%rip),%rax
mov    (%rax),%edi
lea    0xdbe(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    128f <tokenizer_next_udp_number+0x13f>
jmp    11d1 <tokenizer_next_udp_number+0x81>
mov    -0x10(%rbp),%rax
lea    -0x28(%rbp),%rsi
mov    $0xa,%edx
movsbl (%rax),%edi
call   1060 <strtol@plt>
mov    %eax,-0x14(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tokenizer_next_udp_number>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%r15
xor    %edi,%edi
test   %r15,%r15
setne  %dil
call   1040 <assert@plt>
mov    (%r15),%al
mov    $0xffffffff,%r14d
test   %al,%al
je     1216 <tokenizer_next_udp_number+0xc6>
movsbl %al,%edi
call   1070 <valid_numeral_first_char@plt>
test   %eax,%eax
je     11cf <tokenizer_next_udp_number+0x7f>
lea    0x1(%r15),%rbx
nopl   0x0(%rax,%rax,1)
movzbl (%rbx),%eax
test   %al,%al
je     11fb <tokenizer_next_udp_number+0xab>
cmp    $0x3b,%al
je     11e6 <tokenizer_next_udp_number+0x96>
cmp    $0x2c,%al
je     11e6 <tokenizer_next_udp_number+0x96>
movsbl %al,%edi
call   1070 <valid_numeral_first_char@plt>
add    $0x1,%rbx
test   %eax,%eax
jne    1190 <tokenizer_next_udp_number+0x40>
add    $0xffffffffffffffff,%rbx
mov    %rbx,0x8(%rsp)
mov    0x2e21(%rip),%rax
mov    (%rax),%edi
lea    0xe49(%rip),%rsi
call   1050 <fprintf@plt>
jmp    1216 <tokenizer_next_udp_number+0xc6>
mov    0x2e0a(%rip),%rax
mov    (%rax),%edi
lea    0xe21(%rip),%rsi
call   1050 <fprintf@plt>
jmp    1216 <tokenizer_next_udp_number+0xc6>
mov    %rbx,0x8(%rsp)
movb   $0x0,(%rbx)
lea    0x1(%rbx),%rdi
call   1030 <strip_whitespace@plt>
mov    %al,(%rbx)
jmp    1200 <tokenizer_next_udp_number+0xb0>
mov    %rbx,0x8(%rsp)
movsbl (%r15),%edi
lea    0x8(%rsp),%rsi
mov    $0xa,%edx
call   1060 <strtol@plt>
mov    %rax,%r14
mov    %r14d,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [17 x i8] c"Number expected\0A\00"
@.str.1 = [19 x i8] c"Invalid character\0A\00"
define i32 @tokenizer_next_udp_number(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
store i8* %0, i8** %3
%7 = load i8*, i8** %3
%8 = icmp ne i8* %7, null
%9 = zext i1 %8 to i32
%10 = call i32 @assert(i32 %9)
%11 = load i8*, i8** %3
store i8* %11, i8** %6
store i8* %11, i8** %5
%12 = load i8*, i8** %6
%13 = load i8, i8* %12
%14 = sext i8 %13 to i32
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %17
16: ; preds = %1
store i32 -1, i32* %2
br label %64
17: ; preds = %1
%18 = load i8*, i8** %6
%19 = load i8, i8* %18
%20 = call i32 @valid_numeral_first_char(i8 signext %19)
%21 = icmp ne i32 %20, 0
br i1 %21, label %25, label %22
22: ; preds = %17
%23 = load i32, i32* @stderr
%24 = call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %2
br label %64
25: ; preds = %17
br label %26
26: ; preds = %56, %25
%27 = load i8*, i8** %6
%28 = getelementptr inbounds i8, i8* %27, i32 1
store i8* %28, i8** %6
%29 = load i8, i8* %28
%30 = sext i8 %29 to i32
%31 = icmp ne i32 %30, 0
br i1 %31, label %32, label %57
32: ; preds = %26
%33 = load i8*, i8** %6
%34 = load i8, i8* %33
%35 = sext i8 %34 to i32
%36 = icmp eq i32 %35, 59
br i1 %36, label %42, label %37
37: ; preds = %32
%38 = load i8*, i8** %6
%39 = load i8, i8* %38
%40 = sext i8 %39 to i32
%41 = icmp eq i32 %40, 44
br i1 %41, label %42, label %48
42: ; preds = %37, %32
%43 = load i8*, i8** %6
store i8 0, i8* %43
%44 = load i8*, i8** %6
%45 = getelementptr inbounds i8, i8* %44, i64 1
%46 = call signext i8 @strip_whitespace(i8* %45)
%47 = load i8*, i8** %6
store i8 %46, i8* %47
br label %57
48: ; preds = %37
%49 = load i8*, i8** %6
%50 = load i8, i8* %49
%51 = call i32 @valid_numeral_first_char(i8 signext %50)
%52 = icmp ne i32 %51, 0
br i1 %52, label %56, label %53
53: ; preds = %48
%54 = load i32, i32* @stderr
%55 = call i32 @fprintf(i32 %54, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %2
br label %64
56: ; preds = %48
br label %26
57: ; preds = %42, %26
%58 = load i8*, i8** %3
%59 = load i8, i8* %58
%60 = call i64 @strtol(i8 signext %59, i8** %6, i32 10)
%61 = trunc i64 %60 to i32
store i32 %61, i32* %4
%62 = load i8*, i8** %6
store i8* %62, i8** %3
%63 = load i32, i32* %4
store i32 %63, i32* %2
br label %64
64: ; preds = %57, %53, %22, %16
%65 = load i32, i32* %2
ret i32 %65
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [17 x i8] c"Number expected\0A\00"
@.str.1 = [19 x i8] c"Invalid character\0A\00"
define i32 @tokenizer_next_udp_number(i8* %0) {
%2 = alloca i8*
%3 = bitcast i8** %2 to i8*
%4 = icmp ne i8* %0, null
%5 = zext i1 %4 to i32
%6 = tail call i32 @assert(i32 %5)
%7 = load i8, i8* %0
%8 = icmp eq i8 %7, 0
br i1 %8, label %33, label %9
9: ; preds = %1
%10 = tail call i32 @valid_numeral_first_char(i8 signext %7)
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %9
%13 = load i32, i32* @stderr
%14 = tail call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
br label %33
15: ; preds = %9, %22
%16 = phi i8* [ %17, %22 ], [ %0, %9 ]
%17 = getelementptr inbounds i8, i8* %16, i64 1
%18 = load i8, i8* %17
switch i8 %18, label %22 [
i8 0, label %28
i8 59, label %19
i8 44, label %19
]
19: ; preds = %15, %15
store i8* %17, i8** %2
store i8 0, i8* %17
%20 = getelementptr inbounds i8, i8* %16, i64 2
%21 = tail call signext i8 @strip_whitespace(i8* %20)
store i8 %21, i8* %17
br label %29
22: ; preds = %15
%23 = tail call i32 @valid_numeral_first_char(i8 signext %18)
%24 = icmp eq i32 %23, 0
br i1 %24, label %25, label %15
25: ; preds = %22
store i8* %17, i8** %2
%26 = load i32, i32* @stderr
%27 = tail call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
br label %33
28: ; preds = %15
store i8* %17, i8** %2
br label %29
29: ; preds = %28, %19
%30 = load i8, i8* %0
%31 = call i64 @strtol(i8 signext %30, i8** %2, i32 10)
%32 = trunc i64 %31 to i32
br label %33
33: ; preds = %1, %29, %25, %12
%34 = phi i32 [ %32, %29 ], [ -1, %25 ], [ -1, %12 ], [ -1, %1 ]
ret i32 %34
}