#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 */
typedef int /*<<< orphan*/ tmpstr;

/* Variables and functions */
int /*<<< orphan*/ memcpy(char *, unsigned char *, int);
int strtoul(char *, int /*<<< orphan*/ *, int);
int _extract_dlab_len(unsigned char *data, int lenlen, int len) {
  char tmpstr[64];
  if (lenlen > len || lenlen > sizeof(tmpstr) - 1)
    return -1;
  memcpy(tmpstr, data, lenlen);
  tmpstr[lenlen] = '\0';
  return strtoul(tmpstr, NULL, 10);
}


x86 assembly (clang, -O0):
<_extract_dlab_len>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jg     114c <_extract_dlab_len+0x2c>
movslq -0x14(%rbp),%rax
cmp    $0x3f,%rax
jbe    1158 <_extract_dlab_len+0x38>
movl   $0xffffffff,-0x4(%rbp)
jmp    1186 <_extract_dlab_len+0x66>
lea    -0x60(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1030 <memcpy@plt>
movslq -0x14(%rbp),%rax
movb   $0x0,-0x60(%rbp,%rax,1)
lea    -0x60(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1040 <strtoul@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_extract_dlab_len>:
mov    %esi,%ecx
mov    $0xffffffff,%eax
cmp    $0x3f,%esi
ja     1163 <_extract_dlab_len+0x43>
cmp    %edx,%ecx
jg     1163 <_extract_dlab_len+0x43>
push   %r14
push   %rbx
sub    $0x48,%rsp
mov    %rdi,%rsi
mov    %ecx,%ebx
mov    %rsp,%r14
mov    %r14,%rdi
mov    %ecx,%edx
call   1030 <memcpy@plt>
movb   $0x0,(%rsp,%rbx,1)
mov    %r14,%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1040 <strtoul@plt>
add    $0x48,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i32 @_extract_dlab_len(i8* %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca [64 x i8]
store i8* %0, i8** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
%9 = load i32, i32* %6
%10 = load i32, i32* %7
%11 = icmp sgt i32 %9, %10
br i1 %11, label %16, label %12
12: ; preds = %3
%13 = load i32, i32* %6
%14 = sext i32 %13 to i64
%15 = icmp ugt i64 %14, 63
br i1 %15, label %16, label %17
16: ; preds = %12, %3
store i32 -1, i32* %4
br label %27
17: ; preds = %12
%18 = getelementptr inbounds [64 x i8], [64 x i8]* %8, i64 0, i64 0
%19 = load i8*, i8** %5
%20 = load i32, i32* %6
%21 = call i32 @memcpy(i8* %18, i8* %19, i32 %20)
%22 = load i32, i32* %6
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds [64 x i8], [64 x i8]* %8, i64 0, i64 %23
store i8 0, i8* %24
%25 = getelementptr inbounds [64 x i8], [64 x i8]* %8, i64 0, i64 0
%26 = call i32 @strtoul(i8* %25, i32* null, i32 10)
store i32 %26, i32* %4
br label %27
27: ; preds = %17, %16
%28 = load i32, i32* %4
ret i32 %28
}

LLVM IR (-O2):
define i32 @_extract_dlab_len(i8* %0, i32 %1, i32 %2) {
%4 = alloca [64 x i8]
%5 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 0
%6 = icmp sgt i32 %1, %2
%7 = icmp ugt i32 %1, 63
%8 = or i1 %7, %6
br i1 %8, label %14, label %9
9: ; preds = %3
%10 = zext i32 %1 to i64
%11 = call i32 @memcpy(i8* %5, i8* %0, i32 %1)
%12 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 %10
store i8 0, i8* %12
%13 = call i32 @strtoul(i8* nocapture %5, i32* null, i32 10)
br label %14
14: ; preds = %3, %9
%15 = phi i32 [ %13, %9 ], [ -1, %3 ]
ret i32 %15
}