#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);
char *skip_whitespace(char *);
int /*<<< orphan*/ sscanf(char *, char *, int *);
char *parse_integer(char *s, int *value) {
  s = skip_whitespace(s);
  if (*s == '+' || *s == '-' || isdigit(*s)) {
    sscanf(s, "%d", value);
    ++s;
    while (isdigit(*s)) {
      ++s;
    }
    return s;
  }
  return NULL;
}


x86 assembly (clang, -O0):
<parse_integer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <skip_whitespace@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2b,%eax
je     1183 <parse_integer+0x53>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2d,%eax
je     1183 <parse_integer+0x53>
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
je     11d7 <parse_integer+0xa7>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xe6e(%rip),%rsi
call   1050 <sscanf@plt>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
je     11ca <parse_integer+0x9a>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    11a3 <parse_integer+0x73>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11df <parse_integer+0xaf>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_integer>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
call   1040 <skip_whitespace@plt>
mov    %rax,%rbx
mov    (%rax),%al
cmp    $0x2b,%al
je     1156 <parse_integer+0x26>
cmp    $0x2d,%al
je     1156 <parse_integer+0x26>
movsbl %al,%edi
call   1030 <isdigit@plt>
test   %rax,%rax
je     118d <parse_integer+0x5d>
lea    0xea3(%rip),%rsi
mov    %rbx,%rdi
mov    %r14,%rdx
call   1050 <sscanf@plt>
nopl   0x0(%rax,%rax,1)
movsbl 0x1(%rbx),%edi
add    $0x1,%rbx
call   1030 <isdigit@plt>
test   %rax,%rax
jne    1170 <parse_integer+0x40>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
xor    %ebx,%ebx
jmp    1182 <parse_integer+0x52>

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
define i8* @parse_integer(i8* %0, i32* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32*
store i8* %0, i8** %4
store i32* %1, i32** %5
%6 = load i8*, i8** %4
%7 = call i8* @skip_whitespace(i8* %6)
store i8* %7, i8** %4
%8 = load i8*, i8** %4
%9 = load i8, i8* %8
%10 = sext i8 %9 to i32
%11 = icmp eq i32 %10, 43
br i1 %11, label %22, label %12
12: ; preds = %2
%13 = load i8*, i8** %4
%14 = load i8, i8* %13
%15 = sext i8 %14 to i32
%16 = icmp eq i32 %15, 45
br i1 %16, label %22, label %17
17: ; preds = %12
%18 = load i8*, i8** %4
%19 = load i8, i8* %18
%20 = call i64 @isdigit(i8 signext %19)
%21 = icmp ne i64 %20, 0
br i1 %21, label %22, label %38
22: ; preds = %17, %12, %2
%23 = load i8*, i8** %4
%24 = load i32*, i32** %5
%25 = call i32 @sscanf(i8* %23, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %24)
%26 = load i8*, i8** %4
%27 = getelementptr inbounds i8, i8* %26, i32 1
store i8* %27, i8** %4
br label %28
28: ; preds = %33, %22
%29 = load i8*, i8** %4
%30 = load i8, i8* %29
%31 = call i64 @isdigit(i8 signext %30)
%32 = icmp ne i64 %31, 0
br i1 %32, label %33, label %36
33: ; preds = %28
%34 = load i8*, i8** %4
%35 = getelementptr inbounds i8, i8* %34, i32 1
store i8* %35, i8** %4
br label %28
36: ; preds = %28
%37 = load i8*, i8** %4
store i8* %37, i8** %3
br label %39
38: ; preds = %17
store i8* null, i8** %3
br label %39
39: ; preds = %38, %36
%40 = load i8*, i8** %3
ret i8* %40
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
define i8* @parse_integer(i8* %0, i32* %1) {
%3 = tail call i8* @skip_whitespace(i8* %0)
%4 = load i8, i8* %3
switch i8 %4, label %5 [
i8 43, label %8
i8 45, label %8
]
5: ; preds = %2
%6 = tail call i64 @isdigit(i8 signext %4)
%7 = icmp eq i64 %6, 0
br i1 %7, label %16, label %8
8: ; preds = %2, %2, %5
%9 = tail call i32 @sscanf(i8* %3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %1)
br label %10
10: ; preds = %10, %8
%11 = phi i8* [ %3, %8 ], [ %12, %10 ]
%12 = getelementptr inbounds i8, i8* %11, i64 1
%13 = load i8, i8* %12
%14 = tail call i64 @isdigit(i8 signext %13)
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %10
16: ; preds = %10, %5
%17 = phi i8* [ null, %5 ], [ %12, %10 ]
ret i8* %17
}