#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*/ name;

/* Variables and functions */
int EINVAL;
int ENAMETOOLONG;
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
char *strchr(char const *, char);
int /*<<< orphan*/ strncpy(char *, char const *, size_t);
int tapdisk_disktype_find(char *);
int tapdisk_disktype_parse_params(const char *params, const char **_path) {
  char name[32], *ptr;
  size_t len;
  int type;
  ptr = strchr(params, ':');
  if (!ptr)
    return -EINVAL;
  len = ptr - params;
  if (len > sizeof(name) - 1)
    return -ENAMETOOLONG;
  memset(name, 0, sizeof(name));
  strncpy(name, params, len);
  type = tapdisk_disktype_find(name);
  *_path = params + len + 1;
  return type;
}


x86 assembly (clang, -O0):
<tapdisk_disktype_parse_params>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x3a,%esi
call   1050 <strchr@plt>
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x48(%rbp)
jne    1180 <tapdisk_disktype_parse_params+0x40>
xor    %eax,%eax
mov    0x2e6a(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    11f3 <tapdisk_disktype_parse_params+0xb3>
mov    -0x48(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
mov    %rax,-0x50(%rbp)
cmpq   $0x1f,-0x50(%rbp)
jbe    11ad <tapdisk_disktype_parse_params+0x6d>
xor    %eax,%eax
mov    0x2e35(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    11f3 <tapdisk_disktype_parse_params+0xb3>
lea    -0x40(%rbp),%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1060 <memset@plt>
lea    -0x40(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x50(%rbp),%rdx
call   1030 <strncpy@plt>
lea    -0x40(%rbp),%rdi
call   1040 <tapdisk_disktype_find@plt>
mov    %eax,-0x54(%rbp)
mov    -0x10(%rbp),%rcx
add    -0x50(%rbp),%rcx
add    $0x1,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x54(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tapdisk_disktype_parse_params>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rsi,%r14
mov    %rdi,%r15
mov    $0x3a,%esi
call   1050 <strchr@plt>
test   %rax,%rax
je     1175 <tapdisk_disktype_parse_params+0x35>
mov    %rax,%rbx
sub    %r15,%rbx
cmp    $0x20,%rbx
jb     1182 <tapdisk_disktype_parse_params+0x42>
mov    0x2e65(%rip),%rcx
jmp    117c <tapdisk_disktype_parse_params+0x3c>
mov    0x2e64(%rip),%rcx
xor    %eax,%eax
sub    (%rcx),%eax
jmp    11b5 <tapdisk_disktype_parse_params+0x75>
mov    %rsp,%r12
mov    %r12,%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1060 <memset@plt>
mov    %r12,%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
call   1030 <strncpy@plt>
mov    %r12,%rdi
call   1040 <tapdisk_disktype_find@plt>
lea    (%r15,%rbx,1),%rcx
add    $0x1,%rcx
mov    %rcx,(%r14)
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@EINVAL = global i32 0
@ENAMETOOLONG = global i32 0
define i32 @tapdisk_disktype_parse_params(i8* %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8**
%6 = alloca [32 x i8]
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i32
store i8* %0, i8** %4
store i8** %1, i8*** %5
%10 = load i8*, i8** %4
%11 = call i8* @strchr(i8* %10, i8 signext 58)
store i8* %11, i8** %7
%12 = load i8*, i8** %7
%13 = icmp ne i8* %12, null
br i1 %13, label %17, label %14
14: ; preds = %2
%15 = load i32, i32* @EINVAL
%16 = sub nsw i32 0, %15
store i32 %16, i32* %3
br label %43
17: ; preds = %2
%18 = load i8*, i8** %7
%19 = load i8*, i8** %4
%20 = ptrtoint i8* %18 to i64
%21 = ptrtoint i8* %19 to i64
%22 = sub i64 %20, %21
store i64 %22, i64* %8
%23 = load i64, i64* %8
%24 = icmp ugt i64 %23, 31
br i1 %24, label %25, label %28
25: ; preds = %17
%26 = load i32, i32* @ENAMETOOLONG
%27 = sub nsw i32 0, %26
store i32 %27, i32* %3
br label %43
28: ; preds = %17
%29 = getelementptr inbounds [32 x i8], [32 x i8]* %6, i64 0, i64 0
%30 = call i32 @memset(i8* %29, i32 0, i32 32)
%31 = getelementptr inbounds [32 x i8], [32 x i8]* %6, i64 0, i64 0
%32 = load i8*, i8** %4
%33 = load i64, i64* %8
%34 = call i32 @strncpy(i8* %31, i8* %32, i64 %33)
%35 = getelementptr inbounds [32 x i8], [32 x i8]* %6, i64 0, i64 0
%36 = call i32 @tapdisk_disktype_find(i8* %35)
store i32 %36, i32* %9
%37 = load i8*, i8** %4
%38 = load i64, i64* %8
%39 = getelementptr inbounds i8, i8* %37, i64 %38
%40 = getelementptr inbounds i8, i8* %39, i64 1
%41 = load i8**, i8*** %5
store i8* %40, i8** %41
%42 = load i32, i32* %9
store i32 %42, i32* %3
br label %43
43: ; preds = %28, %25, %14
%44 = load i32, i32* %3
ret i32 %44
}

LLVM IR (-O2):
@EINVAL = global i32 0
@ENAMETOOLONG = global i32 0
define i32 @tapdisk_disktype_parse_params(i8* %0, i8** nocapture writeonly %1) {
%3 = alloca [32 x i8]
%4 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 0
%5 = tail call i8* @strchr(i8* dereferenceable(1) %0, i8 signext 58)
%6 = icmp eq i8* %5, null
br i1 %6, label %7, label %10
7: ; preds = %2
%8 = load i32, i32* @EINVAL
%9 = sub nsw i32 0, %8
br label %24
10: ; preds = %2
%11 = ptrtoint i8* %5 to i64
%12 = ptrtoint i8* %0 to i64
%13 = sub i64 %11, %12
%14 = icmp ugt i64 %13, 31
br i1 %14, label %15, label %18
15: ; preds = %10
%16 = load i32, i32* @ENAMETOOLONG
%17 = sub nsw i32 0, %16
br label %24
18: ; preds = %10
%19 = call i32 @memset(i8* %4, i32 0, i32 32)
%20 = call i32 @strncpy(i8* %4, i8* %0, i64 %13)
%21 = call i32 @tapdisk_disktype_find(i8* %4)
%22 = getelementptr inbounds i8, i8* %0, i64 %13
%23 = getelementptr inbounds i8, i8* %22, i64 1
store i8* %23, i8** %1
br label %24
24: ; preds = %18, %15, %7
%25 = phi i32 [ %17, %15 ], [ %21, %18 ], [ %9, %7 ]
ret i32 %25
}