#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*/ memcpy(char *, char *, unsigned int);
int /*<<< orphan*/ read(int, ...);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ write(unsigned int, int *, int);
void pathserver(void) {
  char paths[(10 * 5) - 10 - 3][255];
  int npaths = 0;
  int i = 0;
  unsigned int plen = 0;
  unsigned int replyfd = 0;
  char path[255];
  memcpy(paths[npaths++], "/sys/pathserver", sizeof("/sys/pathserver"));
  while (1) {
    read((10 + 3), &replyfd, 4);
    read((10 + 3), &plen, 4);
    read((10 + 3), path, plen);
    if (!replyfd) {
      memcpy(paths[npaths++], path, plen);
    } else {
      for (i = 0; i < npaths; i++) {
        if (*paths[i] && strcmp(path, paths[i]) == 0) {
          i += 3;
          i += 10;
          write(replyfd, &i, 4);
          i = 0;
          break;
        }
      }
      if (i >= npaths) {
        i = -1;
        write(replyfd, &i, 4);
      }
    }
  }
}


x86 assembly (clang, -O0):
<pathserver>:
push   %rbp
mov    %rsp,%rbp
sub    $0x25f0,%rsp
movl   $0x0,-0x24e4(%rbp)
movl   $0x0,-0x24e8(%rbp)
movl   $0x0,-0x24ec(%rbp)
movl   $0x0,-0x24f0(%rbp)
mov    -0x24e4(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x24e4(%rbp)
cltq
lea    -0x24e0(%rbp),%rdi
imul   $0xff,%rax,%rax
add    %rax,%rdi
lea    0xe62(%rip),%rsi
mov    $0x10,%edx
call   1060 <memcpy@plt>
mov    $0xd,%edi
lea    -0x24f0(%rbp),%rsi
mov    $0x4,%edx
mov    $0x0,%al
call   1040 <read@plt>
mov    $0xd,%edi
lea    -0x24ec(%rbp),%rsi
mov    $0x4,%edx
mov    $0x0,%al
call   1040 <read@plt>
lea    -0x25f0(%rbp),%rsi
mov    -0x24ec(%rbp),%edx
mov    $0xd,%edi
mov    $0x0,%al
call   1040 <read@plt>
cmpl   $0x0,-0x24f0(%rbp)
jne    1239 <pathserver+0xf9>
mov    -0x24e4(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x24e4(%rbp)
cltq
lea    -0x24e0(%rbp),%rdi
imul   $0xff,%rax,%rax
add    %rax,%rdi
lea    -0x25f0(%rbp),%rsi
mov    -0x24ec(%rbp),%edx
call   1060 <memcpy@plt>
jmp    133c <pathserver+0x1fc>
movl   $0x0,-0x24e8(%rbp)
mov    -0x24e8(%rbp),%eax
cmp    -0x24e4(%rbp),%eax
jge    1304 <pathserver+0x1c4>
movslq -0x24e8(%rbp),%rcx
lea    -0x24e0(%rbp),%rax
imul   $0xff,%rcx,%rcx
add    %rcx,%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     12eb <pathserver+0x1ab>
lea    -0x25f0(%rbp),%rdi
movslq -0x24e8(%rbp),%rax
lea    -0x24e0(%rbp),%rsi
imul   $0xff,%rax,%rax
add    %rax,%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    12eb <pathserver+0x1ab>
mov    -0x24e8(%rbp),%eax
add    $0x3,%eax
mov    %eax,-0x24e8(%rbp)
mov    -0x24e8(%rbp),%eax
add    $0xa,%eax
mov    %eax,-0x24e8(%rbp)
mov    -0x24f0(%rbp),%edi
lea    -0x24e8(%rbp),%rsi
mov    $0x4,%edx
call   1030 <write@plt>
movl   $0x0,-0x24e8(%rbp)
jmp    1304 <pathserver+0x1c4>
jmp    12f0 <pathserver+0x1b0>
mov    -0x24e8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24e8(%rbp)
jmp    1243 <pathserver+0x103>
mov    -0x24e8(%rbp),%eax
cmp    -0x24e4(%rbp),%eax
jl     1337 <pathserver+0x1f7>
movl   $0xffffffff,-0x24e8(%rbp)
ff ff ff
mov    -0x24f0(%rbp),%edi
lea    -0x24e8(%rbp),%rsi
mov    $0x4,%edx
call   1030 <write@plt>
jmp    133c <pathserver+0x1fc>
jmp    11a8 <pathserver+0x68>

x86 assembly (clang, -O2):
<pathserver>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x25f8,%rsp
movl   $0x0,0x8(%rsp)
movl   $0x0,(%rsp)
lea    0xe99(%rip),%rsi
lea    0x110(%rsp),%rdi
mov    $0x10,%edx
call   1060 <memcpy@plt>
movl   $0x1,0xc(%rsp)
mov    %rsp,%r15
lea    0x8(%rsp),%r12
lea    0x10(%rsp),%rbx
xor    %r14d,%r14d
jmp    11ba <pathserver+0x7a>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movl   $0xffffffff,0x4(%rsp)
ff
mov    (%rsp),%edi
lea    0x4(%rsp),%rsi
mov    $0x4,%edx
call   1030 <write@plt>
mov    $0xd,%edi
mov    %r15,%rsi
mov    $0x4,%edx
xor    %eax,%eax
call   1040 <read@plt>
mov    $0xd,%edi
mov    %r12,%rsi
mov    $0x4,%edx
xor    %eax,%eax
call   1040 <read@plt>
mov    0x8(%rsp),%edx
mov    $0xd,%edi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <read@plt>
cmpl   $0x0,(%rsp)
je     125e <pathserver+0x11e>
mov    $0xffffffffffffffff,%r13
lea    0x110(%rsp),%rbp
jmp    1220 <pathserver+0xe0>
nopl   0x0(%rax)
add    $0x1,%r13
add    $0xff,%rbp
cmp    %r13,%r14
je     11a0 <pathserver+0x60>
cmpb   $0x0,0x0(%rbp)
je     1210 <pathserver+0xd0>
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
jne    1210 <pathserver+0xd0>
add    $0xe,%r13d
mov    %r13d,0x4(%rsp)
mov    (%rsp),%edi
lea    0x4(%rsp),%rsi
mov    $0x4,%edx
call   1030 <write@plt>
movl   $0x0,0x4(%rsp)
jmp    11ba <pathserver+0x7a>
mov    0xc(%rsp),%ecx
mov    %ecx,%eax
add    $0x1,%ecx
mov    %ecx,0xc(%rsp)
mov    %rax,%rcx
shl    $0x8,%rcx
sub    %rax,%rcx
lea    (%rsp,%rcx,1),%rdi
add    $0x110,%rdi
mov    0x8(%rsp),%edx
mov    %rbx,%rsi
call   1060 <memcpy@plt>
add    $0x1,%r14
jmp    11ba <pathserver+0x7a>

LLVM IR (-O0):
@.str = [16 x i8] c"/sys/pathserver\00"
define void @pathserver() {
%1 = alloca [37 x [255 x i8]]
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca [255 x i8]
store i32 0, i32* %2
store i32 0, i32* %3
store i32 0, i32* %4
store i32 0, i32* %5
%7 = load i32, i32* %2
%8 = add nsw i32 %7, 1
store i32 %8, i32* %2
%9 = sext i32 %7 to i64
%10 = getelementptr inbounds [37 x [255 x i8]], [37 x [255 x i8]]* %1, i64 0, i64 %9
%11 = getelementptr inbounds [255 x i8], [255 x i8]* %10, i64 0, i64 0
%12 = call i32 @memcpy(i8* %11, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 16)
br label %13
13: ; preds = %0, %70
%14 = call i32 (i32, ...) @read(i32 13, i32* %5, i32 4)
%15 = call i32 (i32, ...) @read(i32 13, i32* %4, i32 4)
%16 = getelementptr inbounds [255 x i8], [255 x i8]* %6, i64 0, i64 0
%17 = load i32, i32* %4
%18 = call i32 (i32, ...) @read(i32 13, i8* %16, i32 %17)
%19 = load i32, i32* %5
%20 = icmp ne i32 %19, 0
br i1 %20, label %30, label %21
21: ; preds = %13
%22 = load i32, i32* %2
%23 = add nsw i32 %22, 1
store i32 %23, i32* %2
%24 = sext i32 %22 to i64
%25 = getelementptr inbounds [37 x [255 x i8]], [37 x [255 x i8]]* %1, i64 0, i64 %24
%26 = getelementptr inbounds [255 x i8], [255 x i8]* %25, i64 0, i64 0
%27 = getelementptr inbounds [255 x i8], [255 x i8]* %6, i64 0, i64 0
%28 = load i32, i32* %4
%29 = call i32 @memcpy(i8* %26, i8* %27, i32 %28)
br label %70
30: ; preds = %13
store i32 0, i32* %3
br label %31
31: ; preds = %59, %30
%32 = load i32, i32* %3
%33 = load i32, i32* %2
%34 = icmp slt i32 %32, %33
br i1 %34, label %35, label %62
35: ; preds = %31
%36 = load i32, i32* %3
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds [37 x [255 x i8]], [37 x [255 x i8]]* %1, i64 0, i64 %37
%39 = getelementptr inbounds [255 x i8], [255 x i8]* %38, i64 0, i64 0
%40 = load i8, i8* %39
%41 = sext i8 %40 to i32
%42 = icmp ne i32 %41, 0
br i1 %42, label %43, label %58
43: ; preds = %35
%44 = getelementptr inbounds [255 x i8], [255 x i8]* %6, i64 0, i64 0
%45 = load i32, i32* %3
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds [37 x [255 x i8]], [37 x [255 x i8]]* %1, i64 0, i64 %46
%48 = getelementptr inbounds [255 x i8], [255 x i8]* %47, i64 0, i64 0
%49 = call i64 @strcmp(i8* %44, i8* %48)
%50 = icmp eq i64 %49, 0
br i1 %50, label %51, label %58
51: ; preds = %43
%52 = load i32, i32* %3
%53 = add nsw i32 %52, 3
store i32 %53, i32* %3
%54 = load i32, i32* %3
%55 = add nsw i32 %54, 10
store i32 %55, i32* %3
%56 = load i32, i32* %5
%57 = call i32 @write(i32 %56, i32* %3, i32 4)
store i32 0, i32* %3
br label %62
58: ; preds = %43, %35
br label %59
59: ; preds = %58
%60 = load i32, i32* %3
%61 = add nsw i32 %60, 1
store i32 %61, i32* %3
br label %31
62: ; preds = %51, %31
%63 = load i32, i32* %3
%64 = load i32, i32* %2
%65 = icmp sge i32 %63, %64
br i1 %65, label %66, label %69
66: ; preds = %62
store i32 -1, i32* %3
%67 = load i32, i32* %5
%68 = call i32 @write(i32 %67, i32* %3, i32 4)
br label %69
69: ; preds = %66, %62
br label %70
70: ; preds = %69, %21
br label %13
}

LLVM IR (-O2):
@.str = [16 x i8] c"/sys/pathserver\00"
define void @pathserver() {
%1 = alloca [37 x [255 x i8]]
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca [255 x i8]
%6 = getelementptr inbounds [37 x [255 x i8]], [37 x [255 x i8]]* %1, i64 0, i64 0, i64 0
%7 = bitcast i32* %2 to i8*
%8 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%9 = bitcast i32* %4 to i8*
store i32 0, i32* %4
%10 = getelementptr inbounds [255 x i8], [255 x i8]* %5, i64 0, i64 0
%11 = call i32 @memcpy(i8* %6, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 16)
br label %12
12: ; preds = %22, %0
%13 = phi i32 [ %23, %22 ], [ 1, %0 ]
%14 = zext i32 %13 to i64
br label %15
15: ; preds = %44, %12
%16 = call i32 (i32, ...) @read(i32 13, i32* %4, i32 4)
%17 = call i32 (i32, ...) @read(i32 13, i32* %3, i32 4)
%18 = load i32, i32* %3
%19 = call i32 (i32, ...) @read(i32 13, i8* %10, i32 %18)
%20 = load i32, i32* %4
%21 = icmp eq i32 %20, 0
br i1 %21, label %22, label %28
22: ; preds = %15
%23 = add nuw nsw i32 %13, 1
%24 = zext i32 %13 to i64
%25 = getelementptr inbounds [37 x [255 x i8]], [37 x [255 x i8]]* %1, i64 0, i64 %24, i64 0
%26 = load i32, i32* %3
%27 = call i32 @memcpy(i8* %25, i8* %10, i32 %26)
br label %12
28: ; preds = %15, %41
%29 = phi i64 [ %42, %41 ], [ 0, %15 ]
%30 = getelementptr inbounds [37 x [255 x i8]], [37 x [255 x i8]]* %1, i64 0, i64 %29, i64 0
%31 = load i8, i8* %30
%32 = icmp eq i8 %31, 0
br i1 %32, label %41, label %33
33: ; preds = %28
%34 = call i64 @strcmp(i8* %10, i8* %30)
%35 = icmp eq i64 %34, 0
br i1 %35, label %36, label %41
36: ; preds = %33
%37 = trunc i64 %29 to i32
%38 = add nuw nsw i32 %37, 13
store i32 %38, i32* %2
%39 = load i32, i32* %4
%40 = call i32 @write(i32 %39, i32* %2, i32 4)
store i32 0, i32* %2
br label %44
41: ; preds = %28, %33
%42 = add nuw nsw i64 %29, 1
%43 = icmp eq i64 %42, %14
br i1 %43, label %45, label %28
44: ; preds = %36, %45
br label %15
45: ; preds = %41
store i32 -1, i32* %2
%46 = load i32, i32* %4
%47 = call i32 @write(i32 %46, i32* %2, i32 4)
br label %44
}