#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 */
struct udev {
  int dummy;
};

/* Variables and functions */
scalar_t__ isdigit(char);
scalar_t__ strtoul(char *, char **, int);
int /*<<< orphan*/ udev_log_null(struct udev *, char *, ...);
int get_format_len(struct udev *udev, char **str) {
  int num;
  char *tail;
  if (isdigit(*str[0])) {
    num = (int)strtoul(*str, &tail, 10);
    if (num > 0) {
      *str = tail;
      udev_log_null(udev, "format length=%i\n", num);
      return num;
    } else {
      udev_log_null(udev, "format parsing error '%s'\n", *str);
    }
  }
  return -1;
}


x86 assembly (clang, -O0):
<get_format_len>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
movsbl (%rax),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
je     11c4 <get_format_len+0x94>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
lea    -0x28(%rbp),%rsi
mov    $0xa,%edx
call   1050 <strtoul@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jle    11a6 <get_format_len+0x76>
mov    -0x28(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rdi
mov    -0x1c(%rbp),%edx
lea    0xe6c(%rip),%rsi
mov    $0x0,%al
call   1040 <udev_log_null@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11cb <get_format_len+0x9b>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    (%rax),%rdx
lea    0xe5a(%rip),%rsi
mov    $0x0,%al
call   1040 <udev_log_null@plt>
jmp    11c4 <get_format_len+0x94>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_format_len>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r15
mov    %rdi,%r14
mov    (%rsi),%rax
movsbl (%rax),%edi
call   1030 <isdigit@plt>
mov    $0xffffffff,%ebx
test   %rax,%rax
je     11a3 <get_format_len+0x73>
mov    (%r15),%rdi
lea    0x8(%rsp),%rsi
mov    $0xa,%edx
call   1050 <strtoul@plt>
mov    %rax,%rbx
test   %ebx,%ebx
jle    118a <get_format_len+0x5a>
mov    0x8(%rsp),%rax
mov    %rax,(%r15)
lea    0xe84(%rip),%rsi
mov    %r14,%rdi
mov    %ebx,%edx
xor    %eax,%eax
call   1040 <udev_log_null@plt>
jmp    11a3 <get_format_len+0x73>
mov    (%r15),%rdx
lea    0xe7e(%rip),%rsi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <udev_log_null@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.udev = type { i32 }
@.str = [18 x i8] c"format length=%i\0A\00"
@.str.1 = [27 x i8] c"format parsing error '%s'\0A\00"
define i32 @get_format_len(%struct.udev* %0, i8** %1) {
%3 = alloca i32
%4 = alloca %struct.udev*
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8*
store %struct.udev* %0, %struct.udev** %4
store i8** %1, i8*** %5
%8 = load i8**, i8*** %5
%9 = getelementptr inbounds i8*, i8** %8, i64 0
%10 = load i8*, i8** %9
%11 = load i8, i8* %10
%12 = call i64 @isdigit(i8 signext %11)
%13 = icmp ne i64 %12, 0
br i1 %13, label %14, label %34
14: ; preds = %2
%15 = load i8**, i8*** %5
%16 = load i8*, i8** %15
%17 = call i64 @strtoul(i8* %16, i8** %7, i32 10)
%18 = trunc i64 %17 to i32
store i32 %18, i32* %6
%19 = load i32, i32* %6
%20 = icmp sgt i32 %19, 0
br i1 %20, label %21, label %28
21: ; preds = %14
%22 = load i8*, i8** %7
%23 = load i8**, i8*** %5
store i8* %22, i8** %23
%24 = load %struct.udev*, %struct.udev** %4
%25 = load i32, i32* %6
%26 = call i32 (%struct.udev*, i8*, ...) @udev_log_null(%struct.udev* %24, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 %25)
%27 = load i32, i32* %6
store i32 %27, i32* %3
br label %35
28: ; preds = %14
%29 = load %struct.udev*, %struct.udev** %4
%30 = load i8**, i8*** %5
%31 = load i8*, i8** %30
%32 = call i32 (%struct.udev*, i8*, ...) @udev_log_null(%struct.udev* %29, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %31)
br label %33
33: ; preds = %28
br label %34
34: ; preds = %33, %2
store i32 -1, i32* %3
br label %35
35: ; preds = %34, %21
%36 = load i32, i32* %3
ret i32 %36
}

LLVM IR (-O2):
%struct.udev = type { i32 }
@.str = [18 x i8] c"format length=%i\0A\00"
@.str.1 = [27 x i8] c"format parsing error '%s'\0A\00"
define i32 @get_format_len(%struct.udev* %0, i8** nocapture %1) {
%3 = alloca i8*
%4 = bitcast i8** %3 to i8*
%5 = load i8*, i8** %1
%6 = load i8, i8* %5
%7 = tail call i64 @isdigit(i8 signext %6)
%8 = icmp eq i64 %7, 0
br i1 %8, label %20, label %9
9: ; preds = %2
%10 = load i8*, i8** %1
%11 = call i64 @strtoul(i8* %10, i8** %3, i32 10)
%12 = trunc i64 %11 to i32
%13 = icmp sgt i32 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %9
%15 = load i8*, i8** %3
store i8* %15, i8** %1
%16 = tail call i32 (%struct.udev*, i8*, ...) @udev_log_null(%struct.udev* %0, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 %12)
br label %20
17: ; preds = %9
%18 = load i8*, i8** %1
%19 = tail call i32 (%struct.udev*, i8*, ...) @udev_log_null(%struct.udev* %0, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %18)
br label %20
20: ; preds = %2, %17, %14
%21 = phi i32 [ %12, %14 ], [ -1, %17 ], [ -1, %2 ]
ret i32 %21
}