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


x86 assembly (clang, -O0):
<handle_scsi_tape>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
je     1163 <handle_scsi_tape+0x23>
jmp    1224 <handle_scsi_tape+0xe4>
mov    -0x8(%rbp),%rdi
call   1060 <udev_device_get_sysname@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe85(%rip),%rsi
mov    $0x3,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%rax
jne    11ca <handle_scsi_tape+0x8a>
mov    -0x18(%rbp),%rax
lea    0xe6a(%rip),%rdi
movsbl 0x3(%rax),%esi
call   1050 <strchr@plt>
cmp    $0x0,%rax
je     11ca <handle_scsi_tape+0x8a>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rax
lea    0xe4c(%rip),%rsi
movsbl 0x3(%rax),%edx
call   1030 <path_prepend@plt>
jmp    1224 <handle_scsi_tape+0xe4>
mov    -0x18(%rbp),%rdi
lea    0xe2c(%rip),%rsi
mov    $0x2,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%rax
jne    121f <handle_scsi_tape+0xdf>
mov    -0x18(%rbp),%rax
lea    0xe10(%rip),%rdi
movsbl 0x2(%rax),%esi
call   1050 <strchr@plt>
cmp    $0x0,%rax
je     121f <handle_scsi_tape+0xdf>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rax
lea    0xdf3(%rip),%rsi
movsbl 0x2(%rax),%edx
call   1030 <path_prepend@plt>
jmp    1224 <handle_scsi_tape+0xe4>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<handle_scsi_tape>:
push   %r14
push   %rbx
push   %rax
cmpq   $0x0,(%rsi)
jne    1187 <handle_scsi_tape+0x47>
mov    %rsi,%rbx
call   1060 <udev_device_get_sysname@plt>
mov    %rax,%r14
lea    0xea4(%rip),%rsi
mov    %rax,%rdi
mov    $0x3,%edx
call   1040 <strncmp@plt>
test   %rax,%rax
je     118f <handle_scsi_tape+0x4f>
lea    0xe8c(%rip),%rsi
mov    %r14,%rdi
mov    $0x2,%edx
call   1040 <strncmp@plt>
test   %rax,%rax
je     11b2 <handle_scsi_tape+0x72>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
movsbl 0x3(%r14),%esi
lea    0xe69(%rip),%rdi
call   1050 <strchr@plt>
test   %rax,%rax
je     116e <handle_scsi_tape+0x2e>
add    $0x3,%r14
lea    0xe58(%rip),%rsi
jmp    11d3 <handle_scsi_tape+0x93>
movsbl 0x2(%r14),%esi
lea    0xe46(%rip),%rdi
call   1050 <strchr@plt>
test   %rax,%rax
je     1187 <handle_scsi_tape+0x47>
add    $0x2,%r14
lea    0xe36(%rip),%rsi
movsbl (%r14),%edx
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <path_prepend@plt>

LLVM IR (-O0):
%struct.udev_device = type { i32 }
@.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(%struct.udev_device* %0, i8** %1) {
%3 = alloca %struct.udev_device*
%4 = alloca i8**
%5 = alloca i8*
store %struct.udev_device* %0, %struct.udev_device** %3
store i8** %1, i8*** %4
%6 = load i8**, i8*** %4
%7 = load i8*, i8** %6
%8 = icmp ne i8* %7, null
br i1 %8, label %9, label %10
9: ; preds = %2
br label %45
10: ; preds = %2
%11 = load %struct.udev_device*, %struct.udev_device** %3
%12 = call i8* @udev_device_get_sysname(%struct.udev_device* %11)
store i8* %12, i8** %5
%13 = load i8*, i8** %5
%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 %28
16: ; preds = %10
%17 = load i8*, i8** %5
%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 ne i32* %20, null
br i1 %21, label %22, label %28
22: ; preds = %16
%23 = load i8**, i8*** %4
%24 = load i8*, i8** %5
%25 = getelementptr inbounds i8, i8* %24, i64 3
%26 = load i8, i8* %25
%27 = call i32 @path_prepend(i8** %23, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8 signext %26)
br label %45
28: ; preds = %16, %10
%29 = load i8*, i8** %5
%30 = call i64 @strncmp(i8* %29, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 2)
%31 = icmp eq i64 %30, 0
br i1 %31, label %32, label %44
32: ; preds = %28
%33 = load i8*, i8** %5
%34 = getelementptr inbounds i8, i8* %33, i64 2
%35 = load i8, i8* %34
%36 = call i32* @strchr(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8 signext %35)
%37 = icmp ne i32* %36, null
br i1 %37, label %38, label %44
38: ; preds = %32
%39 = load i8**, i8*** %4
%40 = load i8*, i8** %5
%41 = getelementptr inbounds i8, i8* %40, i64 2
%42 = load i8, i8* %41
%43 = call i32 @path_prepend(i8** %39, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i8 signext %42)
br label %44
44: ; preds = %38, %32, %28
br label %45
45: ; preds = %9, %44, %22
ret void
}

LLVM IR (-O2):
%struct.udev_device = type { i32 }
@.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(%struct.udev_device* %0, i8** %1) {
%3 = load i8*, i8** %1
%4 = icmp eq i8* %3, null
br i1 %4, label %5, label %27
5: ; preds = %2
%6 = tail call i8* @udev_device_get_sysname(%struct.udev_device* %0)
%7 = tail call i64 @strncmp(i8* %6, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 3)
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %14
9: ; preds = %5
%10 = getelementptr inbounds i8, i8* %6, i64 3
%11 = load i8, i8* %10
%12 = tail call i32* @strchr(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8 signext %11)
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %22
14: ; preds = %9, %5
%15 = tail call i64 @strncmp(i8* %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 2)
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %27
17: ; preds = %14
%18 = getelementptr inbounds i8, i8* %6, i64 2
%19 = load i8, i8* %18
%20 = tail 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 %27, label %22
22: ; preds = %17, %9
%23 = phi i8* [ %10, %9 ], [ %18, %17 ]
%24 = phi i8* [ getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), %9 ], [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), %17 ]
%25 = load i8, i8* %23
%26 = tail call i32 @path_prepend(i8** %1, i8* %24, i8 signext %25)
br label %27
27: ; preds = %22, %17, %14, %2
ret void
}