#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*/ asprintf(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 **suffix) {
  const char *name;
  name = udev_device_get_sysname(dev);
  if (strncmp(name, "nst", 3) == 0 && strchr("lma", name[3]) != NULL)
    asprintf(suffix, "nst%c", name[3]);
  else if (strncmp(name, "st", 2) == 0 && strchr("lma", name[2]) != NULL)
    asprintf(suffix, "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    -0x8(%rbp),%rdi
call   1060 <udev_device_get_sysname@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe98(%rip),%rsi
mov    $0x3,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    11b7 <handle_scsi_tape+0x77>
mov    -0x18(%rbp),%rax
lea    0xe7d(%rip),%rdi
movsbl 0x3(%rax),%esi
call   1040 <strchr@plt>
cmp    $0x0,%rax
je     11b7 <handle_scsi_tape+0x77>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rax
lea    0xe5f(%rip),%rsi
movsbl 0x3(%rax),%edx
call   1050 <asprintf@plt>
jmp    1211 <handle_scsi_tape+0xd1>
mov    -0x18(%rbp),%rdi
lea    0xe3f(%rip),%rsi
mov    $0x2,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    120c <handle_scsi_tape+0xcc>
mov    -0x18(%rbp),%rax
lea    0xe23(%rip),%rdi
movsbl 0x2(%rax),%esi
call   1040 <strchr@plt>
cmp    $0x0,%rax
je     120c <handle_scsi_tape+0xcc>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rax
lea    0xe06(%rip),%rsi
movsbl 0x2(%rax),%edx
call   1050 <asprintf@plt>
jmp    1211 <handle_scsi_tape+0xd1>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<handle_scsi_tape>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
call   1060 <udev_device_get_sysname@plt>
mov    %rax,%rbx
lea    0xeaa(%rip),%rsi
mov    %rax,%rdi
mov    $0x3,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     1189 <handle_scsi_tape+0x49>
lea    0xe92(%rip),%rsi
mov    %rbx,%rdi
mov    $0x2,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     11ab <handle_scsi_tape+0x6b>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
movsbl 0x3(%rbx),%esi
lea    0xe70(%rip),%rdi
call   1040 <strchr@plt>
test   %rax,%rax
je     1168 <handle_scsi_tape+0x28>
add    $0x3,%rbx
lea    0xe5f(%rip),%rsi
jmp    11cb <handle_scsi_tape+0x8b>
movsbl 0x2(%rbx),%esi
lea    0xe4e(%rip),%rdi
call   1040 <strchr@plt>
test   %rax,%rax
je     1181 <handle_scsi_tape+0x41>
add    $0x2,%rbx
lea    0xe3e(%rip),%rsi
movsbl (%rbx),%edx
mov    %r14,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1050 <asprintf@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 %struct.udev_device*, %struct.udev_device** %3
%7 = call i8* @udev_device_get_sysname(%struct.udev_device* %6)
store i8* %7, i8** %5
%8 = load i8*, i8** %5
%9 = call i64 @strncmp(i8* %8, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 3)
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %23
11: ; preds = %2
%12 = load i8*, i8** %5
%13 = getelementptr inbounds i8, i8* %12, i64 3
%14 = load i8, i8* %13
%15 = call i32* @strchr(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8 signext %14)
%16 = icmp ne i32* %15, null
br i1 %16, label %17, label %23
17: ; preds = %11
%18 = load i8**, i8*** %4
%19 = load i8*, i8** %5
%20 = getelementptr inbounds i8, i8* %19, i64 3
%21 = load i8, i8* %20
%22 = call i32 @asprintf(i8** %18, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8 signext %21)
br label %40
23: ; preds = %11, %2
%24 = load i8*, i8** %5
%25 = call i64 @strncmp(i8* %24, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 2)
%26 = icmp eq i64 %25, 0
br i1 %26, label %27, label %39
27: ; preds = %23
%28 = load i8*, i8** %5
%29 = getelementptr inbounds i8, i8* %28, i64 2
%30 = load i8, i8* %29
%31 = call i32* @strchr(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8 signext %30)
%32 = icmp ne i32* %31, null
br i1 %32, label %33, label %39
33: ; preds = %27
%34 = load i8**, i8*** %4
%35 = load i8*, i8** %5
%36 = getelementptr inbounds i8, i8* %35, i64 2
%37 = load i8, i8* %36
%38 = call i32 @asprintf(i8** %34, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i8 signext %37)
br label %39
39: ; preds = %33, %27, %23
br label %40
40: ; preds = %39, %17
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 = tail call i8* @udev_device_get_sysname(%struct.udev_device* %0)
%4 = tail call i64 @strncmp(i8* %3, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 3)
%5 = icmp eq i64 %4, 0
br i1 %5, label %6, label %11
6: ; preds = %2
%7 = getelementptr inbounds i8, i8* %3, i64 3
%8 = load i8, i8* %7
%9 = tail call i32* @strchr(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8 signext %8)
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %19
11: ; preds = %6, %2
%12 = tail call i64 @strncmp(i8* %3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 2)
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %24
14: ; preds = %11
%15 = getelementptr inbounds i8, i8* %3, i64 2
%16 = load i8, i8* %15
%17 = tail call i32* @strchr(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8 signext %16)
%18 = icmp eq i32* %17, null
br i1 %18, label %24, label %19
19: ; preds = %14, %6
%20 = phi i8* [ %7, %6 ], [ %15, %14 ]
%21 = phi i8* [ getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), %6 ], [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), %14 ]
%22 = load i8, i8* %20
%23 = tail call i32 @asprintf(i8** %1, i8* %21, i8 signext %22)
br label %24
24: ; preds = %19, %11, %14
ret void
}