#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 /*<<< orphan*/ _PC_PATH_MAX;
scalar_t__ errno;
long pathconf(char const *, int /*<<< orphan*/);
size_t get_pathmax(const char *ptr __attribute__((__unused__))) {
  long int pathmax;
  errno = 0;
  pathmax = pathconf(ptr ? ptr : "/", _PC_PATH_MAX);
  if (pathmax < 0 && errno)
    return 256;
  if (pathmax < 0 || pathmax > 4096)
    return 4096;
  return (size_t)pathmax;
}


x86 assembly (clang, -O0):
<get_pathmax>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    0x2eb5(%rip),%rax
movq   $0x0,(%rax)
cmpq   $0x0,-0x10(%rbp)
je     1142 <get_pathmax+0x32>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
jmp    1152 <get_pathmax+0x42>
lea    0xeb7(%rip),%rax
mov    %rax,-0x20(%rbp)
jmp    1152 <get_pathmax+0x42>
mov    -0x20(%rbp),%rdi
mov    0x2e83(%rip),%rax
mov    (%rax),%esi
call   1030 <pathconf@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jge    1191 <get_pathmax+0x81>
mov    0x2e5e(%rip),%rax
cmpq   $0x0,(%rax)
je     1191 <get_pathmax+0x81>
movq   $0x100,-0x8(%rbp)
jmp    11bf <get_pathmax+0xaf>
cmpq   $0x0,-0x18(%rbp)
jl     11aa <get_pathmax+0x9a>
cmpq   $0x1000,-0x18(%rbp)
jle    11b7 <get_pathmax+0xa7>
movq   $0x1000,-0x8(%rbp)
jmp    11bf <get_pathmax+0xaf>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_pathmax>:
push   %rbx
mov    0x2ec0(%rip),%rbx
movq   $0x0,(%rbx)
test   %rdi,%rdi
lea    0xed7(%rip),%rax
cmove  %rax,%rdi
mov    0x2eac(%rip),%rax
mov    (%rax),%esi
call   1030 <pathconf@plt>
cmp    $0x1000,%rax
mov    $0x1000,%edx
cmovb  %rax,%rdx
cmpq   $0x0,(%rbx)
mov    $0x100,%ecx
cmove  %rdx,%rcx
test   %rax,%rax
cmovns %rdx,%rcx
mov    %rcx,%rax
pop    %rbx
ret

LLVM IR (-O0):
@errno = global i64 0
@.str = [2 x i8] c"/\00"
@_PC_PATH_MAX = global i32 0
define i64 @get_pathmax(i8* %0) {
%2 = alloca i64
%3 = alloca i8*
%4 = alloca i64
store i8* %0, i8** %3
store i64 0, i64* @errno
%5 = load i8*, i8** %3
%6 = icmp ne i8* %5, null
br i1 %6, label %7, label %9
7: ; preds = %1
%8 = load i8*, i8** %3
br label %10
9: ; preds = %1
br label %10
10: ; preds = %9, %7
%11 = phi i8* [ %8, %7 ], [ getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), %9 ]
%12 = load i32, i32* @_PC_PATH_MAX
%13 = call i64 @pathconf(i8* %11, i32 %12)
store i64 %13, i64* %4
%14 = load i64, i64* %4
%15 = icmp slt i64 %14, 0
br i1 %15, label %16, label %20
16: ; preds = %10
%17 = load i64, i64* @errno
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %20
19: ; preds = %16
store i64 256, i64* %2
br label %29
20: ; preds = %16, %10
%21 = load i64, i64* %4
%22 = icmp slt i64 %21, 0
br i1 %22, label %26, label %23
23: ; preds = %20
%24 = load i64, i64* %4
%25 = icmp sgt i64 %24, 4096
br i1 %25, label %26, label %27
26: ; preds = %23, %20
store i64 4096, i64* %2
br label %29
27: ; preds = %23
%28 = load i64, i64* %4
store i64 %28, i64* %2
br label %29
29: ; preds = %27, %26, %19
%30 = load i64, i64* %2
ret i64 %30
}

LLVM IR (-O2):
@errno = global i64 0
@.str = [2 x i8] c"/\00"
@_PC_PATH_MAX = global i32 0
define i64 @get_pathmax(i8* %0) {
store i64 0, i64* @errno
%2 = icmp eq i8* %0, null
%3 = select i1 %2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8* %0
%4 = load i32, i32* @_PC_PATH_MAX
%5 = tail call i64 @pathconf(i8* %3, i32 %4)
%6 = icmp slt i64 %5, 0
%7 = load i64, i64* @errno
%8 = icmp ne i64 %7, 0
%9 = select i1 %6, i1 %8, i1 false
%10 = icmp ult i64 %5, 4096
%11 = select i1 %10, i64 %5, i64 4096
%12 = select i1 %9, i64 256, i64 %11
ret i64 %12
}