#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 ENOENT;
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ path_prepend(char **, char *, unsigned int);
int skip_subsystem(char const *, char *, char **);
int sscanf(char *, char *, unsigned int *, unsigned int *);
int vdev_sysfs_get_sysname(char const *, char **, size_t *);
int handle_cciss(char const *parent, char **path, char **new_parent) {
  unsigned int controller = 0, disk = 0;
  char *parent_sysname = NULL;
  size_t parent_sysname_len = 0;
  int rc = 0;
  rc = vdev_sysfs_get_sysname(parent, &parent_sysname, &parent_sysname_len);
  if (rc != 0) {
    return rc;
  }
  rc = sscanf(parent_sysname, "c%ud%u%*s", &controller, &disk);
  free(parent_sysname);
  if (rc != 2) {
    return -ENOENT;
  }
  path_prepend(path, "cciss-disk%u", disk);
  rc = skip_subsystem(parent, "cciss", new_parent);
  return rc;
}


x86 assembly (clang, -O0):
<handle_cciss>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
movl   $0x0,-0x3c(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x30(%rbp),%rsi
lea    -0x38(%rbp),%rdx
call   1060 <vdev_sysfs_get_sysname@plt>
mov    %eax,-0x3c(%rbp)
cmpl   $0x0,-0x3c(%rbp)
je     11b2 <handle_cciss+0x62>
mov    -0x3c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1223 <handle_cciss+0xd3>
mov    -0x30(%rbp),%rdi
lea    0xe43(%rip),%rsi
lea    -0x24(%rbp),%rdx
lea    -0x28(%rbp),%rcx
call   1070 <sscanf@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x30(%rbp),%rdi
call   1040 <free@plt>
cmpl   $0x2,-0x3c(%rbp)
je     11f3 <handle_cciss+0xa3>
xor    %eax,%eax
mov    0x2def(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    1223 <handle_cciss+0xd3>
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%edx
lea    0xe09(%rip),%rsi
call   1030 <path_prepend@plt>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rdx
lea    0xe02(%rip),%rsi
call   1050 <skip_subsystem@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<handle_cciss>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
movl   $0x0,0x1c(%rsp)
movl   $0x0,0xc(%rsp)
movq   $0x0,0x10(%rsp)
movq   $0x0,0x20(%rsp)
lea    0x10(%rsp),%rsi
lea    0x20(%rsp),%rdx
call   1060 <vdev_sysfs_get_sysname@plt>
test   %eax,%eax
jne    11f6 <handle_cciss+0xa6>
mov    0x10(%rsp),%rdi
lea    0xe5c(%rip),%rsi
lea    0x1c(%rsp),%rdx
lea    0xc(%rsp),%rcx
call   1070 <sscanf@plt>
mov    %eax,%ebp
mov    0x10(%rsp),%rdi
call   1040 <free@plt>
cmp    $0x2,%ebp
jne    11eb <handle_cciss+0x9b>
mov    0xc(%rsp),%edx
lea    0xe3b(%rip),%rsi
mov    %r15,%rdi
call   1030 <path_prepend@plt>
lea    0xe39(%rip),%rsi
mov    %rbx,%rdi
mov    %r14,%rdx
call   1050 <skip_subsystem@plt>
jmp    11f6 <handle_cciss+0xa6>
mov    0x2de6(%rip),%rcx
xor    %eax,%eax
sub    (%rcx),%eax
add    $0x28,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [10 x i8] c"c%ud%u%*s\00"
@ENOENT = global i32 0
@.str.1 = [13 x i8] c"cciss-disk%u\00"
@.str.2 = [6 x i8] c"cciss\00"
define i32 @handle_cciss(i8* %0, i8** %1, i8** %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8**
%7 = alloca i8**
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i64
%12 = alloca i32
store i8* %0, i8** %5
store i8** %1, i8*** %6
store i8** %2, i8*** %7
store i32 0, i32* %8
store i32 0, i32* %9
store i8* null, i8** %10
store i64 0, i64* %11
store i32 0, i32* %12
%13 = load i8*, i8** %5
%14 = call i32 @vdev_sysfs_get_sysname(i8* %13, i8** %10, i64* %11)
store i32 %14, i32* %12
%15 = load i32, i32* %12
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %3
%18 = load i32, i32* %12
store i32 %18, i32* %4
br label %37
19: ; preds = %3
%20 = load i8*, i8** %10
%21 = call i32 @sscanf(i8* %20, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32* %8, i32* %9)
store i32 %21, i32* %12
%22 = load i8*, i8** %10
%23 = call i32 @free(i8* %22)
%24 = load i32, i32* %12
%25 = icmp ne i32 %24, 2
br i1 %25, label %26, label %29
26: ; preds = %19
%27 = load i32, i32* @ENOENT
%28 = sub nsw i32 0, %27
store i32 %28, i32* %4
br label %37
29: ; preds = %19
%30 = load i8**, i8*** %6
%31 = load i32, i32* %9
%32 = call i32 @path_prepend(i8** %30, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 %31)
%33 = load i8*, i8** %5
%34 = load i8**, i8*** %7
%35 = call i32 @skip_subsystem(i8* %33, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8** %34)
store i32 %35, i32* %12
%36 = load i32, i32* %12
store i32 %36, i32* %4
br label %37
37: ; preds = %29, %26, %17
%38 = load i32, i32* %4
ret i32 %38
}

LLVM IR (-O2):
@.str = [10 x i8] c"c%ud%u%*s\00"
@ENOENT = global i32 0
@.str.1 = [13 x i8] c"cciss-disk%u\00"
@.str.2 = [6 x i8] c"cciss\00"
define i32 @handle_cciss(i8* %0, i8** %1, i8** %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i64
%8 = bitcast i32* %4 to i8*
store i32 0, i32* %4
%9 = bitcast i32* %5 to i8*
store i32 0, i32* %5
%10 = bitcast i8** %6 to i8*
store i8* null, i8** %6
%11 = bitcast i64* %7 to i8*
store i64 0, i64* %7
%12 = call i32 @vdev_sysfs_get_sysname(i8* %0, i8** %6, i64* %7)
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %27
14: ; preds = %3
%15 = load i8*, i8** %6
%16 = call i32 @sscanf(i8* %15, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32* %4, i32* %5)
%17 = load i8*, i8** %6
%18 = call i32 @free(i8* %17)
%19 = icmp eq i32 %16, 2
br i1 %19, label %23, label %20
20: ; preds = %14
%21 = load i32, i32* @ENOENT
%22 = sub nsw i32 0, %21
br label %27
23: ; preds = %14
%24 = load i32, i32* %5
%25 = call i32 @path_prepend(i8** %1, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 %24)
%26 = call i32 @skip_subsystem(i8* %0, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8** %2)
br label %27
27: ; preds = %3, %23, %20
%28 = phi i32 [ %22, %20 ], [ %26, %23 ], [ %12, %3 ]
ret i32 %28
}