#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 *);
scalar_t__ isdigit(char);
int get_next_id(char **cp) {
  int ret;
  if (**cp == 0)
    return -1;
  while (!isdigit(**cp)) {
    if (**cp == 0)
      return -1;
    else
      (*cp)++;
  }
  ret = atoi(*cp);
  while (isdigit(**cp))
    (*cp)++;
  return ret;
}


x86 assembly (clang, -O0):
<get_next_id>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    114b <get_next_id+0x2b>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e8 <get_next_id+0xc8>
jmp    1150 <get_next_id+0x30>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
movsbl (%rax),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1175 <get_next_id+0x55>
jmp    11a7 <get_next_id+0x87>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    1194 <get_next_id+0x74>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e8 <get_next_id+0xc8>
mov    -0x10(%rbp),%rax
mov    (%rax),%rcx
add    $0x1,%rcx
mov    %rcx,(%rax)
jmp    1150 <get_next_id+0x30>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1040 <atoi@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
movsbl (%rax),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
je     11e2 <get_next_id+0xc2>
mov    -0x10(%rbp),%rax
mov    (%rax),%rcx
add    $0x1,%rcx
mov    %rcx,(%rax)
jmp    11b6 <get_next_id+0x96>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_next_id>:
push   %rbp
push   %r14
push   %rbx
mov    (%rdi),%rax
mov    (%rax),%al
mov    $0xffffffff,%r14d
test   %al,%al
je     119a <get_next_id+0x7a>
mov    %rdi,%rbx
movsbl %al,%edi
nopl   0x0(%rax)
call   1030 <isdigit@plt>
test   %rax,%rax
jne    115f <get_next_id+0x3f>
mov    (%rbx),%rax
cmpb   $0x0,(%rax)
je     119a <get_next_id+0x7a>
lea    0x1(%rax),%rcx
mov    %rcx,(%rbx)
movsbl 0x1(%rax),%edi
jmp    1140 <get_next_id+0x20>
mov    (%rbx),%rbp
mov    %rbp,%rdi
call   1040 <atoi@plt>
mov    %eax,%r14d
movsbl 0x0(%rbp),%edi
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
call   1030 <isdigit@plt>
test   %rax,%rax
je     119a <get_next_id+0x7a>
mov    (%rbx),%rax
lea    0x1(%rax),%rcx
mov    %rcx,(%rbx)
movsbl 0x1(%rax),%edi
jmp    1180 <get_next_id+0x60>
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @get_next_id(i8** nocapture %0) {
%2 = load i8*, i8** %0
%3 = load i8, i8* %2
%4 = icmp eq i8 %3, 0
br i1 %4, label %29, label %5
5: ; preds = %1
%6 = tail call i64 @isdigit(i8 signext %3)
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %17
8: ; preds = %5, %12
%9 = load i8*, i8** %0
%10 = load i8, i8* %9
%11 = icmp eq i8 %10, 0
br i1 %11, label %29, label %12
12: ; preds = %8
%13 = getelementptr inbounds i8, i8* %9, i64 1
store i8* %13, i8** %0
%14 = load i8, i8* %13
%15 = tail call i64 @isdigit(i8 signext %14)
%16 = icmp eq i64 %15, 0
br i1 %16, label %8, label %17
17: ; preds = %12, %5
%18 = load i8*, i8** %0
%19 = tail call i32 @atoi(i8* %18)
%20 = load i8, i8* %18
%21 = tail call i64 @isdigit(i8 signext %20)
%22 = icmp eq i64 %21, 0
br i1 %22, label %29, label %23
23: ; preds = %17, %23
%24 = load i8*, i8** %0
%25 = getelementptr inbounds i8, i8* %24, i64 1
store i8* %25, i8** %0
%26 = load i8, i8* %25
%27 = tail call i64 @isdigit(i8 signext %26)
%28 = icmp eq i64 %27, 0
br i1 %28, label %29, label %23
29: ; preds = %8, %23, %17, %1
%30 = phi i32 [ -1, %1 ], [ %19, %17 ], [ %19, %23 ], [ -1, %8 ]
ret i32 %30
}