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


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

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

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

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