#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*/ bitch(char *, char *);
scalar_t__ isdigit(char);
int /*<<< orphan*/ isspace(char);
char *skip_white_space(char *);
long long strtoll(char *, int /*<<< orphan*/ *, int);
long long extract_integer(char **input, char *what) {
  char *s = *input;
  long long r = -1;
  char *end = NULL;
  char c;
  if (!isdigit(*s)) {
    bitch("%s expected", what);
    return -1;
  }
  s++;
  while (isdigit(*s))
    s++;
  if (*s && !isspace(*s) && *s != ';' && *s != ')') {
    bitch("%s is not valid", what);
    return -1;
  }
  if (!*s)
    end = s;
  c = *s;
  *s = '\0';
  r = strtoll(*input, NULL, 10);
  *s = c;
  if (end) {
    *input = end;
  } else {
    *input = skip_white_space(s);
    if (!*input)
      return -1;
  }
  return r;
}


x86 assembly (clang, -O0):
<extract_integer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
movq   $0xffffffffffffffff,-0x28(%rbp)
ff
movq   $0x0,-0x30(%rbp)
mov    -0x20(%rbp),%rax
movsbl (%rax),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
jne    11ae <extract_integer+0x5e>
mov    -0x18(%rbp),%rsi
lea    0xe64(%rip),%rdi
call   1040 <bitch@plt>
movq   $0xffffffffffffffff,-0x8(%rbp)
ff
jmp    12e0 <extract_integer+0x190>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movsbl (%rax),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
je     11e1 <extract_integer+0x91>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    11ba <extract_integer+0x6a>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1243 <extract_integer+0xf3>
mov    -0x20(%rbp),%rax
movsbl (%rax),%edi
call   1050 <isspace@plt>
cmp    $0x0,%eax
jne    1243 <extract_integer+0xf3>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x3b,%eax
je     1243 <extract_integer+0xf3>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x29,%eax
je     1243 <extract_integer+0xf3>
mov    -0x18(%rbp),%rsi
lea    0xddb(%rip),%rdi
call   1040 <bitch@plt>
movq   $0xffffffffffffffff,-0x8(%rbp)
ff
jmp    12e0 <extract_integer+0x190>
mov    -0x20(%rbp),%rax
cmpb   $0x0,(%rax)
jne    1258 <extract_integer+0x108>
mov    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rax
mov    (%rax),%al
mov    %al,-0x31(%rbp)
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1060 <strtoll@plt>
mov    %rax,-0x28(%rbp)
mov    -0x31(%rbp),%cl
mov    -0x20(%rbp),%rax
mov    %cl,(%rax)
cmpq   $0x0,-0x30(%rbp)
je     12a5 <extract_integer+0x155>
mov    -0x30(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
jmp    12d8 <extract_integer+0x188>
mov    -0x20(%rbp),%rdi
call   1070 <skip_white_space@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
jne    12d3 <extract_integer+0x183>
movq   $0xffffffffffffffff,-0x8(%rbp)
ff
jmp    12e0 <extract_integer+0x190>
jmp    12d8 <extract_integer+0x188>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<extract_integer>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %rdi,%r14
mov    (%rdi),%rbx
movsbl (%rbx),%edi
call   1030 <isdigit@plt>
test   %rax,%rax
je     11ac <extract_integer+0x5c>
nopl   (%rax)
movsbl 0x1(%rbx),%edi
add    $0x1,%rbx
call   1030 <isdigit@plt>
test   %rax,%rax
jne    1170 <extract_integer+0x20>
mov    (%rbx),%al
test   %al,%al
je     11bd <extract_integer+0x6d>
movsbl %al,%edi
call   1050 <isspace@plt>
mov    (%rbx),%bpl
test   %eax,%eax
jne    11bf <extract_integer+0x6f>
cmp    $0x29,%bpl
je     11bf <extract_integer+0x6f>
cmp    $0x3b,%bpl
je     11bf <extract_integer+0x6f>
lea    0xe62(%rip),%rdi
jmp    11b3 <extract_integer+0x63>
lea    0xe4d(%rip),%rdi
mov    %r15,%rsi
call   1040 <bitch@plt>
jmp    11ec <extract_integer+0x9c>
xor    %ebp,%ebp
movb   $0x0,(%rbx)
mov    (%r14),%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1060 <strtoll@plt>
mov    %rax,%r15
mov    %bpl,(%rbx)
test   %bpl,%bpl
je     11f5 <extract_integer+0xa5>
mov    %rbx,%rdi
call   1070 <skip_white_space@plt>
mov    %rax,(%r14)
test   %rax,%rax
jne    11f8 <extract_integer+0xa8>
mov    $0xffffffffffffffff,%r15
jmp    11f8 <extract_integer+0xa8>
mov    %rbx,(%r14)
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [12 x i8] c"%s expected\00"
@.str.1 = [16 x i8] c"%s is not valid\00"
define i64 @extract_integer(i8** %0, i8* %1) {
%3 = alloca i64
%4 = alloca i8**
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i8*
%9 = alloca i8
store i8** %0, i8*** %4
store i8* %1, i8** %5
%10 = load i8**, i8*** %4
%11 = load i8*, i8** %10
store i8* %11, i8** %6
store i64 -1, i64* %7
store i8* null, i8** %8
%12 = load i8*, i8** %6
%13 = load i8, i8* %12
%14 = call i64 @isdigit(i8 signext %13)
%15 = icmp ne i64 %14, 0
br i1 %15, label %19, label %16
16: ; preds = %2
%17 = load i8*, i8** %5
%18 = call i32 @bitch(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* %17)
store i64 -1, i64* %3
br label %84
19: ; preds = %2
%20 = load i8*, i8** %6
%21 = getelementptr inbounds i8, i8* %20, i32 1
store i8* %21, i8** %6
br label %22
22: ; preds = %27, %19
%23 = load i8*, i8** %6
%24 = load i8, i8* %23
%25 = call i64 @isdigit(i8 signext %24)
%26 = icmp ne i64 %25, 0
br i1 %26, label %27, label %30
27: ; preds = %22
%28 = load i8*, i8** %6
%29 = getelementptr inbounds i8, i8* %28, i32 1
store i8* %29, i8** %6
br label %22
30: ; preds = %22
%31 = load i8*, i8** %6
%32 = load i8, i8* %31
%33 = sext i8 %32 to i32
%34 = icmp ne i32 %33, 0
br i1 %34, label %35, label %53
35: ; preds = %30
%36 = load i8*, i8** %6
%37 = load i8, i8* %36
%38 = call i32 @isspace(i8 signext %37)
%39 = icmp ne i32 %38, 0
br i1 %39, label %53, label %40
40: ; preds = %35
%41 = load i8*, i8** %6
%42 = load i8, i8* %41
%43 = sext i8 %42 to i32
%44 = icmp ne i32 %43, 59
br i1 %44, label %45, label %53
45: ; preds = %40
%46 = load i8*, i8** %6
%47 = load i8, i8* %46
%48 = sext i8 %47 to i32
%49 = icmp ne i32 %48, 41
br i1 %49, label %50, label %53
50: ; preds = %45
%51 = load i8*, i8** %5
%52 = call i32 @bitch(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* %51)
store i64 -1, i64* %3
br label %84
53: ; preds = %45, %40, %35, %30
%54 = load i8*, i8** %6
%55 = load i8, i8* %54
%56 = icmp ne i8 %55, 0
br i1 %56, label %59, label %57
57: ; preds = %53
%58 = load i8*, i8** %6
store i8* %58, i8** %8
br label %59
59: ; preds = %57, %53
%60 = load i8*, i8** %6
%61 = load i8, i8* %60
store i8 %61, i8* %9
%62 = load i8*, i8** %6
store i8 0, i8* %62
%63 = load i8**, i8*** %4
%64 = load i8*, i8** %63
%65 = call i64 @strtoll(i8* %64, i32* null, i32 10)
store i64 %65, i64* %7
%66 = load i8, i8* %9
%67 = load i8*, i8** %6
store i8 %66, i8* %67
%68 = load i8*, i8** %8
%69 = icmp ne i8* %68, null
br i1 %69, label %70, label %73
70: ; preds = %59
%71 = load i8*, i8** %8
%72 = load i8**, i8*** %4
store i8* %71, i8** %72
br label %82
73: ; preds = %59
%74 = load i8*, i8** %6
%75 = call i8* @skip_white_space(i8* %74)
%76 = load i8**, i8*** %4
store i8* %75, i8** %76
%77 = load i8**, i8*** %4
%78 = load i8*, i8** %77
%79 = icmp ne i8* %78, null
br i1 %79, label %81, label %80
80: ; preds = %73
store i64 -1, i64* %3
br label %84
81: ; preds = %73
br label %82
82: ; preds = %81, %70
%83 = load i64, i64* %7
store i64 %83, i64* %3
br label %84
84: ; preds = %82, %80, %50, %16
%85 = load i64, i64* %3
ret i64 %85
}

LLVM IR (-O2):
@.str = [12 x i8] c"%s expected\00"
@.str.1 = [16 x i8] c"%s is not valid\00"
define i64 @extract_integer(i8** nocapture %0, i8* %1) {
%3 = load i8*, i8** %0
%4 = load i8, i8* %3
%5 = tail call i64 @isdigit(i8 signext %4)
%6 = icmp eq i64 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %2
%8 = tail call i32 @bitch(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* %1)
br label %35
9: ; preds = %2, %9
%10 = phi i8* [ %11, %9 ], [ %3, %2 ]
%11 = getelementptr inbounds i8, i8* %10, i64 1
%12 = load i8, i8* %11
%13 = tail call i64 @isdigit(i8 signext %12)
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %9
15: ; preds = %9
%16 = load i8, i8* %11
%17 = icmp eq i8 %16, 0
br i1 %17, label %25, label %18
18: ; preds = %15
%19 = tail call i32 @isspace(i8 signext %16)
%20 = icmp eq i32 %19, 0
%21 = load i8, i8* %11
br i1 %20, label %22, label %25
22: ; preds = %18
switch i8 %21, label %23 [
i8 59, label %25
i8 41, label %25
]
23: ; preds = %22
%24 = tail call i32 @bitch(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* %1)
br label %35
25: ; preds = %18, %22, %22, %15
%26 = phi i8 [ %21, %22 ], [ %21, %22 ], [ 0, %15 ], [ %21, %18 ]
%27 = icmp eq i8 %26, 0
store i8 0, i8* %11
%28 = load i8*, i8** %0
%29 = tail call i64 @strtoll(i8* nocapture %28, i32* null, i32 10)
store i8 %26, i8* %11
br i1 %27, label %30, label %31
30: ; preds = %25
store i8* %11, i8** %0
br label %34
31: ; preds = %25
%32 = tail call i8* @skip_white_space(i8* %11)
store i8* %32, i8** %0
%33 = icmp eq i8* %32, null
br i1 %33, label %35, label %34
34: ; preds = %31, %30
br label %35
35: ; preds = %31, %34, %23, %7
%36 = phi i64 [ %29, %34 ], [ -1, %23 ], [ -1, %7 ], [ -1, %31 ]
ret i64 %36
}