#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 */

/* Variables and functions */
int ENOMEM;
int asprintf(char **, char *, char *);
int /*<<< orphan*/ format_lun_number(char const *, char **);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ path_prepend(char **, char *, char *, char *, char *,
                                char *);
char *strdup(char const *);
int /*<<< orphan*/ strlen(char *);
scalar_t__ strncmp(char *, char *, int /*<<< orphan*/);
int vdev_sysfs_device_path_from_subsystem_sysname(char *, char *, char *,
                                                  char **, size_t *);
int vdev_sysfs_get_parent_device(char *, char **, size_t *);
int vdev_sysfs_get_sysname(char *, char **, size_t *);
int vdev_sysfs_read_attr(char *, char *, char **, size_t *);
int handle_scsi_iscsi(char const *parent, char **path, char **new_parent) {
  char *transportdev = NULL;
  char *transportdev_sysname = NULL;
  size_t transportdev_sysname_len = 0;
  char *sessiondev = NULL;
  size_t sessiondev_len = 0;
  char *target = NULL;
  size_t target_len = 0;
  char *connname = NULL;
  char *conndev = NULL;
  size_t conndev_len = 0;
  char *addr = NULL;
  size_t addr_len = 0;
  char *port = NULL;
  size_t port_len = 0;
  char *lun = NULL;
  int rc = 0;
  transportdev = (char *)parent;
  while (1) {
    char *transport_parent = NULL;
    size_t transport_parent_len = 0;
    rc = vdev_sysfs_get_parent_device(transportdev, &transport_parent,
                                      &transport_parent_len);
    if (rc != 0) {
      return rc;
    }
    transportdev = transport_parent;
    if (strncmp(transportdev, "session", strlen("session")) == 0) {
      break;
    }
    free(transportdev);
  }
  rc = vdev_sysfs_get_sysname(transportdev, &transportdev_sysname,
                              &transportdev_sysname_len);
  if (rc != 0) {
    free(transportdev);
    return rc;
  }
  free(transportdev);
  rc = vdev_sysfs_device_path_from_subsystem_sysname(
      "/sys", "iscsi_session", transportdev_sysname, &sessiondev,
      &sessiondev_len);
  if (rc != 0) {
    free(transportdev_sysname);
    return rc;
  }
  rc = vdev_sysfs_read_attr(sessiondev, "targetname", &target, &target_len);
  free(sessiondev);
  if (rc != 0) {
    free(transportdev_sysname);
    return rc;
  }
  rc = asprintf(&connname, "connection%s:0", transportdev_sysname);
  free(transportdev_sysname);
  if (rc < 0) {
    free(target);
    free(connname);
    return rc;
  }
  rc = vdev_sysfs_device_path_from_subsystem_sysname(
      "/sys", "iscsi_connection", connname, &conndev, &conndev_len);
  free(connname);
  if (rc != 0) {
    free(target);
    return rc;
  }
  rc = vdev_sysfs_read_attr(conndev, "persistent_address", &addr, &addr_len);
  if (rc != 0) {
    free(target);
    return rc;
  }
  rc = vdev_sysfs_read_attr(conndev, "persistent_port", &port, &port_len);
  if (rc != 0) {
    free(addr);
    free(target);
    return rc;
  }
  format_lun_number(parent, &lun);
  path_prepend(path, "ip-%s:%s-iscsi-%s-%s", addr, port, target, lun);
  if (lun != NULL) {
    free(lun);
  }
  free(port);
  free(target);
  free(addr);
  *new_parent = strdup(parent);
  if (*new_parent == NULL) {
    return -ENOMEM;
  }
  return 0;
}


