#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 */
struct udev_device *handle_scsi_default(struct udev_device *, char **);
struct udev_device *handle_scsi_fibre_channel(struct udev_device *, char **);
struct udev_device *handle_scsi_iscsi(struct udev_device *, char **);
struct udev_device *handle_scsi_sas(struct udev_device *, char **);
int /*<<< orphan*/ path_prepend(char **, char *, char const *);
struct udev_device *skip_subsystem(struct udev_device *, char *);
scalar_t__ strcmp(char const *, char *);
int /*<<< orphan*/ *strstr(char const *, char *);
char *udev_device_get_devtype(struct udev_device *);
char *udev_device_get_sysattr_value(struct udev_device *, char *);
char *udev_device_get_syspath(struct udev_device *);
struct udev_device *handle_scsi(struct udev_device *parent, char **path) {
  const char *devtype;
  const char *name;
  const char *id;
  devtype = udev_device_get_devtype(parent);
  if (devtype == NULL || strcmp(devtype, "scsi_device") != 0)
    return parent;
  id = udev_device_get_sysattr_value(parent, "ieee1394_id");
  if (id != NULL) {
    parent = skip_subsystem(parent, "scsi");
    path_prepend(path, "ieee1394-0x%s", id);
    goto out;
  }
  name = udev_device_get_syspath(parent);
  if (strstr(name, "/rport-") != NULL) {
    parent = handle_scsi_fibre_channel(parent, path);
    goto out;
  }
  if (strstr(name, "/end_device-") != NULL) {
    parent = handle_scsi_sas(parent, path);
    goto out;
  }
  if (strstr(name, "/session") != NULL) {
    parent = handle_scsi_iscsi(parent, path);
    goto out;
  }
  parent = handle_scsi_default(parent, path);
out:
  return parent;
}


x86 assembly (clang, -O0):
<handle_scsi>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   10c0 <udev_device_get_devtype@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11f2 <handle_scsi+0x42>
mov    -0x20(%rbp),%rdi
lea    0xe1d(%rip),%rsi
call   1090 <strcmp@plt>
cmp    $0x0,%rax
je     11ff <handle_scsi+0x4f>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1301 <handle_scsi+0x151>
mov    -0x10(%rbp),%rdi
lea    0xe02(%rip),%rsi
call   10b0 <udev_device_get_sysattr_value@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     124b <handle_scsi+0x9b>
mov    -0x10(%rbp),%rdi
lea    0xdef(%rip),%rsi
call   1060 <skip_subsystem@plt>
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x30(%rbp),%rdx
lea    0xddc(%rip),%rsi
call   1040 <path_prepend@plt>
jmp    12f9 <handle_scsi+0x149>
mov    -0x10(%rbp),%rdi
call   1030 <udev_device_get_syspath@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
lea    0xdc8(%rip),%rsi
call   10d0 <strstr@plt>
cmp    $0x0,%rax
je     1288 <handle_scsi+0xd8>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1080 <handle_scsi_fibre_channel@plt>
mov    %rax,-0x10(%rbp)
jmp    12f9 <handle_scsi+0x149>
mov    -0x28(%rbp),%rdi
lea    0xda0(%rip),%rsi
call   10d0 <strstr@plt>
cmp    $0x0,%rax
je     12b8 <handle_scsi+0x108>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <handle_scsi_sas@plt>
mov    %rax,-0x10(%rbp)
jmp    12f9 <handle_scsi+0x149>
mov    -0x28(%rbp),%rdi
lea    0xd7d(%rip),%rsi
call   10d0 <strstr@plt>
cmp    $0x0,%rax
je     12e8 <handle_scsi+0x138>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   10a0 <handle_scsi_iscsi@plt>
mov    %rax,-0x10(%rbp)
jmp    12f9 <handle_scsi+0x149>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1070 <handle_scsi_default@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<handle_scsi>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbx
call   10c0 <udev_device_get_devtype@plt>
test   %rax,%rax
je     1214 <handle_scsi+0x64>
lea    0xe34(%rip),%rsi
mov    %rax,%rdi
call   1090 <strcmp@plt>
test   %rax,%rax
jne    1214 <handle_scsi+0x64>
lea    0xe2c(%rip),%rsi
mov    %rbx,%rdi
call   10b0 <udev_device_get_sysattr_value@plt>
test   %rax,%rax
je     121d <handle_scsi+0x6d>
mov    %rax,%r15
lea    0xe21(%rip),%rsi
mov    %rbx,%rdi
call   1060 <skip_subsystem@plt>
mov    %rax,%rbx
lea    0xe14(%rip),%rsi
mov    %r14,%rdi
mov    %r15,%rdx
call   1040 <path_prepend@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret
mov    %rbx,%rdi
call   1030 <udev_device_get_syspath@plt>
mov    %rax,%r15
lea    0xdfc(%rip),%rsi
mov    %rax,%rdi
call   10d0 <strstr@plt>
test   %rax,%rax
je     124c <handle_scsi+0x9c>
mov    %rbx,%rdi
mov    %r14,%rsi
pop    %rbx
pop    %r14
pop    %r15
jmp    1080 <handle_scsi_fibre_channel@plt>
lea    0xde0(%rip),%rsi
mov    %r15,%rdi
call   10d0 <strstr@plt>
test   %rax,%rax
je     1270 <handle_scsi+0xc0>
mov    %rbx,%rdi
mov    %r14,%rsi
pop    %rbx
pop    %r14
pop    %r15
jmp    1050 <handle_scsi_sas@plt>
lea    0xdc9(%rip),%rsi
mov    %r15,%rdi
call   10d0 <strstr@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
test   %rax,%rax
je     1294 <handle_scsi+0xe4>
pop    %rbx
pop    %r14
pop    %r15
jmp    10a0 <handle_scsi_iscsi@plt>
pop    %rbx
pop    %r14
pop    %r15
jmp    1070 <handle_scsi_default@plt>

