#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 int /*<<< orphan*/ buf;

/* Variables and functions */
scalar_t__ EINVAL;
scalar_t__ ENOSYS;
scalar_t__ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int parrot_locate(char const *, char *, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stderr;
char *strerror(scalar_t__);
int main(int argc, char *argv[]) {
  const char *path;
  char buf[4096];
  int result;
  if (argc < 2) {
    path = ".";
  } else {
    path = argv[1];
  }
  if (argc > 2 || path[0] == '-') {
    printf("use: parrot_locate [path]\n");
    return 0;
  }
  result = parrot_locate(path, buf, sizeof(buf));
  if (result < 0) {
    if (errno == ENOSYS || errno == EINVAL)
      fprintf(stderr,
              "locate: This filesystem doesn't support parrot_locate\n");
    else
      fprintf(stderr, "locate: %s\n", strerror(errno));
    return 1;
  } else
    do {
      buf[result] = 0;
      printf("%s\n", buf);
    } while ((result = parrot_locate(NULL, buf, sizeof(buf))) > 0);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1030,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    1173 <main+0x33>
lea    0xe96(%rip),%rax
mov    %rax,-0x18(%rbp)
jmp    117f <main+0x3f>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
cmpl   $0x2,-0x8(%rbp)
jg     1199 <main+0x59>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2d,%eax
jne    11b3 <main+0x73>
lea    0xe62(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    12c5 <main+0x185>
mov    -0x18(%rbp),%rdi
lea    -0x1020(%rbp),%rsi
mov    $0x1000,%edx
call   1030 <parrot_locate@plt>
mov    %eax,-0x1024(%rbp)
cmpl   $0x0,-0x1024(%rbp)
jge    126c <main+0x12c>
mov    0x2dee(%rip),%rax
mov    (%rax),%rax
mov    0x2dfc(%rip),%rcx
cmp    (%rcx),%rax
je     120f <main+0xcf>
mov    0x2dd4(%rip),%rax
mov    (%rax),%rax
mov    0x2dc2(%rip),%rcx
cmp    (%rcx),%rax
jne    122b <main+0xeb>
mov    0x2dc2(%rip),%rax
mov    (%rax),%edi
lea    0xdfe(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
jmp    1260 <main+0x120>
mov    0x2da6(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1028(%rbp)
mov    0x2d8f(%rip),%rax
mov    (%rax),%rdi
call   1060 <strerror@plt>
mov    -0x1028(%rbp),%edi
mov    %rax,%rdx
lea    0xdfb(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12c5 <main+0x185>
jmp    1271 <main+0x131>
movslq -0x1024(%rbp),%rax
movb   $0x0,-0x1020(%rbp,%rax,1)
lea    -0x1020(%rbp),%rsi
lea    0xdce(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x1020(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edi
mov    $0x1000,%edx
call   1030 <parrot_locate@plt>
mov    %eax,-0x1024(%rbp)
cmp    $0x0,%eax
jg     1271 <main+0x131>
jmp    12be <main+0x17e>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1030,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x1008,%rsp
cmp    $0x2,%edi
jge    115d <main+0x1d>
lea    0xeaa(%rip),%rdi
cmpb   $0x2d,(%rdi)
je     1168 <main+0x28>
jmp    117b <main+0x3b>
jne    1168 <main+0x28>
mov    0x8(%rsi),%rdi
cmpb   $0x2d,(%rdi)
jne    117b <main+0x3b>
lea    0xed6(%rip),%rdi
call   1030 <puts@plt>
xor    %ebx,%ebx
jmp    120f <main+0xcf>
mov    %rsp,%rsi
mov    $0x1000,%edx
call   1040 <parrot_locate@plt>
test   %eax,%eax
js     11b5 <main+0x75>
mov    %rsp,%r14
nop
mov    %eax,%eax
movb   $0x0,(%rsp,%rax,1)
mov    %r14,%rdi
call   1030 <puts@plt>
xor    %ebx,%ebx
xor    %edi,%edi
mov    %r14,%rsi
mov    $0x1000,%edx
call   1040 <parrot_locate@plt>
test   %eax,%eax
jg     1190 <main+0x50>
jmp    120f <main+0xcf>
mov    0x2e14(%rip),%rax
mov    (%rax),%rdi
mov    0x2e22(%rip),%rax
mov    0x2e0b(%rip),%rcx
mov    (%rcx),%ebx
cmp    (%rax),%rdi
je     11fa <main+0xba>
mov    0x2ded(%rip),%rax
cmp    (%rax),%rdi
je     11fa <main+0xba>
call   1060 <strerror@plt>
lea    0xe4d(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1050 <fprintf@plt>
jmp    120a <main+0xca>
lea    0xe01(%rip),%rsi
mov    %ebx,%edi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0x1,%ebx
mov    %ebx,%eax
add    $0x1008,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
@.str = [2 x i8] c".\00"
@errno = global i64 0
@ENOSYS = global i64 0
@EINVAL = global i64 0
@stderr = global i32 0
@.str.2 = [55 x i8] c"locate: This filesystem doesn't support parrot_locate\0A\00"
@.str.3 = [12 x i8] c"locate: %s\0A\00"
@str = [26 x i8] c"use: parrot_locate [path]\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [4096 x i8]
%4 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%5 = icmp slt i32 %0, 2
br i1 %5, label %10, label %6
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = icmp eq i32 %0, 2
br i1 %9, label %10, label %14
10: ; preds = %2, %6
%11 = phi i8* [ %8, %6 ], [ getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), %2 ]
%12 = load i8, i8* %11
%13 = icmp eq i8 %12, 45
br i1 %13, label %14, label %16
14: ; preds = %10, %6
%15 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str, i64 0, i64 0))
br label %39
16: ; preds = %10
%17 = call i32 @parrot_locate(i8* %11, i8* %4, i32 4096)
%18 = icmp slt i32 %17, 0
br i1 %18, label %19, label %32
19: ; preds = %16
%20 = load i64, i64* @errno
%21 = load i64, i64* @ENOSYS
%22 = icmp eq i64 %20, %21
%23 = load i64, i64* @EINVAL
%24 = icmp eq i64 %20, %23
%25 = select i1 %22, i1 true, i1 %24
%26 = load i32, i32* @stderr
br i1 %25, label %27, label %29
27: ; preds = %19
%28 = call i32 (i32, i8*, ...) @fprintf(i32 %26, i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.2, i64 0, i64 0))
br label %39
29: ; preds = %19
%30 = call i8* @strerror(i64 %20)
%31 = call i32 (i32, i8*, ...) @fprintf(i32 %26, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8* %30)
br label %39
32: ; preds = %16, %32
%33 = phi i32 [ %37, %32 ], [ %17, %16 ]
%34 = zext i32 %33 to i64
%35 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 %34
store i8 0, i8* %35
%36 = call i32 @puts(i8* %4)
%37 = call i32 @parrot_locate(i8* null, i8* %4, i32 4096)
%38 = icmp sgt i32 %37, 0
br i1 %38, label %32, label %39
39: ; preds = %32, %27, %29, %14
%40 = phi i32 [ 0, %14 ], [ 1, %29 ], [ 1, %27 ], [ 0, %32 ]
ret i32 %40
}