#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 /*<<< orphan*/ free(char *);
int /*<<< orphan*/ path_prepend(char **, char *, char);
int /*<<< orphan*/ *strchr(char *, char);
scalar_t__ strncmp(char *, char *, int);
int vdev_sysfs_get_sysname(char const *, char **, size_t *);
void handle_scsi_tape(char const *dev, char **path) {
  if (*path != NULL) {
    return;
  }
  char *sysname = NULL;
  size_t sysname_len = 0;
  int rc = 0;
  rc = vdev_sysfs_get_sysname(dev, &sysname, &sysname_len);
  if (rc != 0) {
    return;
  }
  if (strncmp(sysname, "nst", 3) == 0 && strchr("lma", sysname[3]) != NULL) {
    path_prepend(path, "nst%c", sysname[3]);
  } else if (strncmp(sysname, "st", 2) == 0 &&
             strchr("lma", sysname[2]) != NULL) {
    path_prepend(path, "st%c", sysname[2]);
  }
  free(sysname);
  return;
}


x86 assembly (clang, -O0):
<handle_scsi_tape>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
je     1173 <handle_scsi_tape+0x23>
jmp    126a <handle_scsi_tape+0x11a>
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x18(%rbp),%rsi
lea    -0x20(%rbp),%rdx
call   1070 <vdev_sysfs_get_sysname@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
je     11ad <handle_scsi_tape+0x5d>
jmp    126a <handle_scsi_tape+0x11a>
mov    -0x18(%rbp),%rdi
lea    0xe48(%rip),%rsi
mov    $0x3,%edx
call   1050 <strncmp@plt>
cmp    $0x0,%rax
jne    1207 <handle_scsi_tape+0xb7>
mov    -0x18(%rbp),%rax
lea    0xe2d(%rip),%rdi
movsbl 0x3(%rax),%esi
call   1060 <strchr@plt>
cmp    $0x0,%rax
je     1207 <handle_scsi_tape+0xb7>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rax
lea    0xe0f(%rip),%rsi
movsbl 0x3(%rax),%edx
call   1030 <path_prepend@plt>
jmp    1261 <handle_scsi_tape+0x111>
mov    -0x18(%rbp),%rdi
lea    0xdef(%rip),%rsi
mov    $0x2,%edx
call   1050 <strncmp@plt>
cmp    $0x0,%rax
jne    125c <handle_scsi_tape+0x10c>
mov    -0x18(%rbp),%rax
lea    0xdd3(%rip),%rdi
movsbl 0x2(%rax),%esi
call   1060 <strchr@plt>
cmp    $0x0,%rax
je     125c <handle_scsi_tape+0x10c>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rax
lea    0xdb6(%rip),%rsi
movsbl 0x2(%rax),%edx
call   1030 <path_prepend@plt>
jmp    1261 <handle_scsi_tape+0x111>
mov    -0x18(%rbp),%rdi
call   1040 <free@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<handle_scsi_tape>:
push   %rbx
sub    $0x10,%rsp
cmpq   $0x0,(%rsi)
jne    1222 <handle_scsi_tape+0xd2>
mov    %rsi,%rbx
movq   $0x0,(%rsp)
movq   $0x0,0x8(%rsp)
mov    %rsp,%rsi
lea    0x8(%rsp),%rdx
call   1070 <vdev_sysfs_get_sysname@plt>
test   %eax,%eax
jne    1222 <handle_scsi_tape+0xd2>
mov    (%rsp),%rdi
lea    0xe6d(%rip),%rsi
mov    $0x3,%edx
call   1050 <strncmp@plt>
test   %rax,%rax
je     11e6 <handle_scsi_tape+0x96>
mov    (%rsp),%rdi
lea    0xe54(%rip),%rsi
mov    $0x2,%edx
call   1050 <strncmp@plt>
test   %rax,%rax
jne    1219 <handle_scsi_tape+0xc9>
mov    (%rsp),%rax
movsbl 0x2(%rax),%esi
lea    0xe39(%rip),%rdi
call   1060 <strchr@plt>
test   %rax,%rax
je     1219 <handle_scsi_tape+0xc9>
mov    (%rsp),%rax
add    $0x2,%rax
lea    0xe25(%rip),%rsi
jmp    120e <handle_scsi_tape+0xbe>
mov    (%rsp),%rax
movsbl 0x3(%rax),%esi
lea    0xe0f(%rip),%rdi
call   1060 <strchr@plt>
test   %rax,%rax
je     11a2 <handle_scsi_tape+0x52>
mov    (%rsp),%rax
add    $0x3,%rax
lea    0xdfa(%rip),%rsi
movsbl (%rax),%edx
mov    %rbx,%rdi
call   1030 <path_prepend@plt>
mov    (%rsp),%rdi
call   1040 <free@plt>
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [4 x i8] c"nst\00"
@.str.1 = [4 x i8] c"lma\00"
@.str.2 = [6 x i8] c"nst%c\00"
@.str.3 = [3 x i8] c"st\00"
@.str.4 = [5 x i8] c"st%c\00"
define void @handle_scsi_tape(i8* %0, i8** %1) {
%3 = alloca i8*
%4 = alloca i8**
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i32
store i8* %0, i8** %3
store i8** %1, i8*** %4
%8 = load i8**, i8*** %4
%9 = load i8*, i8** %8
%10 = icmp ne i8* %9, null
br i1 %10, label %11, label %12
11: ; preds = %2
br label %54
12: ; preds = %2
store i8* null, i8** %5
store i64 0, i64* %6
store i32 0, i32* %7
%13 = load i8*, i8** %3
%14 = call i32 @vdev_sysfs_get_sysname(i8* %13, i8** %5, i64* %6)
store i32 %14, i32* %7
%15 = load i32, i32* %7
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %12
br label %54
18: ; preds = %12
%19 = load i8*, i8** %5
%20 = call i64 @strncmp(i8* %19, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 3)
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %34
22: ; preds = %18
%23 = load i8*, i8** %5
%24 = getelementptr inbounds i8, i8* %23, i64 3
%25 = load i8, i8* %24
%26 = call i32* @strchr(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8 signext %25)
%27 = icmp ne i32* %26, null
br i1 %27, label %28, label %34
28: ; preds = %22
%29 = load i8**, i8*** %4
%30 = load i8*, i8** %5
%31 = getelementptr inbounds i8, i8* %30, i64 3
%32 = load i8, i8* %31
%33 = call i32 @path_prepend(i8** %29, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8 signext %32)
br label %51
34: ; preds = %22, %18
%35 = load i8*, i8** %5
%36 = call i64 @strncmp(i8* %35, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 2)
%37 = icmp eq i64 %36, 0
br i1 %37, label %38, label %50
38: ; preds = %34
%39 = load i8*, i8** %5
%40 = getelementptr inbounds i8, i8* %39, i64 2
%41 = load i8, i8* %40
%42 = call i32* @strchr(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8 signext %41)
%43 = icmp ne i32* %42, null
br i1 %43, label %44, label %50
44: ; preds = %38
%45 = load i8**, i8*** %4
%46 = load i8*, i8** %5
%47 = getelementptr inbounds i8, i8* %46, i64 2
%48 = load i8, i8* %47
%49 = call i32 @path_prepend(i8** %45, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i8 signext %48)
br label %50
50: ; preds = %44, %38, %34
br label %51
51: ; preds = %50, %28
%52 = load i8*, i8** %5
%53 = call i32 @free(i8* %52)
br label %54
54: ; preds = %51, %17, %11
ret void
}

