#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 strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
char *strstr(char const *, char *);
int parseID(const char *id, int *bt, char *vendor, char *device,
            char *subvendor, char *subdevice) {
  char *ptr1, *ptr2, *ptr3;
  ptr1 = strstr(id, "PCI\\VEN_");
  ptr2 = strstr(id, "&DEV_");
  ptr3 = strstr(id, "&SUBSYS_");
  if (ptr1 && ptr2) {
    *bt = 5;
    strncpy(vendor, ptr1 + strlen("PCI\\VEN_"), 4);
    vendor[4] = '\0';
    strncpy(device, ptr2 + strlen("&DEV_"), 4);
    device[4] = '\0';
    if (ptr3) {
      strncpy(subdevice, ptr3 + strlen("&SUBSYS_"), 4);
      subdevice[4] = '\0';
      strncpy(subvendor, ptr3 + strlen("&SUBSYS_") + 4, 4);
      subvendor[4] = '\0';
    } else {
      subvendor[0] = '\0';
      subdevice[0] = '\0';
    }
  } else {
    ptr1 = strstr(id, "USB\\VID_");
    ptr2 = strstr(id, "&PID_");
    *bt = 15;
    strncpy(vendor, ptr1 + strlen("USB\\VID_"), 4);
    vendor[4] = '\0';
    strncpy(device, ptr2 + strlen("&PID_"), 4);
    device[4] = '\0';
    subvendor[0] = '\0';
    subdevice[0] = '\0';
  }
  return 1;
}


