#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 bladerf_devinfo {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ assert(struct bladerf_devinfo *);
int /*<<< orphan*/ bladerf_init_devinfo(struct bladerf_devinfo *);
int /*<<< orphan*/ free(char *);
int handle_backend(char *, struct bladerf_devinfo *);
int handle_device(struct bladerf_devinfo *, char *);
int handle_instance(struct bladerf_devinfo *, char *);
int handle_serial(struct bladerf_devinfo *, char *);
int next_arg(char **, char **, char **);
int /*<<< orphan*/ strcasecmp(char *, char *);
char *strdup(char const *);
scalar_t__ strlen(char const *);
char *strtok_r(char *, char *, char **);
int str2devinfo(const char *dev_id_const, struct bladerf_devinfo *d) {
  char *dev_id = NULL;
  char *token = NULL;
  char *arg = NULL;
  char *val = NULL;
  char *saveptr = NULL;
  int status = (-1);
  int arg_status = (-1);
  assert(d);
  bladerf_init_devinfo(d);
  if (dev_id_const == NULL || strlen(dev_id_const) == 0) {
    return 0;
  }
  dev_id = strdup(dev_id_const);
  if (!dev_id) {
    return (-4);
  }
  token = strtok_r(dev_id, ":", &saveptr);
  if (token) {
    status = handle_backend(token, d);
    arg_status = 1;
    while (arg_status == 1 && status == 0) {
      arg_status = next_arg(&saveptr, &arg, &val);
      if (arg_status == 1) {
        if (!strcasecmp("device", arg)) {
          status = handle_device(d, val);
        } else if (!strcasecmp("instance", arg)) {
          status = handle_instance(d, val);
        } else if (!strcasecmp("serial", arg)) {
          status = handle_serial(d, val);
        } else {
          arg_status = (-3);
        }
      }
    };
    if (arg_status < 0) {
      status = arg_status;
    }
  } else {
    status = (-3);
  }
  free(dev_id);
  return status;
}