LLVM IR (-O2):
@.str = [4 x i8] c"nst\00"
@.str.1 = [4 x i8] c"lma\00"
@.str.2 = [6 x i8] c"nst%c\00"
@.str.3 = [3 x i8] c"st\00"
@.str.4 = [5 x i8] c"st%c\00"
define void @handle_scsi_tape(i8* %0, i8** %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = load i8*, i8** %1
%6 = icmp eq i8* %5, null
br i1 %6, label %7, label %47
7: ; preds = %2
%8 = bitcast i8** %3 to i8*
store i8* null, i8** %3
%9 = bitcast i64* %4 to i8*
store i64 0, i64* %4
%10 = call i32 @vdev_sysfs_get_sysname(i8* %0, i8** %3, i64* %4)
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %46
12: ; preds = %7
%13 = load i8*, i8** %3
%14 = call i64 @strncmp(i8* %13, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 3)
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %25
16: ; preds = %12
%17 = load i8*, i8** %3
%18 = getelementptr inbounds i8, i8* %17, i64 3
%19 = load i8, i8* %18
%20 = call i32* @strchr(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8 signext %19)
%21 = icmp eq i32* %20, null
br i1 %21, label %25, label %22
22: ; preds = %16
%23 = load i8*, i8** %3
%24 = getelementptr inbounds i8, i8* %23, i64 3
br label %38
25: ; preds = %16, %12
%26 = load i8*, i8** %3
%27 = call i64 @strncmp(i8* %26, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 2)
%28 = icmp eq i64 %27, 0
br i1 %28, label %29, label %43
29: ; preds = %25
%30 = load i8*, i8** %3
%31 = getelementptr inbounds i8, i8* %30, i64 2
%32 = load i8, i8* %31
%33 = call i32* @strchr(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8 signext %32)
%34 = icmp eq i32* %33, null
br i1 %34, label %43, label %35
35: ; preds = %29
%36 = load i8*, i8** %3
%37 = getelementptr inbounds i8, i8* %36, i64 2
br label %38
38: ; preds = %22, %35
%39 = phi i8* [ %37, %35 ], [ %24, %22 ]
%40 = phi i8* [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), %35 ], [ getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), %22 ]
%41 = load i8, i8* %39
%42 = call i32 @path_prepend(i8** %1, i8* %40, i8 signext %41)
br label %43
43: ; preds = %38, %25, %29
%44 = load i8*, i8** %3
%45 = call i32 @free(i8* %44)
br label %46
46: ; preds = %7, %43
br label %47
47: ; preds = %2, %46
ret void
}