x86 assembly (clang, -O0):
<parseID>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xea2(%rip),%rsi
call   1050 <strstr@plt>
mov    %rax,-0x38(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe97(%rip),%rsi
call   1050 <strstr@plt>
mov    %rax,-0x40(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe89(%rip),%rsi
call   1050 <strstr@plt>
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x38(%rbp)
je     12c8 <parseID+0x198>
cmpq   $0x0,-0x40(%rbp)
je     12c8 <parseID+0x198>
mov    -0x10(%rbp),%rax
movl   $0x5,(%rax)
mov    -0x18(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,-0x68(%rbp)
lea    0xe3a(%rip),%rdi
call   1040 <strlen@plt>
mov    -0x68(%rbp),%rsi
mov    -0x60(%rbp),%rdi
cltq
add    %rax,%rsi
mov    $0x4,%edx
call   1030 <strncpy@plt>
mov    -0x18(%rbp),%rax
movb   $0x0,0x4(%rax)
mov    -0x20(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x40(%rbp),%rax
mov    %rax,-0x58(%rbp)
lea    0xe08(%rip),%rdi
call   1040 <strlen@plt>
mov    -0x58(%rbp),%rsi
mov    -0x50(%rbp),%rdi
cltq
add    %rax,%rsi
mov    $0x4,%edx
call   1030 <strncpy@plt>
mov    -0x20(%rbp),%rax
movb   $0x0,0x4(%rax)
cmpq   $0x0,-0x48(%rbp)
je     12b5 <parseID+0x185>
mov    -0x30(%rbp),%rax
mov    %rax,-0x80(%rbp)
mov    -0x48(%rbp),%rax
mov    %rax,-0x88(%rbp)
lea    0xdc5(%rip),%rdi
call   1040 <strlen@plt>
mov    -0x88(%rbp),%rsi
mov    -0x80(%rbp),%rdi
cltq
add    %rax,%rsi
mov    $0x4,%edx
call   1030 <strncpy@plt>
mov    -0x30(%rbp),%rax
movb   $0x0,0x4(%rax)
mov    -0x28(%rbp),%rax
mov    %rax,-0x70(%rbp)
mov    -0x48(%rbp),%rax
mov    %rax,-0x78(%rbp)
lea    0xd87(%rip),%rdi
call   1040 <strlen@plt>
mov    -0x78(%rbp),%rsi
mov    -0x70(%rbp),%rdi
cltq
add    %rax,%rsi
add    $0x4,%rsi
mov    $0x4,%edx
call   1030 <strncpy@plt>
mov    -0x28(%rbp),%rax
movb   $0x0,0x4(%rax)
jmp    12c3 <parseID+0x193>
mov    -0x28(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x30(%rbp),%rax
movb   $0x0,(%rax)
jmp    1396 <parseID+0x266>
mov    -0x8(%rbp),%rdi
lea    0xd45(%rip),%rsi
call   1050 <strstr@plt>
mov    %rax,-0x38(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xd3a(%rip),%rsi
call   1050 <strstr@plt>
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rax
movl   $0xf,(%rax)
mov    -0x18(%rbp),%rax
mov    %rax,-0xa0(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,-0xa8(%rbp)
lea    0xd01(%rip),%rdi
call   1040 <strlen@plt>
mov    -0xa8(%rbp),%rsi
mov    -0xa0(%rbp),%rdi
cltq
add    %rax,%rsi
mov    $0x4,%edx
call   1030 <strncpy@plt>
mov    -0x18(%rbp),%rax
movb   $0x0,0x4(%rax)
mov    -0x20(%rbp),%rax
mov    %rax,-0x90(%rbp)
mov    -0x40(%rbp),%rax
mov    %rax,-0x98(%rbp)
lea    0xcc3(%rip),%rdi
call   1040 <strlen@plt>
mov    -0x98(%rbp),%rsi
mov    -0x90(%rbp),%rdi
cltq
add    %rax,%rsi
mov    $0x4,%edx
call   1030 <strncpy@plt>
mov    -0x20(%rbp),%rax
movb   $0x0,0x4(%rax)
mov    -0x28(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x30(%rbp),%rax
movb   $0x0,(%rax)
mov    $0x1,%eax
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parseID>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r9,(%rsp)
mov    %r8,0x8(%rsp)
mov    %rcx,0x10(%rsp)
mov    %rdx,%rbx
mov    %rsi,%rbp
mov    %rdi,%r15
lea    0xea4(%rip),%rsi
call   1050 <strstr@plt>
mov    %rax,%r12
lea    0xe9e(%rip),%rsi
mov    %r15,%rdi
call   1050 <strstr@plt>
mov    %rax,%r14
lea    0xe92(%rip),%rsi
mov    %r15,%rdi
call   1050 <strstr@plt>
test   %r12,%r12
je     1250 <parseID+0x120>
test   %r14,%r14
je     1250 <parseID+0x120>
mov    %rax,%r13
movl   $0x5,0x0(%rbp)
lea    0xe58(%rip),%rdi
call   1040 <strlen@plt>
cltq
add    %rax,%r12
mov    %rbx,%rdi
mov    %r12,%rsi
mov    $0x4,%edx
call   1030 <strncpy@plt>
movb   $0x0,0x4(%rbx)
lea    0xe3c(%rip),%rdi
call   1040 <strlen@plt>
cltq
add    %rax,%r14
mov    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x4,%edx
call   1030 <strncpy@plt>
movb   $0x0,0x4(%rbx)
test   %r13,%r13
je     12c4 <parseID+0x194>
lea    0xe0f(%rip),%rbx
mov    %rbx,%rdi
call   1040 <strlen@plt>
movslq %eax,%rsi
add    %r13,%rsi
mov    (%rsp),%rbp
mov    %rbp,%rdi
mov    $0x4,%edx
call   1030 <strncpy@plt>
movb   $0x0,0x4(%rbp)
mov    %rbx,%rdi
call   1040 <strlen@plt>
cltq
lea    (%rax,%r13,1),%rsi
add    $0x4,%rsi
mov    0x8(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x4,%edx
call   1030 <strncpy@plt>
add    $0x4,%rbx
jmp    12d0 <parseID+0x1a0>
lea    0xdc1(%rip),%r14
mov    %r15,%rdi
mov    %r14,%rsi
call   1050 <strstr@plt>
mov    %rax,%r12
lea    0xdb5(%rip),%r13
mov    %r15,%rdi
mov    %r13,%rsi
call   1050 <strstr@plt>
mov    %rax,%r15
movl   $0xf,0x0(%rbp)
mov    %r14,%rdi
call   1040 <strlen@plt>
movslq %eax,%rsi
add    %r12,%rsi
mov    %rbx,%rdi
mov    $0x4,%edx
call   1030 <strncpy@plt>
movb   $0x0,0x4(%rbx)
mov    %r13,%rdi
call   1040 <strlen@plt>
movslq %eax,%rsi
add    %r15,%rsi
mov    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x4,%edx
call   1030 <strncpy@plt>
movb   $0x0,0x4(%rbx)
mov    0x8(%rsp),%rax
movb   $0x0,(%rax)
mov    (%rsp),%rbx
movb   $0x0,(%rbx)
mov    $0x1,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [9 x i8] c"PCI\\VEN_\00"
@.str.1 = [6 x i8] c"&DEV_\00"
@.str.2 = [9 x i8] c"&SUBSYS_\00"
@.str.3 = [9 x i8] c"USB\\VID_\00"
@.str.4 = [6 x i8] c"&PID_\00"
define i32 @parseID(i8* %0, i32* %1, i8* %2, i8* %3, i8* %4, i8* %5) {
%7 = alloca i8*
%8 = alloca i32*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca i8*
%14 = alloca i8*
%15 = alloca i8*
store i8* %0, i8** %7
store i32* %1, i32** %8
store i8* %2, i8** %9
store i8* %3, i8** %10
store i8* %4, i8** %11
store i8* %5, i8** %12
%16 = load i8*, i8** %7
%17 = call i8* @strstr(i8* %16, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
store i8* %17, i8** %13
%18 = load i8*, i8** %7
%19 = call i8* @strstr(i8* %18, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
store i8* %19, i8** %14
%20 = load i8*, i8** %7
%21 = call i8* @strstr(i8* %20, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
store i8* %21, i8** %15
%22 = load i8*, i8** %13
%23 = icmp ne i8* %22, null
br i1 %23, label %24, label %71
24: ; preds = %6
%25 = load i8*, i8** %14
%26 = icmp ne i8* %25, null
br i1 %26, label %27, label %71
27: ; preds = %24
%28 = load i32*, i32** %8
store i32 5, i32* %28
%29 = load i8*, i8** %9
%30 = load i8*, i8** %13
%31 = call i32 @strlen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8, i8* %30, i64 %32
%34 = call i32 @strncpy(i8* %29, i8* %33, i32 4)
%35 = load i8*, i8** %9
%36 = getelementptr inbounds i8, i8* %35, i64 4
store i8 0, i8* %36
%37 = load i8*, i8** %10
%38 = load i8*, i8** %14
%39 = call i32 @strlen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i8, i8* %38, i64 %40
%42 = call i32 @strncpy(i8* %37, i8* %41, i32 4)
%43 = load i8*, i8** %10
%44 = getelementptr inbounds i8, i8* %43, i64 4
store i8 0, i8* %44
%45 = load i8*, i8** %15
%46 = icmp ne i8* %45, null
br i1 %46, label %47, label %65
47: ; preds = %27
%48 = load i8*, i8** %12
%49 = load i8*, i8** %15
%50 = call i32 @strlen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds i8, i8* %49, i64 %51
%53 = call i32 @strncpy(i8* %48, i8* %52, i32 4)
%54 = load i8*, i8** %12
%55 = getelementptr inbounds i8, i8* %54, i64 4
store i8 0, i8* %55
%56 = load i8*, i8** %11
%57 = load i8*, i8** %15
%58 = call i32 @strlen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds i8, i8* %57, i64 %59
%61 = getelementptr inbounds i8, i8* %60, i64 4
%62 = call i32 @strncpy(i8* %56, i8* %61, i32 4)
%63 = load i8*, i8** %11
%64 = getelementptr inbounds i8, i8* %63, i64 4
store i8 0, i8* %64
br label %70
65: ; preds = %27
%66 = load i8*, i8** %11
%67 = getelementptr inbounds i8, i8* %66, i64 0
store i8 0, i8* %67
%68 = load i8*, i8** %12
%69 = getelementptr inbounds i8, i8* %68, i64 0
store i8 0, i8* %69
br label %70
70: ; preds = %65, %47
br label %97
71: ; preds = %24, %6
%72 = load i8*, i8** %7
%73 = call i8* @strstr(i8* %72, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
store i8* %73, i8** %13
%74 = load i8*, i8** %7
%75 = call i8* @strstr(i8* %74, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
store i8* %75, i8** %14
%76 = load i32*, i32** %8
store i32 15, i32* %76
%77 = load i8*, i8** %9
%78 = load i8*, i8** %13
%79 = call i32 @strlen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
%80 = sext i32 %79 to i64
%81 = getelementptr inbounds i8, i8* %78, i64 %80
%82 = call i32 @strncpy(i8* %77, i8* %81, i32 4)
%83 = load i8*, i8** %9
%84 = getelementptr inbounds i8, i8* %83, i64 4
store i8 0, i8* %84
%85 = load i8*, i8** %10
%86 = load i8*, i8** %14
%87 = call i32 @strlen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
%88 = sext i32 %87 to i64
%89 = getelementptr inbounds i8, i8* %86, i64 %88
%90 = call i32 @strncpy(i8* %85, i8* %89, i32 4)
%91 = load i8*, i8** %10
%92 = getelementptr inbounds i8, i8* %91, i64 4
store i8 0, i8* %92
%93 = load i8*, i8** %11
%94 = getelementptr inbounds i8, i8* %93, i64 0
store i8 0, i8* %94
%95 = load i8*, i8** %12
%96 = getelementptr inbounds i8, i8* %95, i64 0
store i8 0, i8* %96
br label %97
97: ; preds = %71, %70
ret i32 1
}

LLVM IR (-O2):
@.str = [9 x i8] c"PCI\\VEN_\00"
@.str.1 = [6 x i8] c"&DEV_\00"
@.str.2 = [9 x i8] c"&SUBSYS_\00"
@.str.3 = [9 x i8] c"USB\\VID_\00"
@.str.4 = [6 x i8] c"&PID_\00"
define i32 @parseID(i8* %0, i32* nocapture writeonly %1, i8* %2, i8* %3, i8* %4, i8* %5) {
%7 = tail call i8* @strstr(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%8 = tail call i8* @strstr(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%9 = tail call i8* @strstr(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
%10 = icmp ne i8* %7, null
%11 = icmp ne i8* %8, null
%12 = select i1 %10, i1 %11, i1 false
br i1 %12, label %13, label %38
13: ; preds = %6
store i32 5, i32* %1
%14 = tail call i32 @strlen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i8, i8* %7, i64 %15
%17 = tail call i32 @strncpy(i8* %2, i8* %16, i32 4)
%18 = getelementptr inbounds i8, i8* %2, i64 4
store i8 0, i8* %18
%19 = tail call i32 @strlen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i8, i8* %8, i64 %20
%22 = tail call i32 @strncpy(i8* %3, i8* %21, i32 4)
%23 = getelementptr inbounds i8, i8* %3, i64 4
store i8 0, i8* %23
%24 = icmp eq i8* %9, null
br i1 %24, label %37, label %25
25: ; preds = %13
%26 = tail call i32 @strlen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %9, i64 %27
%29 = tail call i32 @strncpy(i8* %5, i8* %28, i32 4)
%30 = getelementptr inbounds i8, i8* %5, i64 4
store i8 0, i8* %30
%31 = tail call i32 @strlen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8, i8* %9, i64 %32
%34 = getelementptr inbounds i8, i8* %33, i64 4
%35 = tail call i32 @strncpy(i8* %4, i8* %34, i32 4)
%36 = getelementptr inbounds i8, i8* %4, i64 4
br label %51
37: ; preds = %13
store i8 0, i8* %4
br label %51
38: ; preds = %6
%39 = tail call i8* @strstr(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
%40 = tail call i8* @strstr(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
store i32 15, i32* %1
%41 = tail call i32 @strlen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i8, i8* %39, i64 %42
%44 = tail call i32 @strncpy(i8* %2, i8* %43, i32 4)
%45 = getelementptr inbounds i8, i8* %2, i64 4
store i8 0, i8* %45
%46 = tail call i32 @strlen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds i8, i8* %40, i64 %47
%49 = tail call i32 @strncpy(i8* %3, i8* %48, i32 4)
%50 = getelementptr inbounds i8, i8* %3, i64 4
store i8 0, i8* %50
store i8 0, i8* %4
br label %51
51: ; preds = %25, %37, %38
%52 = phi i8* [ %36, %25 ], [ %5, %37 ], [ %5, %38 ]
store i8 0, i8* %52
ret i32 1
}