#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 uint32_t;

/* Variables and functions */
int /*<<< orphan*/ EINVAL;
int /*<<< orphan*/ assert(int);
scalar_t__ atoi(char const *);
int /*<<< orphan*/ errno;
scalar_t__ isdigit(char const);
int /*<<< orphan*/ snprintf(char *, int, char *, int);
scalar_t__ strcmp(char *, char const *);
scalar_t__ strlen(char const *);
int /*<<< orphan*/ strncpy(char *, char const *, int);
int /*<<< orphan*/ *strstr(char const *, char *);
char *strtok(char *, char *);
int dag_parse_name(const char *name, char *buffer, int buflen,
                   int *stream_number) {
  uint32_t device_number = 0;
  int result;
  const char *device;
  const char *stream;
  char tokbuf[16];
  assert(NULL != buffer);
  assert(NULL != name);
  assert(NULL != stream_number);
  assert(0 != buflen);
  if ((NULL == name) || (NULL == buffer) || (NULL == stream_number) ||
      (buflen < 16)) {
    errno = EINVAL;
    return -1;
  }
  buffer[0] = '\0';
  *stream_number = 0;
  device = NULL;
  if ((0 != strcmp("", name)) && (0 != strlen(name))) {
    strncpy(tokbuf, name, 16);
    device = strtok(tokbuf, ":\n");
  }
  if ((NULL == device) || (0 == strlen(device))) {
    strncpy(buffer, "/dev/dag0", buflen);
    return 0;
  }
  result = 0;
  if (device[0] == '/') {
    if (NULL == strstr(device, "/dev/dag")) {
      result = -1;
    }
  } else if (device[0] == 'd') {
    if (NULL == strstr(device, "dag")) {
      result = -1;
    }
  }
  if (0 == result) {
    const char *tmp_str = device;
    while (*tmp_str && !isdigit(*tmp_str))
      tmp_str++;
    if (*tmp_str) {
      while (isdigit(*tmp_str)) {
        device_number = (device_number * 10) + (*tmp_str - '0');
        tmp_str++;
      }
      snprintf(buffer, buflen, "/dev/dag%u", device_number);
    } else {
      result = -1;
    }
  }
  if (-1 == result) {
    errno = EINVAL;
    return -1;
  }
  stream = strtok(NULL, " \t:\n");
  if (NULL != stream) {
    if (isdigit(stream[0])) {
      *stream_number = (int)atoi(stream);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<dag_parse_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %rcx,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
xor    %eax,%eax
cmp    -0x18(%rbp),%rax
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1080 <assert@plt>
xor    %eax,%eax
cmp    -0x10(%rbp),%rax
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1080 <assert@plt>
xor    %eax,%eax
cmp    -0x28(%rbp),%rax
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1080 <assert@plt>
xor    %eax,%eax
cmp    -0x1c(%rbp),%eax
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1080 <assert@plt>
xor    %eax,%eax
cmp    -0x10(%rbp),%rax
je     1227 <dag_parse_name+0x97>
xor    %eax,%eax
cmp    -0x18(%rbp),%rax
je     1227 <dag_parse_name+0x97>
xor    %eax,%eax
cmp    -0x28(%rbp),%rax
je     1227 <dag_parse_name+0x97>
cmpl   $0x10,-0x1c(%rbp)
jge    1245 <dag_parse_name+0xb5>
mov    0x2daa(%rip),%rax
mov    (%rax),%ecx
mov    0x2da9(%rip),%rax
mov    %ecx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    14ce <dag_parse_name+0x33e>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x28(%rbp),%rax
movl   $0x0,(%rax)
movq   $0x0,-0x38(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xdb9(%rip),%rdi
call   1070 <strcmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
je     12b9 <dag_parse_name+0x129>
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
je     12b9 <dag_parse_name+0x129>
lea    -0x50(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0x10,%edx
call   1030 <strncpy@plt>
lea    -0x50(%rbp),%rdi
lea    0xd70(%rip),%rsi
call   1090 <strtok@plt>
mov    %rax,-0x38(%rbp)
xor    %eax,%eax
cmp    -0x38(%rbp),%rax
je     12dc <dag_parse_name+0x14c>
mov    -0x38(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    12fb <dag_parse_name+0x16b>
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%edx
lea    0xd16(%rip),%rsi
call   1030 <strncpy@plt>
movl   $0x0,-0x4(%rbp)
jmp    14ce <dag_parse_name+0x33e>
movl   $0x0,-0x30(%rbp)
mov    -0x38(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
jne    133c <dag_parse_name+0x1ac>
mov    -0x38(%rbp),%rdi
lea    0xced(%rip),%rsi
call   10b0 <strstr@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    1337 <dag_parse_name+0x1a7>
movl   $0xffffffff,-0x30(%rbp)
jmp    137b <dag_parse_name+0x1eb>
mov    -0x38(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x64,%eax
jne    1376 <dag_parse_name+0x1e6>
mov    -0x38(%rbp),%rdi
lea    0xcb8(%rip),%rsi
call   10b0 <strstr@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    1371 <dag_parse_name+0x1e1>
movl   $0xffffffff,-0x30(%rbp)
jmp    1376 <dag_parse_name+0x1e6>
jmp    137b <dag_parse_name+0x1eb>
xor    %eax,%eax
cmp    -0x30(%rbp),%eax
jne    144f <dag_parse_name+0x2bf>
mov    -0x38(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x58(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x59(%rbp)
je     13bb <dag_parse_name+0x22b>
mov    -0x58(%rbp),%rax
movsbl (%rax),%edi
call   1040 <isdigit@plt>
cmp    $0x0,%rax
setne  %al
xor    $0xff,%al
mov    %al,-0x59(%rbp)
mov    -0x59(%rbp),%al
test   $0x1,%al
jne    13cb <dag_parse_name+0x23b>
jmp    13dc <dag_parse_name+0x24c>
mov    -0x58(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x58(%rbp)
jmp    138e <dag_parse_name+0x1fe>
mov    -0x58(%rbp),%rax
cmpb   $0x0,(%rax)
je     1443 <dag_parse_name+0x2b3>
jmp    13ee <dag_parse_name+0x25e>
mov    -0x58(%rbp),%rax
movsbl (%rax),%edi
call   1040 <isdigit@plt>
cmp    $0x0,%rax
je     1428 <dag_parse_name+0x298>
imul   $0xa,-0x2c(%rbp),%eax
mov    -0x58(%rbp),%rcx
movsbl (%rcx),%ecx
sub    $0x30,%ecx
add    %ecx,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x58(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x58(%rbp)
jmp    13ee <dag_parse_name+0x25e>
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    -0x2c(%rbp),%ecx
lea    0xbda(%rip),%rdx
call   1060 <snprintf@plt>
jmp    144a <dag_parse_name+0x2ba>
movl   $0xffffffff,-0x30(%rbp)
jmp    144f <dag_parse_name+0x2bf>
mov    $0xffffffff,%eax
cmp    -0x30(%rbp),%eax
jne    147b <dag_parse_name+0x2eb>
mov    0x2b74(%rip),%rax
mov    (%rax),%ecx
mov    0x2b73(%rip),%rax
mov    %ecx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    14ce <dag_parse_name+0x33e>
xor    %eax,%eax
mov    %eax,%edi
lea    0xb98(%rip),%rsi
call   1090 <strtok@plt>
mov    %rax,-0x40(%rbp)
xor    %eax,%eax
cmp    -0x40(%rbp),%rax
je     14c7 <dag_parse_name+0x337>
mov    -0x40(%rbp),%rax
movsbl (%rax),%edi
call   1040 <isdigit@plt>
cmp    $0x0,%rax
je     14c2 <dag_parse_name+0x332>
mov    -0x40(%rbp),%rdi
call   10a0 <atoi@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,(%rax)
jmp    14c7 <dag_parse_name+0x337>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dag_parse_name>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rcx,%r14
mov    %edx,%r15d
mov    %rsi,%r12
mov    %rdi,%rbx
xor    %edi,%edi
test   %rsi,%rsi
setne  %dil
call   1070 <assert@plt>
xor    %edi,%edi
test   %rbx,%rbx
setne  %dil
call   1070 <assert@plt>
xor    %edi,%edi
test   %r14,%r14
setne  %dil
call   1070 <assert@plt>
xor    %edi,%edi
test   %r15d,%r15d
setne  %dil
call   1070 <assert@plt>
cmp    $0x10,%r15d
jl     1343 <dag_parse_name+0x1c3>
test   %rbx,%rbx
je     1343 <dag_parse_name+0x1c3>
test   %r12,%r12
je     1343 <dag_parse_name+0x1c3>
test   %r14,%r14
je     1343 <dag_parse_name+0x1c3>
movb   $0x0,(%r12)
movl   $0x0,(%r14)
lea    0xe18(%rip),%rdi
mov    %rbx,%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
je     1256 <dag_parse_name+0xd6>
cmpb   $0x0,(%rbx)
je     1256 <dag_parse_name+0xd6>
mov    %rsp,%rbp
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    $0x10,%edx
call   1030 <strncpy@plt>
lea    0xdea(%rip),%rsi
mov    %rbp,%rdi
call   1080 <strtok@plt>
test   %rax,%rax
je     1256 <dag_parse_name+0xd6>
mov    %rax,%rbp
mov    (%rax),%bl
cmp    $0x64,%bl
je     1270 <dag_parse_name+0xf0>
cmp    $0x2f,%bl
je     1279 <dag_parse_name+0xf9>
test   %bl,%bl
jne    1291 <dag_parse_name+0x111>
lea    0xda3(%rip),%rsi
mov    %r12,%rdi
mov    %r15d,%edx
call   1030 <strncpy@plt>
xor    %r13d,%r13d
jmp    135b <dag_parse_name+0x1db>
lea    0xd98(%rip),%rsi
jmp    1280 <dag_parse_name+0x100>
lea    0xd8a(%rip),%rsi
mov    %rbp,%rdi
call   10a0 <strstr@plt>
test   %rax,%rax
je     1343 <dag_parse_name+0x1c3>
add    $0x1,%rbp
cs nopw 0x0(%rax,%rax,1)
nop
movsbl %bl,%edi
call   1040 <isdigit@plt>
test   %rax,%rax
jne    12be <dag_parse_name+0x13e>
movzbl 0x0(%rbp),%ebx
add    $0x1,%rbp
test   %bl,%bl
jne    12a0 <dag_parse_name+0x120>
jmp    1343 <dag_parse_name+0x1c3>
mov    -0x1(%rbp),%al
test   %al,%al
je     1343 <dag_parse_name+0x1c3>
movsbl %al,%edi
call   1040 <isdigit@plt>
xor    %r13d,%r13d
mov    $0x0,%ebx
test   %rax,%rax
je     12ff <dag_parse_name+0x17f>
xor    %ebx,%ebx
lea    (%rbx,%rbx,4),%eax
movsbl -0x1(%rbp),%ecx
lea    (%rcx,%rax,2),%ebx
add    $0xffffffd0,%ebx
movsbl 0x0(%rbp),%edi
call   1040 <isdigit@plt>
add    $0x1,%rbp
test   %rax,%rax
jne    12e0 <dag_parse_name+0x160>
lea    0xd0d(%rip),%rdx
mov    %r12,%rdi
mov    %r15d,%esi
mov    %ebx,%ecx
call   1050 <snprintf@plt>
lea    0xd04(%rip),%rsi
xor    %edi,%edi
call   1080 <strtok@plt>
test   %rax,%rax
je     135b <dag_parse_name+0x1db>
mov    %rax,%rbx
movsbl (%rax),%edi
call   1040 <isdigit@plt>
test   %rax,%rax
je     135b <dag_parse_name+0x1db>
mov    %rbx,%rdi
call   1090 <atoi@plt>
mov    %eax,(%r14)
jmp    135b <dag_parse_name+0x1db>
mov    0x2c8e(%rip),%rax
mov    (%rax),%eax
mov    0x2c8d(%rip),%rcx
mov    %eax,(%rcx)
mov    $0xffffffff,%r13d
mov    %r13d,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@EINVAL = global i32 0
@errno = global i32 0
@.str = [1 x i8] zeroinitializer
@.str.1 = [3 x i8] c":\0A\00"
@.str.2 = [10 x i8] c"/dev/dag0\00"
@.str.3 = [9 x i8] c"/dev/dag\00"
@.str.4 = [4 x i8] c"dag\00"
@.str.5 = [11 x i8] c"/dev/dag%u\00"
@.str.6 = [5 x i8] c" \09:\0A\00"
define i32 @dag_parse_name(i8* %0, i8* %1, i32 %2, i32* %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i8*
%13 = alloca i8*
%14 = alloca [16 x i8]
%15 = alloca i8*
store i8* %0, i8** %6
store i8* %1, i8** %7
store i32 %2, i32* %8
store i32* %3, i32** %9
store i32 0, i32* %10
%16 = load i8*, i8** %7
%17 = icmp ne i8* null, %16
%18 = zext i1 %17 to i32
%19 = call i32 @assert(i32 %18)
%20 = load i8*, i8** %6
%21 = icmp ne i8* null, %20
%22 = zext i1 %21 to i32
%23 = call i32 @assert(i32 %22)
%24 = load i32*, i32** %9
%25 = icmp ne i32* null, %24
%26 = zext i1 %25 to i32
%27 = call i32 @assert(i32 %26)
%28 = load i32, i32* %8
%29 = icmp ne i32 0, %28
%30 = zext i1 %29 to i32
%31 = call i32 @assert(i32 %30)
%32 = load i8*, i8** %6
%33 = icmp eq i8* null, %32
br i1 %33, label %43, label %34
34: ; preds = %4
%35 = load i8*, i8** %7
%36 = icmp eq i8* null, %35
br i1 %36, label %43, label %37
37: ; preds = %34
%38 = load i32*, i32** %9
%39 = icmp eq i32* null, %38
br i1 %39, label %43, label %40
40: ; preds = %37
%41 = load i32, i32* %8
%42 = icmp slt i32 %41, 16
br i1 %42, label %43, label %45
43: ; preds = %40, %37, %34, %4
%44 = load i32, i32* @EINVAL
store i32 %44, i32* @errno
store i32 -1, i32* %5
br label %168
45: ; preds = %40
%46 = load i8*, i8** %7
%47 = getelementptr inbounds i8, i8* %46, i64 0
store i8 0, i8* %47
%48 = load i32*, i32** %9
store i32 0, i32* %48
store i8* null, i8** %12
%49 = load i8*, i8** %6
%50 = call i64 @strcmp(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8* %49)
%51 = icmp ne i64 0, %50
br i1 %51, label %52, label %62
52: ; preds = %45
%53 = load i8*, i8** %6
%54 = call i64 @strlen(i8* %53)
%55 = icmp ne i64 0, %54
br i1 %55, label %56, label %62
56: ; preds = %52
%57 = getelementptr inbounds [16 x i8], [16 x i8]* %14, i64 0, i64 0
%58 = load i8*, i8** %6
%59 = call i32 @strncpy(i8* %57, i8* %58, i32 16)
%60 = getelementptr inbounds [16 x i8], [16 x i8]* %14, i64 0, i64 0
%61 = call i8* @strtok(i8* %60, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i8* %61, i8** %12
br label %62
62: ; preds = %56, %52, %45
%63 = load i8*, i8** %12
%64 = icmp eq i8* null, %63
br i1 %64, label %69, label %65
65: ; preds = %62
%66 = load i8*, i8** %12
%67 = call i64 @strlen(i8* %66)
%68 = icmp eq i64 0, %67
br i1 %68, label %69, label %73
69: ; preds = %65, %62
%70 = load i8*, i8** %7
%71 = load i32, i32* %8
%72 = call i32 @strncpy(i8* %70, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32 %71)
store i32 0, i32* %5
br label %168
73: ; preds = %65
store i32 0, i32* %11
%74 = load i8*, i8** %12
%75 = getelementptr inbounds i8, i8* %74, i64 0
%76 = load i8, i8* %75
%77 = sext i8 %76 to i32
%78 = icmp eq i32 %77, 47
br i1 %78, label %79, label %85
79: ; preds = %73
%80 = load i8*, i8** %12
%81 = call i32* @strstr(i8* %80, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
%82 = icmp eq i32* null, %81
br i1 %82, label %83, label %84
83: ; preds = %79
store i32 -1, i32* %11
br label %84
84: ; preds = %83, %79
br label %98
85: ; preds = %73
%86 = load i8*, i8** %12
%87 = getelementptr inbounds i8, i8* %86, i64 0
%88 = load i8, i8* %87
%89 = sext i8 %88 to i32
%90 = icmp eq i32 %89, 100
br i1 %90, label %91, label %97
91: ; preds = %85
%92 = load i8*, i8** %12
%93 = call i32* @strstr(i8* %92, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
%94 = icmp eq i32* null, %93
br i1 %94, label %95, label %96
95: ; preds = %91
store i32 -1, i32* %11
br label %96
96: ; preds = %95, %91
br label %97
97: ; preds = %96, %85
br label %98
98: ; preds = %97, %84
%99 = load i32, i32* %11
%100 = icmp eq i32 0, %99
br i1 %100, label %101, label %146
101: ; preds = %98
%102 = load i8*, i8** %12
store i8* %102, i8** %15
br label %103
103: ; preds = %116, %101
%104 = load i8*, i8** %15
%105 = load i8, i8* %104
%106 = sext i8 %105 to i32
%107 = icmp ne i32 %106, 0
br i1 %107, label %108, label %114
108: ; preds = %103
%109 = load i8*, i8** %15
%110 = load i8, i8* %109
%111 = call i64 @isdigit(i8 signext %110)
%112 = icmp ne i64 %111, 0
%113 = xor i1 %112, true
br label %114
114: ; preds = %108, %103
%115 = phi i1 [ false, %103 ], [ %113, %108 ]
br i1 %115, label %116, label %119
116: ; preds = %114
%117 = load i8*, i8** %15
%118 = getelementptr inbounds i8, i8* %117, i32 1
store i8* %118, i8** %15
br label %103
119: ; preds = %114
%120 = load i8*, i8** %15
%121 = load i8, i8* %120
%122 = icmp ne i8 %121, 0
br i1 %122, label %123, label %144
123: ; preds = %119
br label %124
124: ; preds = %129, %123
%125 = load i8*, i8** %15
%126 = load i8, i8* %125
%127 = call i64 @isdigit(i8 signext %126)
%128 = icmp ne i64 %127, 0
br i1 %128, label %129, label %139
129: ; preds = %124
%130 = load i32, i32* %10
%131 = mul nsw i32 %130, 10
%132 = load i8*, i8** %15
%133 = load i8, i8* %132
%134 = sext i8 %133 to i32
%135 = sub nsw i32 %134, 48
%136 = add nsw i32 %131, %135
store i32 %136, i32* %10
%137 = load i8*, i8** %15
%138 = getelementptr inbounds i8, i8* %137, i32 1
store i8* %138, i8** %15
br label %124
139: ; preds = %124
%140 = load i8*, i8** %7
%141 = load i32, i32* %8
%142 = load i32, i32* %10
%143 = call i32 @snprintf(i8* %140, i32 %141, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0), i32 %142)
br label %145
144: ; preds = %119
store i32 -1, i32* %11
br label %145
145: ; preds = %144, %139
br label %146
146: ; preds = %145, %98
%147 = load i32, i32* %11
%148 = icmp eq i32 -1, %147
br i1 %148, label %149, label %151
149: ; preds = %146
%150 = load i32, i32* @EINVAL
store i32 %150, i32* @errno
store i32 -1, i32* %5
br label %168
151: ; preds = %146
%152 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0))
store i8* %152, i8** %13
%153 = load i8*, i8** %13
%154 = icmp ne i8* null, %153
br i1 %154, label %155, label %167
155: ; preds = %151
%156 = load i8*, i8** %13
%157 = getelementptr inbounds i8, i8* %156, i64 0
%158 = load i8, i8* %157
%159 = call i64 @isdigit(i8 signext %158)
%160 = icmp ne i64 %159, 0
br i1 %160, label %161, label %166
161: ; preds = %155
%162 = load i8*, i8** %13
%163 = call i64 @atoi(i8* %162)
%164 = trunc i64 %163 to i32
%165 = load i32*, i32** %9
store i32 %164, i32* %165
br label %166
166: ; preds = %161, %155
br label %167
167: ; preds = %166, %151
store i32 0, i32* %5
br label %168
168: ; preds = %167, %149, %69, %43
%169 = load i32, i32* %5
ret i32 %169
}

LLVM IR (-O2):
@EINVAL = global i32 0
@errno = global i32 0
@.str = [1 x i8] zeroinitializer
@.str.1 = [3 x i8] c":\0A\00"
@.str.2 = [10 x i8] c"/dev/dag0\00"
@.str.3 = [9 x i8] c"/dev/dag\00"
@.str.4 = [4 x i8] c"dag\00"
@.str.5 = [11 x i8] c"/dev/dag%u\00"
@.str.6 = [5 x i8] c" \09:\0A\00"
define i32 @dag_parse_name(i8* %0, i8* %1, i32 %2, i32* writeonly %3) {
%5 = alloca [16 x i8]
%6 = getelementptr inbounds [16 x i8], [16 x i8]* %5, i64 0, i64 0
%7 = icmp ne i8* %1, null
%8 = zext i1 %7 to i32
%9 = tail call i32 @assert(i32 %8)
%10 = icmp ne i8* %0, null
%11 = zext i1 %10 to i32
%12 = tail call i32 @assert(i32 %11)
%13 = icmp ne i32* %3, null
%14 = zext i1 %13 to i32
%15 = tail call i32 @assert(i32 %14)
%16 = icmp ne i32 %2, 0
%17 = zext i1 %16 to i32
%18 = tail call i32 @assert(i32 %17)
%19 = icmp eq i8* %0, null
%20 = icmp eq i8* %1, null
%21 = or i1 %19, %20
%22 = icmp eq i32* %3, null
%23 = or i1 %21, %22
%24 = icmp slt i32 %2, 16
%25 = or i1 %24, %23
br i1 %25, label %26, label %28
26: ; preds = %4
%27 = load i32, i32* @EINVAL
store i32 %27, i32* @errno
br label %90
28: ; preds = %4
store i8 0, i8* %1
store i32 0, i32* %3
%29 = tail call i64 @strcmp(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8* %0)
%30 = icmp eq i64 %29, 0
br i1 %30, label %40, label %31
31: ; preds = %28
%32 = load i8, i8* %0
%33 = icmp eq i8 %32, 0
br i1 %33, label %40, label %34
34: ; preds = %31
%35 = call i32 @strncpy(i8* %6, i8* %0, i32 16)
%36 = call i8* @strtok(i8* %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%37 = icmp eq i8* %36, null
br i1 %37, label %40, label %38
38: ; preds = %34
%39 = load i8, i8* %36
switch i8 %39, label %48 [
i8 0, label %40
i8 47, label %42
i8 100, label %45
]
40: ; preds = %38, %28, %31, %34
%41 = call i32 @strncpy(i8* %1, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32 %2)
br label %90
42: ; preds = %38
%43 = call i32* @strstr(i8* %36, i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
%44 = icmp eq i32* %43, null
br i1 %44, label %76, label %48
45: ; preds = %38
%46 = call i32* @strstr(i8* %36, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
%47 = icmp eq i32* %46, null
br i1 %47, label %76, label %48
48: ; preds = %38, %45, %42
br label %49
49: ; preds = %48, %54
%50 = phi i8 [ %56, %54 ], [ %39, %48 ]
%51 = phi i8* [ %55, %54 ], [ %36, %48 ]
%52 = call i64 @isdigit(i8 signext %50)
%53 = icmp eq i64 %52, 0
br i1 %53, label %54, label %58
54: ; preds = %49
%55 = getelementptr inbounds i8, i8* %51, i64 1
%56 = load i8, i8* %55
%57 = icmp eq i8 %56, 0
br i1 %57, label %76, label %49
58: ; preds = %49
%59 = load i8, i8* %51
%60 = icmp eq i8 %59, 0
br i1 %60, label %76, label %61
61: ; preds = %58
%62 = call i64 @isdigit(i8 signext %59)
%63 = icmp eq i64 %62, 0
br i1 %63, label %78, label %64
64: ; preds = %61, %64
%65 = phi i8* [ %72, %64 ], [ %51, %61 ]
%66 = phi i32 [ %71, %64 ], [ 0, %61 ]
%67 = mul nsw i32 %66, 10
%68 = load i8, i8* %65
%69 = sext i8 %68 to i32
%70 = add i32 %67, -48
%71 = add i32 %70, %69
%72 = getelementptr inbounds i8, i8* %65, i64 1
%73 = load i8, i8* %72
%74 = call i64 @isdigit(i8 signext %73)
%75 = icmp eq i64 %74, 0
br i1 %75, label %78, label %64
76: ; preds = %54, %45, %58, %42
%77 = load i32, i32* @EINVAL
store i32 %77, i32* @errno
br label %90
78: ; preds = %64, %61
%79 = phi i32 [ 0, %61 ], [ %71, %64 ]
%80 = call i32 @snprintf(i8* %1, i32 %2, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0), i32 %79)
%81 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0))
%82 = icmp eq i8* %81, null
br i1 %82, label %90, label %83
83: ; preds = %78
%84 = load i8, i8* %81
%85 = call i64 @isdigit(i8 signext %84)
%86 = icmp eq i64 %85, 0
br i1 %86, label %90, label %87
87: ; preds = %83
%88 = call i64 @atoi(i8* %81)
%89 = trunc i64 %88 to i32
store i32 %89, i32* %3
br label %90
90: ; preds = %78, %87, %83, %76, %40, %26
%91 = phi i32 [ -1, %26 ], [ 0, %40 ], [ -1, %76 ], [ 0, %83 ], [ 0, %87 ], [ 0, %78 ]
ret i32 %91
}