#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*/ EINVAL;
int /*<<< orphan*/ ENOENT;
int /*<<< orphan*/ errno;
scalar_t__ strcmp(char const *, char const *);
char *udev_device_get_devtype(struct udev_device *);
struct udev_device *udev_device_get_parent(struct udev_device *);
char *udev_device_get_subsystem(struct udev_device *);
struct udev_device *
udev_device_get_parent_with_subsystem_devtype(struct udev_device *udev_device,
                                              const char *subsystem,
                                              const char *devtype) {
  struct udev_device *parent;
  if (subsystem == NULL) {
    errno = EINVAL;
    return NULL;
  }
  parent = udev_device_get_parent(udev_device);
  while (parent != NULL) {
    const char *parent_subsystem;
    const char *parent_devtype;
    parent_subsystem = udev_device_get_subsystem(parent);
    if (parent_subsystem != NULL &&
        (strcmp((parent_subsystem), (subsystem)) == 0)) {
      if (devtype == NULL)
        break;
      parent_devtype = udev_device_get_devtype(parent);
      if (parent_devtype != NULL && (strcmp((parent_devtype), (devtype)) == 0))
        break;
    }
    parent = udev_device_get_parent(parent);
  }
  if (!parent)
    errno = ENOENT;
  return parent;
}


