char *unique_zero_length_section_name(const char *s) {
  static int auto_zero_sec_cnt = 0;
  char *name;
  int len;
  len = strlen(s) + 2 + 5;
  name = xmalloc(len + 1);
  snprintf(name, len, "%s%s%d", s, "%z", ++auto_zero_sec_cnt);
  return name;
}


x86 assembly (clang, -O0):
<unique_zero_length_section_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
add    $0x2,%rax
add    $0x5,%rax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
add    $0x1,%edi
mov    $0x0,%al
call   1050 <xmalloc@plt>
cltq
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
movslq -0x14(%rbp),%rsi
mov    -0x8(%rbp),%rcx
mov    0x2ec6(%rip),%r9d
add    $0x1,%r9d
mov    %r9d,0x2ebb(%rip)
lea    0xe78(%rip),%rdx
lea    0xe78(%rip),%r8
mov    $0x0,%al
call   1040 <snprintf@plt>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<unique_zero_length_section_name>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
call   1030 <strlen@plt>
mov    %rax,%rbx
lea    0x8(%rax),%edi
xor    %eax,%eax
call   1050 <xmalloc@plt>
movslq %eax,%r15
add    $0x7,%ebx
movslq %ebx,%rsi
mov    0x2ee2(%rip),%r9d
add    $0x1,%r9d
mov    %r9d,0x2ed7(%rip)
lea    0xe94(%rip),%rdx
lea    0xe94(%rip),%r8
mov    %r15,%rdi
mov    %r14,%rcx
xor    %eax,%eax
call   1040 <snprintf@plt>
mov    %r15,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@unique_zero_length_section_name.auto_zero_sec_cnt = internal global i32 0
@.str = [7 x i8] c"%s%s%d\00"
@.str.1 = [3 x i8] c"%z\00"
define i8* @unique_zero_length_section_name(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = call i64 @strlen(i8* %5)
%7 = add i64 %6, 2
%8 = add i64 %7, 5
%9 = trunc i64 %8 to i32
store i32 %9, i32* %4
%10 = load i32, i32* %4
%11 = add nsw i32 %10, 1
%12 = call i32 (i32, ...) bitcast (i32 (...)* @xmalloc to i32 (i32, ...)*)(i32 %11)
%13 = sext i32 %12 to i64
%14 = inttoptr i64 %13 to i8*
store i8* %14, i8** %3
%15 = load i8*, i8** %3
%16 = load i32, i32* %4
%17 = sext i32 %16 to i64
%18 = load i8*, i8** %2
%19 = load i32, i32* @unique_zero_length_section_name.auto_zero_sec_cnt
%20 = add nsw i32 %19, 1
store i32 %20, i32* @unique_zero_length_section_name.auto_zero_sec_cnt
%21 = call i32 (i8*, i64, i8*, ...) @snprintf(i8* %15, i64 %17, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %20)
%22 = load i8*, i8** %3
ret i8* %22
}

LLVM IR (-O2):
@unique_zero_length_section_name.auto_zero_sec_cnt = internal unnamed_addr global i32 0
@.str = [7 x i8] c"%s%s%d\00"
@.str.1 = [3 x i8] c"%z\00"
define i8* @unique_zero_length_section_name(i8* %0) {
%2 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%3 = trunc i64 %2 to i32
%4 = add i32 %3, 8
%5 = tail call i32 (i32, ...) bitcast (i32 (...)* @xmalloc to i32 (i32, ...)*)(i32 %4)
%6 = sext i32 %5 to i64
%7 = inttoptr i64 %6 to i8*
%8 = shl i64 %2, 32
%9 = add i64 %8, 30064771072
%10 = ashr exact i64 %9, 32
%11 = load i32, i32* @unique_zero_length_section_name.auto_zero_sec_cnt
%12 = add nsw i32 %11, 1
store i32 %12, i32* @unique_zero_length_section_name.auto_zero_sec_cnt
%13 = tail call i32 (i8*, i64, i8*, ...) @snprintf(i8* %7, i64 %10, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %12)
ret i8* %7
}