LLVM IR (-O0):
%struct.udev_device = type { i32 }
@.str = [12 x i8] c"scsi_device\00"
@.str.1 = [12 x i8] c"ieee1394_id\00"
@.str.2 = [5 x i8] c"scsi\00"
@.str.3 = [14 x i8] c"ieee1394-0x%s\00"
@.str.4 = [8 x i8] c"/rport-\00"
@.str.5 = [13 x i8] c"/end_device-\00"
@.str.6 = [9 x i8] c"/session\00"
define %struct.udev_device* @handle_scsi(%struct.udev_device* %0, i8** %1) {
%3 = alloca %struct.udev_device*
%4 = alloca %struct.udev_device*
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
store %struct.udev_device* %0, %struct.udev_device** %4
store i8** %1, i8*** %5
%9 = load %struct.udev_device*, %struct.udev_device** %4
%10 = call i8* @udev_device_get_devtype(%struct.udev_device* %9)
store i8* %10, i8** %6
%11 = load i8*, i8** %6
%12 = icmp eq i8* %11, null
br i1 %12, label %17, label %13
13: ; preds = %2
%14 = load i8*, i8** %6
%15 = call i64 @strcmp(i8* %14, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %13, %2
%18 = load %struct.udev_device*, %struct.udev_device** %4
store %struct.udev_device* %18, %struct.udev_device** %3
br label %62
19: ; preds = %13
%20 = load %struct.udev_device*, %struct.udev_device** %4
%21 = call i8* @udev_device_get_sysattr_value(%struct.udev_device* %20, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
store i8* %21, i8** %8
%22 = load i8*, i8** %8
%23 = icmp ne i8* %22, null
br i1 %23, label %24, label %30
24: ; preds = %19
%25 = load %struct.udev_device*, %struct.udev_device** %4
%26 = call %struct.udev_device* @skip_subsystem(%struct.udev_device* %25, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
store %struct.udev_device* %26, %struct.udev_device** %4
%27 = load i8**, i8*** %5
%28 = load i8*, i8** %8
%29 = call i32 @path_prepend(i8** %27, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i8* %28)
br label %60
30: ; preds = %19
%31 = load %struct.udev_device*, %struct.udev_device** %4
%32 = call i8* @udev_device_get_syspath(%struct.udev_device* %31)
store i8* %32, i8** %7
%33 = load i8*, i8** %7
%34 = call i32* @strstr(i8* %33, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
%35 = icmp ne i32* %34, null
br i1 %35, label %36, label %40
36: ; preds = %30
%37 = load %struct.udev_device*, %struct.udev_device** %4
%38 = load i8**, i8*** %5
%39 = call %struct.udev_device* @handle_scsi_fibre_channel(%struct.udev_device* %37, i8** %38)
store %struct.udev_device* %39, %struct.udev_device** %4
br label %60
40: ; preds = %30
%41 = load i8*, i8** %7
%42 = call i32* @strstr(i8* %41, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0))
%43 = icmp ne i32* %42, null
br i1 %43, label %44, label %48
44: ; preds = %40
%45 = load %struct.udev_device*, %struct.udev_device** %4
%46 = load i8**, i8*** %5
%47 = call %struct.udev_device* @handle_scsi_sas(%struct.udev_device* %45, i8** %46)
store %struct.udev_device* %47, %struct.udev_device** %4
br label %60
48: ; preds = %40
%49 = load i8*, i8** %7
%50 = call i32* @strstr(i8* %49, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0))
%51 = icmp ne i32* %50, null
br i1 %51, label %52, label %56
52: ; preds = %48
%53 = load %struct.udev_device*, %struct.udev_device** %4
%54 = load i8**, i8*** %5
%55 = call %struct.udev_device* @handle_scsi_iscsi(%struct.udev_device* %53, i8** %54)
store %struct.udev_device* %55, %struct.udev_device** %4
br label %60
56: ; preds = %48
%57 = load %struct.udev_device*, %struct.udev_device** %4
%58 = load i8**, i8*** %5
%59 = call %struct.udev_device* @handle_scsi_default(%struct.udev_device* %57, i8** %58)
store %struct.udev_device* %59, %struct.udev_device** %4
br label %60
60: ; preds = %56, %52, %44, %36, %24
%61 = load %struct.udev_device*, %struct.udev_device** %4
store %struct.udev_device* %61, %struct.udev_device** %3
br label %62
62: ; preds = %60, %17
%63 = load %struct.udev_device*, %struct.udev_device** %3
ret %struct.udev_device* %63
}

LLVM IR (-O2):
%struct.udev_device = type { i32 }
@.str = [12 x i8] c"scsi_device\00"
@.str.1 = [12 x i8] c"ieee1394_id\00"
@.str.2 = [5 x i8] c"scsi\00"
@.str.3 = [14 x i8] c"ieee1394-0x%s\00"
@.str.4 = [8 x i8] c"/rport-\00"
@.str.5 = [13 x i8] c"/end_device-\00"
@.str.6 = [9 x i8] c"/session\00"
define %struct.udev_device* @handle_scsi(%struct.udev_device* %0, i8** %1) {
%3 = tail call i8* @udev_device_get_devtype(%struct.udev_device* %0)
%4 = icmp eq i8* %3, null
br i1 %4, label %32, label %5
5: ; preds = %2
%6 = tail call i64 @strcmp(i8* %3, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %32
8: ; preds = %5
%9 = tail call i8* @udev_device_get_sysattr_value(%struct.udev_device* %0, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
%10 = icmp eq i8* %9, null
br i1 %10, label %14, label %11
11: ; preds = %8
%12 = tail call %struct.udev_device* @skip_subsystem(%struct.udev_device* %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%13 = tail call i32 @path_prepend(i8** %1, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i8* %9)
br label %32
14: ; preds = %8
%15 = tail call i8* @udev_device_get_syspath(%struct.udev_device* %0)
%16 = tail call i32* @strstr(i8* dereferenceable(1) %15, i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
%17 = icmp eq i32* %16, null
br i1 %17, label %20, label %18
18: ; preds = %14
%19 = tail call %struct.udev_device* @handle_scsi_fibre_channel(%struct.udev_device* %0, i8** %1)
br label %32
20: ; preds = %14
%21 = tail call i32* @strstr(i8* dereferenceable(1) %15, i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0))
%22 = icmp eq i32* %21, null
br i1 %22, label %25, label %23
23: ; preds = %20
%24 = tail call %struct.udev_device* @handle_scsi_sas(%struct.udev_device* %0, i8** %1)
br label %32
25: ; preds = %20
%26 = tail call i32* @strstr(i8* dereferenceable(1) %15, i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0))
%27 = icmp eq i32* %26, null
br i1 %27, label %30, label %28
28: ; preds = %25
%29 = tail call %struct.udev_device* @handle_scsi_iscsi(%struct.udev_device* %0, i8** %1)
br label %32
30: ; preds = %25
%31 = tail call %struct.udev_device* @handle_scsi_default(%struct.udev_device* %0, i8** %1)
br label %32
32: ; preds = %11, %18, %23, %28, %30, %2, %5
%33 = phi %struct.udev_device* [ %0, %5 ], [ %0, %2 ], [ %12, %11 ], [ %19, %18 ], [ %24, %23 ], [ %29, %28 ], [ %31, %30 ]
ret %struct.udev_device* %33
}