x86 assembly (clang, -O0):
<udev_device_get_parent_with_subsystem_devtype>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    117e <udev_device_get_parent_with_subsystem_devtype+0x3e>
mov    0x2e72(%rip),%rax
mov    (%rax),%ecx
mov    0x2e71(%rip),%rax
mov    %ecx,(%rax)
movq   $0x0,-0x8(%rbp)
jmp    1245 <udev_device_get_parent_with_subsystem_devtype+0x105>
mov    -0x10(%rbp),%rdi
call   1050 <udev_device_get_parent@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     1220 <udev_device_get_parent_with_subsystem_devtype+0xe0>
mov    -0x28(%rbp),%rdi
call   1030 <udev_device_get_subsystem@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     120e <udev_device_get_parent_with_subsystem_devtype+0xce>
mov    -0x30(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    120e <udev_device_get_parent_with_subsystem_devtype+0xce>
cmpq   $0x0,-0x20(%rbp)
jne    11d5 <udev_device_get_parent_with_subsystem_devtype+0x95>
jmp    1220 <udev_device_get_parent_with_subsystem_devtype+0xe0>
mov    -0x28(%rbp),%rdi
call   1060 <udev_device_get_devtype@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
je     1209 <udev_device_get_parent_with_subsystem_devtype+0xc9>
mov    -0x38(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    1209 <udev_device_get_parent_with_subsystem_devtype+0xc9>
jmp    1220 <udev_device_get_parent_with_subsystem_devtype+0xe0>
jmp    120e <udev_device_get_parent_with_subsystem_devtype+0xce>
mov    -0x28(%rbp),%rdi
call   1050 <udev_device_get_parent@plt>
mov    %rax,-0x28(%rbp)
jmp    118b <udev_device_get_parent_with_subsystem_devtype+0x4b>
cmpq   $0x0,-0x28(%rbp)
jne    123d <udev_device_get_parent_with_subsystem_devtype+0xfd>
mov    0x2d96(%rip),%rax
mov    (%rax),%ecx
mov    0x2da5(%rip),%rax
mov    %ecx,(%rax)
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<udev_device_get_parent_with_subsystem_devtype>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
test   %rsi,%rsi
je     11c1 <udev_device_get_parent_with_subsystem_devtype+0x81>
mov    %rdx,%r14
mov    %rsi,%r15
call   1050 <udev_device_get_parent@plt>
mov    0x2e69(%rip),%r12
test   %rax,%rax
je     11c8 <udev_device_get_parent_with_subsystem_devtype+0x88>
mov    %rax,%rbx
jmp    1180 <udev_device_get_parent_with_subsystem_devtype+0x40>
nopl   0x0(%rax)
mov    %rbx,%rdi
call   1050 <udev_device_get_parent@plt>
mov    %rax,%rbx
test   %rax,%rax
je     11c8 <udev_device_get_parent_with_subsystem_devtype+0x88>
mov    %rbx,%rdi
call   1030 <udev_device_get_subsystem@plt>
test   %rax,%rax
je     1170 <udev_device_get_parent_with_subsystem_devtype+0x30>
mov    %rax,%rdi
mov    %r15,%rsi
call   1040 <strcmp@plt>
test   %rax,%rax
jne    1170 <udev_device_get_parent_with_subsystem_devtype+0x30>
test   %r14,%r14
je     11d7 <udev_device_get_parent_with_subsystem_devtype+0x97>
mov    %rbx,%rdi
call   1060 <udev_device_get_devtype@plt>
test   %rax,%rax
je     1170 <udev_device_get_parent_with_subsystem_devtype+0x30>
mov    %rax,%rdi
mov    %r14,%rsi
call   1040 <strcmp@plt>
test   %rax,%rax
jne    1170 <udev_device_get_parent_with_subsystem_devtype+0x30>
jmp    11d7 <udev_device_get_parent_with_subsystem_devtype+0x97>
mov    0x2e10(%rip),%r12
mov    (%r12),%eax
mov    0x2e0d(%rip),%rcx
mov    %eax,(%rcx)
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.udev_device = type { i32 }
@EINVAL = global i32 0
@errno = global i32 0
@ENOENT = global i32 0
define %struct.udev_device* @udev_device_get_parent_with_subsystem_devtype(%struct.udev_device* %0, i8* %1, i8* %2) {
%4 = alloca %struct.udev_device*
%5 = alloca %struct.udev_device*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca %struct.udev_device*
%9 = alloca i8*
%10 = alloca i8*
store %struct.udev_device* %0, %struct.udev_device** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
%11 = load i8*, i8** %6
%12 = icmp eq i8* %11, null
br i1 %12, label %13, label %15
13: ; preds = %3
%14 = load i32, i32* @EINVAL
store i32 %14, i32* @errno
store %struct.udev_device* null, %struct.udev_device** %4
br label %57
15: ; preds = %3
%16 = load %struct.udev_device*, %struct.udev_device** %5
%17 = call %struct.udev_device* @udev_device_get_parent(%struct.udev_device* %16)
store %struct.udev_device* %17, %struct.udev_device** %8
br label %18
18: ; preds = %47, %15
%19 = load %struct.udev_device*, %struct.udev_device** %8
%20 = icmp ne %struct.udev_device* %19, null
br i1 %20, label %21, label %50
21: ; preds = %18
%22 = load %struct.udev_device*, %struct.udev_device** %8
%23 = call i8* @udev_device_get_subsystem(%struct.udev_device* %22)
store i8* %23, i8** %9
%24 = load i8*, i8** %9
%25 = icmp ne i8* %24, null
br i1 %25, label %26, label %47
26: ; preds = %21
%27 = load i8*, i8** %9
%28 = load i8*, i8** %6
%29 = call i64 @strcmp(i8* %27, i8* %28)
%30 = icmp eq i64 %29, 0
br i1 %30, label %31, label %47
31: ; preds = %26
%32 = load i8*, i8** %7
%33 = icmp eq i8* %32, null
br i1 %33, label %34, label %35
34: ; preds = %31
br label %50
35: ; preds = %31
%36 = load %struct.udev_device*, %struct.udev_device** %8
%37 = call i8* @udev_device_get_devtype(%struct.udev_device* %36)
store i8* %37, i8** %10
%38 = load i8*, i8** %10
%39 = icmp ne i8* %38, null
br i1 %39, label %40, label %46
40: ; preds = %35
%41 = load i8*, i8** %10
%42 = load i8*, i8** %7
%43 = call i64 @strcmp(i8* %41, i8* %42)
%44 = icmp eq i64 %43, 0
br i1 %44, label %45, label %46
45: ; preds = %40
br label %50
46: ; preds = %40, %35
br label %47
47: ; preds = %46, %26, %21
%48 = load %struct.udev_device*, %struct.udev_device** %8
%49 = call %struct.udev_device* @udev_device_get_parent(%struct.udev_device* %48)
store %struct.udev_device* %49, %struct.udev_device** %8
br label %18
50: ; preds = %45, %34, %18
%51 = load %struct.udev_device*, %struct.udev_device** %8
%52 = icmp ne %struct.udev_device* %51, null
br i1 %52, label %55, label %53
53: ; preds = %50
%54 = load i32, i32* @ENOENT
store i32 %54, i32* @errno
br label %55
55: ; preds = %53, %50
%56 = load %struct.udev_device*, %struct.udev_device** %8
store %struct.udev_device* %56, %struct.udev_device** %4
br label %57
57: ; preds = %55, %13
%58 = load %struct.udev_device*, %struct.udev_device** %4
ret %struct.udev_device* %58
}

LLVM IR (-O2):
%struct.udev_device = type { i32 }
@EINVAL = global i32 0
@errno = global i32 0
@ENOENT = global i32 0
define %struct.udev_device* @udev_device_get_parent_with_subsystem_devtype(%struct.udev_device* %0, i8* %1, i8* %2) {
%4 = icmp eq i8* %1, null
br i1 %4, label %27, label %5
5: ; preds = %3
%6 = tail call %struct.udev_device* @udev_device_get_parent(%struct.udev_device* %0)
%7 = icmp eq %struct.udev_device* %6, null
br i1 %7, label %27, label %8
8: ; preds = %5
%9 = icmp eq i8* %2, null
br label %10
10: ; preds = %8, %24
%11 = phi %struct.udev_device* [ %6, %8 ], [ %25, %24 ]
%12 = tail call i8* @udev_device_get_subsystem(%struct.udev_device* %11)
%13 = icmp eq i8* %12, null
br i1 %13, label %24, label %14
14: ; preds = %10
%15 = tail call i64 @strcmp(i8* %12, i8* %1)
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %24
17: ; preds = %14
br i1 %9, label %30, label %18
18: ; preds = %17
%19 = tail call i8* @udev_device_get_devtype(%struct.udev_device* %11)
%20 = icmp eq i8* %19, null
br i1 %20, label %24, label %21
21: ; preds = %18
%22 = tail call i64 @strcmp(i8* %19, i8* %2)
%23 = icmp eq i64 %22, 0
br i1 %23, label %30, label %24
24: ; preds = %10, %14, %21, %18
%25 = tail call %struct.udev_device* @udev_device_get_parent(%struct.udev_device* %11)
%26 = icmp eq %struct.udev_device* %25, null
br i1 %26, label %27, label %10
27: ; preds = %24, %5, %3
%28 = phi i32* [ @EINVAL, %3 ], [ @ENOENT, %5 ], [ @ENOENT, %24 ]
%29 = load i32, i32* %28
store i32 %29, i32* @errno
br label %30
30: ; preds = %21, %17, %27
%31 = phi %struct.udev_device* [ null, %27 ], [ %11, %17 ], [ %11, %21 ]
ret %struct.udev_device* %31
}