#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 *);
struct udev_device *
udev_device_get_parent_with_subsystem_devtype(struct udev_device *, char *,
                                              char *);
char *udev_device_get_sysattr_value(struct udev_device *, char *);
int /*<<< orphan*/ udev_device_get_sysname(struct udev_device *);
struct udev_device *handle_ccw(struct udev_device *parent,
                               struct udev_device *dev, char **path) {
  struct udev_device *scsi_dev;
  scsi_dev =
      udev_device_get_parent_with_subsystem_devtype(dev, "scsi", "scsi_device");
  if (scsi_dev != NULL) {
    const char *wwpn;
    const char *lun;
    const char *hba_id;
    hba_id = udev_device_get_sysattr_value(scsi_dev, "hba_id");
    wwpn = udev_device_get_sysattr_value(scsi_dev, "wwpn");
    lun = udev_device_get_sysattr_value(scsi_dev, "fcp_lun");
    if (hba_id != NULL && lun != NULL && wwpn != NULL) {
      path_prepend(path, "ccw-%s-zfcp-%s:%s", hba_id, wwpn, lun);
      goto out;
    }
  }
  path_prepend(path, "ccw-%s", udev_device_get_sysname(parent));
out:
  parent = skip_subsystem(parent, "ccw");
  return parent;
}


