#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;
};
struct udev {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ path_prepend(char **, char *, char const *, unsigned int,
                                unsigned int);
unsigned int strtoul(int /*<<< orphan*/, int /*<<< orphan*/ *, int);
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 *);
int /*<<< orphan*/ udev_device_get_sysnum(struct udev_device *);
struct udev *udev_device_get_udev(struct udev_device *);
struct udev_device *udev_device_new_from_subsystem_sysname(struct udev *,
                                                           char *,
                                                           int /*<<< orphan*/);
int /*<<< orphan*/ udev_device_unref(struct udev_device *);
struct udev_device *handle_scsi_fibre_channel(struct udev_device *parent,
                                              char **path) {
  struct udev *udev = udev_device_get_udev(parent);
  struct udev_device *targetdev;
  struct udev_device *fcdev = NULL;
  const char *port;
  unsigned int lun;
  targetdev = udev_device_get_parent_with_subsystem_devtype(parent, "scsi",
                                                            "scsi_target");
  if (targetdev == NULL)
    return NULL;
  fcdev = udev_device_new_from_subsystem_sysname(
      udev, "fc_transport", udev_device_get_sysname(targetdev));
  if (fcdev == NULL)
    return NULL;
  port = udev_device_get_sysattr_value(fcdev, "port_name");
  if (port == NULL) {
    parent = NULL;
    goto out;
  }
  lun = strtoul(udev_device_get_sysnum(parent), NULL, 10);
  path_prepend(path, "fc-%s:0x%04x%04x00000000", port, lun & 0xffff,
               (lun >> 16) & 0xffff);
out:
  udev_device_unref(fcdev);
  return parent;
}


