#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__ isdigit(char const);
scalar_t__ isspace(char const);
int /*<<< orphan*/ warning(char *);
int get_optional_number(const char *p) {
  int val = -1;
  while (isspace(*p))
    ++p;
  if (*p++ == '(') {
    int got_digit = 0;
    while (isspace(*p))
      ++p;
    if (isdigit(*p)) {
      got_digit = 1;
      val = *p++ - '0';
    }
    while (isspace(*p))
      ++p;
    if (*p != ')')
      val = got_digit = 0;
    if (!got_digit)
      warning("expected \"(0..9)\"");
  }
  return val;
}


x86 assembly (clang, -O0):
<get_optional_number>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0xffffffff,-0xc(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%edi
call   1050 <isspace@plt>
cmp    $0x0,%rax
je     116a <get_optional_number+0x3a>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    1143 <get_optional_number+0x13>
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movsbl (%rax),%eax
cmp    $0x28,%eax
jne    124d <get_optional_number+0x11d>
movl   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%edi
call   1050 <isspace@plt>
cmp    $0x0,%rax
je     11b3 <get_optional_number+0x83>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    118c <get_optional_number+0x5c>
mov    -0x8(%rbp),%rax
movsbl (%rax),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
je     11e8 <get_optional_number+0xb8>
movl   $0x1,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movsbl (%rax),%eax
sub    $0x30,%eax
mov    %eax,-0xc(%rbp)
jmp    11ed <get_optional_number+0xbd>
mov    -0x8(%rbp),%rax
movsbl (%rax),%edi
call   1050 <isspace@plt>
cmp    $0x0,%rax
je     1214 <get_optional_number+0xe4>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    11ed <get_optional_number+0xbd>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x29,%eax
je     1232 <get_optional_number+0x102>
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0xc(%rbp)
cmpl   $0x0,-0x10(%rbp)
jne    1248 <get_optional_number+0x118>
lea    0xdbd(%rip),%rdi
call   1040 <warning@plt>
jmp    124d <get_optional_number+0x11d>
mov    -0xc(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_optional_number>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdi,%rbx
nopl   0x0(%rax,%rax,1)
movsbl (%rbx),%edi
call   1050 <isspace@plt>
add    $0x1,%rbx
test   %rax,%rax
jne    1140 <get_optional_number+0x10>
mov    $0xffffffff,%r15d
cmpb   $0x28,-0x1(%rbx)
jne    11d0 <get_optional_number+0xa0>
nopl   (%rax)
movsbl (%rbx),%edi
call   1050 <isspace@plt>
add    $0x1,%rbx
test   %rax,%rax
jne    1160 <get_optional_number+0x30>
lea    -0x1(%rbx),%rbp
movsbl -0x1(%rbx),%edi
call   1030 <isdigit@plt>
mov    %rax,%r14
test   %rax,%rax
je     1194 <get_optional_number+0x64>
movsbl 0x0(%rbp),%r12d
add    $0xffffffd0,%r12d
mov    %rbx,%rbp
jmp    11a0 <get_optional_number+0x70>
mov    $0xffffffff,%r12d
nopw   0x0(%rax,%rax,1)
movsbl 0x0(%rbp),%edi
call   1050 <isspace@plt>
add    $0x1,%rbp
test   %rax,%rax
jne    11a0 <get_optional_number+0x70>
xor    %r15d,%r15d
cmpb   $0x29,-0x1(%rbp)
cmove  %r12d,%r15d
jne    11c4 <get_optional_number+0x94>
test   %r14,%r14
jne    11d0 <get_optional_number+0xa0>
lea    0xe35(%rip),%rdi
call   1040 <warning@plt>
mov    %r15d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [18 x i8] c"expected \22(0..9)\22\00"
define i32 @get_optional_number(i8* nocapture %0) {
br label %2
2: ; preds = %2, %1
%3 = phi i8* [ %0, %1 ], [ %7, %2 ]
%4 = load i8, i8* %3
%5 = tail call i64 @isspace(i8 signext %4)
%6 = icmp eq i64 %5, 0
%7 = getelementptr inbounds i8, i8* %3, i64 1
br i1 %6, label %8, label %2
8: ; preds = %2
%9 = load i8, i8* %3
%10 = icmp eq i8 %9, 40
br i1 %10, label %11, label %43
11: ; preds = %8, %11
%12 = phi i8* [ %13, %11 ], [ %3, %8 ]
%13 = getelementptr inbounds i8, i8* %12, i64 1
%14 = load i8, i8* %13
%15 = tail call i64 @isspace(i8 signext %14)
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %11
17: ; preds = %11
%18 = load i8, i8* %13
%19 = tail call i64 @isdigit(i8 signext %18)
%20 = icmp eq i64 %19, 0
br i1 %20, label %26, label %21
21: ; preds = %17
%22 = getelementptr inbounds i8, i8* %12, i64 2
%23 = load i8, i8* %13
%24 = sext i8 %23 to i32
%25 = add nsw i32 %24, -48
br label %26
26: ; preds = %21, %17
%27 = phi i8* [ %22, %21 ], [ %13, %17 ]
%28 = phi i32 [ %25, %21 ], [ -1, %17 ]
br label %29
29: ; preds = %29, %26
%30 = phi i8* [ %27, %26 ], [ %34, %29 ]
%31 = load i8, i8* %30
%32 = tail call i64 @isspace(i8 signext %31)
%33 = icmp eq i64 %32, 0
%34 = getelementptr inbounds i8, i8* %30, i64 1
br i1 %33, label %35, label %29
35: ; preds = %29
%36 = load i8, i8* %30
%37 = icmp eq i8 %36, 41
%38 = select i1 %37, i32 %28, i32 0
%39 = xor i1 %37, true
%40 = select i1 %39, i1 true, i1 %20
br i1 %40, label %41, label %43
41: ; preds = %35
%42 = tail call i32 @warning(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
br label %43
43: ; preds = %35, %41, %8
%44 = phi i32 [ -1, %8 ], [ %38, %41 ], [ %38, %35 ]
ret i32 %44
}