#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 */
typedef int /*<<< orphan*/ dev_t;
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int major(int /*<<< orphan*/);
int minor(int /*<<< orphan*/);
int /*<<< orphan*/ scansysdir(char *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ snprintf(char *, int, char *, int, int);
char *strchr(char *, char);
int /*<<< orphan*/ strcpy(char *, char *);
const char *bdevname(dev_t dev) {
  static char buf[512];
  char sysdir[512];
  char *p;
  strcpy(sysdir, "/sys/block");
  if (!scansysdir(buf, sysdir, dev))
    strcpy(buf, "dev");
  p = strchr(buf, '\0');
  snprintf(p, sizeof(buf) - (size_t)(p - buf), "(%d,%d)", major(dev),
           minor(dev));
  return buf;
}


x86 assembly (clang, -O0):
<bdevname>:
push   %rbp
mov    %rsp,%rbp
sub    $0x230,%rsp
mov    %edi,-0x4(%rbp)
lea    -0x210(%rbp),%rdi
lea    0xe84(%rip),%rsi
call   1030 <strcpy@plt>
lea    -0x210(%rbp),%rsi
mov    -0x4(%rbp),%edx
lea    0x2ece(%rip),%rdi
call   1080 <scansysdir@plt>
cmp    $0x0,%eax
jne    11b3 <bdevname+0x53>
lea    0x2eb9(%rip),%rdi
lea    0xe5d(%rip),%rsi
call   1030 <strcpy@plt>
lea    0x2ea6(%rip),%rdi
xor    %esi,%esi
call   1050 <strchr@plt>
mov    %rax,-0x218(%rbp)
mov    -0x218(%rbp),%rax
mov    %rax,-0x228(%rbp)
mov    -0x218(%rbp),%rcx
lea    0x2e7c(%rip),%rax
sub    %rax,%rcx
mov    $0x200,%eax
sub    %rcx,%rax
mov    %eax,-0x220(%rbp)
mov    -0x4(%rbp),%edi
call   1070 <major@plt>
mov    %eax,-0x21c(%rbp)
mov    -0x4(%rbp),%edi
call   1040 <minor@plt>
mov    -0x228(%rbp),%rdi
mov    -0x220(%rbp),%esi
mov    -0x21c(%rbp),%ecx
mov    %eax,%r8d
lea    0xde7(%rip),%rdx
call   1060 <snprintf@plt>
lea    0x2e2c(%rip),%rax
add    $0x230,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bdevname>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x200,%rsp
mov    %edi,%ebp
lea    0xe88(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1030 <strcpy@plt>
lea    0x2ed6(%rip),%r14
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %ebp,%edx
call   1080 <scansysdir@plt>
test   %eax,%eax
jne    11ae <bdevname+0x4e>
lea    0x2ebe(%rip),%rdi
lea    0xe62(%rip),%rsi
call   1030 <strcpy@plt>
mov    %r14,%rdi
call   1050 <strlen@plt>
lea    (%r14,%rax,1),%r15
mov    $0x200,%ebx
sub    %eax,%ebx
mov    %ebp,%edi
call   1070 <major@plt>
mov    %eax,%r12d
mov    %ebp,%edi
call   1040 <minor@plt>
lea    0xe36(%rip),%rdx
mov    %r15,%rdi
mov    %ebx,%esi
mov    %r12d,%ecx
mov    %eax,%r8d
call   1060 <snprintf@plt>
mov    %r14,%rax
add    $0x200,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@bdevname.buf = internal global [512 x i8] zeroinitializer
@.str = [11 x i8] c"/sys/block\00"
@.str.1 = [4 x i8] c"dev\00"
@.str.2 = [8 x i8] c"(%d,%d)\00"
define i8* @bdevname(i32 %0) {
%2 = alloca i32
%3 = alloca [512 x i8]
%4 = alloca i8*
store i32 %0, i32* %2
%5 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%6 = call i32 @strcpy(i8* %5, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%7 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%8 = load i32, i32* %2
%9 = call i32 @scansysdir(i8* getelementptr inbounds ([512 x i8], [512 x i8]* @bdevname.buf, i64 0, i64 0), i8* %7, i32 %8)
%10 = icmp ne i32 %9, 0
br i1 %10, label %13, label %11
11: ; preds = %1
%12 = call i32 @strcpy(i8* getelementptr inbounds ([512 x i8], [512 x i8]* @bdevname.buf, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
br label %13
13: ; preds = %11, %1
%14 = call i8* @strchr(i8* getelementptr inbounds ([512 x i8], [512 x i8]* @bdevname.buf, i64 0, i64 0), i8 signext 0)
store i8* %14, i8** %4
%15 = load i8*, i8** %4
%16 = load i8*, i8** %4
%17 = ptrtoint i8* %16 to i64
%18 = sub i64 %17, ptrtoint ([512 x i8]* @bdevname.buf to i64)
%19 = sub i64 512, %18
%20 = trunc i64 %19 to i32
%21 = load i32, i32* %2
%22 = call i32 @major(i32 %21)
%23 = load i32, i32* %2
%24 = call i32 @minor(i32 %23)
%25 = call i32 @snprintf(i8* %15, i32 %20, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32 %22, i32 %24)
ret i8* getelementptr inbounds ([512 x i8], [512 x i8]* @bdevname.buf, i64 0, i64 0)
}

LLVM IR (-O2):
@bdevname.buf = internal global [512 x i8] zeroinitializer
@.str = [11 x i8] c"/sys/block\00"
@.str.1 = [4 x i8] c"dev\00"
@.str.2 = [8 x i8] c"(%d,%d)\00"
define i8* @bdevname(i32 %0) {
%2 = alloca [512 x i8]
%3 = getelementptr inbounds [512 x i8], [512 x i8]* %2, i64 0, i64 0
%4 = call i32 @strcpy(i8* %3, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%5 = call i32 @scansysdir(i8* getelementptr inbounds ([512 x i8], [512 x i8]* @bdevname.buf, i64 0, i64 0), i8* %3, i32 %0)
%6 = icmp eq i32 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %1
%8 = call i32 @strcpy(i8* getelementptr inbounds ([512 x i8], [512 x i8]* @bdevname.buf, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
br label %9
9: ; preds = %7, %1
%10 = call i64 @strlen(i8* dereferenceable(1) getelementptr inbounds ([512 x i8], [512 x i8]* @bdevname.buf, i64 0, i64 0))
%11 = getelementptr [512 x i8], [512 x i8]* @bdevname.buf, i64 0, i64 %10
%12 = trunc i64 %10 to i32
%13 = sub i32 512, %12
%14 = call i32 @major(i32 %0)
%15 = call i32 @minor(i32 %0)
%16 = call i32 @snprintf(i8* %11, i32 %13, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32 %14, i32 %15)
ret i8* getelementptr inbounds ([512 x i8], [512 x i8]* @bdevname.buf, i64 0, i64 0)
}