#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 */
typedef int /*<<< orphan*/ buf1;

/* Variables and functions */
int /*<<< orphan*/ snprintf(char *, size_t, char *, ...);
char *saved_arg_name(char *buf, size_t buf_size, int grp, int num) {
  char buf1[16];
  buf1[0] = 0;
  if (grp > 0)
    snprintf(buf1, sizeof(buf1), "%d", grp);
  snprintf(buf, buf_size, "s%s_a%d", buf1, num);
  return buf;
}


x86 assembly (clang, -O0):
<saved_arg_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
movb   $0x0,-0x30(%rbp)
cmpl   $0x0,-0x14(%rbp)
jle    114e <saved_arg_name+0x3e>
lea    -0x30(%rbp),%rdi
mov    -0x14(%rbp),%ecx
mov    $0x10,%esi
lea    0xebe(%rip),%rdx
mov    $0x0,%al
call   1030 <snprintf@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
lea    -0x30(%rbp),%rcx
mov    -0x18(%rbp),%r8d
lea    0xe9b(%rip),%rdx
mov    $0x0,%al
call   1030 <snprintf@plt>
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<saved_arg_name>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %ecx,%r14d
mov    %rsi,%rbp
mov    %rdi,%rbx
movb   $0x0,(%rsp)
test   %edx,%edx
jle    1141 <saved_arg_name+0x31>
mov    %edx,%ecx
lea    0xed3(%rip),%rdx
mov    %rsp,%rdi
mov    $0x10,%esi
xor    %eax,%eax
call   1030 <snprintf@plt>
lea    0xeb8(%rip),%rdx
mov    %rsp,%rcx
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    %r14d,%r8d
xor    %eax,%eax
call   1030 <snprintf@plt>
mov    %rbx,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@.str.1 = [8 x i8] c"s%s_a%d\00"
define i8* @saved_arg_name(i8* %0, i64 %1, i32 %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i32
%8 = alloca i32
%9 = alloca [16 x i8]
store i8* %0, i8** %5
store i64 %1, i64* %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%10 = getelementptr inbounds [16 x i8], [16 x i8]* %9, i64 0, i64 0
store i8 0, i8* %10
%11 = load i32, i32* %7
%12 = icmp sgt i32 %11, 0
br i1 %12, label %13, label %17
13: ; preds = %4
%14 = getelementptr inbounds [16 x i8], [16 x i8]* %9, i64 0, i64 0
%15 = load i32, i32* %7
%16 = call i32 (i8*, i64, i8*, ...) @snprintf(i8* %14, i64 16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %15)
br label %17
17: ; preds = %13, %4
%18 = load i8*, i8** %5
%19 = load i64, i64* %6
%20 = getelementptr inbounds [16 x i8], [16 x i8]* %9, i64 0, i64 0
%21 = load i32, i32* %8
%22 = call i32 (i8*, i64, i8*, ...) @snprintf(i8* %18, i64 %19, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %20, i32 %21)
%23 = load i8*, i8** %5
ret i8* %23
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.1 = [8 x i8] c"s%s_a%d\00"
define i8* @saved_arg_name(i8* returned writeonly %0, i64 %1, i32 %2, i32 %3) {
%5 = alloca [16 x i8]
%6 = getelementptr inbounds [16 x i8], [16 x i8]* %5, i64 0, i64 0
store i8 0, i8* %6
%7 = icmp sgt i32 %2, 0
br i1 %7, label %8, label %10
8: ; preds = %4
%9 = call i32 (i8*, i64, i8*, ...) @snprintf(i8* %6, i64 16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %2)
br label %10
10: ; preds = %8, %4
%11 = call i32 (i8*, i64, i8*, ...) @snprintf(i8* %0, i64 %1, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %6, i32 %3)
ret i8* %0
}