x86 assembly (clang, -O0):
<handle_ccw>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe91(%rip),%rsi
lea    0xe8f(%rip),%rdx
call   1050 <udev_device_get_parent_with_subsystem_devtype@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     120f <handle_ccw+0xbf>
mov    -0x20(%rbp),%rdi
lea    0xe7c(%rip),%rsi
call   1070 <udev_device_get_sysattr_value@plt>
mov    %rax,-0x38(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xe6f(%rip),%rsi
call   1070 <udev_device_get_sysattr_value@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xe60(%rip),%rsi
call   1070 <udev_device_get_sysattr_value@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x38(%rbp)
je     120a <handle_ccw+0xba>
cmpq   $0x0,-0x30(%rbp)
je     120a <handle_ccw+0xba>
cmpq   $0x0,-0x28(%rbp)
je     120a <handle_ccw+0xba>
mov    -0x18(%rbp),%rdi
mov    -0x38(%rbp),%rdx
mov    -0x28(%rbp),%rcx
mov    -0x30(%rbp),%r8
lea    0xe27(%rip),%rsi
mov    $0x0,%al
call   1030 <path_prepend@plt>
jmp    1235 <handle_ccw+0xe5>
jmp    120f <handle_ccw+0xbf>
mov    -0x18(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <udev_device_get_sysname@plt>
mov    -0x40(%rbp),%rdi
movslq %eax,%rdx
lea    0xe09(%rip),%rsi
mov    $0x0,%al
call   1030 <path_prepend@plt>
mov    -0x8(%rbp),%rdi
lea    0xdfe(%rip),%rsi
call   1040 <skip_subsystem@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<handle_ccw>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdx,%r14
mov    %rsi,%rax
mov    %rdi,%r15
lea    0xe97(%rip),%rsi
lea    0xe95(%rip),%rdx
mov    %rax,%rdi
call   1050 <udev_device_get_parent_with_subsystem_devtype@plt>
test   %rax,%rax
je     11de <handle_ccw+0x8e>
mov    %rax,%rbx
lea    0xe8a(%rip),%rsi
mov    %rax,%rdi
call   1070 <udev_device_get_sysattr_value@plt>
mov    %rax,%r13
lea    0xe7f(%rip),%rsi
mov    %rbx,%rdi
call   1070 <udev_device_get_sysattr_value@plt>
mov    %rax,%r12
lea    0xe72(%rip),%rsi
mov    %rbx,%rdi
call   1070 <udev_device_get_sysattr_value@plt>
test   %r13,%r13
je     11de <handle_ccw+0x8e>
test   %rax,%rax
je     11de <handle_ccw+0x8e>
test   %r12,%r12
je     11de <handle_ccw+0x8e>
lea    0xe5c(%rip),%rsi
mov    %r14,%rdi
mov    %r13,%rdx
mov    %r12,%rcx
mov    %rax,%r8
xor    %eax,%eax
call   1030 <path_prepend@plt>
jmp    11fa <handle_ccw+0xaa>
mov    %r15,%rdi
call   1060 <udev_device_get_sysname@plt>
movslq %eax,%rdx
lea    0xe47(%rip),%rsi
mov    %r14,%rdi
xor    %eax,%eax
call   1030 <path_prepend@plt>
lea    0xe3d(%rip),%rsi
mov    %r15,%rdi
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
jmp    1040 <skip_subsystem@plt>

LLVM IR (-O0):
%struct.udev_device = type { i32 }
@.str = [5 x i8] c"scsi\00"
@.str.1 = [12 x i8] c"scsi_device\00"
@.str.2 = [7 x i8] c"hba_id\00"
@.str.3 = [5 x i8] c"wwpn\00"
@.str.4 = [8 x i8] c"fcp_lun\00"
@.str.5 = [18 x i8] c"ccw-%s-zfcp-%s:%s\00"
@.str.6 = [7 x i8] c"ccw-%s\00"
@.str.7 = [4 x i8] c"ccw\00"
define %struct.udev_device* @handle_ccw(%struct.udev_device* %0, %struct.udev_device* %1, i8** %2) {
%4 = alloca %struct.udev_device*
%5 = alloca %struct.udev_device*
%6 = alloca i8**
%7 = alloca %struct.udev_device*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
store %struct.udev_device* %0, %struct.udev_device** %4
store %struct.udev_device* %1, %struct.udev_device** %5
store i8** %2, i8*** %6
%11 = load %struct.udev_device*, %struct.udev_device** %5
%12 = call %struct.udev_device* @udev_device_get_parent_with_subsystem_devtype(%struct.udev_device* %11, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
store %struct.udev_device* %12, %struct.udev_device** %7
%13 = load %struct.udev_device*, %struct.udev_device** %7
%14 = icmp ne %struct.udev_device* %13, null
br i1 %14, label %15, label %37
15: ; preds = %3
%16 = load %struct.udev_device*, %struct.udev_device** %7
%17 = call i8* @udev_device_get_sysattr_value(%struct.udev_device* %16, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
store i8* %17, i8** %10
%18 = load %struct.udev_device*, %struct.udev_device** %7
%19 = call i8* @udev_device_get_sysattr_value(%struct.udev_device* %18, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
store i8* %19, i8** %8
%20 = load %struct.udev_device*, %struct.udev_device** %7
%21 = call i8* @udev_device_get_sysattr_value(%struct.udev_device* %20, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
store i8* %21, i8** %9
%22 = load i8*, i8** %10
%23 = icmp ne i8* %22, null
br i1 %23, label %24, label %36
24: ; preds = %15
%25 = load i8*, i8** %9
%26 = icmp ne i8* %25, null
br i1 %26, label %27, label %36
27: ; preds = %24
%28 = load i8*, i8** %8
%29 = icmp ne i8* %28, null
br i1 %29, label %30, label %36
30: ; preds = %27
%31 = load i8**, i8*** %6
%32 = load i8*, i8** %10
%33 = load i8*, i8** %8
%34 = load i8*, i8** %9
%35 = call i32 (i8**, i8*, i8*, ...) @path_prepend(i8** %31, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0), i8* %32, i8* %33, i8* %34)
br label %44
36: ; preds = %27, %24, %15
br label %37
37: ; preds = %36, %3
%38 = load i8**, i8*** %6
%39 = load %struct.udev_device*, %struct.udev_device** %4
%40 = call i32 @udev_device_get_sysname(%struct.udev_device* %39)
%41 = sext i32 %40 to i64
%42 = inttoptr i64 %41 to i8*
%43 = call i32 (i8**, i8*, i8*, ...) @path_prepend(i8** %38, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0), i8* %42)
br label %44
44: ; preds = %37, %30
%45 = load %struct.udev_device*, %struct.udev_device** %4
%46 = call %struct.udev_device* @skip_subsystem(%struct.udev_device* %45, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0))
store %struct.udev_device* %46, %struct.udev_device** %4
%47 = load %struct.udev_device*, %struct.udev_device** %4
ret %struct.udev_device* %47
}

LLVM IR (-O2):
%struct.udev_device = type { i32 }
@.str = [5 x i8] c"scsi\00"
@.str.1 = [12 x i8] c"scsi_device\00"
@.str.2 = [7 x i8] c"hba_id\00"
@.str.3 = [5 x i8] c"wwpn\00"
@.str.4 = [8 x i8] c"fcp_lun\00"
@.str.5 = [18 x i8] c"ccw-%s-zfcp-%s:%s\00"
@.str.6 = [7 x i8] c"ccw-%s\00"
@.str.7 = [4 x i8] c"ccw\00"
define %struct.udev_device* @handle_ccw(%struct.udev_device* %0, %struct.udev_device* %1, i8** %2) {
%4 = tail call %struct.udev_device* @udev_device_get_parent_with_subsystem_devtype(%struct.udev_device* %1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
%5 = icmp eq %struct.udev_device* %4, null
br i1 %5, label %17, label %6
6: ; preds = %3
%7 = tail call i8* @udev_device_get_sysattr_value(%struct.udev_device* %4, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%8 = tail call i8* @udev_device_get_sysattr_value(%struct.udev_device* %4, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%9 = tail call i8* @udev_device_get_sysattr_value(%struct.udev_device* %4, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
%10 = icmp ne i8* %7, null
%11 = icmp ne i8* %9, null
%12 = select i1 %10, i1 %11, i1 false
%13 = icmp ne i8* %8, null
%14 = select i1 %12, i1 %13, i1 false
br i1 %14, label %15, label %17
15: ; preds = %6
%16 = tail call i32 (i8**, i8*, i8*, ...) @path_prepend(i8** %2, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0), i8* %7, i8* %8, i8* %9)
br label %22
17: ; preds = %6, %3
%18 = tail call i32 @udev_device_get_sysname(%struct.udev_device* %0)
%19 = sext i32 %18 to i64
%20 = inttoptr i64 %19 to i8*
%21 = tail call i32 (i8**, i8*, i8*, ...) @path_prepend(i8** %2, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0), i8* %20)
br label %22
22: ; preds = %15, %17
%23 = tail call %struct.udev_device* @skip_subsystem(%struct.udev_device* %0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0))
ret %struct.udev_device* %23
}