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

/* Variables and functions */
int /*<<< orphan*/ path_prepend(char **, char *, char const *);
struct udev_device *skip_subsystem(struct udev_device *, char *);
char *strchr(char const *, char);
scalar_t__ strcmp(char const *, char *);
char *udev_device_get_devtype(struct udev_device *);
char *udev_device_get_sysname(struct udev_device *);
struct udev_device *handle_usb(struct udev_device *parent, char **path) {
  const char *devtype;
  const char *str;
  const char *port;
  devtype = udev_device_get_devtype(parent);
  if (devtype == NULL)
    return parent;
  if (strcmp(devtype, "usb_interface") != 0 &&
      strcmp(devtype, "usb_device") != 0)
    return parent;
  str = udev_device_get_sysname(parent);
  port = strchr(str, '-');
  if (port == NULL)
    return parent;
  port++;
  parent = skip_subsystem(parent, "usb");
  path_prepend(path, "usb-0:%s", port);
  return parent;
}


x86 assembly (clang, -O0):
<handle_usb>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1080 <udev_device_get_devtype@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1195 <handle_usb+0x35>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1249 <handle_usb+0xe9>
mov    -0x20(%rbp),%rdi
lea    0xe60(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
je     11d6 <handle_usb+0x76>
mov    -0x20(%rbp),%rdi
lea    0xe54(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
je     11d6 <handle_usb+0x76>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1249 <handle_usb+0xe9>
mov    -0x10(%rbp),%rdi
call   1070 <udev_device_get_sysname@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    $0x2d,%esi
call   1050 <strchr@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    120d <handle_usb+0xad>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1249 <handle_usb+0xe9>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xdf5(%rip),%rsi
call   1040 <skip_subsystem@plt>
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x30(%rbp),%rdx
lea    0xde1(%rip),%rsi
call   1030 <path_prepend@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<handle_usb>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
call   1080 <udev_device_get_devtype@plt>
test   %rax,%rax
je     11e5 <handle_usb+0x85>
mov    %rax,%rbx
lea    0xe81(%rip),%rsi
mov    %rax,%rdi
call   1060 <strcmp@plt>
test   %rax,%rax
je     11a0 <handle_usb+0x40>
lea    0xe7b(%rip),%rsi
mov    %rbx,%rdi
call   1060 <strcmp@plt>
test   %rax,%rax
jne    11e5 <handle_usb+0x85>
mov    %r15,%rdi
call   1070 <udev_device_get_sysname@plt>
mov    %rax,%rdi
mov    $0x2d,%esi
call   1050 <strchr@plt>
test   %rax,%rax
je     11e5 <handle_usb+0x85>
mov    %rax,%rbx
add    $0x1,%rbx
lea    0xe51(%rip),%rsi
mov    %r15,%rdi
call   1040 <skip_subsystem@plt>
mov    %rax,%r15
lea    0xe43(%rip),%rsi
mov    %r14,%rdi
mov    %rbx,%rdx
call   1030 <path_prepend@plt>
mov    %r15,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.udev_device = type { i32 }
@.str = [14 x i8] c"usb_interface\00"
@.str.1 = [11 x i8] c"usb_device\00"
@.str.2 = [4 x i8] c"usb\00"
@.str.3 = [9 x i8] c"usb-0:%s\00"
define %struct.udev_device* @handle_usb(%struct.udev_device* %0, i8** %1) {
%3 = alloca %struct.udev_device*
%4 = alloca %struct.udev_device*
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
store %struct.udev_device* %0, %struct.udev_device** %4
store i8** %1, i8*** %5
%9 = load %struct.udev_device*, %struct.udev_device** %4
%10 = call i8* @udev_device_get_devtype(%struct.udev_device* %9)
store i8* %10, i8** %6
%11 = load i8*, i8** %6
%12 = icmp eq i8* %11, null
br i1 %12, label %13, label %15
13: ; preds = %2
%14 = load %struct.udev_device*, %struct.udev_device** %4
store %struct.udev_device* %14, %struct.udev_device** %3
br label %43
15: ; preds = %2
%16 = load i8*, i8** %6
%17 = call i64 @strcmp(i8* %16, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %25
19: ; preds = %15
%20 = load i8*, i8** %6
%21 = call i64 @strcmp(i8* %20, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%22 = icmp ne i64 %21, 0
br i1 %22, label %23, label %25
23: ; preds = %19
%24 = load %struct.udev_device*, %struct.udev_device** %4
store %struct.udev_device* %24, %struct.udev_device** %3
br label %43
25: ; preds = %19, %15
%26 = load %struct.udev_device*, %struct.udev_device** %4
%27 = call i8* @udev_device_get_sysname(%struct.udev_device* %26)
store i8* %27, i8** %7
%28 = load i8*, i8** %7
%29 = call i8* @strchr(i8* %28, i8 signext 45)
store i8* %29, i8** %8
%30 = load i8*, i8** %8
%31 = icmp eq i8* %30, null
br i1 %31, label %32, label %34
32: ; preds = %25
%33 = load %struct.udev_device*, %struct.udev_device** %4
store %struct.udev_device* %33, %struct.udev_device** %3
br label %43
34: ; preds = %25
%35 = load i8*, i8** %8
%36 = getelementptr inbounds i8, i8* %35, i32 1
store i8* %36, i8** %8
%37 = load %struct.udev_device*, %struct.udev_device** %4
%38 = call %struct.udev_device* @skip_subsystem(%struct.udev_device* %37, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
store %struct.udev_device* %38, %struct.udev_device** %4
%39 = load i8**, i8*** %5
%40 = load i8*, i8** %8
%41 = call i32 @path_prepend(i8** %39, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i8* %40)
%42 = load %struct.udev_device*, %struct.udev_device** %4
store %struct.udev_device* %42, %struct.udev_device** %3
br label %43
43: ; preds = %34, %32, %23, %13
%44 = load %struct.udev_device*, %struct.udev_device** %3
ret %struct.udev_device* %44
}

LLVM IR (-O2):
%struct.udev_device = type { i32 }
@.str = [14 x i8] c"usb_interface\00"
@.str.1 = [11 x i8] c"usb_device\00"
@.str.2 = [4 x i8] c"usb\00"
@.str.3 = [9 x i8] c"usb-0:%s\00"
define %struct.udev_device* @handle_usb(%struct.udev_device* %0, i8** %1) {
%3 = tail call i8* @udev_device_get_devtype(%struct.udev_device* %0)
%4 = icmp eq i8* %3, null
br i1 %4, label %19, label %5
5: ; preds = %2
%6 = tail call i64 @strcmp(i8* %3, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i64 %6, 0
br i1 %7, label %11, label %8
8: ; preds = %5
%9 = tail call i64 @strcmp(i8* %3, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %19
11: ; preds = %8, %5
%12 = tail call i8* @udev_device_get_sysname(%struct.udev_device* %0)
%13 = tail call i8* @strchr(i8* dereferenceable(1) %12, i8 signext 45)
%14 = icmp eq i8* %13, null
br i1 %14, label %19, label %15
15: ; preds = %11
%16 = getelementptr inbounds i8, i8* %13, i64 1
%17 = tail call %struct.udev_device* @skip_subsystem(%struct.udev_device* %0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%18 = tail call i32 @path_prepend(i8** %1, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i8* %16)
br label %19
19: ; preds = %11, %8, %2, %15
%20 = phi %struct.udev_device* [ %17, %15 ], [ %0, %2 ], [ %0, %8 ], [ %0, %11 ]
ret %struct.udev_device* %20
}