#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*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ sprintf(char *, char *, unsigned int);
int /*<<< orphan*/ sscanf(char *, char *, unsigned int *);
int /*<<< orphan*/ stderr;
int strlen(char *);
scalar_t__ strncmp(char *, char *, int);
char *nvme_char_from_block(char *block) {
  char slen[16];
  unsigned len;
  if (strncmp("nvme", block, 4)) {
    fprintf(stderr, "Device %s is not a nvme device.", block);
    return NULL;
  }
  sscanf(block, "nvme%d", &len);
  sprintf(slen, "%d", len);
  block[4 + strlen(slen)] = 0;
  return block;
}


x86 assembly (clang, -O0):
<nvme_char_from_block>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xe99(%rip),%rdi
mov    $0x4,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
je     11a1 <nvme_char_from_block+0x51>
mov    0x2e5e(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe76(%rip),%rsi
call   1050 <fprintf@plt>
movq   $0x0,-0x8(%rbp)
jmp    11f1 <nvme_char_from_block+0xa1>
mov    -0x10(%rbp),%rdi
lea    0xe79(%rip),%rsi
lea    -0x24(%rbp),%rdx
call   1060 <sscanf@plt>
lea    -0x20(%rbp),%rdi
mov    -0x24(%rbp),%edx
lea    0xe66(%rip),%rsi
call   1070 <sprintf@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
lea    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%rax
add    $0x4,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<nvme_char_from_block>:
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    %rdi,%rbx
lea    0xe9f(%rip),%rdi
mov    %rbx,%rsi
mov    $0x4,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     118f <nvme_char_from_block+0x3f>
mov    0x2e66(%rip),%rax
mov    (%rax),%edi
lea    0xe82(%rip),%rsi
mov    %rbx,%rdx
call   1050 <fprintf@plt>
xor    %ebx,%ebx
jmp    11ca <nvme_char_from_block+0x7a>
lea    0xe8f(%rip),%rsi
lea    0xc(%rsp),%rdx
mov    %rbx,%rdi
call   1060 <sscanf@plt>
mov    0xc(%rsp),%edx
lea    0xe7b(%rip),%rsi
lea    0x10(%rsp),%r14
mov    %r14,%rdi
call   1070 <sprintf@plt>
mov    %r14,%rdi
call   1040 <strlen@plt>
cltq
movb   $0x0,0x4(%rax,%rbx,1)
mov    %rbx,%rax
add    $0x28,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [5 x i8] c"nvme\00"
@stderr = global i32 0
@.str.1 = [32 x i8] c"Device %s is not a nvme device.\00"
@.str.2 = [7 x i8] c"nvme%d\00"
@.str.3 = [3 x i8] c"%d\00"
define i8* @nvme_char_from_block(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca [16 x i8]
%5 = alloca i32
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = call i64 @strncmp(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %6, i32 4)
%8 = icmp ne i64 %7, 0
br i1 %8, label %9, label %13
9: ; preds = %1
%10 = load i32, i32* @stderr
%11 = load i8*, i8** %3
%12 = call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i8* %11)
store i8* null, i8** %2
br label %26
13: ; preds = %1
%14 = load i8*, i8** %3
%15 = call i32 @sscanf(i8* %14, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32* %5)
%16 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 0
%17 = load i32, i32* %5
%18 = call i32 @sprintf(i8* %16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 %17)
%19 = load i8*, i8** %3
%20 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 0
%21 = call i32 @strlen(i8* %20)
%22 = add nsw i32 4, %21
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %19, i64 %23
store i8 0, i8* %24
%25 = load i8*, i8** %3
store i8* %25, i8** %2
br label %26
26: ; preds = %13, %9
%27 = load i8*, i8** %2
ret i8* %27
}

LLVM IR (-O2):
@.str = [5 x i8] c"nvme\00"
@stderr = global i32 0
@.str.1 = [32 x i8] c"Device %s is not a nvme device.\00"
@.str.2 = [7 x i8] c"nvme%d\00"
@.str.3 = [3 x i8] c"%d\00"
define i8* @nvme_char_from_block(i8* %0) {
%2 = alloca [16 x i8]
%3 = alloca i32
%4 = getelementptr inbounds [16 x i8], [16 x i8]* %2, i64 0, i64 0
%5 = bitcast i32* %3 to i8*
%6 = tail call i64 @strncmp(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %0, i32 4)
%7 = icmp eq i64 %6, 0
br i1 %7, label %11, label %8
8: ; preds = %1
%9 = load i32, i32* @stderr
%10 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %19
11: ; preds = %1
%12 = call i32 @sscanf(i8* %0, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32* %3)
%13 = load i32, i32* %3
%14 = call i32 @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 %13)
%15 = call i32 @strlen(i8* %4)
%16 = add nsw i32 %15, 4
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8, i8* %0, i64 %17
store i8 0, i8* %18
br label %19
19: ; preds = %11, %8
%20 = phi i8* [ null, %8 ], [ %0, %11 ]
ret i8* %20
}