#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 */
struct dir_entry {
  int dummy;
};

/* Variables and functions */
int dev_getdent(char *, int, struct dir_entry *);
int /*<<< orphan*/ get_dev_and_path(char *, short *, short *, char *);
int mx_getdent(short, char *, int, struct dir_entry *);
int /*<<< orphan*/ relpath_to_abspath(char const *, char *);
int /*<<< orphan*/ strncpy(char *, char const *, int);
int u_getdent(const char *path, int index, struct dir_entry *buf) {
  char localpath[256], abspath[256];
  short device, fs;
  if (*path != '/')
    relpath_to_abspath(path, abspath);
  else
    strncpy(abspath, path, 256);
  get_dev_and_path(abspath, &device, &fs, (char *)&localpath);
  switch (fs) {
  case 1:
    return mx_getdent(device, localpath, index, buf);
  case 2:
    return -1;
  case 3:
    return dev_getdent(localpath, index, buf);
  case 0:
    return -1;
  default:
    return -1;
  }
}


x86 assembly (clang, -O0):
<u_getdent>:
push   %rbp
mov    %rsp,%rbp
sub    $0x230,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
je     118b <u_getdent+0x3b>
mov    -0x10(%rbp),%rdi
lea    -0x220(%rbp),%rsi
call   1040 <relpath_to_abspath@plt>
jmp    11a0 <u_getdent+0x50>
lea    -0x220(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0x100,%edx
call   1030 <strncpy@plt>
lea    -0x220(%rbp),%rdi
lea    -0x222(%rbp),%rsi
lea    -0x224(%rbp),%rdx
lea    -0x120(%rbp),%rcx
call   1060 <get_dev_and_path@plt>
movswl -0x224(%rbp),%eax
mov    %eax,%ecx
mov    %rcx,-0x230(%rbp)
sub    $0x3,%eax
ja     1249 <u_getdent+0xf9>
mov    -0x230(%rbp),%rax
lea    0xe18(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x222(%rbp),%ax
lea    -0x120(%rbp),%rsi
mov    -0x14(%rbp),%edx
mov    -0x20(%rbp),%rcx
movswl %ax,%edi
call   1050 <mx_getdent@plt>
mov    %eax,-0x4(%rbp)
jmp    1250 <u_getdent+0x100>
movl   $0xffffffff,-0x4(%rbp)
jmp    1250 <u_getdent+0x100>
lea    -0x120(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x20(%rbp),%rdx
call   1070 <dev_getdent@plt>
mov    %eax,-0x4(%rbp)
jmp    1250 <u_getdent+0x100>
movl   $0xffffffff,-0x4(%rbp)
jmp    1250 <u_getdent+0x100>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x230,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<u_getdent>:
push   %rbp
push   %rbx
sub    $0x218,%rsp
mov    %rdx,%rbx
mov    %esi,%ebp
mov    %rdi,%rax
cmpb   $0x2f,(%rdi)
jne    117a <u_getdent+0x2a>
lea    0x10(%rsp),%rdi
mov    %rax,%rsi
mov    $0x100,%edx
call   1030 <strncpy@plt>
jmp    1187 <u_getdent+0x37>
lea    0x10(%rsp),%rsi
mov    %rax,%rdi
call   1040 <relpath_to_abspath@plt>
lea    0x10(%rsp),%rdi
lea    0xe(%rsp),%rsi
lea    0xc(%rsp),%rdx
lea    0x110(%rsp),%rcx
call   1060 <get_dev_and_path@plt>
movswl 0xc(%rsp),%ecx
cmp    $0x3,%ecx
je     11d0 <u_getdent+0x80>
mov    $0xffffffff,%eax
cmp    $0x1,%ecx
jne    11e2 <u_getdent+0x92>
movswl 0xe(%rsp),%edi
lea    0x110(%rsp),%rsi
mov    %ebp,%edx
mov    %rbx,%rcx
call   1050 <mx_getdent@plt>
jmp    11e2 <u_getdent+0x92>
lea    0x110(%rsp),%rdi
mov    %ebp,%esi
mov    %rbx,%rdx
call   1070 <dev_getdent@plt>
add    $0x218,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.dir_entry = type { i32 }
define i32 @u_getdent(i8* %0, i32 %1, %struct.dir_entry* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca %struct.dir_entry*
%8 = alloca [256 x i8]
%9 = alloca [256 x i8]
%10 = alloca i16
%11 = alloca i16
store i8* %0, i8** %5
store i32 %1, i32* %6
store %struct.dir_entry* %2, %struct.dir_entry** %7
%12 = load i8*, i8** %5
%13 = load i8, i8* %12
%14 = sext i8 %13 to i32
%15 = icmp ne i32 %14, 47
br i1 %15, label %16, label %20
16: ; preds = %3
%17 = load i8*, i8** %5
%18 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%19 = call i32 @relpath_to_abspath(i8* %17, i8* %18)
br label %24
20: ; preds = %3
%21 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%22 = load i8*, i8** %5
%23 = call i32 @strncpy(i8* %21, i8* %22, i32 256)
br label %24
24: ; preds = %20, %16
%25 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%26 = bitcast [256 x i8]* %8 to i8*
%27 = call i32 @get_dev_and_path(i8* %25, i16* %10, i16* %11, i8* %26)
%28 = load i16, i16* %11
%29 = sext i16 %28 to i32
switch i32 %29, label %43 [
i32 1, label %30
i32 2, label %36
i32 3, label %37
i32 0, label %42
]
30: ; preds = %24
%31 = load i16, i16* %10
%32 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%33 = load i32, i32* %6
%34 = load %struct.dir_entry*, %struct.dir_entry** %7
%35 = call i32 @mx_getdent(i16 signext %31, i8* %32, i32 %33, %struct.dir_entry* %34)
store i32 %35, i32* %4
br label %44
36: ; preds = %24
store i32 -1, i32* %4
br label %44
37: ; preds = %24
%38 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%39 = load i32, i32* %6
%40 = load %struct.dir_entry*, %struct.dir_entry** %7
%41 = call i32 @dev_getdent(i8* %38, i32 %39, %struct.dir_entry* %40)
store i32 %41, i32* %4
br label %44
42: ; preds = %24
store i32 -1, i32* %4
br label %44
43: ; preds = %24
store i32 -1, i32* %4
br label %44
44: ; preds = %43, %42, %37, %36, %30
%45 = load i32, i32* %4
ret i32 %45
}

LLVM IR (-O2):
%struct.dir_entry = type { i32 }
define i32 @u_getdent(i8* %0, i32 %1, %struct.dir_entry* %2) {
%4 = alloca [256 x i8]
%5 = alloca [256 x i8]
%6 = alloca i16
%7 = alloca i16
%8 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%9 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%10 = bitcast i16* %6 to i8*
%11 = bitcast i16* %7 to i8*
%12 = load i8, i8* %0
%13 = icmp eq i8 %12, 47
br i1 %13, label %16, label %14
14: ; preds = %3
%15 = call i32 @relpath_to_abspath(i8* %0, i8* %9)
br label %18
16: ; preds = %3
%17 = call i32 @strncpy(i8* %9, i8* %0, i32 256)
br label %18
18: ; preds = %16, %14
%19 = call i32 @get_dev_and_path(i8* %9, i16* %6, i16* %7, i8* %8)
%20 = load i16, i16* %7
%21 = sext i16 %20 to i32
switch i32 %21, label %27 [
i32 1, label %22
i32 3, label %25
]
22: ; preds = %18
%23 = load i16, i16* %6
%24 = call i32 @mx_getdent(i16 signext %23, i8* %8, i32 %1, %struct.dir_entry* %2)
br label %27
25: ; preds = %18
%26 = call i32 @dev_getdent(i8* %8, i32 %1, %struct.dir_entry* %2)
br label %27
27: ; preds = %18, %25, %22
%28 = phi i32 [ %26, %25 ], [ %24, %22 ], [ -1, %18 ]
ret i32 %28
}