#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*/ bb_varname_max_len();
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ snprintf(char *, int /*<<< orphan*/, char *, char const *,
                            ...);
scalar_t__ strcmp(char const *, char *);
void gen_var_name(char *gen_var_name, const int module_instance,
                  const char *module_name, const char *var_name) {
  memset(gen_var_name, 0, bb_varname_max_len());
  if (strcmp(module_name, "") == 0) {
    snprintf(gen_var_name, bb_varname_max_len(), "%s", var_name);
  } else if (-1 != module_instance) {
    snprintf(gen_var_name, bb_varname_max_len(), "%s_%d_%s", module_name,
             module_instance, var_name);
  } else {
    snprintf(gen_var_name, bb_varname_max_len(), "%s_%s", module_name,
             var_name);
  }
}


x86 assembly (clang, -O0):
<gen_var_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    $0x0,%al
call   1060 <bb_varname_max_len@plt>
mov    -0x28(%rbp),%rdi
mov    %eax,%edx
xor    %esi,%esi
call   1040 <memset@plt>
mov    -0x18(%rbp),%rdi
lea    0xe8a(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    11b9 <gen_var_name+0x79>
mov    -0x8(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    $0x0,%al
call   1060 <bb_varname_max_len@plt>
mov    -0x30(%rbp),%rdi
mov    %eax,%esi
mov    -0x20(%rbp),%rcx
lea    0xe59(%rip),%rdx
mov    $0x0,%al
call   1030 <snprintf@plt>
jmp    122b <gen_var_name+0xeb>
mov    $0xffffffff,%eax
cmp    -0xc(%rbp),%eax
je     11fb <gen_var_name+0xbb>
mov    -0x8(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    $0x0,%al
call   1060 <bb_varname_max_len@plt>
mov    -0x38(%rbp),%rdi
mov    %eax,%esi
mov    -0x18(%rbp),%rcx
mov    -0xc(%rbp),%r8d
mov    -0x20(%rbp),%r9
lea    0xe11(%rip),%rdx
mov    $0x0,%al
call   1030 <snprintf@plt>
jmp    1226 <gen_var_name+0xe6>
mov    -0x8(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    $0x0,%al
call   1060 <bb_varname_max_len@plt>
mov    -0x40(%rbp),%rdi
mov    %eax,%esi
mov    -0x18(%rbp),%rcx
mov    -0x20(%rbp),%r8
lea    0xdea(%rip),%rdx
mov    $0x0,%al
call   1030 <snprintf@plt>
jmp    122b <gen_var_name+0xeb>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gen_var_name>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rcx,%r14
mov    %rdx,%r15
mov    %esi,%ebp
mov    %rdi,%rbx
xor    %eax,%eax
call   1060 <bb_varname_max_len@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    %eax,%edx
call   1040 <memset@plt>
lea    0xe9c(%rip),%rsi
mov    %r15,%rdi
call   1050 <strcmp@plt>
test   %rax,%rax
je     11ab <gen_var_name+0x6b>
xor    %eax,%eax
call   1060 <bb_varname_max_len@plt>
cmp    $0xffffffff,%ebp
je     11d2 <gen_var_name+0x92>
lea    0xe74(%rip),%rdx
mov    %rbx,%rdi
mov    %eax,%esi
mov    %r15,%rcx
mov    %ebp,%r8d
mov    %r14,%r9
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <snprintf@plt>
xor    %eax,%eax
call   1060 <bb_varname_max_len@plt>
lea    0xe4d(%rip),%rdx
mov    %rbx,%rdi
mov    %eax,%esi
mov    %r14,%rcx
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <snprintf@plt>
lea    0xe30(%rip),%rdx
mov    %rbx,%rdi
mov    %eax,%esi
mov    %r15,%rcx
mov    %r14,%r8
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <snprintf@plt>

LLVM IR (-O0):
@.str = [1 x i8] zeroinitializer
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [9 x i8] c"%s_%d_%s\00"
@.str.3 = [6 x i8] c"%s_%s\00"
define void @gen_var_name(i8* %0, i32 %1, i8* %2, i8* %3) {
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
store i8* %0, i8** %5
store i32 %1, i32* %6
store i8* %2, i8** %7
store i8* %3, i8** %8
%9 = load i8*, i8** %5
%10 = call i32 (...) @bb_varname_max_len()
%11 = call i32 @memset(i8* %9, i32 0, i32 %10)
%12 = load i8*, i8** %7
%13 = call i64 @strcmp(i8* %12, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %20
15: ; preds = %4
%16 = load i8*, i8** %5
%17 = call i32 (...) @bb_varname_max_len()
%18 = load i8*, i8** %8
%19 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %16, i32 %17, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %18)
br label %37
20: ; preds = %4
%21 = load i32, i32* %6
%22 = icmp ne i32 -1, %21
br i1 %22, label %23, label %30
23: ; preds = %20
%24 = load i8*, i8** %5
%25 = call i32 (...) @bb_varname_max_len()
%26 = load i8*, i8** %7
%27 = load i32, i32* %6
%28 = load i8*, i8** %8
%29 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %24, i32 %25, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* %26, i32 %27, i8* %28)
br label %36
30: ; preds = %20
%31 = load i8*, i8** %5
%32 = call i32 (...) @bb_varname_max_len()
%33 = load i8*, i8** %7
%34 = load i8*, i8** %8
%35 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %31, i32 %32, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* %33, i8* %34)
br label %36
36: ; preds = %30, %23
br label %37
37: ; preds = %36, %15
ret void
}

LLVM IR (-O2):
@.str = [1 x i8] zeroinitializer
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [9 x i8] c"%s_%d_%s\00"
@.str.3 = [6 x i8] c"%s_%s\00"
define void @gen_var_name(i8* %0, i32 %1, i8* %2, i8* %3) {
%5 = tail call i32 (...) @bb_varname_max_len()
%6 = tail call i32 @memset(i8* %0, i32 0, i32 %5)
%7 = tail call i64 @strcmp(i8* %2, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %12
9: ; preds = %4
%10 = tail call i32 (...) @bb_varname_max_len()
%11 = tail call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %0, i32 %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %3)
br label %19
12: ; preds = %4
%13 = icmp eq i32 %1, -1
%14 = tail call i32 (...) @bb_varname_max_len()
br i1 %13, label %17, label %15
15: ; preds = %12
%16 = tail call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %0, i32 %14, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* %2, i32 %1, i8* %3)
br label %19
17: ; preds = %12
%18 = tail call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %0, i32 %14, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* %2, i8* %3)
br label %19
19: ; preds = %15, %17, %9
ret void
}