#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 PATH_MAX;
long entry_size(char *);
int /*<<< orphan*/ error(char *);
int /*<<< orphan*/ *realpath(char const *, char *);
unsigned long space(const char *path) {
  char fpath[PATH_MAX];
  if (realpath(path, fpath) == NULL)
    error("main.realpath");
  long size = entry_size(fpath);
  if (size < 0)
    error("main.entry_size");
  return (unsigned long)size;
}


x86 assembly (clang, -O0):
<space>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    0x2ead(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x10(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rsi
sub    %rcx,%rsi
mov    %rsi,-0x28(%rbp)
mov    %rsi,%rsp
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <realpath@plt>
cmp    $0x0,%rax
jne    1187 <space+0x57>
lea    0xe7e(%rip),%rdi
call   1050 <error@plt>
mov    -0x28(%rbp),%rdi
call   1030 <entry_size@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jge    11ab <space+0x7b>
lea    0xe68(%rip),%rdi
call   1050 <error@plt>
mov    -0x20(%rbp),%rax
mov    -0x10(%rbp),%rcx
mov    %rcx,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<space>:
push   %rbp
mov    %rsp,%rbp
push   %rbx
push   %rax
mov    0x2eb3(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %rbx,%rsi
call   1040 <realpath@plt>
test   %rax,%rax
jne    1169 <space+0x39>
lea    0xe9c(%rip),%rdi
call   1050 <error@plt>
mov    %rbx,%rdi
call   1030 <entry_size@plt>
mov    %rax,%rbx
test   %rax,%rax
jns    1185 <space+0x55>
lea    0xe8e(%rip),%rdi
call   1050 <error@plt>
mov    %rbx,%rax
lea    -0x8(%rbp),%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@PATH_MAX = global i32 0
@.str = [14 x i8] c"main.realpath\00"
@.str.1 = [16 x i8] c"main.entry_size\00"
define i64 @space(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i64
store i8* %0, i8** %2
%6 = load i32, i32* @PATH_MAX
%7 = zext i32 %6 to i64
%8 = call i8* @llvm.stacksave()
store i8* %8, i8** %3
%9 = alloca i8, i64 %7
store i64 %7, i64* %4
%10 = load i8*, i8** %2
%11 = call i32* @realpath(i8* %10, i8* %9)
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %15
13: ; preds = %1
%14 = call i32 @error(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %15
15: ; preds = %13, %1
%16 = call i64 @entry_size(i8* %9)
store i64 %16, i64* %5
%17 = load i64, i64* %5
%18 = icmp slt i64 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %15
%20 = call i32 @error(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
br label %21
21: ; preds = %19, %15
%22 = load i64, i64* %5
%23 = load i8*, i8** %3
ret i64 %22
}

LLVM IR (-O2):
@PATH_MAX = global i32 0
@.str = [14 x i8] c"main.realpath\00"
@.str.1 = [16 x i8] c"main.entry_size\00"
define i64 @space(i8* nocapture %0) {
%2 = load i32, i32* @PATH_MAX
%3 = zext i32 %2 to i64
%4 = alloca i8, i64 %3
%5 = call i32* @realpath(i8* %0, i8* %4)
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %9
7: ; preds = %1
%8 = call i32 @error(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %9
9: ; preds = %7, %1
%10 = call i64 @entry_size(i8* %4)
%11 = icmp slt i64 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %9
%13 = call i32 @error(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
br label %14
14: ; preds = %12, %9
ret i64 %10
}