#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 getpid();
int snprintf(char *, size_t const, char *, char const *, char const *, int);
int tapdisk_logfile_name(char *path, size_t size, const char *dir,
                         const char *ident) {
  const size_t max = (((size) < (128UL)) ? (size) : (128UL));
  return snprintf(path, max, "%s/%s.%d.log", dir, ident, getpid());
}


x86 assembly (clang, -O0):
<tapdisk_logfile_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
cmpq   $0x80,-0x10(%rbp)
jae    1153 <tapdisk_logfile_name+0x33>
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
jmp    1161 <tapdisk_logfile_name+0x41>
mov    $0x80,%eax
mov    %rax,-0x30(%rbp)
jmp    1161 <tapdisk_logfile_name+0x41>
mov    -0x30(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    -0x50(%rbp),%rdi
mov    -0x48(%rbp),%rsi
mov    -0x40(%rbp),%rcx
mov    -0x38(%rbp),%r8
mov    %eax,%r9d
lea    0xe56(%rip),%rdx
call   1040 <snprintf@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tapdisk_logfile_name>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r14
mov    %rdx,%r15
mov    %rsi,%rbx
mov    %rdi,%r12
cmp    $0x80,%rsi
mov    $0x80,%eax
cmovae %rax,%rbx
xor    %eax,%eax
call   1030 <getpid@plt>
lea    0xeae(%rip),%rdx
mov    %r12,%rdi
mov    %rbx,%rsi
mov    %r15,%rcx
mov    %r14,%r8
mov    %eax,%r9d
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1040 <snprintf@plt>

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

LLVM IR (-O2):
@.str = [13 x i8] c"%s/%s.%d.log\00"
define i32 @tapdisk_logfile_name(i8* %0, i64 %1, i8* %2, i8* %3) {
%5 = icmp ult i64 %1, 128
%6 = select i1 %5, i64 %1, i64 128
%7 = tail call i32 (...) @getpid()
%8 = tail call i32 @snprintf(i8* %0, i64 %6, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* %2, i8* %3, i32 %7)
ret i32 %8
}