#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*/ die(char *, char const *);
scalar_t__ errno;
char *strstr(char const *, char *);
int strtol(char const *, char **, int);
int prefix_len_parse(const char *prefix_string, int max_len) {
  int prefix_len = 0;
  const char *len_str = NULL;
  len_str = strstr(prefix_string, "/");
  if (len_str != NULL) {
    char *end = NULL;
    ++len_str;
    errno = 0;
    prefix_len = strtol(len_str, &end, 10);
    if (errno != 0 || *end != '\0' || (prefix_len < 0) ||
        (prefix_len > max_len))
      die("bad prefix length in prefix '%s'\n", prefix_string);
  } else {
    prefix_len = max_len;
  }
  return prefix_len;
}


x86 assembly (clang, -O0):
<prefix_len_parse>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xea7(%rip),%rsi
call   1050 <strstr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11f0 <prefix_len_parse+0xc0>
movq   $0x0,-0x20(%rbp)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    0x2e58(%rip),%rax
movq   $0x0,(%rax)
mov    -0x18(%rbp),%rdi
lea    -0x20(%rbp),%rsi
mov    $0xa,%edx
call   1030 <strtol@plt>
mov    %eax,-0x10(%rbp)
mov    0x2e35(%rip),%rax
cmpq   $0x0,(%rax)
jne    11db <prefix_len_parse+0xab>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    11db <prefix_len_parse+0xab>
cmpl   $0x0,-0x10(%rbp)
jl     11db <prefix_len_parse+0xab>
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jle    11eb <prefix_len_parse+0xbb>
mov    -0x8(%rbp),%rsi
lea    0xe1c(%rip),%rdi
call   1040 <die@plt>
jmp    11f6 <prefix_len_parse+0xc6>
mov    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<prefix_len_parse>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%rbx
mov    $0x2f,%esi
call   1030 <strchr@plt>
test   %rax,%rax
je     1190 <prefix_len_parse+0x60>
movq   $0x0,(%rsp)
add    $0x1,%rax
mov    0x2e82(%rip),%r15
movq   $0x0,(%r15)
mov    %rsp,%rsi
mov    %rax,%rdi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    %eax,%r14d
cmpq   $0x0,(%r15)
je     119d <prefix_len_parse+0x6d>
lea    0xe7b(%rip),%rdi
mov    %rbx,%rsi
call   1050 <die@plt>
mov    %r14d,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    (%rsp),%rax
cmpb   $0x0,(%rax)
jne    117e <prefix_len_parse+0x4e>
test   %r14d,%r14d
js     117e <prefix_len_parse+0x4e>
cmp    %ebp,%r14d
jle    118d <prefix_len_parse+0x5d>
jmp    117e <prefix_len_parse+0x4e>

LLVM IR (-O0):
@.str = [2 x i8] c"/\00"
@errno = global i64 0
@.str.1 = [34 x i8] c"bad prefix length in prefix '%s'\0A\00"
define i32 @prefix_len_parse(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
store i8* %0, i8** %3
store i32 %1, i32* %4
store i32 0, i32* %5
store i8* null, i8** %6
%8 = load i8*, i8** %3
%9 = call i8* @strstr(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %9, i8** %6
%10 = load i8*, i8** %6
%11 = icmp ne i8* %10, null
br i1 %11, label %12, label %35
12: ; preds = %2
store i8* null, i8** %7
%13 = load i8*, i8** %6
%14 = getelementptr inbounds i8, i8* %13, i32 1
store i8* %14, i8** %6
store i64 0, i64* @errno
%15 = load i8*, i8** %6
%16 = call i32 @strtol(i8* %15, i8** %7, i32 10)
store i32 %16, i32* %5
%17 = load i64, i64* @errno
%18 = icmp ne i64 %17, 0
br i1 %18, label %31, label %19
19: ; preds = %12
%20 = load i8*, i8** %7
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
%23 = icmp ne i32 %22, 0
br i1 %23, label %31, label %24
24: ; preds = %19
%25 = load i32, i32* %5
%26 = icmp slt i32 %25, 0
br i1 %26, label %31, label %27
27: ; preds = %24
%28 = load i32, i32* %5
%29 = load i32, i32* %4
%30 = icmp sgt i32 %28, %29
br i1 %30, label %31, label %34
31: ; preds = %27, %24, %19, %12
%32 = load i8*, i8** %3
%33 = call i32 @die(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i8* %32)
br label %34
34: ; preds = %31, %27
br label %37
35: ; preds = %2
%36 = load i32, i32* %4
store i32 %36, i32* %5
br label %37
37: ; preds = %35, %34
%38 = load i32, i32* %5
ret i32 %38
}

LLVM IR (-O2):
@errno = global i64 0
@.str.1 = [34 x i8] c"bad prefix length in prefix '%s'\0A\00"
define i32 @prefix_len_parse(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = tail call i8* @strchr(i8* dereferenceable(1) %0, i32 47)
%5 = icmp eq i8* %4, null
br i1 %5, label %23, label %6
6: ; preds = %2
%7 = bitcast i8** %3 to i8*
store i8* null, i8** %3
%8 = getelementptr inbounds i8, i8* %4, i64 1
store i64 0, i64* @errno
%9 = call i32 @strtol(i8* %8, i8** %3, i32 10)
%10 = load i64, i64* @errno
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %20
12: ; preds = %6
%13 = load i8*, i8** %3
%14 = load i8, i8* %13
%15 = icmp ne i8 %14, 0
%16 = icmp slt i32 %9, 0
%17 = select i1 %15, i1 true, i1 %16
%18 = icmp sgt i32 %9, %1
%19 = select i1 %17, i1 true, i1 %18
br i1 %19, label %20, label %22
20: ; preds = %12, %6
%21 = tail call i32 @die(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %22
22: ; preds = %12, %20
br label %23
23: ; preds = %2, %22
%24 = phi i32 [ %9, %22 ], [ %1, %2 ]
ret i32 %24
}