#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 atoi(char *);
int /*<<< orphan*/ consume_number(char **);
int parse_number(char **s, int *ret) {
  char *ss = *s;
  int n = atoi(ss);
  if (n) {
    consume_number(s);
    *ret = n;
    return 0;
  }
  if ((ss[0] == '-' && ss[1] == '0') || ss[0] == '0') {
    consume_number(s);
    *ret = 0;
    return 0;
  }
  return -1;
}


x86 assembly (clang, -O0):
<parse_number>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <atoi@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
je     116f <parse_number+0x4f>
mov    -0x10(%rbp),%rdi
call   1040 <consume_number@plt>
mov    -0x24(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x0,-0x4(%rbp)
jmp    11c6 <parse_number+0xa6>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2d,%eax
jne    1190 <parse_number+0x70>
mov    -0x20(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x30,%eax
je     11a0 <parse_number+0x80>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x30,%eax
jne    11bf <parse_number+0x9f>
mov    -0x10(%rbp),%rdi
call   1040 <consume_number@plt>
mov    -0x18(%rbp),%rax
movl   $0x0,(%rax)
movl   $0x0,-0x4(%rbp)
jmp    11c6 <parse_number+0xa6>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_number>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
mov    (%rdi),%rbx
mov    %rbx,%rdi
call   1030 <atoi@plt>
mov    %eax,%ebp
test   %eax,%eax
je     1156 <parse_number+0x36>
mov    %r15,%rdi
call   1040 <consume_number@plt>
mov    %ebp,(%r14)
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    (%rbx),%cl
xor    %ebp,%ebp
cmp    $0x30,%cl
je     113e <parse_number+0x1e>
mov    $0xffffffff,%eax
cmp    $0x2d,%cl
jne    114b <parse_number+0x2b>
cmpb   $0x30,0x1(%rbx)
je     113e <parse_number+0x1e>
jmp    114b <parse_number+0x2b>

LLVM IR (-O0):
define i32 @parse_number(i8** %0, i32* %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca i32
store i8** %0, i8*** %4
store i32* %1, i32** %5
%8 = load i8**, i8*** %4
%9 = load i8*, i8** %8
store i8* %9, i8** %6
%10 = load i8*, i8** %6
%11 = call i32 @atoi(i8* %10)
store i32 %11, i32* %7
%12 = load i32, i32* %7
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %19
14: ; preds = %2
%15 = load i8**, i8*** %4
%16 = call i32 @consume_number(i8** %15)
%17 = load i32, i32* %7
%18 = load i32*, i32** %5
store i32 %17, i32* %18
store i32 0, i32* %3
br label %42
19: ; preds = %2
%20 = load i8*, i8** %6
%21 = getelementptr inbounds i8, i8* %20, i64 0
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
%24 = icmp eq i32 %23, 45
br i1 %24, label %25, label %31
25: ; preds = %19
%26 = load i8*, i8** %6
%27 = getelementptr inbounds i8, i8* %26, i64 1
%28 = load i8, i8* %27
%29 = sext i8 %28 to i32
%30 = icmp eq i32 %29, 48
br i1 %30, label %37, label %31
31: ; preds = %25, %19
%32 = load i8*, i8** %6
%33 = getelementptr inbounds i8, i8* %32, i64 0
%34 = load i8, i8* %33
%35 = sext i8 %34 to i32
%36 = icmp eq i32 %35, 48
br i1 %36, label %37, label %41
37: ; preds = %31, %25
%38 = load i8**, i8*** %4
%39 = call i32 @consume_number(i8** %38)
%40 = load i32*, i32** %5
store i32 0, i32* %40
store i32 0, i32* %3
br label %42
41: ; preds = %31
store i32 -1, i32* %3
br label %42
42: ; preds = %41, %37, %14
%43 = load i32, i32* %3
ret i32 %43
}

LLVM IR (-O2):
define i32 @parse_number(i8** %0, i32* nocapture writeonly %1) {
%3 = load i8*, i8** %0
%4 = tail call i32 @atoi(i8* %3)
%5 = icmp eq i32 %4, 0
br i1 %5, label %6, label %12
6: ; preds = %2
%7 = load i8, i8* %3
switch i8 %7, label %15 [
i8 45, label %8
i8 48, label %12
]
8: ; preds = %6
%9 = getelementptr inbounds i8, i8* %3, i64 1
%10 = load i8, i8* %9
%11 = icmp eq i8 %10, 48
br i1 %11, label %12, label %15
12: ; preds = %8, %6, %2
%13 = phi i32 [ %4, %2 ], [ 0, %6 ], [ 0, %8 ]
%14 = tail call i32 @consume_number(i8** %0)
store i32 %13, i32* %1
br label %15
15: ; preds = %12, %6, %8
%16 = phi i32 [ -1, %8 ], [ -1, %6 ], [ 0, %12 ]
ret i32 %16
}