#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 stat {
  int dummy;
};

/* Variables and functions */
int dev_stat(char *, struct stat *);
int /*<<< orphan*/ get_dev_and_path(char *, short *, short *, char *);
int mx_stat(short, char *, struct stat *);
int /*<<< orphan*/ relpath_to_abspath(char const *, char *);
int /*<<< orphan*/ strncpy(char *, char const *, int);
int u_stat(const char *path, struct stat *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_stat(device, localpath, buf);
  case 2:
    return -1;
  case 3:
    return dev_stat(localpath, buf);
  case 0:
    return -1;
  default:
    return -1;
  }
}


x86 assembly (clang, -O0):
<u_stat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x230,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
je     1188 <u_stat+0x38>
mov    -0x10(%rbp),%rdi
lea    -0x220(%rbp),%rsi
call   1040 <relpath_to_abspath@plt>
jmp    119d <u_stat+0x4d>
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     1240 <u_stat+0xf0>
mov    -0x230(%rbp),%rax
lea    0xe1b(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x222(%rbp),%ax
lea    -0x120(%rbp),%rsi
mov    -0x18(%rbp),%rdx
movswl %ax,%edi
call   1050 <mx_stat@plt>
mov    %eax,-0x4(%rbp)
jmp    1247 <u_stat+0xf7>
movl   $0xffffffff,-0x4(%rbp)
jmp    1247 <u_stat+0xf7>
lea    -0x120(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1070 <dev_stat@plt>
mov    %eax,-0x4(%rbp)
jmp    1247 <u_stat+0xf7>
movl   $0xffffffff,-0x4(%rbp)
jmp    1247 <u_stat+0xf7>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x230,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<u_stat>:
push   %rbx
sub    $0x210,%rsp
mov    %rsi,%rbx
mov    %rdi,%rax
cmpb   $0x2f,(%rdi)
jne    1177 <u_stat+0x27>
lea    0x10(%rsp),%rdi
mov    %rax,%rsi
mov    $0x100,%edx
call   1030 <strncpy@plt>
jmp    1184 <u_stat+0x34>
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     11cb <u_stat+0x7b>
mov    $0xffffffff,%eax
cmp    $0x1,%ecx
jne    11db <u_stat+0x8b>
movswl 0xe(%rsp),%edi
lea    0x110(%rsp),%rsi
mov    %rbx,%rdx
call   1050 <mx_stat@plt>
jmp    11db <u_stat+0x8b>
lea    0x110(%rsp),%rdi
mov    %rbx,%rsi
call   1070 <dev_stat@plt>
add    $0x210,%rsp
pop    %rbx
ret

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

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