#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 scalar_t__ int64_t;

/* Variables and functions */
scalar_t__ EINVAL;
scalar_t__ ENOSYS;
scalar_t__ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
scalar_t__ parrot_lsalloc(char const *, char *, scalar_t__ *, scalar_t__ *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stderr;
char *strerror(scalar_t__);
char *string_metric(scalar_t__, int, int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  const char *path;
  char alloc_path[4096];
  int64_t total, inuse;
  if (argc < 2) {
    path = ".";
  } else {
    path = argv[1];
  }
  if (argc > 2 || path[0] == '-') {
    printf("use: parrot_lsalloc [path]\n");
    return 0;
  }
  if (parrot_lsalloc(path, alloc_path, &total, &inuse) == 0) {
    printf("%s\n", alloc_path);
    printf("%sB TOTAL\n", string_metric(total, -1, 0));
    printf("%sB INUSE\n", string_metric(inuse, -1, 0));
    printf("%sB AVAIL\n", string_metric((total - inuse), -1, 0));
    return 0;
  } else {
    if (errno == ENOSYS || errno == EINVAL) {
      fprintf(
          stderr,
          "parrot_lsalloc: This filesystem does not support allocations.\n");
    } else {
      fprintf(stderr, "parrot_lsalloc: %s\n", strerror(errno));
    }
    return 1;
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1040,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    1183 <main+0x33>
lea    0xe86(%rip),%rax
mov    %rax,-0x18(%rbp)
jmp    118f <main+0x3f>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
cmpl   $0x2,-0x8(%rbp)
jg     11a9 <main+0x59>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2d,%eax
jne    11c3 <main+0x73>
lea    0xe52(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    130b <main+0x1bb>
mov    -0x18(%rbp),%rdi
lea    -0x1020(%rbp),%rsi
lea    -0x1028(%rbp),%rdx
lea    -0x1030(%rbp),%rcx
call   1060 <parrot_lsalloc@plt>
cmp    $0x0,%rax
jne    127f <main+0x12f>
lea    -0x1020(%rbp),%rsi
lea    0xe95(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x1028(%rbp),%rdi
mov    $0xffffffff,%esi
xor    %edx,%edx
call   1030 <string_metric@plt>
mov    %rax,%rsi
lea    0xe01(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x1030(%rbp),%rdi
mov    $0xffffffff,%esi
xor    %edx,%edx
call   1030 <string_metric@plt>
mov    %rax,%rsi
lea    0xde8(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x1028(%rbp),%rdi
sub    -0x1030(%rbp),%rdi
mov    $0xffffffff,%esi
xor    %edx,%edx
call   1030 <string_metric@plt>
mov    %rax,%rsi
lea    0xdc8(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    130b <main+0x1bb>
mov    0x2d4a(%rip),%rax
mov    (%rax),%rax
mov    0x2d58(%rip),%rcx
cmp    (%rcx),%rax
je     12b3 <main+0x163>
mov    0x2d30(%rip),%rax
mov    (%rax),%rax
mov    0x2d1e(%rip),%rcx
cmp    (%rcx),%rax
jne    12cf <main+0x17f>
mov    0x2d1e(%rip),%rax
mov    (%rax),%edi
lea    0xd7c(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
jmp    1304 <main+0x1b4>
mov    0x2d02(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1034(%rbp)
mov    0x2ceb(%rip),%rax
mov    (%rax),%rdi
call   1070 <strerror@plt>
mov    -0x1034(%rbp),%edi
mov    %rax,%rdx
lea    0xd81(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1040,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x1010,%rsp
cmp    $0x2,%edi
jge    117b <main+0x1b>
lea    0xe8c(%rip),%rdi
cmpb   $0x2d,(%rdi)
je     1186 <main+0x26>
jmp    1199 <main+0x39>
jne    1186 <main+0x26>
mov    0x8(%rsi),%rdi
cmpb   $0x2d,(%rdi)
jne    1199 <main+0x39>
lea    0xee9(%rip),%rdi
call   1030 <puts@plt>
xor    %ebx,%ebx
jmp    128c <main+0x12c>
lea    0x10(%rsp),%rsi
lea    0x8(%rsp),%rdx
mov    %rsp,%rcx
call   1070 <parrot_lsalloc@plt>
test   %rax,%rax
je     1200 <main+0xa0>
mov    0x2e19(%rip),%rax
mov    (%rax),%rdi
mov    0x2e27(%rip),%rax
mov    0x2e10(%rip),%rcx
mov    (%rcx),%ebx
cmp    (%rax),%rdi
je     1277 <main+0x117>
mov    0x2dee(%rip),%rax
cmp    (%rax),%rdi
je     1277 <main+0x117>
call   1080 <strerror@plt>
lea    0xe73(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1060 <fprintf@plt>
jmp    1287 <main+0x127>
lea    0x10(%rsp),%rdi
call   1030 <puts@plt>
mov    0x8(%rsp),%rdi
xor    %ebx,%ebx
mov    $0xffffffff,%esi
xor    %edx,%edx
call   1040 <string_metric@plt>
lea    0xdde(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    (%rsp),%rdi
mov    $0xffffffff,%esi
xor    %edx,%edx
call   1040 <string_metric@plt>
lea    0xdc8(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x8(%rsp),%rdi
sub    (%rsp),%rdi
mov    $0xffffffff,%esi
xor    %edx,%edx
call   1040 <string_metric@plt>
lea    0xdad(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    128c <main+0x12c>
lea    0xda5(%rip),%rsi
mov    %ebx,%edi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x1,%ebx
mov    %ebx,%eax
add    $0x1010,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [2 x i8] c".\00"
@.str.1 = [28 x i8] c"use: parrot_lsalloc [path]\0A\00"
@.str.2 = [4 x i8] c"%s\0A\00"
@.str.3 = [11 x i8] c"%sB TOTAL\0A\00"
@.str.4 = [11 x i8] c"%sB INUSE\0A\00"
@.str.5 = [11 x i8] c"%sB AVAIL\0A\00"
@errno = global i64 0
@ENOSYS = global i64 0
@EINVAL = global i64 0
@stderr = global i32 0
@.str.6 = [63 x i8] c"parrot_lsalloc: This filesystem does not support allocations.\0A\00"
@.str.7 = [20 x i8] c"parrot_lsalloc: %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca [4096 x i8]
%8 = alloca i64
%9 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp slt i32 %10, 2
br i1 %11, label %12, label %13
12: ; preds = %2
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8** %6
br label %17
13: ; preds = %2
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 1
%16 = load i8*, i8** %15
store i8* %16, i8** %6
br label %17
17: ; preds = %13, %12
%18 = load i32, i32* %4
%19 = icmp sgt i32 %18, 2
br i1 %19, label %26, label %20
20: ; preds = %17
%21 = load i8*, i8** %6
%22 = getelementptr inbounds i8, i8* %21, i64 0
%23 = load i8, i8* %22
%24 = sext i8 %23 to i32
%25 = icmp eq i32 %24, 45
br i1 %25, label %26, label %28
26: ; preds = %20, %17
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %3
br label %64
28: ; preds = %20
%29 = load i8*, i8** %6
%30 = getelementptr inbounds [4096 x i8], [4096 x i8]* %7, i64 0, i64 0
%31 = call i64 @parrot_lsalloc(i8* %29, i8* %30, i64* %8, i64* %9)
%32 = icmp eq i64 %31, 0
br i1 %32, label %33, label %47
33: ; preds = %28
%34 = getelementptr inbounds [4096 x i8], [4096 x i8]* %7, i64 0, i64 0
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %34)
%36 = load i64, i64* %8
%37 = call i8* @string_metric(i64 %36, i32 -1, i32 0)
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i8* %37)
%39 = load i64, i64* %9
%40 = call i8* @string_metric(i64 %39, i32 -1, i32 0)
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i8* %40)
%42 = load i64, i64* %8
%43 = load i64, i64* %9
%44 = sub nsw i64 %42, %43
%45 = call i8* @string_metric(i64 %44, i32 -1, i32 0)
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0), i8* %45)
store i32 0, i32* %3
br label %64
47: ; preds = %28
%48 = load i64, i64* @errno
%49 = load i64, i64* @ENOSYS
%50 = icmp eq i64 %48, %49
br i1 %50, label %55, label %51
51: ; preds = %47
%52 = load i64, i64* @errno
%53 = load i64, i64* @EINVAL
%54 = icmp eq i64 %52, %53
br i1 %54, label %55, label %58
55: ; preds = %51, %47
%56 = load i32, i32* @stderr
%57 = call i32 (i32, i8*, ...) @fprintf(i32 %56, i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str.6, i64 0, i64 0))
br label %63
58: ; preds = %51
%59 = load i32, i32* @stderr
%60 = load i64, i64* @errno
%61 = call i8* @strerror(i64 %60)
%62 = call i32 (i32, i8*, ...) @fprintf(i32 %59, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.7, i64 0, i64 0), i8* %61)
br label %63
63: ; preds = %58, %55
store i32 1, i32* %3
br label %64
64: ; preds = %63, %33, %26
%65 = load i32, i32* %3
ret i32 %65
}

LLVM IR (-O2):
@.str = [2 x i8] c".\00"
@.str.3 = [11 x i8] c"%sB TOTAL\0A\00"
@.str.4 = [11 x i8] c"%sB INUSE\0A\00"
@.str.5 = [11 x i8] c"%sB AVAIL\0A\00"
@errno = global i64 0
@ENOSYS = global i64 0
@EINVAL = global i64 0
@stderr = global i32 0
@.str.6 = [63 x i8] c"parrot_lsalloc: This filesystem does not support allocations.\0A\00"
@.str.7 = [20 x i8] c"parrot_lsalloc: %s\0A\00"
@str = [27 x i8] c"use: parrot_lsalloc [path]\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [4096 x i8]
%4 = alloca i64
%5 = alloca i64
%6 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%7 = bitcast i64* %4 to i8*
%8 = bitcast i64* %5 to i8*
%9 = icmp slt i32 %0, 2
br i1 %9, label %14, label %10
10: ; preds = %2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = icmp eq i32 %0, 2
br i1 %13, label %14, label %18
14: ; preds = %2, %10
%15 = phi i8* [ %12, %10 ], [ getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), %2 ]
%16 = load i8, i8* %15
%17 = icmp eq i8 %16, 45
br i1 %17, label %18, label %20
18: ; preds = %14, %10
%19 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str, i64 0, i64 0))
br label %49
20: ; preds = %14
%21 = call i64 @parrot_lsalloc(i8* %15, i8* %6, i64* %4, i64* %5)
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %36
23: ; preds = %20
%24 = call i32 @puts(i8* %6)
%25 = load i64, i64* %4
%26 = call i8* @string_metric(i64 %25, i32 -1, i32 0)
%27 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i8* %26)
%28 = load i64, i64* %5
%29 = call i8* @string_metric(i64 %28, i32 -1, i32 0)
%30 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i8* %29)
%31 = load i64, i64* %4
%32 = load i64, i64* %5
%33 = sub nsw i64 %31, %32
%34 = call i8* @string_metric(i64 %33, i32 -1, i32 0)
%35 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0), i8* %34)
br label %49
36: ; preds = %20
%37 = load i64, i64* @errno
%38 = load i64, i64* @ENOSYS
%39 = icmp eq i64 %37, %38
%40 = load i64, i64* @EINVAL
%41 = icmp eq i64 %37, %40
%42 = select i1 %39, i1 true, i1 %41
%43 = load i32, i32* @stderr
br i1 %42, label %44, label %46
44: ; preds = %36
%45 = call i32 (i32, i8*, ...) @fprintf(i32 %43, i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str.6, i64 0, i64 0))
br label %49
46: ; preds = %36
%47 = call i8* @strerror(i64 %37)
%48 = call i32 (i32, i8*, ...) @fprintf(i32 %43, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.7, i64 0, i64 0), i8* %47)
br label %49
49: ; preds = %44, %46, %23, %18
%50 = phi i32 [ 0, %18 ], [ 0, %23 ], [ 1, %46 ], [ 1, %44 ]
ret i32 %50
}