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

/* Variables and functions */
int getpid();
size_t snprintf(char *, size_t, char *, ...);
char *strdup(char *);
char *tapdisk_syslog_ident(const char *name) {
  char ident[32 + 1];
  size_t size, len;
  pid_t pid;
  pid = getpid();
  size = sizeof(ident);
  len = 0;
  len = snprintf(NULL, 0, "[%d]", pid);
  len = snprintf(ident, size - len, "%s", name);
  len += snprintf(ident + len, size - len, "[%d]", pid);
  return strdup(ident);
}


x86 assembly (clang, -O0):
<tapdisk_syslog_ident>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,-0x44(%rbp)
movq   $0x21,-0x38(%rbp)
movq   $0x0,-0x40(%rbp)
mov    -0x44(%rbp),%ecx
xor    %eax,%eax
mov    %eax,%esi
lea    0xe9c(%rip),%rdx
mov    %rsi,%rdi
mov    $0x0,%al
call   1040 <snprintf@plt>
mov    %rax,-0x40(%rbp)
lea    -0x30(%rbp),%rdi
mov    -0x38(%rbp),%rsi
sub    -0x40(%rbp),%rsi
mov    -0x8(%rbp),%rcx
lea    0xe7c(%rip),%rdx
mov    $0x0,%al
call   1040 <snprintf@plt>
mov    %rax,-0x40(%rbp)
lea    -0x30(%rbp),%rdi
add    -0x40(%rbp),%rdi
mov    -0x38(%rbp),%rsi
sub    -0x40(%rbp),%rsi
mov    -0x44(%rbp),%ecx
lea    0xe52(%rip),%rdx
mov    $0x0,%al
call   1040 <snprintf@plt>
add    -0x40(%rbp),%rax
mov    %rax,-0x40(%rbp)
lea    -0x30(%rbp),%rdi
call   1050 <strdup@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tapdisk_syslog_ident>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x30,%rsp
mov    %rdi,%r14
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %eax,%ebp
lea    0xeb1(%rip),%r15
xor    %edi,%edi
xor    %esi,%esi
mov    %r15,%rdx
mov    %eax,%ecx
xor    %eax,%eax
call   1040 <snprintf@plt>
mov    $0x21,%ebx
mov    $0x21,%esi
sub    %rax,%rsi
lea    0xe92(%rip),%rdx
mov    %rsp,%r12
mov    %r12,%rdi
mov    %r14,%rcx
xor    %eax,%eax
call   1040 <snprintf@plt>
lea    (%rsp,%rax,1),%rdi
sub    %rax,%rbx
mov    %rbx,%rsi
mov    %r15,%rdx
mov    %ebp,%ecx
xor    %eax,%eax
call   1040 <snprintf@plt>
mov    %r12,%rdi
call   1050 <strdup@plt>
add    $0x30,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"[%d]\00"
@.str.1 = [3 x i8] c"%s\00"
define i8* @tapdisk_syslog_ident(i8* %0) {
%2 = alloca i8*
%3 = alloca [33 x i8]
%4 = alloca i64
%5 = alloca i64
%6 = alloca i32
store i8* %0, i8** %2
%7 = call i32 (...) @getpid()
store i32 %7, i32* %6
store i64 33, i64* %4
store i64 0, i64* %5
%8 = load i32, i32* %6
%9 = call i64 (i8*, i64, i8*, ...) @snprintf(i8* null, i64 0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %8)
store i64 %9, i64* %5
%10 = getelementptr inbounds [33 x i8], [33 x i8]* %3, i64 0, i64 0
%11 = load i64, i64* %4
%12 = load i64, i64* %5
%13 = sub i64 %11, %12
%14 = load i8*, i8** %2
%15 = call i64 (i8*, i64, i8*, ...) @snprintf(i8* %10, i64 %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %14)
store i64 %15, i64* %5
%16 = getelementptr inbounds [33 x i8], [33 x i8]* %3, i64 0, i64 0
%17 = load i64, i64* %5
%18 = getelementptr inbounds i8, i8* %16, i64 %17
%19 = load i64, i64* %4
%20 = load i64, i64* %5
%21 = sub i64 %19, %20
%22 = load i32, i32* %6
%23 = call i64 (i8*, i64, i8*, ...) @snprintf(i8* %18, i64 %21, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %22)
%24 = load i64, i64* %5
%25 = add i64 %24, %23
store i64 %25, i64* %5
%26 = getelementptr inbounds [33 x i8], [33 x i8]* %3, i64 0, i64 0
%27 = call i8* @strdup(i8* %26)
ret i8* %27
}

LLVM IR (-O2):
@.str = [5 x i8] c"[%d]\00"
@.str.1 = [3 x i8] c"%s\00"
define noalias i8* @tapdisk_syslog_ident(i8* %0) {
%2 = alloca [33 x i8]
%3 = getelementptr inbounds [33 x i8], [33 x i8]* %2, i64 0, i64 0
%4 = tail call i32 (...) @getpid()
%5 = tail call i64 (i8*, i64, i8*, ...) @snprintf(i8* null, i64 0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %4)
%6 = sub i64 33, %5
%7 = call i64 (i8*, i64, i8*, ...) @snprintf(i8* %3, i64 %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%8 = getelementptr inbounds [33 x i8], [33 x i8]* %2, i64 0, i64 %7
%9 = sub i64 33, %7
%10 = call i64 (i8*, i64, i8*, ...) @snprintf(i8* %8, i64 %9, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %4)
%11 = call i8* @strdup(i8* %3)
ret i8* %11
}