#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 *);
struct udev_device *udev_device_get_parent(struct udev_device *);
char *udev_device_get_subsystem(struct udev_device *);
struct udev_device *skip_subsystem(struct udev_device *dev,
                                   const char *subsys) {
  struct udev_device *parent = dev;
  while (parent != NULL) {
    const char *subsystem;
    subsystem = udev_device_get_subsystem(parent);
    if (subsystem == NULL || strcmp(subsystem, subsys) != 0)
      break;
    dev = parent;
    parent = udev_device_get_parent(parent);
  }
  return dev;
}


x86 assembly (clang, -O0):
<skip_subsystem>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11a1 <skip_subsystem+0x71>
mov    -0x18(%rbp),%rdi
call   1030 <udev_device_get_subsystem@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1182 <skip_subsystem+0x52>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
je     1187 <skip_subsystem+0x57>
jmp    11a1 <skip_subsystem+0x71>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <udev_device_get_parent@plt>
mov    %rax,-0x18(%rbp)
jmp    1148 <skip_subsystem+0x18>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<skip_subsystem>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
test   %rdi,%rdi
je     1188 <skip_subsystem+0x58>
mov    %rsi,%r14
mov    %rdi,%r12
call   1030 <udev_device_get_subsystem@plt>
test   %rax,%rax
je     118c <skip_subsystem+0x5c>
mov    %r12,%r15
mov    %r15,%rbx
mov    %r12,%r15
mov    %rax,%rdi
mov    %r14,%rsi
call   1040 <strcmp@plt>
test   %rax,%rax
jne    1194 <skip_subsystem+0x64>
mov    %r15,%rdi
call   1050 <udev_device_get_parent@plt>
test   %rax,%rax
je     1191 <skip_subsystem+0x61>
mov    %rax,%r12
mov    %rax,%rdi
call   1030 <udev_device_get_subsystem@plt>
mov    %r15,%rbx
test   %rax,%rax
jne    1150 <skip_subsystem+0x20>
jmp    1194 <skip_subsystem+0x64>
xor    %ebx,%ebx
jmp    1194 <skip_subsystem+0x64>
mov    %r12,%rbx
jmp    1194 <skip_subsystem+0x64>
mov    %r15,%rbx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.udev_device = type { i32 }
define %struct.udev_device* @skip_subsystem(%struct.udev_device* %0, i8* %1) {
%3 = alloca %struct.udev_device*
%4 = alloca i8*
%5 = alloca %struct.udev_device*
%6 = alloca i8*
store %struct.udev_device* %0, %struct.udev_device** %3
store i8* %1, i8** %4
%7 = load %struct.udev_device*, %struct.udev_device** %3
store %struct.udev_device* %7, %struct.udev_device** %5
br label %8
8: ; preds = %22, %2
%9 = load %struct.udev_device*, %struct.udev_device** %5
%10 = icmp ne %struct.udev_device* %9, null
br i1 %10, label %11, label %26
11: ; preds = %8
%12 = load %struct.udev_device*, %struct.udev_device** %5
%13 = call i8* @udev_device_get_subsystem(%struct.udev_device* %12)
store i8* %13, i8** %6
%14 = load i8*, i8** %6
%15 = icmp eq i8* %14, null
br i1 %15, label %21, label %16
16: ; preds = %11
%17 = load i8*, i8** %6
%18 = load i8*, i8** %4
%19 = call i64 @strcmp(i8* %17, i8* %18)
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %22
21: ; preds = %16, %11
br label %26
22: ; preds = %16
%23 = load %struct.udev_device*, %struct.udev_device** %5
store %struct.udev_device* %23, %struct.udev_device** %3
%24 = load %struct.udev_device*, %struct.udev_device** %5
%25 = call %struct.udev_device* @udev_device_get_parent(%struct.udev_device* %24)
store %struct.udev_device* %25, %struct.udev_device** %5
br label %8
26: ; preds = %21, %8
%27 = load %struct.udev_device*, %struct.udev_device** %3
ret %struct.udev_device* %27
}

LLVM IR (-O2):
%struct.udev_device = type { i32 }
define %struct.udev_device* @skip_subsystem(%struct.udev_device* %0, i8* %1) {
%3 = icmp eq %struct.udev_device* %0, null
br i1 %3, label %19, label %4
4: ; preds = %2
%5 = tail call i8* @udev_device_get_subsystem(%struct.udev_device* %0)
%6 = icmp eq i8* %5, null
br i1 %6, label %19, label %10
7: ; preds = %16
%8 = tail call i8* @udev_device_get_subsystem(%struct.udev_device* %17)
%9 = icmp eq i8* %8, null
br i1 %9, label %19, label %10
10: ; preds = %4, %7
%11 = phi i8* [ %8, %7 ], [ %5, %4 ]
%12 = phi %struct.udev_device* [ %17, %7 ], [ %0, %4 ]
%13 = phi %struct.udev_device* [ %12, %7 ], [ %0, %4 ]
%14 = tail call i64 @strcmp(i8* %11, i8* %1)
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %10
%17 = tail call %struct.udev_device* @udev_device_get_parent(%struct.udev_device* %12)
%18 = icmp eq %struct.udev_device* %17, null
br i1 %18, label %19, label %7
19: ; preds = %7, %10, %16, %4, %2
%20 = phi %struct.udev_device* [ null, %2 ], [ %0, %4 ], [ %12, %16 ], [ %13, %10 ], [ %12, %7 ]
ret %struct.udev_device* %20
}