#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 */
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)
    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);
  }
  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    116c <udev_device_get_parent_with_subsystem_devtype+0x2c>
movq   $0x0,-0x8(%rbp)
jmp    1216 <udev_device_get_parent_with_subsystem_devtype+0xd6>
mov    -0x10(%rbp),%rdi
call   1050 <udev_device_get_parent@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     120e <udev_device_get_parent_with_subsystem_devtype+0xce>
mov    -0x28(%rbp),%rdi
call   1030 <udev_device_get_subsystem@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     11fc <udev_device_get_parent_with_subsystem_devtype+0xbc>
mov    -0x30(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    11fc <udev_device_get_parent_with_subsystem_devtype+0xbc>
cmpq   $0x0,-0x20(%rbp)
jne    11c3 <udev_device_get_parent_with_subsystem_devtype+0x83>
jmp    120e <udev_device_get_parent_with_subsystem_devtype+0xce>
mov    -0x28(%rbp),%rdi
call   1060 <udev_device_get_devtype@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
je     11f7 <udev_device_get_parent_with_subsystem_devtype+0xb7>
mov    -0x38(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    11f7 <udev_device_get_parent_with_subsystem_devtype+0xb7>
jmp    120e <udev_device_get_parent_with_subsystem_devtype+0xce>
jmp    11fc <udev_device_get_parent_with_subsystem_devtype+0xbc>
mov    -0x28(%rbp),%rdi
call   1050 <udev_device_get_parent@plt>
mov    %rax,-0x28(%rbp)
jmp    1179 <udev_device_get_parent_with_subsystem_devtype+0x39>
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   %rbx
test   %rsi,%rsi
je     11b1 <udev_device_get_parent_with_subsystem_devtype+0x71>
mov    %rdx,%r14
mov    %rsi,%r15
call   1050 <udev_device_get_parent@plt>
test   %rax,%rax
je     11b1 <udev_device_get_parent_with_subsystem_devtype+0x71>
mov    %rax,%rbx
jmp    1170 <udev_device_get_parent_with_subsystem_devtype+0x30>
nop
mov    %rbx,%rdi
call   1050 <udev_device_get_parent@plt>
mov    %rax,%rbx
test   %rax,%rax
je     11b1 <udev_device_get_parent_with_subsystem_devtype+0x71>
mov    %rbx,%rdi
call   1030 <udev_device_get_subsystem@plt>
test   %rax,%rax
je     1160 <udev_device_get_parent_with_subsystem_devtype+0x20>
mov    %rax,%rdi
mov    %r15,%rsi
call   1040 <strcmp@plt>
test   %rax,%rax
jne    1160 <udev_device_get_parent_with_subsystem_devtype+0x20>
test   %r14,%r14
je     11b3 <udev_device_get_parent_with_subsystem_devtype+0x73>
mov    %rbx,%rdi
call   1060 <udev_device_get_devtype@plt>
test   %rax,%rax
je     1160 <udev_device_get_parent_with_subsystem_devtype+0x20>
mov    %rax,%rdi
mov    %r14,%rsi
call   1040 <strcmp@plt>
test   %rax,%rax
jne    1160 <udev_device_get_parent_with_subsystem_devtype+0x20>
jmp    11b3 <udev_device_get_parent_with_subsystem_devtype+0x73>
xor    %ebx,%ebx
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.udev_device = type { i32 }
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 %14
13: ; preds = %3
store %struct.udev_device* null, %struct.udev_device** %4
br label %51
14: ; preds = %3
%15 = load %struct.udev_device*, %struct.udev_device** %5
%16 = call %struct.udev_device* @udev_device_get_parent(%struct.udev_device* %15)
store %struct.udev_device* %16, %struct.udev_device** %8
br label %17
17: ; preds = %46, %14
%18 = load %struct.udev_device*, %struct.udev_device** %8
%19 = icmp ne %struct.udev_device* %18, null
br i1 %19, label %20, label %49
20: ; preds = %17
%21 = load %struct.udev_device*, %struct.udev_device** %8
%22 = call i8* @udev_device_get_subsystem(%struct.udev_device* %21)
store i8* %22, i8** %9
%23 = load i8*, i8** %9
%24 = icmp ne i8* %23, null
br i1 %24, label %25, label %46
25: ; preds = %20
%26 = load i8*, i8** %9
%27 = load i8*, i8** %6
%28 = call i64 @strcmp(i8* %26, i8* %27)
%29 = icmp eq i64 %28, 0
br i1 %29, label %30, label %46
30: ; preds = %25
%31 = load i8*, i8** %7
%32 = icmp eq i8* %31, null
br i1 %32, label %33, label %34
33: ; preds = %30
br label %49
34: ; preds = %30
%35 = load %struct.udev_device*, %struct.udev_device** %8
%36 = call i8* @udev_device_get_devtype(%struct.udev_device* %35)
store i8* %36, i8** %10
%37 = load i8*, i8** %10
%38 = icmp ne i8* %37, null
br i1 %38, label %39, label %45
39: ; preds = %34
%40 = load i8*, i8** %10
%41 = load i8*, i8** %7
%42 = call i64 @strcmp(i8* %40, i8* %41)
%43 = icmp eq i64 %42, 0
br i1 %43, label %44, label %45
44: ; preds = %39
br label %49
45: ; preds = %39, %34
br label %46
46: ; preds = %45, %25, %20
%47 = load %struct.udev_device*, %struct.udev_device** %8
%48 = call %struct.udev_device* @udev_device_get_parent(%struct.udev_device* %47)
store %struct.udev_device* %48, %struct.udev_device** %8
br label %17
49: ; preds = %44, %33, %17
%50 = load %struct.udev_device*, %struct.udev_device** %8
store %struct.udev_device* %50, %struct.udev_device** %4
br label %51
51: ; preds = %49, %13
%52 = load %struct.udev_device*, %struct.udev_device** %4
ret %struct.udev_device* %52
}

LLVM IR (-O2):
%struct.udev_device = type { i32 }
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 %27, 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 %27, 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, %17, %21, %5, %3
%28 = phi %struct.udev_device* [ null, %3 ], [ null, %5 ], [ null, %24 ], [ %11, %17 ], [ %11, %21 ]
ret %struct.udev_device* %28
}