#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*/ memcpy(char *, char const *, int);
int platformParseDeviceTypeString(const char *deviceTypeString,
                                  char *deviceType) {
  if (deviceTypeString[0] != '0' || deviceTypeString[1] != ';') {
    return 1;
  }
  const int start = 2;
  const int last = start + (4 + 1) - 1;
  int end = 0;
  for (end = start; end <= last; end++) {
    if (deviceTypeString[end] == '\0' || deviceTypeString[end] == ';') {
      break;
    }
  }
  if (end > last) {
    return 1;
  }
  int length = end - start;
  memcpy(deviceType, &deviceTypeString[start], length);
  deviceType[length] = '\0';
  return 0;
}


x86 assembly (clang, -O0):
<platformParseDeviceTypeString>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x30,%eax
jne    1141 <platformParseDeviceTypeString+0x31>
mov    -0x10(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x3b,%eax
je     114d <platformParseDeviceTypeString+0x3d>
movl   $0x1,-0x4(%rbp)
jmp    11fb <platformParseDeviceTypeString+0xeb>
movl   $0x2,-0x1c(%rbp)
movl   $0x6,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x2,-0x24(%rbp)
cmpl   $0x6,-0x24(%rbp)
jg     11b5 <platformParseDeviceTypeString+0xa5>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
je     119d <platformParseDeviceTypeString+0x8d>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x3b,%eax
jne    11a2 <platformParseDeviceTypeString+0x92>
jmp    11b5 <platformParseDeviceTypeString+0xa5>
jmp    11a7 <platformParseDeviceTypeString+0x97>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1169 <platformParseDeviceTypeString+0x59>
cmpl   $0x6,-0x24(%rbp)
jle    11cb <platformParseDeviceTypeString+0xbb>
movl   $0x1,-0x4(%rbp)
jmp    11fb <platformParseDeviceTypeString+0xeb>
mov    -0x24(%rbp),%eax
sub    $0x2,%eax
mov    %eax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
add    $0x2,%rsi
mov    -0x28(%rbp),%edx
call   1030 <memcpy@plt>
mov    -0x18(%rbp),%rax
movslq -0x28(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<platformParseDeviceTypeString>:
push   %rbp
push   %rbx
push   %rax
mov    $0x1,%eax
cmpb   $0x30,(%rdi)
jne    1192 <platformParseDeviceTypeString+0x82>
mov    %rsi,%rbx
mov    %rdi,%rsi
cmpb   $0x3b,0x1(%rdi)
jne    1192 <platformParseDeviceTypeString+0x82>
mov    0x2(%rsi),%al
xor    %ebp,%ebp
test   %al,%al
je     117c <platformParseDeviceTypeString+0x6c>
cmp    $0x3b,%al
je     117c <platformParseDeviceTypeString+0x6c>
mov    0x3(%rsi),%al
mov    $0x1,%ebp
test   %al,%al
je     117c <platformParseDeviceTypeString+0x6c>
cmp    $0x3b,%al
je     117c <platformParseDeviceTypeString+0x6c>
mov    0x4(%rsi),%al
mov    $0x2,%ebp
test   %al,%al
je     117c <platformParseDeviceTypeString+0x6c>
cmp    $0x3b,%al
je     117c <platformParseDeviceTypeString+0x6c>
mov    0x5(%rsi),%al
mov    $0x3,%ebp
test   %al,%al
je     117c <platformParseDeviceTypeString+0x6c>
cmp    $0x3b,%al
je     117c <platformParseDeviceTypeString+0x6c>
mov    0x6(%rsi),%cl
mov    $0x4,%ebp
cmp    $0x3b,%cl
je     117c <platformParseDeviceTypeString+0x6c>
mov    $0x1,%eax
test   %cl,%cl
jne    1192 <platformParseDeviceTypeString+0x82>
add    $0x2,%rsi
mov    %rbx,%rdi
mov    %ebp,%edx
call   1030 <memcpy@plt>
mov    %ebp,%eax
movb   $0x0,(%rbx,%rax,1)
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @platformParseDeviceTypeString(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%10 = load i8*, i8** %4
%11 = getelementptr inbounds i8, i8* %10, i64 0
%12 = load i8, i8* %11
%13 = sext i8 %12 to i32
%14 = icmp ne i32 %13, 48
br i1 %14, label %21, label %15
15: ; preds = %2
%16 = load i8*, i8** %4
%17 = getelementptr inbounds i8, i8* %16, i64 1
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
%20 = icmp ne i32 %19, 59
br i1 %20, label %21, label %22
21: ; preds = %15, %2
store i32 1, i32* %3
br label %63
22: ; preds = %15
store i32 2, i32* %6
store i32 6, i32* %7
store i32 0, i32* %8
store i32 2, i32* %8
br label %23
23: ; preds = %44, %22
%24 = load i32, i32* %8
%25 = icmp sle i32 %24, 6
br i1 %25, label %26, label %47
26: ; preds = %23
%27 = load i8*, i8** %4
%28 = load i32, i32* %8
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %27, i64 %29
%31 = load i8, i8* %30
%32 = sext i8 %31 to i32
%33 = icmp eq i32 %32, 0
br i1 %33, label %42, label %34
34: ; preds = %26
%35 = load i8*, i8** %4
%36 = load i32, i32* %8
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i8, i8* %35, i64 %37
%39 = load i8, i8* %38
%40 = sext i8 %39 to i32
%41 = icmp eq i32 %40, 59
br i1 %41, label %42, label %43
42: ; preds = %34, %26
br label %47
43: ; preds = %34
br label %44
44: ; preds = %43
%45 = load i32, i32* %8
%46 = add nsw i32 %45, 1
store i32 %46, i32* %8
br label %23
47: ; preds = %42, %23
%48 = load i32, i32* %8
%49 = icmp sgt i32 %48, 6
br i1 %49, label %50, label %51
50: ; preds = %47
store i32 1, i32* %3
br label %63
51: ; preds = %47
%52 = load i32, i32* %8
%53 = sub nsw i32 %52, 2
store i32 %53, i32* %9
%54 = load i8*, i8** %5
%55 = load i8*, i8** %4
%56 = getelementptr inbounds i8, i8* %55, i64 2
%57 = load i32, i32* %9
%58 = call i32 @memcpy(i8* %54, i8* %56, i32 %57)
%59 = load i8*, i8** %5
%60 = load i32, i32* %9
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds i8, i8* %59, i64 %61
store i8 0, i8* %62
store i32 0, i32* %3
br label %63
63: ; preds = %51, %50, %21
%64 = load i32, i32* %3
ret i32 %64
}

LLVM IR (-O2):
define i32 @platformParseDeviceTypeString(i8* %0, i8* %1) {
%3 = load i8, i8* %0
%4 = icmp eq i8 %3, 48
br i1 %4, label %5, label %29
5: ; preds = %2
%6 = getelementptr inbounds i8, i8* %0, i64 1
%7 = load i8, i8* %6
%8 = icmp eq i8 %7, 59
br i1 %8, label %9, label %29
9: ; preds = %5
%10 = getelementptr inbounds i8, i8* %0, i64 2
%11 = load i8, i8* %10
switch i8 %11, label %12 [
i8 0, label %24
i8 59, label %24
]
12: ; preds = %9
%13 = getelementptr inbounds i8, i8* %0, i64 3
%14 = load i8, i8* %13
switch i8 %14, label %15 [
i8 0, label %24
i8 59, label %24
]
15: ; preds = %12
%16 = getelementptr inbounds i8, i8* %0, i64 4
%17 = load i8, i8* %16
switch i8 %17, label %18 [
i8 0, label %24
i8 59, label %24
]
18: ; preds = %15
%19 = getelementptr inbounds i8, i8* %0, i64 5
%20 = load i8, i8* %19
switch i8 %20, label %21 [
i8 0, label %24
i8 59, label %24
]
21: ; preds = %18
%22 = getelementptr inbounds i8, i8* %0, i64 6
%23 = load i8, i8* %22
switch i8 %23, label %29 [
i8 0, label %24
i8 59, label %24
]
24: ; preds = %21, %21, %18, %18, %15, %15, %12, %12, %9, %9
%25 = phi i32 [ 0, %9 ], [ 0, %9 ], [ 1, %12 ], [ 1, %12 ], [ 2, %15 ], [ 2, %15 ], [ 3, %18 ], [ 3, %18 ], [ 4, %21 ], [ 4, %21 ]
%26 = tail call i32 @memcpy(i8* %1, i8* %10, i32 %25)
%27 = zext i32 %25 to i64
%28 = getelementptr inbounds i8, i8* %1, i64 %27
store i8 0, i8* %28
br label %29
29: ; preds = %21, %24, %2, %5
%30 = phi i32 [ 1, %5 ], [ 1, %2 ], [ 0, %24 ], [ 1, %21 ]
ret i32 %30
}