x86 assembly (clang, -O0):
<handle_scsi_iscsi>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
movq   $0x0,-0x40(%rbp)
movq   $0x0,-0x48(%rbp)
movq   $0x0,-0x50(%rbp)
movq   $0x0,-0x58(%rbp)
movq   $0x0,-0x60(%rbp)
movq   $0x0,-0x68(%rbp)
movq   $0x0,-0x70(%rbp)
movq   $0x0,-0x78(%rbp)
movq   $0x0,-0x80(%rbp)
movq   $0x0,-0x88(%rbp)
movq   $0x0,-0x90(%rbp)
movq   $0x0,-0x98(%rbp)
movl   $0x0,-0x9c(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
movq   $0x0,-0xa8(%rbp)
movq   $0x0,-0xb0(%rbp)
mov    -0x28(%rbp),%rdi
lea    -0xa8(%rbp),%rsi
lea    -0xb0(%rbp),%rdx
call   10b0 <vdev_sysfs_get_parent_device@plt>
mov    %eax,-0x9c(%rbp)
cmpl   $0x0,-0x9c(%rbp)
je     12a8 <handle_scsi_iscsi+0xf8>
mov    -0x9c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    15b2 <handle_scsi_iscsi+0x402>
mov    -0xa8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0xb8(%rbp)
lea    0xd46(%rip),%rdi
call   1060 <strlen@plt>
mov    -0xb8(%rbp),%rdi
mov    %eax,%edx
lea    0xd31(%rip),%rsi
call   1050 <strncmp@plt>
cmp    $0x0,%rax
jne    12ee <handle_scsi_iscsi+0x13e>
jmp    12fc <handle_scsi_iscsi+0x14c>
mov    -0x28(%rbp),%rdi
call   1040 <free@plt>
jmp    125a <handle_scsi_iscsi+0xaa>
mov    -0x28(%rbp),%rdi
lea    -0x30(%rbp),%rsi
lea    -0x38(%rbp),%rdx
call   1080 <vdev_sysfs_get_sysname@plt>
mov    %eax,-0x9c(%rbp)
cmpl   $0x0,-0x9c(%rbp)
je     1337 <handle_scsi_iscsi+0x187>
mov    -0x28(%rbp),%rdi
call   1040 <free@plt>
mov    -0x9c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    15b2 <handle_scsi_iscsi+0x402>
mov    -0x28(%rbp),%rdi
call   1040 <free@plt>
mov    -0x30(%rbp),%rdx
lea    0xcb5(%rip),%rdi
lea    0xcb3(%rip),%rsi
lea    -0x40(%rbp),%rcx
lea    -0x48(%rbp),%r8
call   10d0 <vdev_sysfs_device_path_from_subsystem_sysname@plt>
mov    %eax,-0x9c(%rbp)
cmpl   $0x0,-0x9c(%rbp)
je     1389 <handle_scsi_iscsi+0x1d9>
mov    -0x30(%rbp),%rdi
call   1040 <free@plt>
mov    -0x9c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    15b2 <handle_scsi_iscsi+0x402>
mov    -0x40(%rbp),%rdi
lea    0xc7f(%rip),%rsi
lea    -0x50(%rbp),%rdx
lea    -0x58(%rbp),%rcx
call   1070 <vdev_sysfs_read_attr@plt>
mov    %eax,-0x9c(%rbp)
mov    -0x40(%rbp),%rdi
call   1040 <free@plt>
cmpl   $0x0,-0x9c(%rbp)
je     13d4 <handle_scsi_iscsi+0x224>
mov    -0x30(%rbp),%rdi
call   1040 <free@plt>
mov    -0x9c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    15b2 <handle_scsi_iscsi+0x402>
mov    -0x30(%rbp),%rdx
lea    -0x60(%rbp),%rdi
lea    0xc3b(%rip),%rsi
call   10a0 <asprintf@plt>
mov    %eax,-0x9c(%rbp)
mov    -0x30(%rbp),%rdi
call   1040 <free@plt>
cmpl   $0x0,-0x9c(%rbp)
jge    1424 <handle_scsi_iscsi+0x274>
mov    -0x50(%rbp),%rdi
call   1040 <free@plt>
mov    -0x60(%rbp),%rdi
call   1040 <free@plt>
mov    -0x9c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    15b2 <handle_scsi_iscsi+0x402>
mov    -0x60(%rbp),%rdx
lea    0xbd1(%rip),%rdi
lea    0xbf7(%rip),%rsi
lea    -0x68(%rbp),%rcx
lea    -0x70(%rbp),%r8
call   10d0 <vdev_sysfs_device_path_from_subsystem_sysname@plt>
mov    %eax,-0x9c(%rbp)
mov    -0x60(%rbp),%rdi
call   1040 <free@plt>
cmpl   $0x0,-0x9c(%rbp)
je     1476 <handle_scsi_iscsi+0x2c6>
mov    -0x50(%rbp),%rdi
call   1040 <free@plt>
mov    -0x9c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    15b2 <handle_scsi_iscsi+0x402>
mov    -0x68(%rbp),%rdi
lea    0xbbd(%rip),%rsi
lea    -0x78(%rbp),%rdx
lea    -0x80(%rbp),%rcx
call   1070 <vdev_sysfs_read_attr@plt>
mov    %eax,-0x9c(%rbp)
cmpl   $0x0,-0x9c(%rbp)
je     14b8 <handle_scsi_iscsi+0x308>
mov    -0x50(%rbp),%rdi
call   1040 <free@plt>
mov    -0x9c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    15b2 <handle_scsi_iscsi+0x402>
mov    -0x68(%rbp),%rdi
lea    0xb8e(%rip),%rsi
lea    -0x88(%rbp),%rdx
lea    -0x90(%rbp),%rcx
call   1070 <vdev_sysfs_read_attr@plt>
mov    %eax,-0x9c(%rbp)
cmpl   $0x0,-0x9c(%rbp)
je     1509 <handle_scsi_iscsi+0x359>
mov    -0x78(%rbp),%rdi
call   1040 <free@plt>
mov    -0x50(%rbp),%rdi
call   1040 <free@plt>
mov    -0x9c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    15b2 <handle_scsi_iscsi+0x402>
mov    -0x10(%rbp),%rdi
lea    -0x98(%rbp),%rsi
call   1090 <format_lun_number@plt>
mov    -0x18(%rbp),%rdi
mov    -0x78(%rbp),%rdx
mov    -0x88(%rbp),%rcx
mov    -0x50(%rbp),%r8
mov    -0x98(%rbp),%r9
lea    0xb27(%rip),%rsi
call   1030 <path_prepend@plt>
cmpq   $0x0,-0x98(%rbp)
je     1559 <handle_scsi_iscsi+0x3a9>
mov    -0x98(%rbp),%rdi
call   1040 <free@plt>
mov    -0x88(%rbp),%rdi
call   1040 <free@plt>
mov    -0x50(%rbp),%rdi
call   1040 <free@plt>
mov    -0x78(%rbp),%rdi
call   1040 <free@plt>
mov    -0x10(%rbp),%rdi
call   10c0 <strdup@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x20(%rbp),%rax
cmpq   $0x0,(%rax)
jne    15ab <handle_scsi_iscsi+0x3fb>
xor    %eax,%eax
mov    0x2a3f(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    15b2 <handle_scsi_iscsi+0x402>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<handle_scsi_iscsi>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x98,%rsp
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %rdi,%r12
movq   $0x0,0x10(%rsp)
movq   $0x0,0x90(%rsp)
movq   $0x0,0x50(%rsp)
movq   $0x0,0x88(%rsp)
movq   $0x0,0x8(%rsp)
movq   $0x0,0x80(%rsp)
movq   $0x0,0x28(%rsp)
movq   $0x0,0x48(%rsp)
movq   $0x0,0x78(%rsp)
movq   $0x0,0x20(%rsp)
movq   $0x0,0x70(%rsp)
movq   $0x0,0x40(%rsp)
movq   $0x0,0x68(%rsp)
movq   $0x0,0x38(%rsp)
movq   $0x0,0x18(%rsp)
movq   $0x0,0x30(%rsp)
lea    0x18(%rsp),%rsi
lea    0x30(%rsp),%rdx
call   10b0 <vdev_sysfs_get_parent_device@plt>
mov    %eax,%ebp
test   %eax,%eax
jne    1445 <handle_scsi_iscsi+0x295>
mov    %rbx,0x58(%rsp)
mov    %r14,0x60(%rsp)
lea    0xd7e(%rip),%r13
lea    0x18(%rsp),%r14
lea    0x30(%rsp),%r15
nopw   0x0(%rax,%rax,1)
mov    0x18(%rsp),%rbx
mov    %r13,%rdi
call   1060 <strlen@plt>
mov    %rbx,%rdi
mov    %r13,%rsi
mov    %eax,%edx
call   1050 <strncmp@plt>
test   %rax,%rax
je     12f2 <handle_scsi_iscsi+0x142>
mov    %rbx,%rdi
call   1040 <free@plt>
movq   $0x0,0x18(%rsp)
movq   $0x0,0x30(%rsp)
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   10b0 <vdev_sysfs_get_parent_device@plt>
test   %eax,%eax
je     12a0 <handle_scsi_iscsi+0xf0>
mov    %eax,%ebp
jmp    1445 <handle_scsi_iscsi+0x295>
lea    0x10(%rsp),%rsi
lea    0x90(%rsp),%rdx
mov    %rbx,%rdi
call   1080 <vdev_sysfs_get_sysname@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1040 <free@plt>
test   %ebp,%ebp
jne    1445 <handle_scsi_iscsi+0x295>
mov    0x10(%rsp),%rdx
lea    0xcdb(%rip),%rdi
lea    0xcd9(%rip),%rsi
lea    0x50(%rsp),%rcx
lea    0x88(%rsp),%r8
call   10d0 <vdev_sysfs_device_path_from_subsystem_sysname@plt>
test   %eax,%eax
je     134e <handle_scsi_iscsi+0x19e>
mov    %eax,%ebp
mov    0x10(%rsp),%rdi
jmp    1440 <handle_scsi_iscsi+0x290>
mov    0x50(%rsp),%rdi
lea    0xcb9(%rip),%rsi
lea    0x8(%rsp),%rdx
lea    0x80(%rsp),%rcx
call   1070 <vdev_sysfs_read_attr@plt>
mov    %eax,%ebp
mov    0x50(%rsp),%rdi
call   1040 <free@plt>
mov    0x10(%rsp),%rdx
test   %ebp,%ebp
je     1389 <handle_scsi_iscsi+0x1d9>
mov    %rdx,%rdi
jmp    1440 <handle_scsi_iscsi+0x290>
lea    0xc8e(%rip),%rsi
lea    0x28(%rsp),%rdi
call   10a0 <asprintf@plt>
mov    %eax,%ebp
mov    0x10(%rsp),%rdi
call   1040 <free@plt>
test   %ebp,%ebp
js     13ff <handle_scsi_iscsi+0x24f>
mov    0x28(%rsp),%rdx
lea    0xc4a(%rip),%rdi
lea    0xc70(%rip),%rsi
lea    0x48(%rsp),%rcx
lea    0x78(%rsp),%r8
call   10d0 <vdev_sysfs_device_path_from_subsystem_sysname@plt>
mov    %eax,%ebp
mov    0x28(%rsp),%rdi
call   1040 <free@plt>
test   %ebp,%ebp
jne    143b <handle_scsi_iscsi+0x28b>
mov    0x48(%rsp),%rdi
lea    0xc56(%rip),%rsi
lea    0x20(%rsp),%rdx
lea    0x70(%rsp),%rcx
call   1070 <vdev_sysfs_read_attr@plt>
test   %eax,%eax
je     1410 <handle_scsi_iscsi+0x260>
mov    %eax,%ebp
jmp    143b <handle_scsi_iscsi+0x28b>
mov    0x8(%rsp),%rdi
call   1040 <free@plt>
mov    0x28(%rsp),%rdi
jmp    1440 <handle_scsi_iscsi+0x290>
mov    0x48(%rsp),%rdi
lea    0xc35(%rip),%rsi
lea    0x40(%rsp),%rdx
lea    0x68(%rsp),%rcx
call   1070 <vdev_sysfs_read_attr@plt>
test   %eax,%eax
je     1459 <handle_scsi_iscsi+0x2a9>
mov    %eax,%ebp
mov    0x20(%rsp),%rdi
call   1040 <free@plt>
mov    0x8(%rsp),%rdi
call   1040 <free@plt>
mov    %ebp,%eax
add    $0x98,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0x38(%rsp),%rsi
mov    %r12,%rdi
call   1090 <format_lun_number@plt>
mov    0x20(%rsp),%rdx
mov    0x40(%rsp),%rcx
mov    0x8(%rsp),%r8
mov    0x38(%rsp),%r9
lea    0xbe0(%rip),%rsi
mov    0x58(%rsp),%rdi
call   1030 <path_prepend@plt>
mov    0x38(%rsp),%rdi
test   %rdi,%rdi
je     149a <handle_scsi_iscsi+0x2ea>
call   1040 <free@plt>
mov    0x40(%rsp),%rdi
call   1040 <free@plt>
mov    0x8(%rsp),%rdi
call   1040 <free@plt>
mov    0x20(%rsp),%rdi
call   1040 <free@plt>
mov    %r12,%rdi
call   10c0 <strdup@plt>
mov    0x60(%rsp),%rcx
mov    %rax,(%rcx)
xor    %ebp,%ebp
test   %rax,%rax
jne    1445 <handle_scsi_iscsi+0x295>
mov    0x2b06(%rip),%rax
xor    %ebp,%ebp
sub    (%rax),%ebp
jmp    1445 <handle_scsi_iscsi+0x295>

LLVM IR (-O0):
@.str = [8 x i8] c"session\00"
@.str.1 = [5 x i8] c"/sys\00"
@.str.2 = [14 x i8] c"iscsi_session\00"
@.str.3 = [11 x i8] c"targetname\00"
@.str.4 = [15 x i8] c"connection%s:0\00"
@.str.5 = [17 x i8] c"iscsi_connection\00"
@.str.6 = [19 x i8] c"persistent_address\00"
@.str.7 = [16 x i8] c"persistent_port\00"
@.str.8 = [21 x i8] c"ip-%s:%s-iscsi-%s-%s\00"
@ENOMEM = global i32 0
define i32 @handle_scsi_iscsi(i8* %0, i8** %1, i8** %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8**
%7 = alloca i8**
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i64
%11 = alloca i8*
%12 = alloca i64
%13 = alloca i8*
%14 = alloca i64
%15 = alloca i8*
%16 = alloca i8*
%17 = alloca i64
%18 = alloca i8*
%19 = alloca i64
%20 = alloca i8*
%21 = alloca i64
%22 = alloca i8*
%23 = alloca i32
%24 = alloca i8*
%25 = alloca i64
store i8* %0, i8** %5
store i8** %1, i8*** %6
store i8** %2, i8*** %7
store i8* null, i8** %8
store i8* null, i8** %9
store i64 0, i64* %10
store i8* null, i8** %11
store i64 0, i64* %12
store i8* null, i8** %13
store i64 0, i64* %14
store i8* null, i8** %15
store i8* null, i8** %16
store i64 0, i64* %17
store i8* null, i8** %18
store i64 0, i64* %19
store i8* null, i8** %20
store i64 0, i64* %21
store i8* null, i8** %22
store i32 0, i32* %23
%26 = load i8*, i8** %5
store i8* %26, i8** %8
br label %27
27: ; preds = %3, %41
store i8* null, i8** %24
store i64 0, i64* %25
%28 = load i8*, i8** %8
%29 = call i32 @vdev_sysfs_get_parent_device(i8* %28, i8** %24, i64* %25)
store i32 %29, i32* %23
%30 = load i32, i32* %23
%31 = icmp ne i32 %30, 0
br i1 %31, label %32, label %34
32: ; preds = %27
%33 = load i32, i32* %23
store i32 %33, i32* %4
br label %150
34: ; preds = %27
%35 = load i8*, i8** %24
store i8* %35, i8** %8
%36 = load i8*, i8** %8
%37 = call i32 @strlen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%38 = call i64 @strncmp(i8* %36, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %37)
%39 = icmp eq i64 %38, 0
br i1 %39, label %40, label %41
40: ; preds = %34
br label %44
41: ; preds = %34
%42 = load i8*, i8** %8
%43 = call i32 @free(i8* %42)
br label %27
44: ; preds = %40
%45 = load i8*, i8** %8
%46 = call i32 @vdev_sysfs_get_sysname(i8* %45, i8** %9, i64* %10)
store i32 %46, i32* %23
%47 = load i32, i32* %23
%48 = icmp ne i32 %47, 0
br i1 %48, label %49, label %53
49: ; preds = %44
%50 = load i8*, i8** %8
%51 = call i32 @free(i8* %50)
%52 = load i32, i32* %23
store i32 %52, i32* %4
br label %150
53: ; preds = %44
%54 = load i8*, i8** %8
%55 = call i32 @free(i8* %54)
%56 = load i8*, i8** %9
%57 = call i32 @vdev_sysfs_device_path_from_subsystem_sysname(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i8* %56, i8** %11, i64* %12)
store i32 %57, i32* %23
%58 = load i32, i32* %23
%59 = icmp ne i32 %58, 0
br i1 %59, label %60, label %64
60: ; preds = %53
%61 = load i8*, i8** %9
%62 = call i32 @free(i8* %61)
%63 = load i32, i32* %23
store i32 %63, i32* %4
br label %150
64: ; preds = %53
%65 = load i8*, i8** %11
%66 = call i32 @vdev_sysfs_read_attr(i8* %65, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i8** %13, i64* %14)
store i32 %66, i32* %23
%67 = load i8*, i8** %11
%68 = call i32 @free(i8* %67)
%69 = load i32, i32* %23
%70 = icmp ne i32 %69, 0
br i1 %70, label %71, label %75
71: ; preds = %64
%72 = load i8*, i8** %9
%73 = call i32 @free(i8* %72)
%74 = load i32, i32* %23
store i32 %74, i32* %4
br label %150
75: ; preds = %64
%76 = load i8*, i8** %9
%77 = call i32 @asprintf(i8** %15, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0), i8* %76)
store i32 %77, i32* %23
%78 = load i8*, i8** %9
%79 = call i32 @free(i8* %78)
%80 = load i32, i32* %23
%81 = icmp slt i32 %80, 0
br i1 %81, label %82, label %88
82: ; preds = %75
%83 = load i8*, i8** %13
%84 = call i32 @free(i8* %83)
%85 = load i8*, i8** %15
%86 = call i32 @free(i8* %85)
%87 = load i32, i32* %23
store i32 %87, i32* %4
br label %150
88: ; preds = %75
%89 = load i8*, i8** %15
%90 = call i32 @vdev_sysfs_device_path_from_subsystem_sysname(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0), i8* %89, i8** %16, i64* %17)
store i32 %90, i32* %23
%91 = load i8*, i8** %15
%92 = call i32 @free(i8* %91)
%93 = load i32, i32* %23
%94 = icmp ne i32 %93, 0
br i1 %94, label %95, label %99
95: ; preds = %88
%96 = load i8*, i8** %13
%97 = call i32 @free(i8* %96)
%98 = load i32, i32* %23
store i32 %98, i32* %4
br label %150
99: ; preds = %88
%100 = load i8*, i8** %16
%101 = call i32 @vdev_sysfs_read_attr(i8* %100, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.6, i64 0, i64 0), i8** %18, i64* %19)
store i32 %101, i32* %23
%102 = load i32, i32* %23
%103 = icmp ne i32 %102, 0
br i1 %103, label %104, label %108
104: ; preds = %99
%105 = load i8*, i8** %13
%106 = call i32 @free(i8* %105)
%107 = load i32, i32* %23
store i32 %107, i32* %4
br label %150
108: ; preds = %99
%109 = load i8*, i8** %16
%110 = call i32 @vdev_sysfs_read_attr(i8* %109, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.7, i64 0, i64 0), i8** %20, i64* %21)
store i32 %110, i32* %23
%111 = load i32, i32* %23
%112 = icmp ne i32 %111, 0
br i1 %112, label %113, label %119
113: ; preds = %108
%114 = load i8*, i8** %18
%115 = call i32 @free(i8* %114)
%116 = load i8*, i8** %13
%117 = call i32 @free(i8* %116)
%118 = load i32, i32* %23
store i32 %118, i32* %4
br label %150
119: ; preds = %108
%120 = load i8*, i8** %5
%121 = call i32 @format_lun_number(i8* %120, i8** %22)
%122 = load i8**, i8*** %6
%123 = load i8*, i8** %18
%124 = load i8*, i8** %20
%125 = load i8*, i8** %13
%126 = load i8*, i8** %22
%127 = call i32 @path_prepend(i8** %122, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.8, i64 0, i64 0), i8* %123, i8* %124, i8* %125, i8* %126)
%128 = load i8*, i8** %22
%129 = icmp ne i8* %128, null
br i1 %129, label %130, label %133
130: ; preds = %119
%131 = load i8*, i8** %22
%132 = call i32 @free(i8* %131)
br label %133
133: ; preds = %130, %119
%134 = load i8*, i8** %20
%135 = call i32 @free(i8* %134)
%136 = load i8*, i8** %13
%137 = call i32 @free(i8* %136)
%138 = load i8*, i8** %18
%139 = call i32 @free(i8* %138)
%140 = load i8*, i8** %5
%141 = call i8* @strdup(i8* %140)
%142 = load i8**, i8*** %7
store i8* %141, i8** %142
%143 = load i8**, i8*** %7
%144 = load i8*, i8** %143
%145 = icmp eq i8* %144, null
br i1 %145, label %146, label %149
146: ; preds = %133
%147 = load i32, i32* @ENOMEM
%148 = sub nsw i32 0, %147
store i32 %148, i32* %4
br label %150
149: ; preds = %133
store i32 0, i32* %4
br label %150
150: ; preds = %149, %146, %113, %104, %95, %82, %71, %60, %49, %32
%151 = load i32, i32* %4
ret i32 %151
}

