char *partnamebf(char *dev, int pno, int lth, int bufsiz, char *bufp) {
  static char buffer[80];
  char *p;
  int w, wp;
  if (!bufp) {
    bufp = buffer;
    bufsiz = sizeof(buffer);
  }
  w = strlen(dev);
  p = "";
  if (isdigit(dev[w - 1]))
    p = "p";
  if (strcmp(dev + w - 4, "disc") == 0) {
    w -= 4;
    p = "part";
  }
  wp = strlen(p);
  if (lth) {
    sprintf(bufp, "%*.*s%s%-2u", lth - wp - 2, w, dev, p, pno);
  } else {
    sprintf(bufp, "%.*s%s%-2u", w, dev, p, pno);
  }
  return bufp;
}


x86 assembly (clang, -O0):
<partnamebf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    %r8,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1176 <partnamebf+0x36>
lea    0x2ee5(%rip),%rax
mov    %rax,-0x20(%rbp)
movl   $0x50,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x2c(%rbp)
lea    0xe7d(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x2c(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%eax
je     11b7 <partnamebf+0x77>
lea    0xe4d(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
movslq -0x2c(%rbp),%rax
add    %rax,%rdi
add    $0xfffffffffffffffc,%rdi
lea    0xe35(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
jne    11ef <partnamebf+0xaf>
mov    -0x2c(%rbp),%eax
sub    $0x4,%eax
mov    %eax,-0x2c(%rbp)
lea    0xe1c(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x30(%rbp)
cmpl   $0x0,-0x10(%rbp)
je     1236 <partnamebf+0xf6>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%edx
sub    -0x30(%rbp),%edx
sub    $0x2,%edx
mov    -0x2c(%rbp),%ecx
mov    -0x8(%rbp),%r8
mov    -0x28(%rbp),%r9
mov    -0xc(%rbp),%eax
lea    0xde5(%rip),%rsi
mov    %eax,(%rsp)
mov    $0x0,%al
call   1060 <sprintf@plt>
jmp    1257 <partnamebf+0x117>
mov    -0x20(%rbp),%rdi
mov    -0x2c(%rbp),%edx
mov    -0x8(%rbp),%rcx
mov    -0x28(%rbp),%r8
mov    -0xc(%rbp),%r9d
lea    0xdc8(%rip),%rsi
mov    $0x0,%al
call   1060 <sprintf@plt>
mov    -0x20(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<partnamebf>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %edx,%r13d
mov    %esi,0x14(%rsp)
mov    %rdi,%r12
test   %r8,%r8
lea    0x2efe(%rip),%r14
cmovne %r8,%r14
call   1030 <strlen@plt>
lea    -0x1(%rax),%ecx
movslq %ecx,%rcx
movsbl (%r12,%rcx,1),%ecx
add    $0xffffffd0,%ecx
cmp    $0xa,%ecx
lea    0xe8d(%rip),%rcx
lea    0xe8c(%rip),%rbp
cmovb  %rcx,%rbp
movslq %eax,%r15
lea    (%r12,%r15,1),%rdi
add    $0xfffffffffffffffc,%rdi
lea    0xe72(%rip),%rsi
call   1040 <strcmp@plt>
test   %eax,%eax
lea    0xe69(%rip),%rbx
cmovne %rbp,%rbx
lea    -0x4(%r15),%ebp
cmovne %r15d,%ebp
test   %r13d,%r13d
je     11e3 <partnamebf+0xb3>
mov    %rbx,%rdi
call   1030 <strlen@plt>
sub    %eax,%r13d
add    $0xfffffffe,%r13d
mov    0x14(%rsp),%eax
mov    %eax,(%rsp)
lea    0xe40(%rip),%rsi
mov    %r14,%rdi
mov    %r13d,%edx
mov    %ebp,%ecx
mov    %r12,%r8
mov    %rbx,%r9
xor    %eax,%eax
call   1050 <sprintf@plt>
jmp    1201 <partnamebf+0xd1>
lea    0xe2e(%rip),%rsi
mov    %r14,%rdi
mov    %ebp,%edx
mov    %r12,%rcx
mov    %rbx,%r8
mov    0x14(%rsp),%r9d
xor    %eax,%eax
call   1050 <sprintf@plt>
mov    %r14,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@partnamebf.buffer = internal global [80 x i8] zeroinitializer
@.str = [1 x i8] zeroinitializer
@.str.1 = [2 x i8] c"p\00"
@.str.2 = [5 x i8] c"disc\00"
@.str.3 = [5 x i8] c"part\00"
@.str.4 = [12 x i8] c"%*.*s%s%-2u\00"
@.str.5 = [11 x i8] c"%.*s%s%-2u\00"
define i8* @partnamebf(i8* %0, i32 %1, i32 %2, i32 %3, i8* %4) {
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i32
%13 = alloca i32
store i8* %0, i8** %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store i32 %3, i32* %9
store i8* %4, i8** %10
%14 = load i8*, i8** %10
%15 = icmp ne i8* %14, null
br i1 %15, label %17, label %16
16: ; preds = %5
store i8* getelementptr inbounds ([80 x i8], [80 x i8]* @partnamebf.buffer, i64 0, i64 0), i8** %10
store i32 80, i32* %9
br label %17
17: ; preds = %16, %5
%18 = load i8*, i8** %6
%19 = call i64 @strlen(i8* %18)
%20 = trunc i64 %19 to i32
store i32 %20, i32* %12
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8** %11
%21 = load i8*, i8** %6
%22 = load i32, i32* %12
%23 = sub nsw i32 %22, 1
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %21, i64 %24
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
%28 = call i32 @isdigit(i32 %27)
%29 = icmp ne i32 %28, 0
br i1 %29, label %30, label %31
30: ; preds = %17
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8** %11
br label %31
31: ; preds = %30, %17
%32 = load i8*, i8** %6
%33 = load i32, i32* %12
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i8, i8* %32, i64 %34
%36 = getelementptr inbounds i8, i8* %35, i64 -4
%37 = call i32 @strcmp(i8* %36, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%38 = icmp eq i32 %37, 0
br i1 %38, label %39, label %42
39: ; preds = %31
%40 = load i32, i32* %12
%41 = sub nsw i32 %40, 4
store i32 %41, i32* %12
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8** %11
br label %42
42: ; preds = %39, %31
%43 = load i8*, i8** %11
%44 = call i64 @strlen(i8* %43)
%45 = trunc i64 %44 to i32
store i32 %45, i32* %13
%46 = load i32, i32* %8
%47 = icmp ne i32 %46, 0
br i1 %47, label %48, label %59
48: ; preds = %42
%49 = load i8*, i8** %10
%50 = load i32, i32* %8
%51 = load i32, i32* %13
%52 = sub nsw i32 %50, %51
%53 = sub nsw i32 %52, 2
%54 = load i32, i32* %12
%55 = load i8*, i8** %6
%56 = load i8*, i8** %11
%57 = load i32, i32* %7
%58 = call i32 (i8*, i8*, ...) @sprintf(i8* %49, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i32 %53, i32 %54, i8* %55, i8* %56, i32 %57)
br label %66
59: ; preds = %42
%60 = load i8*, i8** %10
%61 = load i32, i32* %12
%62 = load i8*, i8** %6
%63 = load i8*, i8** %11
%64 = load i32, i32* %7
%65 = call i32 (i8*, i8*, ...) @sprintf(i8* %60, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0), i32 %61, i8* %62, i8* %63, i32 %64)
br label %66
66: ; preds = %59, %48
%67 = load i8*, i8** %10
ret i8* %67
}

LLVM IR (-O2):
@partnamebf.buffer = internal global [80 x i8] zeroinitializer
@.str = [1 x i8] zeroinitializer
@.str.1 = [2 x i8] c"p\00"
@.str.2 = [5 x i8] c"disc\00"
@.str.3 = [5 x i8] c"part\00"
@.str.4 = [12 x i8] c"%*.*s%s%-2u\00"
@.str.5 = [11 x i8] c"%.*s%s%-2u\00"
define i8* @partnamebf(i8* %0, i32 %1, i32 %2, i32 %3, i8* writeonly %4) {
%6 = icmp eq i8* %4, null
%7 = select i1 %6, i8* getelementptr inbounds ([80 x i8], [80 x i8]* @partnamebf.buffer, i64 0, i64 0), i8* %4
%8 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%9 = trunc i64 %8 to i32
%10 = shl i64 %8, 32
%11 = add i64 %10, -4294967296
%12 = ashr exact i64 %11, 32
%13 = getelementptr inbounds i8, i8* %0, i64 %12
%14 = load i8, i8* %13
%15 = sext i8 %14 to i32
%16 = add nsw i32 %15, -48
%17 = icmp ult i32 %16, 10
%18 = select i1 %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0)
%19 = ashr exact i64 %10, 32
%20 = getelementptr inbounds i8, i8* %0, i64 %19
%21 = getelementptr inbounds i8, i8* %20, i64 -4
%22 = tail call i32 @strcmp(i8* %21, i8* dereferenceable(5) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%23 = icmp eq i32 %22, 0
%24 = add nsw i32 %9, -4
%25 = select i1 %23, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* %18
%26 = select i1 %23, i32 %24, i32 %9
%27 = icmp eq i32 %2, 0
br i1 %27, label %34, label %28
28: ; preds = %5
%29 = tail call i64 @strlen(i8* dereferenceable(1) %25)
%30 = trunc i64 %29 to i32
%31 = add i32 %2, -2
%32 = sub i32 %31, %30
%33 = tail call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %7, i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i32 %32, i32 %26, i8* %0, i8* %25, i32 %1)
br label %36
34: ; preds = %5
%35 = tail call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %7, i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0), i32 %26, i8* %0, i8* %25, i32 %1)
br label %36
36: ; preds = %34, %28
ret i8* %7
}