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

/* Variables and functions */
char *dev_find(int /*<<< orphan*/ const);
int major(int /*<<< orphan*/ const);
int minor(int /*<<< orphan*/ const);
int /*<<< orphan*/ snprintf(char *, int, char *, ...);
char *dev_name(const dev_t dev) {
  static char buffer[256];
  char devstr[32];
  char *devname = dev_find(dev);
  snprintf(devstr, sizeof(devstr), "%u:%u", major(dev), minor(dev));
  snprintf(buffer, sizeof(buffer), "%-10.10s%s%s", devstr, devname ? " " : "",
           devname ? devname : "");
  return buffer;
}


x86 assembly (clang, -O0):
<dev_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
call   1060 <dev_find@plt>
mov    %rax,-0x38(%rbp)
lea    -0x30(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x4(%rbp),%edi
call   1050 <major@plt>
mov    %eax,-0x4c(%rbp)
mov    -0x4(%rbp),%edi
call   1030 <minor@plt>
mov    -0x58(%rbp),%rdi
mov    -0x4c(%rbp),%ecx
mov    %eax,%r8d
mov    $0x20,%esi
lea    0xe78(%rip),%rdx
mov    $0x0,%al
call   1040 <snprintf@plt>
lea    -0x30(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x38(%rbp),%rdx
lea    0xe72(%rip),%rax
lea    0xe6a(%rip),%rcx
cmp    $0x0,%rdx
cmovne %rcx,%rax
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x38(%rbp)
je     11cd <dev_name+0x8d>
mov    -0x38(%rbp),%rax
mov    %rax,-0x60(%rbp)
jmp    11dd <dev_name+0x9d>
lea    0xe40(%rip),%rax
mov    %rax,-0x60(%rbp)
jmp    11dd <dev_name+0x9d>
mov    -0x40(%rbp),%r8
mov    -0x48(%rbp),%rcx
mov    -0x60(%rbp),%r9
lea    0x2e60(%rip),%rdi
mov    $0x100,%esi
lea    0xe0a(%rip),%rdx
mov    $0x0,%al
call   1040 <snprintf@plt>
lea    0x2e46(%rip),%rax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dev_name>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    %edi,%ebp
call   1060 <dev_find@plt>
mov    %rax,%rbx
mov    %ebp,%edi
call   1050 <major@plt>
mov    %eax,%r14d
mov    %ebp,%edi
call   1030 <minor@plt>
lea    0xe94(%rip),%rdx
mov    %rsp,%r15
mov    %r15,%rdi
mov    $0x20,%esi
mov    %r14d,%ecx
mov    %eax,%r8d
xor    %eax,%eax
call   1040 <snprintf@plt>
test   %rbx,%rbx
lea    0xe86(%rip),%rax
lea    0xe7e(%rip),%r8
cmove  %rax,%r8
cmove  %rax,%rbx
lea    0x2eac(%rip),%rbp
lea    0xe5b(%rip),%rdx
mov    %rbp,%rdi
mov    $0x100,%esi
mov    %r15,%rcx
mov    %rbx,%r9
xor    %eax,%eax
call   1040 <snprintf@plt>
mov    %rbp,%rax
add    $0x28,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@dev_name.buffer = internal global [256 x i8] zeroinitializer
@.str = [6 x i8] c"%u:%u\00"
@.str.1 = [13 x i8] c"%-10.10s%s%s\00"
@.str.2 = [2 x i8] c" \00"
@.str.3 = [1 x i8] zeroinitializer
define i8* @dev_name(i32 %0) {
%2 = alloca i32
%3 = alloca [32 x i8]
%4 = alloca i8*
store i32 %0, i32* %2
%5 = load i32, i32* %2
%6 = call i8* @dev_find(i32 %5)
store i8* %6, i8** %4
%7 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 0
%8 = load i32, i32* %2
%9 = call i32 @major(i32 %8)
%10 = load i32, i32* %2
%11 = call i32 @minor(i32 %10)
%12 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %7, i32 32, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %9, i32 %11)
%13 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 0
%14 = load i8*, i8** %4
%15 = icmp ne i8* %14, null
%16 = zext i1 %15 to i64
%17 = select i1 %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.3, i64 0, i64 0)
%18 = load i8*, i8** %4
%19 = icmp ne i8* %18, null
br i1 %19, label %20, label %22
20: ; preds = %1
%21 = load i8*, i8** %4
br label %23
22: ; preds = %1
br label %23
23: ; preds = %22, %20
%24 = phi i8* [ %21, %20 ], [ getelementptr inbounds ([1 x i8], [1 x i8]* @.str.3, i64 0, i64 0), %22 ]
%25 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @dev_name.buffer, i64 0, i64 0), i32 256, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* %13, i8* %17, i8* %24)
ret i8* getelementptr inbounds ([256 x i8], [256 x i8]* @dev_name.buffer, i64 0, i64 0)
}

LLVM IR (-O2):
@dev_name.buffer = internal global [256 x i8] zeroinitializer
@.str = [6 x i8] c"%u:%u\00"
@.str.1 = [13 x i8] c"%-10.10s%s%s\00"
@.str.2 = [2 x i8] c" \00"
@.str.3 = [1 x i8] zeroinitializer
define i8* @dev_name(i32 %0) {
%2 = alloca [32 x i8]
%3 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 0
%4 = tail call i8* @dev_find(i32 %0)
%5 = tail call i32 @major(i32 %0)
%6 = tail call i32 @minor(i32 %0)
%7 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %3, i32 32, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %5, i32 %6)
%8 = icmp eq i8* %4, null
%9 = select i1 %8, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0)
%10 = select i1 %8, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.3, i64 0, i64 0), i8* %4
%11 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @dev_name.buffer, i64 0, i64 0), i32 256, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* %3, i8* %9, i8* %10)
ret i8* getelementptr inbounds ([256 x i8], [256 x i8]* @dev_name.buffer, i64 0, i64 0)
}