x86 assembly (clang, -O0):
<handle_scsi_fibre_channel>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <udev_device_get_udev@plt>
mov    %rax,-0x20(%rbp)
movq   $0x0,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe40(%rip),%rsi
lea    0xe3e(%rip),%rdx
call   1060 <udev_device_get_parent_with_subsystem_devtype@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11e8 <handle_scsi_fibre_channel+0x58>
movq   $0x0,-0x8(%rbp)
jmp    12ac <handle_scsi_fibre_channel+0x11c>
mov    -0x20(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x28(%rbp),%rdi
call   1090 <udev_device_get_sysname@plt>
mov    -0x48(%rbp),%rdi
mov    %eax,%edx
lea    0xe0b(%rip),%rsi
call   1050 <udev_device_new_from_subsystem_sysname@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1227 <handle_scsi_fibre_channel+0x97>
movq   $0x0,-0x8(%rbp)
jmp    12ac <handle_scsi_fibre_channel+0x11c>
mov    -0x30(%rbp),%rdi
lea    0xdec(%rip),%rsi
call   10b0 <udev_device_get_sysattr_value@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    1253 <handle_scsi_fibre_channel+0xc3>
movq   $0x0,-0x10(%rbp)
jmp    129b <handle_scsi_fibre_channel+0x10b>
mov    -0x10(%rbp),%rdi
call   1080 <udev_device_get_sysnum@plt>
mov    %eax,%edi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   10a0 <strtoul@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x38(%rbp),%rdx
mov    -0x3c(%rbp),%ecx
and    $0xffff,%ecx
mov    -0x3c(%rbp),%r8d
shr    $0x10,%r8d
and    $0xffff,%r8d
lea    0xd92(%rip),%rsi
call   1030 <path_prepend@plt>
mov    -0x30(%rbp),%rdi
call   1070 <udev_device_unref@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<handle_scsi_fibre_channel>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
call   1040 <udev_device_get_udev@plt>
mov    %rax,%r15
lea    0xe53(%rip),%rsi
lea    0xe51(%rip),%rdx
mov    %rbx,%rdi
call   1060 <udev_device_get_parent_with_subsystem_devtype@plt>
test   %rax,%rax
je     122c <handle_scsi_fibre_channel+0x9c>
mov    %rax,%rdi
call   1090 <udev_device_get_sysname@plt>
lea    0xe41(%rip),%rsi
mov    %r15,%rdi
mov    %eax,%edx
call   1050 <udev_device_new_from_subsystem_sysname@plt>
test   %rax,%rax
je     122c <handle_scsi_fibre_channel+0x9c>
mov    %rax,%r15
lea    0xe35(%rip),%rsi
mov    %rax,%rdi
call   10b0 <udev_device_get_sysattr_value@plt>
test   %rax,%rax
je     1230 <handle_scsi_fibre_channel+0xa0>
mov    %rax,%r12
mov    %rbx,%rdi
call   1080 <udev_device_get_sysnum@plt>
mov    %eax,%edi
xor    %esi,%esi
mov    $0xa,%edx
call   10a0 <strtoul@plt>
movzwl %ax,%ecx
shr    $0x10,%eax
lea    0xe0c(%rip),%rsi
mov    %r14,%rdi
mov    %r12,%rdx
mov    %eax,%r8d
call   1030 <path_prepend@plt>
jmp    1232 <handle_scsi_fibre_channel+0xa2>
xor    %ebx,%ebx
jmp    123a <handle_scsi_fibre_channel+0xaa>
xor    %ebx,%ebx
mov    %r15,%rdi
call   1070 <udev_device_unref@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.udev_device = type { i32 }
%struct.udev = type { i32 }
@.str = [5 x i8] c"scsi\00"
@.str.1 = [12 x i8] c"scsi_target\00"
@.str.2 = [13 x i8] c"fc_transport\00"
@.str.3 = [10 x i8] c"port_name\00"
@.str.4 = [25 x i8] c"fc-%s:0x%04x%04x00000000\00"
define %struct.udev_device* @handle_scsi_fibre_channel(%struct.udev_device* %0, i8** %1) {
%3 = alloca %struct.udev_device*
%4 = alloca %struct.udev_device*
%5 = alloca i8**
%6 = alloca %struct.udev*
%7 = alloca %struct.udev_device*
%8 = alloca %struct.udev_device*
%9 = alloca i8*
%10 = alloca i32
store %struct.udev_device* %0, %struct.udev_device** %4
store i8** %1, i8*** %5
%11 = load %struct.udev_device*, %struct.udev_device** %4
%12 = call %struct.udev* @udev_device_get_udev(%struct.udev_device* %11)
store %struct.udev* %12, %struct.udev** %6
store %struct.udev_device* null, %struct.udev_device** %8
%13 = load %struct.udev_device*, %struct.udev_device** %4
%14 = call %struct.udev_device* @udev_device_get_parent_with_subsystem_devtype(%struct.udev_device* %13, 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* %14, %struct.udev_device** %7
%15 = load %struct.udev_device*, %struct.udev_device** %7
%16 = icmp eq %struct.udev_device* %15, null
br i1 %16, label %17, label %18
17: ; preds = %2
store %struct.udev_device* null, %struct.udev_device** %3
br label %48
18: ; preds = %2
%19 = load %struct.udev*, %struct.udev** %6
%20 = load %struct.udev_device*, %struct.udev_device** %7
%21 = call i32 @udev_device_get_sysname(%struct.udev_device* %20)
%22 = call %struct.udev_device* @udev_device_new_from_subsystem_sysname(%struct.udev* %19, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i32 %21)
store %struct.udev_device* %22, %struct.udev_device** %8
%23 = load %struct.udev_device*, %struct.udev_device** %8
%24 = icmp eq %struct.udev_device* %23, null
br i1 %24, label %25, label %26
25: ; preds = %18
store %struct.udev_device* null, %struct.udev_device** %3
br label %48
26: ; preds = %18
%27 = load %struct.udev_device*, %struct.udev_device** %8
%28 = call i8* @udev_device_get_sysattr_value(%struct.udev_device* %27, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
store i8* %28, i8** %9
%29 = load i8*, i8** %9
%30 = icmp eq i8* %29, null
br i1 %30, label %31, label %32
31: ; preds = %26
store %struct.udev_device* null, %struct.udev_device** %4
br label %44
32: ; preds = %26
%33 = load %struct.udev_device*, %struct.udev_device** %4
%34 = call i32 @udev_device_get_sysnum(%struct.udev_device* %33)
%35 = call i32 @strtoul(i32 %34, i32* null, i32 10)
store i32 %35, i32* %10
%36 = load i8**, i8*** %5
%37 = load i8*, i8** %9
%38 = load i32, i32* %10
%39 = and i32 %38, 65535
%40 = load i32, i32* %10
%41 = lshr i32 %40, 16
%42 = and i32 %41, 65535
%43 = call i32 @path_prepend(i8** %36, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0), i8* %37, i32 %39, i32 %42)
br label %44
44: ; preds = %32, %31
%45 = load %struct.udev_device*, %struct.udev_device** %8
%46 = call i32 @udev_device_unref(%struct.udev_device* %45)
%47 = load %struct.udev_device*, %struct.udev_device** %4
store %struct.udev_device* %47, %struct.udev_device** %3
br label %48
48: ; preds = %44, %25, %17
%49 = load %struct.udev_device*, %struct.udev_device** %3
ret %struct.udev_device* %49
}

LLVM IR (-O2):
%struct.udev_device = type { i32 }
%struct.udev = type { i32 }
@.str = [5 x i8] c"scsi\00"
@.str.1 = [12 x i8] c"scsi_target\00"
@.str.2 = [13 x i8] c"fc_transport\00"
@.str.3 = [10 x i8] c"port_name\00"
@.str.4 = [25 x i8] c"fc-%s:0x%04x%04x00000000\00"
define %struct.udev_device* @handle_scsi_fibre_channel(%struct.udev_device* %0, i8** %1) {
%3 = tail call %struct.udev* @udev_device_get_udev(%struct.udev_device* %0)
%4 = tail call %struct.udev_device* @udev_device_get_parent_with_subsystem_devtype(%struct.udev_device* %0, 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 %22, label %6
6: ; preds = %2
%7 = tail call i32 @udev_device_get_sysname(%struct.udev_device* %4)
%8 = tail call %struct.udev_device* @udev_device_new_from_subsystem_sysname(%struct.udev* %3, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i32 %7)
%9 = icmp eq %struct.udev_device* %8, null
br i1 %9, label %22, label %10
10: ; preds = %6
%11 = tail call i8* @udev_device_get_sysattr_value(%struct.udev_device* %8, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
%12 = icmp eq i8* %11, null
br i1 %12, label %19, label %13
13: ; preds = %10
%14 = tail call i32 @udev_device_get_sysnum(%struct.udev_device* %0)
%15 = tail call i32 @strtoul(i32 %14, i32* null, i32 10)
%16 = and i32 %15, 65535
%17 = lshr i32 %15, 16
%18 = tail call i32 @path_prepend(i8** %1, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0), i8* %11, i32 %16, i32 %17)
br label %19
19: ; preds = %10, %13
%20 = phi %struct.udev_device* [ %0, %13 ], [ null, %10 ]
%21 = tail call i32 @udev_device_unref(%struct.udev_device* %8)
br label %22
22: ; preds = %6, %2, %19
%23 = phi %struct.udev_device* [ %20, %19 ], [ null, %2 ], [ null, %6 ]
ret %struct.udev_device* %23
}