#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 getPCIslot_str(char *);
int readlink(char *, char *, int);
int /*<<< orphan*/ strcat(char *, char *);
char *strrchr(char *, char);
int pcislot_scsi_host(char *buffer) {
  char lbuffer[256], *pbuffer;
  char *value = "";
  int len;
  if ((len = readlink(buffer, lbuffer, 253)) <= 0) {
    strcat(buffer, "/device");
    len = readlink(buffer, lbuffer, 253);
  }
  if (len > 0) {
    lbuffer[len] = '\0';
    pbuffer = strrchr(lbuffer, '/');
    while (pbuffer != (char *)0) {
      *(pbuffer++) = '\0';
      if ((*pbuffer >= 0x30) && (*pbuffer <= 0x39))
        break;
      pbuffer = strrchr(lbuffer, '/');
    }
    if (pbuffer != NULL) {
      value = pbuffer;
      if ((pbuffer = strrchr(pbuffer, '.')) != (char *)0)
        *(pbuffer) = '\0';
    }
  }
  return getPCIslot_str(value);
}


x86 assembly (clang, -O0):
<pcislot_scsi_host>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
mov    %rdi,-0x8(%rbp)
lea    0xeb1(%rip),%rax
mov    %rax,-0x120(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x110(%rbp),%rsi
mov    $0xfd,%edx
call   1030 <readlink@plt>
mov    %eax,-0x124(%rbp)
cmp    $0x0,%eax
jg     11ac <pcislot_scsi_host+0x6c>
mov    -0x8(%rbp),%rdi
lea    0xe74(%rip),%rsi
call   1060 <strcat@plt>
mov    -0x8(%rbp),%rdi
lea    -0x110(%rbp),%rsi
mov    $0xfd,%edx
call   1030 <readlink@plt>
mov    %eax,-0x124(%rbp)
cmpl   $0x0,-0x124(%rbp)
jle    12a0 <pcislot_scsi_host+0x160>
movslq -0x124(%rbp),%rax
movb   $0x0,-0x110(%rbp,%rax,1)
lea    -0x110(%rbp),%rdi
mov    $0x2f,%esi
call   1040 <strrchr@plt>
mov    %rax,-0x118(%rbp)
cmpq   $0x0,-0x118(%rbp)
je     124e <pcislot_scsi_host+0x10e>
mov    -0x118(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x118(%rbp)
movb   $0x0,(%rax)
mov    -0x118(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x30,%eax
jl     1231 <pcislot_scsi_host+0xf1>
mov    -0x118(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x39,%eax
jg     1231 <pcislot_scsi_host+0xf1>
jmp    124e <pcislot_scsi_host+0x10e>
lea    -0x110(%rbp),%rdi
mov    $0x2f,%esi
call   1040 <strrchr@plt>
mov    %rax,-0x118(%rbp)
jmp    11e0 <pcislot_scsi_host+0xa0>
cmpq   $0x0,-0x118(%rbp)
je     129b <pcislot_scsi_host+0x15b>
mov    -0x118(%rbp),%rax
mov    %rax,-0x120(%rbp)
mov    -0x118(%rbp),%rdi
mov    $0x2e,%esi
call   1040 <strrchr@plt>
mov    %rax,-0x118(%rbp)
cmp    $0x0,%rax
je     1296 <pcislot_scsi_host+0x156>
mov    -0x118(%rbp),%rax
movb   $0x0,(%rax)
jmp    129b <pcislot_scsi_host+0x15b>
jmp    12a0 <pcislot_scsi_host+0x160>
mov    -0x120(%rbp),%rdi
call   1050 <getPCIslot_str@plt>
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pcislot_scsi_host>:
push   %r15
push   %r14
push   %rbx
sub    $0x100,%rsp
mov    %rdi,%rbx
mov    %rsp,%rsi
mov    $0xfd,%edx
call   1030 <readlink@plt>
test   %eax,%eax
jg     1183 <pcislot_scsi_host+0x43>
lea    0xe99(%rip),%rsi
mov    %rbx,%rdi
call   1060 <strcat@plt>
mov    %rsp,%rsi
mov    %rbx,%rdi
mov    $0xfd,%edx
call   1030 <readlink@plt>
test   %eax,%eax
jle    11f2 <pcislot_scsi_host+0xb2>
mov    %eax,%eax
movb   $0x0,(%rsp,%rax,1)
mov    %rsp,%rdi
mov    $0x2f,%esi
call   1040 <strrchr@plt>
lea    0xe6a(%rip),%r15
test   %rax,%rax
je     11d2 <pcislot_scsi_host+0x92>
mov    %rax,%rbx
mov    %rsp,%r14
nopl   0x0(%rax,%rax,1)
movb   $0x0,(%rbx)
movzbl 0x1(%rbx),%eax
add    $0xd0,%al
cmp    $0xa,%al
jb     11d7 <pcislot_scsi_host+0x97>
mov    %r14,%rdi
mov    $0x2f,%esi
call   1040 <strrchr@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    11b0 <pcislot_scsi_host+0x70>
mov    %r15,%rbx
jmp    11f9 <pcislot_scsi_host+0xb9>
add    $0x1,%rbx
mov    %rbx,%rdi
mov    $0x2e,%esi
call   1040 <strrchr@plt>
test   %rax,%rax
je     11f9 <pcislot_scsi_host+0xb9>
movb   $0x0,(%rax)
jmp    11f9 <pcislot_scsi_host+0xb9>
lea    0xe0e(%rip),%rbx
mov    %rbx,%rdi
call   1050 <getPCIslot_str@plt>
add    $0x100,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [1 x i8] zeroinitializer
@.str.1 = [8 x i8] c"/device\00"
define i32 @pcislot_scsi_host(i8* %0) {
%2 = alloca i8*
%3 = alloca [256 x i8]
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
store i8* %0, i8** %2
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8** %5
%7 = load i8*, i8** %2
%8 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%9 = call i32 @readlink(i8* %7, i8* %8, i32 253)
store i32 %9, i32* %6
%10 = icmp sle i32 %9, 0
br i1 %10, label %11, label %17
11: ; preds = %1
%12 = load i8*, i8** %2
%13 = call i32 @strcat(i8* %12, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%14 = load i8*, i8** %2
%15 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%16 = call i32 @readlink(i8* %14, i8* %15, i32 253)
store i32 %16, i32* %6
br label %17
17: ; preds = %11, %1
%18 = load i32, i32* %6
%19 = icmp sgt i32 %18, 0
br i1 %19, label %20, label %57
20: ; preds = %17
%21 = load i32, i32* %6
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 %22
store i8 0, i8* %23
%24 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%25 = call i8* @strrchr(i8* %24, i8 signext 47)
store i8* %25, i8** %4
br label %26
26: ; preds = %42, %20
%27 = load i8*, i8** %4
%28 = icmp ne i8* %27, null
br i1 %28, label %29, label %45
29: ; preds = %26
%30 = load i8*, i8** %4
%31 = getelementptr inbounds i8, i8* %30, i32 1
store i8* %31, i8** %4
store i8 0, i8* %30
%32 = load i8*, i8** %4
%33 = load i8, i8* %32
%34 = sext i8 %33 to i32
%35 = icmp sge i32 %34, 48
br i1 %35, label %36, label %42
36: ; preds = %29
%37 = load i8*, i8** %4
%38 = load i8, i8* %37
%39 = sext i8 %38 to i32
%40 = icmp sle i32 %39, 57
br i1 %40, label %41, label %42
41: ; preds = %36
br label %45
42: ; preds = %36, %29
%43 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%44 = call i8* @strrchr(i8* %43, i8 signext 47)
store i8* %44, i8** %4
br label %26
45: ; preds = %41, %26
%46 = load i8*, i8** %4
%47 = icmp ne i8* %46, null
br i1 %47, label %48, label %56
48: ; preds = %45
%49 = load i8*, i8** %4
store i8* %49, i8** %5
%50 = load i8*, i8** %4
%51 = call i8* @strrchr(i8* %50, i8 signext 46)
store i8* %51, i8** %4
%52 = icmp ne i8* %51, null
br i1 %52, label %53, label %55
53: ; preds = %48
%54 = load i8*, i8** %4
store i8 0, i8* %54
br label %55
55: ; preds = %53, %48
br label %56
56: ; preds = %55, %45
br label %57
57: ; preds = %56, %17
%58 = load i8*, i8** %5
%59 = call i32 @getPCIslot_str(i8* %58)
ret i32 %59
}

LLVM IR (-O2):
@.str = [1 x i8] zeroinitializer
@.str.1 = [8 x i8] c"/device\00"
define i32 @pcislot_scsi_host(i8* %0) {
%2 = alloca [256 x i8]
%3 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%4 = call i32 @readlink(i8* %0, i8* %3, i32 253)
%5 = icmp slt i32 %4, 1
br i1 %5, label %6, label %10
6: ; preds = %1
%7 = tail call i32 @strcat(i8* %0, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%8 = call i32 @readlink(i8* %0, i8* %3, i32 253)
%9 = icmp sgt i32 %8, 0
br i1 %9, label %10, label %30
10: ; preds = %1, %6
%11 = phi i32 [ %8, %6 ], [ %4, %1 ]
%12 = zext i32 %11 to i64
%13 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 %12
store i8 0, i8* %13
%14 = call i8* @strrchr(i8* %3, i8 signext 47)
%15 = icmp eq i8* %14, null
br i1 %15, label %30, label %16
16: ; preds = %10, %22
%17 = phi i8* [ %23, %22 ], [ %14, %10 ]
%18 = getelementptr inbounds i8, i8* %17, i64 1
store i8 0, i8* %17
%19 = load i8, i8* %18
%20 = add i8 %19, -48
%21 = icmp ult i8 %20, 10
br i1 %21, label %25, label %22
22: ; preds = %16
%23 = call i8* @strrchr(i8* %3, i8 signext 47)
%24 = icmp eq i8* %23, null
br i1 %24, label %30, label %16
25: ; preds = %16
%26 = getelementptr inbounds i8, i8* %17, i64 1
%27 = call i8* @strrchr(i8* %26, i8 signext 46)
%28 = icmp eq i8* %27, null
br i1 %28, label %30, label %29
29: ; preds = %25
store i8 0, i8* %27
br label %30
30: ; preds = %22, %10, %29, %25, %6
%31 = phi i8* [ %26, %29 ], [ %26, %25 ], [ getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), %6 ], [ getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), %10 ], [ getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), %22 ]
%32 = call i32 @getPCIslot_str(i8* %31)
ret i32 %32
}