#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*/);
int path_max(const char *filename) {
  long result;
  if (!filename)
    filename = "/";
  errno = 0;
  result = pathconf(filename, _PC_PATH_MAX);
  if (result < 0) {
    if (errno)
      result = 256;
    else
      result = 1024;
  } else if (result < 256)
    result = 256;
  return result;
}


x86 assembly (clang, -O0):
<path_max>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    1132 <path_max+0x22>
lea    0xed2(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    0x2e9f(%rip),%rax
movq   $0x0,(%rax)
mov    -0x8(%rbp),%rdi
mov    0x2e95(%rip),%rax
mov    (%rax),%esi
call   1030 <pathconf@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jge    118c <path_max+0x7c>
mov    0x2e70(%rip),%rax
cmpq   $0x0,(%rax)
je     117f <path_max+0x6f>
movq   $0x100,-0x10(%rbp)
jmp    1187 <path_max+0x77>
movq   $0x400,-0x10(%rbp)
jmp    11a7 <path_max+0x97>
cmpq   $0x100,-0x10(%rbp)
jge    11a2 <path_max+0x92>
movq   $0x100,-0x10(%rbp)
jmp    11a7 <path_max+0x97>
mov    -0x10(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<path_max>:
push   %rbx
test   %rdi,%rdi
lea    0xee5(%rip),%rax
cmove  %rax,%rdi
mov    0x2eb2(%rip),%rbx
movq   $0x0,(%rbx)
mov    0x2eac(%rip),%rax
mov    (%rax),%esi
call   1030 <pathconf@plt>
test   %rax,%rax
js     1153 <path_max+0x43>
mov    %rax,%rcx
cmp    $0x101,%rax
mov    $0x100,%eax
cmovae %ecx,%eax
pop    %rbx
ret
cmpq   $0x0,(%rbx)
mov    $0x400,%ecx
mov    $0x100,%eax
cmove  %ecx,%eax
pop    %rbx
ret

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

LLVM IR (-O2):
@.str = [2 x i8] c"/\00"
@errno = global i64 0
@_PC_PATH_MAX = global i32 0
define i32 @path_max(i8* %0) {
%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
store i64 0, i64* @errno
%4 = load i32, i32* @_PC_PATH_MAX
%5 = tail call i64 @pathconf(i8* %3, i32 %4)
%6 = icmp slt i64 %5, 0
br i1 %6, label %7, label %11
7: ; preds = %1
%8 = load i64, i64* @errno
%9 = icmp eq i64 %8, 0
%10 = select i1 %9, i32 1024, i32 256
br label %15
11: ; preds = %1
%12 = icmp ugt i64 %5, 256
%13 = select i1 %12, i64 %5, i64 256
%14 = trunc i64 %13 to i32
br label %15
15: ; preds = %7, %11
%16 = phi i32 [ %14, %11 ], [ %10, %7 ]
ret i32 %16
}