#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*/ format_lun_number(struct udev_device *, char **);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ path_prepend(char **, char *, char const *, 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 *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;
  char *lun = NULL;
  ;
  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;
  }
  format_lun_number(parent, &lun);
  path_prepend(path, "fc-%s-%s", port, lun);
  if (lun)
    free(lun);
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   1050 <udev_device_get_udev@plt>
mov    %rax,-0x20(%rbp)
movq   $0x0,-0x30(%rbp)
movq   $0x0,-0x40(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe38(%rip),%rsi
lea    0xe36(%rip),%rdx
call   1070 <udev_device_get_parent_with_subsystem_devtype@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11f0 <handle_scsi_fibre_channel+0x60>
movq   $0x0,-0x8(%rbp)
jmp    12aa <handle_scsi_fibre_channel+0x11a>
mov    -0x20(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x28(%rbp),%rdi
call   10a0 <udev_device_get_sysname@plt>
mov    -0x48(%rbp),%rdi
mov    %eax,%edx
lea    0xe03(%rip),%rsi
call   1060 <udev_device_new_from_subsystem_sysname@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    122f <handle_scsi_fibre_channel+0x9f>
movq   $0x0,-0x8(%rbp)
jmp    12aa <handle_scsi_fibre_channel+0x11a>
mov    -0x30(%rbp),%rdi
lea    0xde4(%rip),%rsi
call   10b0 <udev_device_get_sysattr_value@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    125b <handle_scsi_fibre_channel+0xcb>
movq   $0x0,-0x10(%rbp)
jmp    1299 <handle_scsi_fibre_channel+0x109>
mov    -0x10(%rbp),%rdi
lea    -0x40(%rbp),%rsi
call   1080 <format_lun_number@plt>
mov    -0x18(%rbp),%rdi
mov    -0x38(%rbp),%rdx
mov    -0x40(%rbp),%rcx
lea    0xdad(%rip),%rsi
call   1030 <path_prepend@plt>
cmpq   $0x0,-0x40(%rbp)
je     1294 <handle_scsi_fibre_channel+0x104>
mov    -0x40(%rbp),%rdi
call   1040 <free@plt>
jmp    1299 <handle_scsi_fibre_channel+0x109>
mov    -0x30(%rbp),%rdi
call   1090 <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   1050 <udev_device_get_udev@plt>
mov    %rax,%r15
movq   $0x0,(%rsp)
lea    0xe4b(%rip),%rsi
lea    0xe49(%rip),%rdx
mov    %rbx,%rdi
call   1070 <udev_device_get_parent_with_subsystem_devtype@plt>
test   %rax,%rax
je     1232 <handle_scsi_fibre_channel+0xa2>
mov    %rax,%rdi
call   10a0 <udev_device_get_sysname@plt>
lea    0xe39(%rip),%rsi
mov    %r15,%rdi
mov    %eax,%edx
call   1060 <udev_device_new_from_subsystem_sysname@plt>
test   %rax,%rax
je     1232 <handle_scsi_fibre_channel+0xa2>
mov    %rax,%r15
lea    0xe2d(%rip),%rsi
mov    %rax,%rdi
call   10b0 <udev_device_get_sysattr_value@plt>
test   %rax,%rax
je     1236 <handle_scsi_fibre_channel+0xa6>
mov    %rax,%r12
mov    %rsp,%rsi
mov    %rbx,%rdi
call   1080 <format_lun_number@plt>
mov    (%rsp),%rcx
lea    0xe11(%rip),%rsi
mov    %r14,%rdi
mov    %r12,%rdx
call   1030 <path_prepend@plt>
mov    (%rsp),%rdi
test   %rdi,%rdi
je     1238 <handle_scsi_fibre_channel+0xa8>
call   1040 <free@plt>
jmp    1238 <handle_scsi_fibre_channel+0xa8>
xor    %ebx,%ebx
jmp    1240 <handle_scsi_fibre_channel+0xb0>
xor    %ebx,%ebx
mov    %r15,%rdi
call   1090 <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 = [9 x i8] c"fc-%s-%s\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 i8*
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
store i8* null, i8** %10
%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 %49
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 %49
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 %45
32: ; preds = %26
%33 = load %struct.udev_device*, %struct.udev_device** %4
%34 = call i32 @format_lun_number(%struct.udev_device* %33, i8** %10)
%35 = load i8**, i8*** %5
%36 = load i8*, i8** %9
%37 = load i8*, i8** %10
%38 = call i32 @path_prepend(i8** %35, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i8* %36, i8* %37)
%39 = load i8*, i8** %10
%40 = icmp ne i8* %39, null
br i1 %40, label %41, label %44
41: ; preds = %32
%42 = load i8*, i8** %10
%43 = call i32 @free(i8* %42)
br label %44
44: ; preds = %41, %32
br label %45
45: ; preds = %44, %31
%46 = load %struct.udev_device*, %struct.udev_device** %8
%47 = call i32 @udev_device_unref(%struct.udev_device* %46)
%48 = load %struct.udev_device*, %struct.udev_device** %4
store %struct.udev_device* %48, %struct.udev_device** %3
br label %49
49: ; preds = %45, %25, %17
%50 = load %struct.udev_device*, %struct.udev_device** %3
ret %struct.udev_device* %50
}

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 = [9 x i8] c"fc-%s-%s\00"
define %struct.udev_device* @handle_scsi_fibre_channel(%struct.udev_device* %0, i8** %1) {
%3 = alloca i8*
%4 = tail call %struct.udev* @udev_device_get_udev(%struct.udev_device* %0)
%5 = bitcast i8** %3 to i8*
store i8* null, i8** %3
%6 = 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))
%7 = icmp eq %struct.udev_device* %6, null
br i1 %7, label %26, label %8
8: ; preds = %2
%9 = tail call i32 @udev_device_get_sysname(%struct.udev_device* %6)
%10 = tail call %struct.udev_device* @udev_device_new_from_subsystem_sysname(%struct.udev* %4, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i32 %9)
%11 = icmp eq %struct.udev_device* %10, null
br i1 %11, label %26, label %12
12: ; preds = %8
%13 = tail call i8* @udev_device_get_sysattr_value(%struct.udev_device* %10, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
%14 = icmp eq i8* %13, null
br i1 %14, label %23, label %15
15: ; preds = %12
%16 = call i32 @format_lun_number(%struct.udev_device* %0, i8** %3)
%17 = load i8*, i8** %3
%18 = call i32 @path_prepend(i8** %1, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i8* %13, i8* %17)
%19 = load i8*, i8** %3
%20 = icmp eq i8* %19, null
br i1 %20, label %23, label %21
21: ; preds = %15
%22 = call i32 @free(i8* %19)
br label %23
23: ; preds = %12, %15, %21
%24 = phi %struct.udev_device* [ %0, %21 ], [ %0, %15 ], [ null, %12 ]
%25 = call i32 @udev_device_unref(%struct.udev_device* %10)
br label %26
26: ; preds = %8, %2, %23
%27 = phi %struct.udev_device* [ %24, %23 ], [ null, %2 ], [ null, %8 ]
ret %struct.udev_device* %27
}