#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 */
char *strchr(char *, char);
int /*<<< orphan*/ strncpy(char *, char *, size_t);
char *strrchr(char *, char);
int get_fcp_dev(char *partition, char *device) {
  char *start, *stop;
  size_t len;
  start = strchr(partition, '/');
  stop = strrchr(partition, '/');
  len = stop - start;
  if (start == NULL || stop == NULL || len <= 0)
    return -1;
  strncpy(device, stop + 1, len - 1);
  device[len] = '\0';
  return 0;
}


x86 assembly (clang, -O0):
<get_fcp_dev>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x2f,%esi
call   1040 <strchr@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x2f,%esi
call   1050 <strrchr@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    -0x20(%rbp),%rcx
sub    %rcx,%rax
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1194 <get_fcp_dev+0x64>
cmpq   $0x0,-0x28(%rbp)
je     1194 <get_fcp_dev+0x64>
cmpq   $0x0,-0x30(%rbp)
ja     11a0 <get_fcp_dev+0x70>
movl   $0xffffffff,-0x4(%rbp)
jmp    11cc <get_fcp_dev+0x9c>
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%rsi
add    $0x1,%rsi
mov    -0x30(%rbp),%rdx
sub    $0x1,%rdx
call   1030 <strncpy@plt>
mov    -0x18(%rbp),%rax
mov    -0x30(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_fcp_dev>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbx
mov    $0x2f,%esi
call   1040 <strchr@plt>
mov    %rax,%r15
mov    %rbx,%rdi
mov    $0x2f,%esi
call   1050 <strrchr@plt>
mov    %rax,%rsi
mov    $0xffffffff,%eax
test   %r15,%r15
je     1186 <get_fcp_dev+0x56>
test   %rsi,%rsi
je     1186 <get_fcp_dev+0x56>
mov    %rsi,%rbx
sub    %r15,%rbx
je     1186 <get_fcp_dev+0x56>
add    $0x1,%rsi
lea    -0x1(%rbx),%rdx
mov    %r14,%rdi
call   1030 <strncpy@plt>
movb   $0x0,(%r14,%rbx,1)
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @get_fcp_dev(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i64
store i8* %0, i8** %4
store i8* %1, i8** %5
%9 = load i8*, i8** %4
%10 = call i8* @strchr(i8* %9, i8 signext 47)
store i8* %10, i8** %6
%11 = load i8*, i8** %4
%12 = call i8* @strrchr(i8* %11, i8 signext 47)
store i8* %12, i8** %7
%13 = load i8*, i8** %7
%14 = load i8*, i8** %6
%15 = ptrtoint i8* %13 to i64
%16 = ptrtoint i8* %14 to i64
%17 = sub i64 %15, %16
store i64 %17, i64* %8
%18 = load i8*, i8** %6
%19 = icmp eq i8* %18, null
br i1 %19, label %26, label %20
20: ; preds = %2
%21 = load i8*, i8** %7
%22 = icmp eq i8* %21, null
br i1 %22, label %26, label %23
23: ; preds = %20
%24 = load i64, i64* %8
%25 = icmp ule i64 %24, 0
br i1 %25, label %26, label %27
26: ; preds = %23, %20, %2
store i32 -1, i32* %3
br label %37
27: ; preds = %23
%28 = load i8*, i8** %5
%29 = load i8*, i8** %7
%30 = getelementptr inbounds i8, i8* %29, i64 1
%31 = load i64, i64* %8
%32 = sub i64 %31, 1
%33 = call i32 @strncpy(i8* %28, i8* %30, i64 %32)
%34 = load i8*, i8** %5
%35 = load i64, i64* %8
%36 = getelementptr inbounds i8, i8* %34, i64 %35
store i8 0, i8* %36
store i32 0, i32* %3
br label %37
37: ; preds = %27, %26
%38 = load i32, i32* %3
ret i32 %38
}

LLVM IR (-O2):
define i32 @get_fcp_dev(i8* %0, i8* %1) {
%3 = tail call i8* @strchr(i8* dereferenceable(1) %0, i8 signext 47)
%4 = tail call i8* @strrchr(i8* dereferenceable(1) %0, i8 signext 47)
%5 = ptrtoint i8* %4 to i64
%6 = ptrtoint i8* %3 to i64
%7 = sub i64 %5, %6
%8 = icmp eq i8* %3, null
%9 = icmp eq i8* %4, null
%10 = select i1 %8, i1 true, i1 %9
%11 = icmp eq i64 %7, 0
%12 = select i1 %10, i1 true, i1 %11
br i1 %12, label %18, label %13
13: ; preds = %2
%14 = getelementptr inbounds i8, i8* %4, i64 1
%15 = add i64 %7, -1
%16 = tail call i32 @strncpy(i8* %1, i8* %14, i64 %15)
%17 = getelementptr inbounds i8, i8* %1, i64 %7
store i8 0, i8* %17
br label %18
18: ; preds = %2, %13
%19 = phi i32 [ 0, %13 ], [ -1, %2 ]
ret i32 %19
}