x86 assembly (clang, -O0):
<str2devinfo>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
movq   $0x0,-0x40(%rbp)
movl   $0xffffffff,-0x44(%rbp)
movl   $0xffffffff,-0x48(%rbp)
mov    -0x18(%rbp),%rdi
call   1070 <assert@plt>
mov    -0x18(%rbp),%rdi
call   10a0 <bladerf_init_devinfo@plt>
cmpq   $0x0,-0x10(%rbp)
je     1236 <str2devinfo+0x76>
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
cmp    $0x0,%rax
jne    1242 <str2devinfo+0x82>
movl   $0x0,-0x4(%rbp)
jmp    13b7 <str2devinfo+0x1f7>
mov    -0x10(%rbp),%rdi
call   10d0 <strdup@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1266 <str2devinfo+0xa6>
movl   $0xfffffffc,-0x4(%rbp)
jmp    13b7 <str2devinfo+0x1f7>
mov    -0x20(%rbp),%rdi
lea    0xd8f(%rip),%rsi
lea    -0x40(%rbp),%rdx
call   1060 <strtok_r@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     13a1 <str2devinfo+0x1e1>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1080 <handle_backend@plt>
mov    %eax,-0x44(%rbp)
movl   $0x1,-0x48(%rbp)
xor    %eax,%eax
cmpl   $0x1,-0x48(%rbp)
mov    %al,-0x49(%rbp)
jne    12b9 <str2devinfo+0xf9>
cmpl   $0x0,-0x44(%rbp)
sete   %al
mov    %al,-0x49(%rbp)
mov    -0x49(%rbp),%al
test   $0x1,%al
jne    12c9 <str2devinfo+0x109>
jmp    138c <str2devinfo+0x1cc>
lea    -0x40(%rbp),%rdi
lea    -0x30(%rbp),%rsi
lea    -0x38(%rbp),%rdx
call   10b0 <next_arg@plt>
mov    %eax,-0x48(%rbp)
cmpl   $0x1,-0x48(%rbp)
jne    1387 <str2devinfo+0x1c7>
mov    -0x30(%rbp),%rsi
lea    0xd10(%rip),%rdi
call   1040 <strcasecmp@plt>
cmp    $0x0,%eax
jne    1315 <str2devinfo+0x155>
mov    -0x18(%rbp),%rdi
mov    -0x38(%rbp),%rsi
call   1090 <handle_device@plt>
mov    %eax,-0x44(%rbp)
jmp    1382 <str2devinfo+0x1c2>
mov    -0x30(%rbp),%rsi
lea    0xce9(%rip),%rdi
call   1040 <strcasecmp@plt>
cmp    $0x0,%eax
jne    1343 <str2devinfo+0x183>
mov    -0x18(%rbp),%rdi
mov    -0x38(%rbp),%rsi
call   10c0 <handle_instance@plt>
mov    %eax,-0x44(%rbp)
jmp    137d <str2devinfo+0x1bd>
mov    -0x30(%rbp),%rsi
lea    0xcc4(%rip),%rdi
call   1040 <strcasecmp@plt>
cmp    $0x0,%eax
jne    1371 <str2devinfo+0x1b1>
mov    -0x18(%rbp),%rdi
mov    -0x38(%rbp),%rsi
call   10e0 <handle_serial@plt>
mov    %eax,-0x44(%rbp)
jmp    1378 <str2devinfo+0x1b8>
movl   $0xfffffffd,-0x48(%rbp)
jmp    137d <str2devinfo+0x1bd>
jmp    1382 <str2devinfo+0x1c2>
jmp    1387 <str2devinfo+0x1c7>
jmp    12a0 <str2devinfo+0xe0>
cmpl   $0x0,-0x48(%rbp)
jge    139c <str2devinfo+0x1dc>
mov    -0x48(%rbp),%eax
mov    %eax,-0x44(%rbp)
jmp    13a8 <str2devinfo+0x1e8>
movl   $0xfffffffd,-0x44(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x44(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str2devinfo>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r15
mov    %rdi,%rbx
movq   $0x0,0x10(%rsp)
movq   $0x0,(%rsp)
movq   $0x0,0x8(%rsp)
mov    %rsi,%rdi
call   1060 <assert@plt>
mov    %r15,%rdi
call   1090 <bladerf_init_devinfo@plt>
xor    %ebp,%ebp
test   %rbx,%rbx
je     12f3 <str2devinfo+0x143>
cmpb   $0x0,(%rbx)
je     12f3 <str2devinfo+0x143>
mov    %rbx,%rdi
call   10c0 <strdup@plt>
test   %rax,%rax
je     12df <str2devinfo+0x12f>
mov    %rax,%r14
lea    0xde3(%rip),%rsi
lea    0x8(%rsp),%rdx
mov    %rax,%rdi
call   1050 <strtok_r@plt>
test   %rax,%rax
je     12e6 <str2devinfo+0x136>
mov    %rax,%rdi
mov    %r15,%rsi
call   1070 <handle_backend@plt>
mov    %eax,%ebp
test   %eax,%eax
jne    12eb <str2devinfo+0x13b>
lea    0x8(%rsp),%rbx
lea    0x10(%rsp),%r12
mov    %rsp,%r13
jmp    1272 <str2devinfo+0xc2>
nopw   0x0(%rax,%rax,1)
mov    (%rsp),%rsi
mov    %r15,%rdi
call   1080 <handle_device@plt>
mov    %eax,%ebp
test   %eax,%eax
jne    12eb <str2devinfo+0x13b>
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %r13,%rdx
call   10a0 <next_arg@plt>
cmp    $0x1,%eax
jne    1304 <str2devinfo+0x154>
mov    0x10(%rsp),%rbp
lea    0xd71(%rip),%rdi
mov    %rbp,%rsi
call   1040 <strcasecmp@plt>
test   %eax,%eax
je     1260 <str2devinfo+0xb0>
lea    0xd65(%rip),%rdi
mov    %rbp,%rsi
call   1040 <strcasecmp@plt>
test   %eax,%eax
je     12d1 <str2devinfo+0x121>
lea    0xd5b(%rip),%rdi
mov    %rbp,%rsi
call   1040 <strcasecmp@plt>
test   %eax,%eax
jne    12e6 <str2devinfo+0x136>
mov    (%rsp),%rsi
mov    %r15,%rdi
call   10d0 <handle_serial@plt>
jmp    126c <str2devinfo+0xbc>
mov    (%rsp),%rsi
mov    %r15,%rdi
call   10b0 <handle_instance@plt>
jmp    126c <str2devinfo+0xbc>
mov    $0xfffffffc,%ebp
jmp    12f3 <str2devinfo+0x143>
mov    $0xfffffffd,%ebp
mov    %r14,%rdi
call   1030 <free@plt>
mov    %ebp,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %ebp,%ebp
test   %eax,%eax
jns    12eb <str2devinfo+0x13b>
mov    %eax,%ebp
jmp    12eb <str2devinfo+0x13b>

LLVM IR (-O0):
%struct.bladerf_devinfo = type { i32 }
@.str = [2 x i8] c":\00"
@.str.1 = [7 x i8] c"device\00"
@.str.2 = [9 x i8] c"instance\00"
@.str.3 = [7 x i8] c"serial\00"
define i32 @str2devinfo(i8* %0, %struct.bladerf_devinfo* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca %struct.bladerf_devinfo*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i32
%12 = alloca i32
store i8* %0, i8** %4
store %struct.bladerf_devinfo* %1, %struct.bladerf_devinfo** %5
store i8* null, i8** %6
store i8* null, i8** %7
store i8* null, i8** %8
store i8* null, i8** %9
store i8* null, i8** %10
store i32 -1, i32* %11
store i32 -1, i32* %12
%13 = load %struct.bladerf_devinfo*, %struct.bladerf_devinfo** %5
%14 = call i32 @assert(%struct.bladerf_devinfo* %13)
%15 = load %struct.bladerf_devinfo*, %struct.bladerf_devinfo** %5
%16 = call i32 @bladerf_init_devinfo(%struct.bladerf_devinfo* %15)
%17 = load i8*, i8** %4
%18 = icmp eq i8* %17, null
br i1 %18, label %23, label %19
19: ; preds = %2
%20 = load i8*, i8** %4
%21 = call i64 @strlen(i8* %20)
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %24
23: ; preds = %19, %2
store i32 0, i32* %3
br label %91
24: ; preds = %19
%25 = load i8*, i8** %4
%26 = call i8* @strdup(i8* %25)
store i8* %26, i8** %6
%27 = load i8*, i8** %6
%28 = icmp ne i8* %27, null
br i1 %28, label %30, label %29
29: ; preds = %24
store i32 -4, i32* %3
br label %91
30: ; preds = %24
%31 = load i8*, i8** %6
%32 = call i8* @strtok_r(i8* %31, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8** %10)
store i8* %32, i8** %7
%33 = load i8*, i8** %7
%34 = icmp ne i8* %33, null
br i1 %34, label %35, label %86
35: ; preds = %30
%36 = load i8*, i8** %7
%37 = load %struct.bladerf_devinfo*, %struct.bladerf_devinfo** %5
%38 = call i32 @handle_backend(i8* %36, %struct.bladerf_devinfo* %37)
store i32 %38, i32* %11
store i32 1, i32* %12
br label %39
39: ; preds = %79, %35
%40 = load i32, i32* %12
%41 = icmp eq i32 %40, 1
br i1 %41, label %42, label %45
42: ; preds = %39
%43 = load i32, i32* %11
%44 = icmp eq i32 %43, 0
br label %45
45: ; preds = %42, %39
%46 = phi i1 [ false, %39 ], [ %44, %42 ]
br i1 %46, label %47, label %80
47: ; preds = %45
%48 = call i32 @next_arg(i8** %10, i8** %8, i8** %9)
store i32 %48, i32* %12
%49 = load i32, i32* %12
%50 = icmp eq i32 %49, 1
br i1 %50, label %51, label %79
51: ; preds = %47
%52 = load i8*, i8** %8
%53 = call i32 @strcasecmp(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* %52)
%54 = icmp ne i32 %53, 0
br i1 %54, label %59, label %55
55: ; preds = %51
%56 = load %struct.bladerf_devinfo*, %struct.bladerf_devinfo** %5
%57 = load i8*, i8** %9
%58 = call i32 @handle_device(%struct.bladerf_devinfo* %56, i8* %57)
store i32 %58, i32* %11
br label %78
59: ; preds = %51
%60 = load i8*, i8** %8
%61 = call i32 @strcasecmp(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* %60)
%62 = icmp ne i32 %61, 0
br i1 %62, label %67, label %63
63: ; preds = %59
%64 = load %struct.bladerf_devinfo*, %struct.bladerf_devinfo** %5
%65 = load i8*, i8** %9
%66 = call i32 @handle_instance(%struct.bladerf_devinfo* %64, i8* %65)
store i32 %66, i32* %11
br label %77
67: ; preds = %59
%68 = load i8*, i8** %8
%69 = call i32 @strcasecmp(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i8* %68)
%70 = icmp ne i32 %69, 0
br i1 %70, label %75, label %71
71: ; preds = %67
%72 = load %struct.bladerf_devinfo*, %struct.bladerf_devinfo** %5
%73 = load i8*, i8** %9
%74 = call i32 @handle_serial(%struct.bladerf_devinfo* %72, i8* %73)
store i32 %74, i32* %11
br label %76
75: ; preds = %67
store i32 -3, i32* %12
br label %76
76: ; preds = %75, %71
br label %77
77: ; preds = %76, %63
br label %78
78: ; preds = %77, %55
br label %79
79: ; preds = %78, %47
br label %39
80: ; preds = %45
%81 = load i32, i32* %12
%82 = icmp slt i32 %81, 0
br i1 %82, label %83, label %85
83: ; preds = %80
%84 = load i32, i32* %12
store i32 %84, i32* %11
br label %85
85: ; preds = %83, %80
br label %87
86: ; preds = %30
store i32 -3, i32* %11
br label %87
87: ; preds = %86, %85
%88 = load i8*, i8** %6
%89 = call i32 @free(i8* %88)
%90 = load i32, i32* %11
store i32 %90, i32* %3
br label %91
91: ; preds = %87, %29, %23
%92 = load i32, i32* %3
ret i32 %92
}

LLVM IR (-O2):
%struct.bladerf_devinfo = type { i32 }
@.str = [2 x i8] c":\00"
@.str.1 = [7 x i8] c"device\00"
@.str.2 = [9 x i8] c"instance\00"
@.str.3 = [7 x i8] c"serial\00"
define i32 @str2devinfo(i8* %0, %struct.bladerf_devinfo* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = bitcast i8** %3 to i8*
store i8* null, i8** %3
%7 = bitcast i8** %4 to i8*
store i8* null, i8** %4
%8 = bitcast i8** %5 to i8*
store i8* null, i8** %5
%9 = tail call i32 @assert(%struct.bladerf_devinfo* %1)
%10 = tail call i32 @bladerf_init_devinfo(%struct.bladerf_devinfo* %1)
%11 = icmp eq i8* %0, null
br i1 %11, label %56, label %12
12: ; preds = %2
%13 = load i8, i8* %0
%14 = icmp eq i8 %13, 0
br i1 %14, label %56, label %15
15: ; preds = %12
%16 = tail call i8* @strdup(i8* %0)
%17 = icmp eq i8* %16, null
br i1 %17, label %56, label %18
18: ; preds = %15
%19 = call i8* @strtok_r(i8* %16, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8** %5)
%20 = icmp eq i8* %19, null
br i1 %20, label %53, label %21
21: ; preds = %18
%22 = call i32 @handle_backend(i8* %19, %struct.bladerf_devinfo* %1)
%23 = icmp eq i32 %22, 0
br i1 %23, label %24, label %53
24: ; preds = %21, %46
%25 = call i32 @next_arg(i8** %5, i8** %3, i8** %4)
%26 = icmp eq i32 %25, 1
br i1 %26, label %27, label %49
27: ; preds = %24
%28 = load i8*, i8** %3
%29 = call i32 @strcasecmp(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* %28)
%30 = icmp eq i32 %29, 0
br i1 %30, label %31, label %34
31: ; preds = %27
%32 = load i8*, i8** %4
%33 = call i32 @handle_device(%struct.bladerf_devinfo* %1, i8* %32)
br label %46
34: ; preds = %27
%35 = call i32 @strcasecmp(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* %28)
%36 = icmp eq i32 %35, 0
br i1 %36, label %37, label %40
37: ; preds = %34
%38 = load i8*, i8** %4
%39 = call i32 @handle_instance(%struct.bladerf_devinfo* %1, i8* %38)
br label %46
40: ; preds = %34
%41 = call i32 @strcasecmp(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i8* %28)
%42 = icmp eq i32 %41, 0
br i1 %42, label %43, label %51
43: ; preds = %40
%44 = load i8*, i8** %4
%45 = call i32 @handle_serial(%struct.bladerf_devinfo* %1, i8* %44)
br label %46
46: ; preds = %31, %43, %37
%47 = phi i32 [ %45, %43 ], [ %39, %37 ], [ %33, %31 ]
%48 = icmp eq i32 %47, 0
br i1 %48, label %24, label %53
49: ; preds = %24
%50 = icmp slt i32 %25, 0
br i1 %50, label %51, label %53
51: ; preds = %40, %49
%52 = phi i32 [ %25, %49 ], [ -3, %40 ]
br label %53
53: ; preds = %46, %21, %51, %49, %18
%54 = phi i32 [ -3, %18 ], [ %52, %51 ], [ 0, %49 ], [ %22, %21 ], [ %47, %46 ]
%55 = call i32 @free(i8* %16)
br label %56
56: ; preds = %15, %2, %12, %53
%57 = phi i32 [ %54, %53 ], [ 0, %12 ], [ 0, %2 ], [ -4, %15 ]
ret i32 %57
}