#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);
int dec_num(const char **s) {
  int n = -1;
  while (**s && isdigit(**s)) {
    if (n < 0)
      n = 0;
    n = n * 10 + (**s - '0');
    (*s)++;
  }
  return n;
}


x86 assembly (clang, -O0):
<dec_num>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0xffffffff,-0xc(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0xd(%rbp)
je     1154 <dec_num+0x44>
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
movsbl (%rax),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0xd(%rbp)
mov    -0xd(%rbp),%al
test   $0x1,%al
jne    1164 <dec_num+0x54>
jmp    119e <dec_num+0x8e>
cmpl   $0x0,-0xc(%rbp)
jge    1175 <dec_num+0x65>
movl   $0x0,-0xc(%rbp)
imul   $0xa,-0xc(%rbp),%eax
mov    -0x8(%rbp),%rcx
mov    (%rcx),%rcx
movsbl (%rcx),%ecx
sub    $0x30,%ecx
add    %ecx,%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rcx
add    $0x1,%rcx
mov    %rcx,(%rax)
jmp    1123 <dec_num+0x13>
mov    -0xc(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dec_num>:
push   %rbp
push   %r14
push   %rbx
mov    (%rdi),%rax
mov    (%rax),%al
test   %al,%al
je     1162 <dec_num+0x52>
mov    %rdi,%r14
mov    $0xffffffff,%ebx
xor    %ebp,%ebp
nopw   0x0(%rax,%rax,1)
movsbl %al,%edi
call   1030 <isdigit@plt>
test   %rax,%rax
je     1167 <dec_num+0x57>
test   %ebx,%ebx
cmovs  %ebp,%ebx
lea    (%rbx,%rbx,4),%eax
mov    (%r14),%rcx
movsbl (%rcx),%edx
lea    (%rdx,%rax,2),%ebx
add    $0xffffffd0,%ebx
lea    0x1(%rcx),%rax
mov    %rax,(%r14)
movzbl 0x1(%rcx),%eax
test   %al,%al
jne    1130 <dec_num+0x20>
jmp    1167 <dec_num+0x57>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @dec_num(i8** %0) {
%2 = alloca i8**
%3 = alloca i32
store i8** %0, i8*** %2
store i32 -1, i32* %3
br label %4
4: ; preds = %22, %1
%5 = load i8**, i8*** %2
%6 = load i8*, i8** %5
%7 = load i8, i8* %6
%8 = sext i8 %7 to i32
%9 = icmp ne i32 %8, 0
br i1 %9, label %10, label %16
10: ; preds = %4
%11 = load i8**, i8*** %2
%12 = load i8*, i8** %11
%13 = load i8, i8* %12
%14 = call i64 @isdigit(i8 signext %13)
%15 = icmp ne i64 %14, 0
br label %16
16: ; preds = %10, %4
%17 = phi i1 [ false, %4 ], [ %15, %10 ]
br i1 %17, label %18, label %34
18: ; preds = %16
%19 = load i32, i32* %3
%20 = icmp slt i32 %19, 0
br i1 %20, label %21, label %22
21: ; preds = %18
store i32 0, i32* %3
br label %22
22: ; preds = %21, %18
%23 = load i32, i32* %3
%24 = mul nsw i32 %23, 10
%25 = load i8**, i8*** %2
%26 = load i8*, i8** %25
%27 = load i8, i8* %26
%28 = sext i8 %27 to i32
%29 = sub nsw i32 %28, 48
%30 = add nsw i32 %24, %29
store i32 %30, i32* %3
%31 = load i8**, i8*** %2
%32 = load i8*, i8** %31
%33 = getelementptr inbounds i8, i8* %32, i32 1
store i8* %33, i8** %31
br label %4
34: ; preds = %16
%35 = load i32, i32* %3
ret i32 %35
}

LLVM IR (-O2):
define i32 @dec_num(i8** nocapture %0) {
%2 = load i8*, i8** %0
%3 = load i8, i8* %2
%4 = icmp eq i8 %3, 0
br i1 %4, label %22, label %5
5: ; preds = %1, %10
%6 = phi i8 [ %20, %10 ], [ %3, %1 ]
%7 = phi i32 [ %18, %10 ], [ -1, %1 ]
%8 = tail call i64 @isdigit(i8 signext %6)
%9 = icmp eq i64 %8, 0
br i1 %9, label %22, label %10
10: ; preds = %5
%11 = icmp sgt i32 %7, 0
%12 = select i1 %11, i32 %7, i32 0
%13 = mul nsw i32 %12, 10
%14 = load i8*, i8** %0
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
%17 = add nsw i32 %13, -48
%18 = add i32 %17, %16
%19 = getelementptr inbounds i8, i8* %14, i64 1
store i8* %19, i8** %0
%20 = load i8, i8* %19
%21 = icmp eq i8 %20, 0
br i1 %21, label %22, label %5
22: ; preds = %5, %10, %1
%23 = phi i32 [ -1, %1 ], [ %18, %10 ], [ %7, %5 ]
ret i32 %23
}