#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*/ va_list;

/* Variables and functions */
int ENAMETOOLONG;
int PATH_MAX;
int errno;
int vsnprintf(char *, int, char const *, int /*<<< orphan*/);
int mkfnv(char fn[PATH_MAX], const char *fmt, va_list ap) {
  int rc;
  rc = vsnprintf(fn, PATH_MAX, fmt, ap);
  if (rc >= PATH_MAX)
    return (ENAMETOOLONG);
  if (rc == -1)
    return (errno);
  return (0);
}


x86 assembly (clang, -O0):
<mkfnv>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2ec2(%rip),%rax
mov    (%rax),%esi
mov    -0x18(%rbp),%rdx
mov    -0x1c(%rbp),%ecx
call   1030 <vsnprintf@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
mov    0x2ea7(%rip),%rcx
cmp    (%rcx),%eax
jl     1162 <mkfnv+0x52>
mov    0x2e78(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1184 <mkfnv+0x74>
cmpl   $0xffffffff,-0x20(%rbp)
jne    117d <mkfnv+0x6d>
mov    0x2e65(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1184 <mkfnv+0x74>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mkfnv>:
push   %rbx
mov    %edx,%ecx
mov    %rsi,%rdx
mov    0x2ed3(%rip),%rbx
mov    (%rbx),%esi
call   1030 <vsnprintf@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0xffffffff,%ecx
je     1133 <mkfnv+0x23>
cmp    (%rbx),%ecx
jge    1140 <mkfnv+0x30>
pop    %rbx
ret
mov    0x2e9e(%rip),%rax
mov    (%rax),%eax
cmp    (%rbx),%ecx
jl     1131 <mkfnv+0x21>
mov    0x2e89(%rip),%rax
mov    (%rax),%eax
pop    %rbx
ret

LLVM IR (-O0):
@PATH_MAX = global i32 0
@ENAMETOOLONG = global i32 0
@errno = global i32 0
define i32 @mkfnv(i8* %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
%9 = load i32, i32* @PATH_MAX
%10 = zext i32 %9 to i64
%11 = load i8*, i8** %5
%12 = load i32, i32* @PATH_MAX
%13 = load i8*, i8** %6
%14 = load i32, i32* %7
%15 = call i32 @vsnprintf(i8* %11, i32 %12, i8* %13, i32 %14)
store i32 %15, i32* %8
%16 = load i32, i32* %8
%17 = load i32, i32* @PATH_MAX
%18 = icmp sge i32 %16, %17
br i1 %18, label %19, label %21
19: ; preds = %3
%20 = load i32, i32* @ENAMETOOLONG
store i32 %20, i32* %4
br label %27
21: ; preds = %3
%22 = load i32, i32* %8
%23 = icmp eq i32 %22, -1
br i1 %23, label %24, label %26
24: ; preds = %21
%25 = load i32, i32* @errno
store i32 %25, i32* %4
br label %27
26: ; preds = %21
store i32 0, i32* %4
br label %27
27: ; preds = %26, %24, %19
%28 = load i32, i32* %4
ret i32 %28
}

LLVM IR (-O2):
@PATH_MAX = global i32 0
@ENAMETOOLONG = global i32 0
@errno = global i32 0
define i32 @mkfnv(i8* nocapture %0, i8* nocapture %1, i32 %2) {
%4 = load i32, i32* @PATH_MAX
%5 = tail call i32 @vsnprintf(i8* %0, i32 %4, i8* %1, i32 %2)
%6 = load i32, i32* @PATH_MAX
%7 = icmp slt i32 %5, %6
%8 = load i32, i32* @ENAMETOOLONG
%9 = icmp eq i32 %5, -1
%10 = load i32, i32* @errno
%11 = select i1 %9, i32 %10, i32 0
%12 = select i1 %7, i32 %11, i32 %8
ret i32 %12
}