LLVM IR (-O2):
@.str = [8 x i8] c"session\00"
@.str.1 = [5 x i8] c"/sys\00"
@.str.2 = [14 x i8] c"iscsi_session\00"
@.str.3 = [11 x i8] c"targetname\00"
@.str.4 = [15 x i8] c"connection%s:0\00"
@.str.5 = [17 x i8] c"iscsi_connection\00"
@.str.6 = [19 x i8] c"persistent_address\00"
@.str.7 = [16 x i8] c"persistent_port\00"
@.str.8 = [21 x i8] c"ip-%s:%s-iscsi-%s-%s\00"
@ENOMEM = global i32 0
define i32 @handle_scsi_iscsi(i8* %0, i8** %1, i8** nocapture writeonly %2) {
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i64
%13 = alloca i8*
%14 = alloca i64
%15 = alloca i8*
%16 = alloca i64
%17 = alloca i8*
%18 = alloca i8*
%19 = alloca i64
%20 = bitcast i8** %4 to i8*
store i8* null, i8** %4
%21 = bitcast i64* %5 to i8*
store i64 0, i64* %5
%22 = bitcast i8** %6 to i8*
store i8* null, i8** %6
%23 = bitcast i64* %7 to i8*
store i64 0, i64* %7
%24 = bitcast i8** %8 to i8*
store i8* null, i8** %8
%25 = bitcast i64* %9 to i8*
store i64 0, i64* %9
%26 = bitcast i8** %10 to i8*
store i8* null, i8** %10
%27 = bitcast i8** %11 to i8*
store i8* null, i8** %11
%28 = bitcast i64* %12 to i8*
store i64 0, i64* %12
%29 = bitcast i8** %13 to i8*
store i8* null, i8** %13
%30 = bitcast i64* %14 to i8*
store i64 0, i64* %14
%31 = bitcast i8** %15 to i8*
store i8* null, i8** %15
%32 = bitcast i64* %16 to i8*
store i64 0, i64* %16
%33 = bitcast i8** %17 to i8*
store i8* null, i8** %17
%34 = bitcast i8** %18 to i8*
%35 = bitcast i64* %19 to i8*
store i8* null, i8** %18
store i64 0, i64* %19
%36 = call i32 @vdev_sysfs_get_parent_device(i8* %0, i8** %18, i64* %19)
%37 = icmp eq i32 %36, 0
br i1 %37, label %40, label %38
38: ; preds = %45, %3
%39 = phi i32 [ %36, %3 ], [ %47, %45 ]
br label %127
40: ; preds = %3, %45
%41 = load i8*, i8** %18
%42 = call i32 @strlen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%43 = call i64 @strncmp(i8* %41, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %42)
%44 = icmp eq i64 %43, 0
br i1 %44, label %49, label %45
45: ; preds = %40
%46 = call i32 @free(i8* %41)
store i8* null, i8** %18
store i64 0, i64* %19
%47 = call i32 @vdev_sysfs_get_parent_device(i8* %41, i8** %18, i64* %19)
%48 = icmp eq i32 %47, 0
br i1 %48, label %40, label %38
49: ; preds = %40
%50 = call i32 @vdev_sysfs_get_sysname(i8* %41, i8** %4, i64* %5)
%51 = icmp eq i32 %50, 0
%52 = call i32 @free(i8* %41)
br i1 %51, label %53, label %127
53: ; preds = %49
%54 = load i8*, i8** %4
%55 = call i32 @vdev_sysfs_device_path_from_subsystem_sysname(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i8* %54, i8** %6, i64* %7)
%56 = icmp eq i32 %55, 0
br i1 %56, label %60, label %57
57: ; preds = %53
%58 = load i8*, i8** %4
%59 = call i32 @free(i8* %58)
br label %127
60: ; preds = %53
%61 = load i8*, i8** %6
%62 = call i32 @vdev_sysfs_read_attr(i8* %61, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i8** %8, i64* %9)
%63 = load i8*, i8** %6
%64 = call i32 @free(i8* %63)
%65 = icmp eq i32 %62, 0
%66 = load i8*, i8** %4
br i1 %65, label %69, label %67
67: ; preds = %60
%68 = call i32 @free(i8* %66)
br label %127
69: ; preds = %60
%70 = call i32 @asprintf(i8** %10, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0), i8* %66)
%71 = load i8*, i8** %4
%72 = call i32 @free(i8* %71)
%73 = icmp slt i32 %70, 0
br i1 %73, label %74, label %79
74: ; preds = %69
%75 = load i8*, i8** %8
%76 = call i32 @free(i8* %75)
%77 = load i8*, i8** %10
%78 = call i32 @free(i8* %77)
br label %127
79: ; preds = %69
%80 = load i8*, i8** %10
%81 = call i32 @vdev_sysfs_device_path_from_subsystem_sysname(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0), i8* %80, i8** %11, i64* %12)
%82 = load i8*, i8** %10
%83 = call i32 @free(i8* %82)
%84 = icmp eq i32 %81, 0
br i1 %84, label %88, label %85
85: ; preds = %79
%86 = load i8*, i8** %8
%87 = call i32 @free(i8* %86)
br label %127
88: ; preds = %79
%89 = load i8*, i8** %11
%90 = call i32 @vdev_sysfs_read_attr(i8* %89, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.6, i64 0, i64 0), i8** %13, i64* %14)
%91 = icmp eq i32 %90, 0
br i1 %91, label %95, label %92
92: ; preds = %88
%93 = load i8*, i8** %8
%94 = call i32 @free(i8* %93)
br label %127
95: ; preds = %88
%96 = load i8*, i8** %11
%97 = call i32 @vdev_sysfs_read_attr(i8* %96, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.7, i64 0, i64 0), i8** %15, i64* %16)
%98 = icmp eq i32 %97, 0
br i1 %98, label %104, label %99
99: ; preds = %95
%100 = load i8*, i8** %13
%101 = call i32 @free(i8* %100)
%102 = load i8*, i8** %8
%103 = call i32 @free(i8* %102)
br label %127
104: ; preds = %95
%105 = call i32 @format_lun_number(i8* %0, i8** %17)
%106 = load i8*, i8** %13
%107 = load i8*, i8** %15
%108 = load i8*, i8** %8
%109 = load i8*, i8** %17
%110 = call i32 @path_prepend(i8** %1, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.8, i64 0, i64 0), i8* %106, i8* %107, i8* %108, i8* %109)
%111 = load i8*, i8** %17
%112 = icmp eq i8* %111, null
br i1 %112, label %115, label %113
113: ; preds = %104
%114 = call i32 @free(i8* %111)
br label %115
115: ; preds = %113, %104
%116 = load i8*, i8** %15
%117 = call i32 @free(i8* %116)
%118 = load i8*, i8** %8
%119 = call i32 @free(i8* %118)
%120 = load i8*, i8** %13
%121 = call i32 @free(i8* %120)
%122 = call i8* @strdup(i8* %0)
store i8* %122, i8** %2
%123 = icmp eq i8* %122, null
br i1 %123, label %124, label %127
124: ; preds = %115
%125 = load i32, i32* @ENOMEM
%126 = sub nsw i32 0, %125
br label %127
127: ; preds = %49, %38, %115, %124, %99, %92, %85, %74, %67, %57
%128 = phi i32 [ %55, %57 ], [ %62, %67 ], [ %70, %74 ], [ %81, %85 ], [ %90, %92 ], [ %97, %99 ], [ %126, %124 ], [ 0, %115 ], [ %39, %38 ], [ %50, %49 ]
ret i32 %128
}