#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 || strcmp(devtype, "usb_interface") != 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)
je     11a2 <handle_usb+0x42>
mov    -0x20(%rbp),%rdi
lea    0xe6d(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
je     11af <handle_usb+0x4f>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1222 <handle_usb+0xc2>
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    11e6 <handle_usb+0x86>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1222 <handle_usb+0xc2>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe11(%rip),%rsi
call   1040 <skip_subsystem@plt>
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x30(%rbp),%rdx
lea    0xdfd(%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,%rbx
call   1080 <udev_device_get_devtype@plt>
test   %rax,%rax
je     11ce <handle_usb+0x6e>
lea    0xe84(%rip),%rsi
mov    %rax,%rdi
call   1060 <strcmp@plt>
test   %rax,%rax
jne    11ce <handle_usb+0x6e>
mov    %rbx,%rdi
call   1070 <udev_device_get_sysname@plt>
mov    %rax,%rdi
mov    $0x2d,%esi
call   1050 <strchr@plt>
test   %rax,%rax
je     11ce <handle_usb+0x6e>
mov    %rax,%r15
add    $0x1,%r15
lea    0xe5d(%rip),%rsi
mov    %rbx,%rdi
call   1040 <skip_subsystem@plt>
mov    %rax,%rbx
lea    0xe4f(%rip),%rsi
mov    %r14,%rdi
mov    %r15,%rdx
call   1030 <path_prepend@plt>
mov    %rbx,%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 = [4 x i8] c"usb\00"
@.str.2 = [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 %17, label %13
13: ; preds = %2
%14 = load i8*, i8** %6
%15 = call i64 @strcmp(i8* %14, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %13, %2
%18 = load %struct.udev_device*, %struct.udev_device** %4
store %struct.udev_device* %18, %struct.udev_device** %3
br label %37
19: ; preds = %13
%20 = load %struct.udev_device*, %struct.udev_device** %4
%21 = call i8* @udev_device_get_sysname(%struct.udev_device* %20)
store i8* %21, i8** %7
%22 = load i8*, i8** %7
%23 = call i8* @strchr(i8* %22, i8 signext 45)
store i8* %23, i8** %8
%24 = load i8*, i8** %8
%25 = icmp eq i8* %24, null
br i1 %25, label %26, label %28
26: ; preds = %19
%27 = load %struct.udev_device*, %struct.udev_device** %4
store %struct.udev_device* %27, %struct.udev_device** %3
br label %37
28: ; preds = %19
%29 = load i8*, i8** %8
%30 = getelementptr inbounds i8, i8* %29, i32 1
store i8* %30, i8** %8
%31 = load %struct.udev_device*, %struct.udev_device** %4
%32 = call %struct.udev_device* @skip_subsystem(%struct.udev_device* %31, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
store %struct.udev_device* %32, %struct.udev_device** %4
%33 = load i8**, i8*** %5
%34 = load i8*, i8** %8
%35 = call i32 @path_prepend(i8** %33, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* %34)
%36 = load %struct.udev_device*, %struct.udev_device** %4
store %struct.udev_device* %36, %struct.udev_device** %3
br label %37
37: ; preds = %28, %26, %17
%38 = load %struct.udev_device*, %struct.udev_device** %3
ret %struct.udev_device* %38
}

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