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) {
    snprintf(bufp, bufsiz, "%*.*s%s%-2u", lth - wp - 2, w, dev, p, pno);
  } else {
    snprintf(bufp, bufsiz, "%.*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   1060 <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     1240 <partnamebf+0x100>
mov    -0x20(%rbp),%rdi
movslq -0x14(%rbp),%rsi
mov    -0x10(%rbp),%ecx
sub    -0x30(%rbp),%ecx
sub    $0x2,%ecx
mov    -0x2c(%rbp),%r8d
mov    -0x8(%rbp),%r9
mov    -0x28(%rbp),%r10
mov    -0xc(%rbp),%eax
lea    0xde0(%rip),%rdx
mov    %r10,(%rsp)
mov    %eax,0x8(%rsp)
mov    $0x0,%al
call   1050 <snprintf@plt>
jmp    1267 <partnamebf+0x127>
mov    -0x20(%rbp),%rdi
movslq -0x14(%rbp),%rsi
mov    -0x2c(%rbp),%ecx
mov    -0x8(%rbp),%r8
mov    -0x28(%rbp),%r9
mov    -0xc(%rbp),%eax
lea    0xdbb(%rip),%rdx
mov    %eax,(%rsp)
mov    $0x0,%al
call   1050 <snprintf@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
test   %r8,%r8
lea    0x2f08(%rip),%rax
cmovne %r8,%rax
mov    %rax,0x10(%rsp)
mov    %edx,%r13d
mov    %rsi,0x8(%rsp)
mov    %rdi,%r12
mov    $0x50,%r14d
cmovne %ecx,%r14d
call   1030 <strlen@plt>
lea    -0x1(%rax),%ecx
movslq %ecx,%rcx
movsbl (%r12,%rcx,1),%ecx
add    $0xffffffd0,%ecx
cmp    $0xa,%ecx
lea    0xe7d(%rip),%rcx
lea    0xe7c(%rip),%rbp
cmovb  %rcx,%rbp
movslq %eax,%r15
lea    (%r12,%r15,1),%rdi
add    $0xfffffffffffffffc,%rdi
lea    0xe62(%rip),%rsi
call   1050 <strcmp@plt>
test   %eax,%eax
lea    0xe59(%rip),%rbx
cmovne %rbp,%rbx
lea    -0x4(%r15),%ebp
cmovne %r15d,%ebp
test   %r13d,%r13d
je     11f7 <partnamebf+0xc7>
mov    %rbx,%rdi
call   1030 <strlen@plt>
movslq %r14d,%rsi
sub    %eax,%r13d
add    $0xfffffffe,%r13d
lea    0xe34(%rip),%rdx
mov    0x10(%rsp),%r14
mov    %r14,%rdi
mov    %r13d,%ecx
mov    %ebp,%r8d
mov    %r12,%r9
xor    %eax,%eax
push   0x8(%rsp)
push   %rbx
call   1040 <snprintf@plt>
jmp    1220 <partnamebf+0xf0>
movslq %r14d,%rsi
sub    $0x8,%rsp
lea    0xe13(%rip),%rdx
mov    0x18(%rsp),%r14
mov    %r14,%rdi
mov    %ebp,%ecx
mov    %r12,%r8
mov    %rbx,%r9
xor    %eax,%eax
push   0x10(%rsp)
call   1040 <snprintf@plt>
add    $0x10,%rsp
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 %61
48: ; preds = %42
%49 = load i8*, i8** %10
%50 = load i32, i32* %9
%51 = sext i32 %50 to i64
%52 = load i32, i32* %8
%53 = load i32, i32* %13
%54 = sub nsw i32 %52, %53
%55 = sub nsw i32 %54, 2
%56 = load i32, i32* %12
%57 = load i8*, i8** %6
%58 = load i8*, i8** %11
%59 = load i32, i32* %7
%60 = call i32 (i8*, i64, i8*, ...) @snprintf(i8* %49, i64 %51, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i32 %55, i32 %56, i8* %57, i8* %58, i32 %59)
br label %70
61: ; preds = %42
%62 = load i8*, i8** %10
%63 = load i32, i32* %9
%64 = sext i32 %63 to i64
%65 = load i32, i32* %12
%66 = load i8*, i8** %6
%67 = load i8*, i8** %11
%68 = load i32, i32* %7
%69 = call i32 (i8*, i64, i8*, ...) @snprintf(i8* %62, i64 %64, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0), i32 %65, i8* %66, i8* %67, i32 %68)
br label %70
70: ; preds = %61, %48
%71 = load i8*, i8** %10
ret i8* %71
}

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 = select i1 %6, i32 80, i32 %3
%9 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%10 = trunc i64 %9 to i32
%11 = shl i64 %9, 32
%12 = add i64 %11, -4294967296
%13 = ashr exact i64 %12, 32
%14 = getelementptr inbounds i8, i8* %0, i64 %13
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
%17 = add nsw i32 %16, -48
%18 = icmp ult i32 %17, 10
%19 = select i1 %18, 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)
%20 = ashr exact i64 %11, 32
%21 = getelementptr inbounds i8, i8* %0, i64 %20
%22 = getelementptr inbounds i8, i8* %21, i64 -4
%23 = tail call i32 @strcmp(i8* %22, i8* dereferenceable(5) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%24 = icmp eq i32 %23, 0
%25 = add nsw i32 %10, -4
%26 = select i1 %24, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* %19
%27 = select i1 %24, i32 %25, i32 %10
%28 = icmp eq i32 %2, 0
br i1 %28, label %36, label %29
29: ; preds = %5
%30 = tail call i64 @strlen(i8* dereferenceable(1) %26)
%31 = trunc i64 %30 to i32
%32 = sext i32 %8 to i64
%33 = add i32 %2, -2
%34 = sub i32 %33, %31
%35 = tail call i32 (i8*, i64, i8*, ...) @snprintf(i8* %7, i64 %32, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i32 %34, i32 %27, i8* %0, i8* %26, i32 %1)
br label %39
36: ; preds = %5
%37 = sext i32 %8 to i64
%38 = tail call i32 (i8*, i64, i8*, ...) @snprintf(i8* %7, i64 %37, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0), i32 %27, i8* %0, i8* %26, i32 %1)
br label %39
39: ; preds = %36, %29
ret i8* %7
}