#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 */
long BUFSIZ;
int /*<<< orphan*/ _PC_PATH_MAX;
char *emalloc(long);
int /*<<< orphan*/ eprintf(char *);
scalar_t__ errno;
long pathconf(char *, int /*<<< orphan*/);
void apathmax(char **p, long *size) {
  errno = 0;
  if ((*size = pathconf("/", _PC_PATH_MAX)) == -1) {
    if (errno == 0) {
      *size = BUFSIZ;
    } else {
      eprintf("pathconf:");
    }
  }
  *p = emalloc(*size);
}


x86 assembly (clang, -O0):
<apathmax>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e89(%rip),%rax
movq   $0x0,(%rax)
mov    0x2e8b(%rip),%rax
mov    (%rax),%esi
lea    0xea2(%rip),%rdi
call   1030 <pathconf@plt>
mov    -0x10(%rbp),%rcx
mov    %rax,(%rcx)
cmp    $0xffffffffffffffff,%rax
jne    11ac <apathmax+0x7c>
mov    0x2e55(%rip),%rax
cmpq   $0x0,(%rax)
jne    119b <apathmax+0x6b>
mov    0x2e4c(%rip),%rax
mov    (%rax),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
jmp    11a7 <apathmax+0x77>
lea    0xe60(%rip),%rdi
call   1050 <eprintf@plt>
jmp    11ac <apathmax+0x7c>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1040 <emalloc@plt>
mov    %rax,%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<apathmax>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%rbx
mov    %rdi,%r14
mov    0x2e8e(%rip),%r15
movq   $0x0,(%r15)
mov    0x2e90(%rip),%rax
mov    (%rax),%esi
lea    0xea7(%rip),%rdi
call   1030 <pathconf@plt>
mov    %rax,(%rbx)
cmp    $0xffffffffffffffff,%rax
jne    118b <apathmax+0x5b>
cmpq   $0x0,(%r15)
je     117e <apathmax+0x4e>
lea    0xe8e(%rip),%rdi
call   1050 <eprintf@plt>
mov    (%rbx),%rax
jmp    118b <apathmax+0x5b>
mov    0x2e53(%rip),%rax
mov    (%rax),%rax
mov    %rax,(%rbx)
mov    %rax,%rdi
call   1040 <emalloc@plt>
mov    %rax,(%r14)
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@errno = global i64 0
@.str = [2 x i8] c"/\00"
@_PC_PATH_MAX = global i32 0
@BUFSIZ = global i64 0
@.str.1 = [10 x i8] c"pathconf:\00"
define void @apathmax(i8** %0, i64* %1) {
%3 = alloca i8**
%4 = alloca i64*
store i8** %0, i8*** %3
store i64* %1, i64** %4
store i64 0, i64* @errno
%5 = load i32, i32* @_PC_PATH_MAX
%6 = call i64 @pathconf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 %5)
%7 = load i64*, i64** %4
store i64 %6, i64* %7
%8 = icmp eq i64 %6, -1
br i1 %8, label %9, label %18
9: ; preds = %2
%10 = load i64, i64* @errno
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %9
%13 = load i64, i64* @BUFSIZ
%14 = load i64*, i64** %4
store i64 %13, i64* %14
br label %17
15: ; preds = %9
%16 = call i32 @eprintf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
br label %17
17: ; preds = %15, %12
br label %18
18: ; preds = %17, %2
%19 = load i64*, i64** %4
%20 = load i64, i64* %19
%21 = call i8* @emalloc(i64 %20)
%22 = load i8**, i8*** %3
store i8* %21, i8** %22
ret void
}

LLVM IR (-O2):
@errno = global i64 0
@.str = [2 x i8] c"/\00"
@_PC_PATH_MAX = global i32 0
@BUFSIZ = global i64 0
@.str.1 = [10 x i8] c"pathconf:\00"
define void @apathmax(i8** nocapture writeonly %0, i64* nocapture %1) {
store i64 0, i64* @errno
%3 = load i32, i32* @_PC_PATH_MAX
%4 = tail call i64 @pathconf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 %3)
store i64 %4, i64* %1
%5 = icmp eq i64 %4, -1
br i1 %5, label %6, label %14
6: ; preds = %2
%7 = load i64, i64* @errno
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %6
%10 = load i64, i64* @BUFSIZ
store i64 %10, i64* %1
br label %14
11: ; preds = %6
%12 = tail call i32 @eprintf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%13 = load i64, i64* %1
br label %14
14: ; preds = %9, %11, %2
%15 = phi i64 [ %10, %9 ], [ %13, %11 ], [ %4, %2 ]
%16 = tail call i8* @emalloc(i64 %15)
store i8* %16, i8** %0
ret void
}