#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 */

/* Variables and functions */
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ snprintf(char *, unsigned int, char *, char const *, int);
unsigned int strlen(char const *);
void mangle_fun_name(char *dst, unsigned int dst_size, const char *name,
                     int arity) {
  assert(arity <= 99 && strlen(name) < dst_size - 6);
  snprintf(dst, dst_size, "%s_#%i", name, arity);
}


x86 assembly (clang, -O0):
<mangle_fun_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
xor    %eax,%eax
cmpl   $0x63,-0x1c(%rbp)
mov    %al,-0x1d(%rbp)
jg     116c <mangle_fun_name+0x3c>
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0xc(%rbp),%ecx
sub    $0x6,%ecx
cmp    %ecx,%eax
setb   %al
mov    %al,-0x1d(%rbp)
mov    -0x1d(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x18(%rbp),%rcx
mov    -0x1c(%rbp),%r8d
lea    0xe71(%rip),%rdx
call   1040 <snprintf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mangle_fun_name>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %ecx,%ebx
mov    %rdx,%r14
mov    %esi,%r15d
mov    %rdi,%r12
xor    %edi,%edi
cmp    $0x63,%ecx
jg     115e <mangle_fun_name+0x2e>
mov    %r14,%rdi
call   1030 <strlen@plt>
lea    -0x6(%r15),%ecx
xor    %edi,%edi
cmp    %ecx,%eax
setb   %dil
call   1050 <assert@plt>
lea    0xe96(%rip),%rdx
mov    %r12,%rdi
mov    %r15d,%esi
mov    %r14,%rcx
mov    %ebx,%r8d
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1040 <snprintf@plt>

LLVM IR (-O0):
@.str = [7 x i8] c"%s_#%i\00"
define void @mangle_fun_name(i8* %0, i32 %1, i8* %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
store i8* %0, i8** %5
store i32 %1, i32* %6
store i8* %2, i8** %7
store i32 %3, i32* %8
%9 = load i32, i32* %8
%10 = icmp sle i32 %9, 99
br i1 %10, label %11, label %17
11: ; preds = %4
%12 = load i8*, i8** %7
%13 = call i32 @strlen(i8* %12)
%14 = load i32, i32* %6
%15 = sub i32 %14, 6
%16 = icmp ult i32 %13, %15
br label %17
17: ; preds = %11, %4
%18 = phi i1 [ false, %4 ], [ %16, %11 ]
%19 = zext i1 %18 to i32
%20 = call i32 @assert(i32 %19)
%21 = load i8*, i8** %5
%22 = load i32, i32* %6
%23 = load i8*, i8** %7
%24 = load i32, i32* %8
%25 = call i32 @snprintf(i8* %21, i32 %22, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %23, i32 %24)
ret void
}

LLVM IR (-O2):
@.str = [7 x i8] c"%s_#%i\00"
define void @mangle_fun_name(i8* %0, i32 %1, i8* %2, i32 %3) {
%5 = icmp slt i32 %3, 100
br i1 %5, label %6, label %11
6: ; preds = %4
%7 = tail call i32 @strlen(i8* %2)
%8 = add i32 %1, -6
%9 = icmp ult i32 %7, %8
%10 = zext i1 %9 to i32
br label %11
11: ; preds = %6, %4
%12 = phi i32 [ 0, %4 ], [ %10, %6 ]
%13 = tail call i32 @assert(i32 %12)
%14 = tail call i32 @snprintf(i8* %0, i32 %1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %2, i32 %3)
ret void
}