#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*/ isdigit(char);
int strlen(char *);
int nl_nid_parse_addr(char *addr) {
  int o;
  for (o = strlen(addr); o > 0; o--)
    if (!isdigit(addr[o - 1]))
      break;
  return o;
}


x86 assembly (clang, -O0):
<nl_nid_parse_addr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jle    1179 <nl_nid_parse_addr+0x59>
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%eax
jne    1166 <nl_nid_parse_addr+0x46>
jmp    1179 <nl_nid_parse_addr+0x59>
jmp    116b <nl_nid_parse_addr+0x4b>
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
jmp    1138 <nl_nid_parse_addr+0x18>
mov    -0xc(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<nl_nid_parse_addr>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%rbx
call   1040 <strlen@plt>
mov    %eax,%ebp
xor    %r14d,%r14d
test   %eax,%eax
cmovs  %eax,%r14d
nopw   0x0(%rax,%rax,1)
test   %ebp,%ebp
jle    115c <nl_nid_parse_addr+0x3c>
movsbl -0x1(%rbx,%rbp,1),%edi
add    $0xffffffffffffffff,%rbp
call   1030 <isdigit@plt>
test   %eax,%eax
jne    1140 <nl_nid_parse_addr+0x20>
add    $0x1,%ebp
mov    %ebp,%r14d
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @nl_nid_parse_addr(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
store i8* %0, i8** %2
%4 = load i8*, i8** %2
%5 = call i32 @strlen(i8* %4)
store i32 %5, i32* %3
br label %6
6: ; preds = %20, %1
%7 = load i32, i32* %3
%8 = icmp sgt i32 %7, 0
br i1 %8, label %9, label %23
9: ; preds = %6
%10 = load i8*, i8** %2
%11 = load i32, i32* %3
%12 = sub nsw i32 %11, 1
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds i8, i8* %10, i64 %13
%15 = load i8, i8* %14
%16 = call i32 @isdigit(i8 signext %15)
%17 = icmp ne i32 %16, 0
br i1 %17, label %19, label %18
18: ; preds = %9
br label %23
19: ; preds = %9
br label %20
20: ; preds = %19
%21 = load i32, i32* %3
%22 = add nsw i32 %21, -1
store i32 %22, i32* %3
br label %6
23: ; preds = %18, %6
%24 = load i32, i32* %3
ret i32 %24
}

LLVM IR (-O2):
define i32 @nl_nid_parse_addr(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = zext i32 %2 to i64
%4 = call i32 @llvm.smin.i32(i32 %2, i32 0)
br label %5
5: ; preds = %9, %1
%6 = phi i64 [ %10, %9 ], [ %3, %1 ]
%7 = trunc i64 %6 to i32
%8 = icmp sgt i32 %7, 0
br i1 %8, label %9, label %17
9: ; preds = %5
%10 = add nsw i64 %6, -1
%11 = getelementptr inbounds i8, i8* %0, i64 %10
%12 = load i8, i8* %11
%13 = tail call i32 @isdigit(i8 signext %12)
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %5
15: ; preds = %9
%16 = trunc i64 %6 to i32
br label %17
17: ; preds = %5, %15
%18 = phi i32 [ %16, %15 ], [ %4, %5 ]
ret i32 %18
}