#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 st_mode;
  int st_size;
};
struct afp_volume {
  int dummy;
};

/* Variables and functions */
int S_IFDIR;
int S_IFREG;
unsigned int extra_translate(struct afp_volume *, char const *, char **);
int /*<<< orphan*/ free(char *);
int get_comment_size(struct afp_volume *, char *, unsigned int);
int get_dirid(struct afp_volume *, char *, char *, unsigned int *);
int ll_getattr(struct afp_volume *, char *, struct stat *, int);
int appledouble_getattr(struct afp_volume *volume, const char *path,
                        struct stat *stbuf) {
  unsigned int resource;
  char *newpath;
  int ret;
  resource = extra_translate(volume, path, &newpath);
  switch (resource) {
  case 1:
    ll_getattr(volume, newpath, stbuf, 1);
    goto okay;
  case 2:
    stbuf->st_mode = 0700 | S_IFDIR;
    goto okay;
  case 3:
    ll_getattr(volume, newpath, stbuf, 0);
    stbuf->st_mode |= S_IFREG;
    stbuf->st_size = 32;
    goto okay;
  case 4: {
    unsigned int did;
    char basename[768];
    ret = ll_getattr(volume, newpath, stbuf, 0);
    if (ret < 0)
      goto error;
    ret = get_dirid(volume, newpath, basename, &did);
    if (ret < 0)
      goto error;
    ret = get_comment_size(volume, basename, did);
    if (ret < 0)
      goto error;
    stbuf->st_mode |= S_IFREG;
    stbuf->st_size = ret;
    goto okay;
  }
  case 5:
    stbuf->st_mode = S_IFREG | 0444;
    stbuf->st_size = 256;
    goto okay;
  }
  return 0;
okay:
  free(newpath);
  return 1;
error:
  free(newpath);
  return ret;
}


x86 assembly (clang, -O0):
<appledouble_getattr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x350,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
lea    -0x30(%rbp),%rdx
call   1040 <extra_translate@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,%ecx
mov    %rcx,-0x348(%rbp)
sub    $0x4,%eax
ja     12cc <appledouble_getattr+0x17c>
mov    -0x348(%rbp),%rax
lea    0xe5f(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x10(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    $0x1,%ecx
call   1070 <ll_getattr@plt>
jmp    12d8 <appledouble_getattr+0x188>
mov    0x2e04(%rip),%rax
mov    (%rax),%ecx
or     $0x1c0,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
jmp    12d8 <appledouble_getattr+0x188>
mov    -0x10(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x20(%rbp),%rdx
xor    %ecx,%ecx
call   1070 <ll_getattr@plt>
mov    0x2def(%rip),%rax
mov    (%rax),%ecx
mov    -0x20(%rbp),%rax
or     (%rax),%ecx
mov    %ecx,(%rax)
mov    -0x20(%rbp),%rax
movl   $0x20,0x4(%rax)
jmp    12d8 <appledouble_getattr+0x188>
mov    -0x10(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x20(%rbp),%rdx
xor    %ecx,%ecx
call   1070 <ll_getattr@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
jge    1238 <appledouble_getattr+0xe8>
jmp    12ed <appledouble_getattr+0x19d>
mov    -0x10(%rbp),%rdi
mov    -0x30(%rbp),%rsi
lea    -0x340(%rbp),%rdx
lea    -0x38(%rbp),%rcx
call   1050 <get_dirid@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
jge    1262 <appledouble_getattr+0x112>
jmp    12ed <appledouble_getattr+0x19d>
mov    -0x10(%rbp),%rdi
lea    -0x340(%rbp),%rsi
mov    -0x38(%rbp),%edx
call   1060 <get_comment_size@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
jge    1287 <appledouble_getattr+0x137>
jmp    12ed <appledouble_getattr+0x19d>
mov    0x2d5a(%rip),%rax
mov    (%rax),%ecx
mov    -0x20(%rbp),%rax
or     (%rax),%ecx
mov    %ecx,(%rax)
mov    -0x34(%rbp),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,0x4(%rax)
jmp    12d8 <appledouble_getattr+0x188>
mov    0x2d3a(%rip),%rax
mov    (%rax),%ecx
or     $0x124,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x20(%rbp),%rax
movl   $0x100,0x4(%rax)
jmp    12d8 <appledouble_getattr+0x188>
movl   $0x0,-0x4(%rbp)
jmp    12fc <appledouble_getattr+0x1ac>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
movl   $0x1,-0x4(%rbp)
jmp    12fc <appledouble_getattr+0x1ac>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x34(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x350,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<appledouble_getattr>:
push   %rbp
push   %r14
push   %rbx
sub    $0x310,%rsp
mov    %rdx,%r14
mov    %rdi,%rbx
mov    %rsp,%rdx
call   1040 <extra_translate@plt>
add    $0xffffffff,%eax
cmp    $0x4,%eax
ja     119f <appledouble_getattr+0x4f>
lea    0xe88(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    (%rsp),%rsi
mov    $0x1,%ebp
mov    %rbx,%rdi
mov    %r14,%rdx
mov    $0x1,%ecx
call   1070 <ll_getattr@plt>
jmp    1259 <appledouble_getattr+0x109>
xor    %ebp,%ebp
jmp    1262 <appledouble_getattr+0x112>
mov    0x2e23(%rip),%rax
mov    $0x1c0,%ecx
or     (%rax),%ecx
mov    %ecx,(%r14)
jmp    1254 <appledouble_getattr+0x104>
mov    (%rsp),%rsi
mov    %rbx,%rdi
mov    %r14,%rdx
xor    %ecx,%ecx
call   1070 <ll_getattr@plt>
mov    0x2e14(%rip),%rax
mov    (%rax),%eax
or     %eax,(%r14)
movl   $0x20,0x4(%r14)
jmp    1254 <appledouble_getattr+0x104>
mov    (%rsp),%rsi
mov    %rbx,%rdi
mov    %r14,%rdx
xor    %ecx,%ecx
call   1070 <ll_getattr@plt>
test   %eax,%eax
js     1270 <appledouble_getattr+0x120>
mov    (%rsp),%rsi
lea    0x10(%rsp),%rdx
lea    0xc(%rsp),%rcx
mov    %rbx,%rdi
call   1050 <get_dirid@plt>
test   %eax,%eax
js     1270 <appledouble_getattr+0x120>
mov    0xc(%rsp),%edx
lea    0x10(%rsp),%rsi
mov    %rbx,%rdi
call   1060 <get_comment_size@plt>
mov    %eax,%ebp
test   %eax,%eax
js     1259 <appledouble_getattr+0x109>
mov    0x2db8(%rip),%rax
mov    (%rax),%eax
or     %eax,(%r14)
mov    %ebp,0x4(%r14)
jmp    1254 <appledouble_getattr+0x104>
mov    0x2da6(%rip),%rax
mov    $0x124,%ecx
or     (%rax),%ecx
mov    %ecx,(%r14)
movl   $0x100,0x4(%r14)
mov    $0x1,%ebp
mov    (%rsp),%rdi
call   1030 <free@plt>
mov    %ebp,%eax
add    $0x310,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    %eax,%ebp
jmp    1259 <appledouble_getattr+0x109>

LLVM IR (-O0):
%struct.afp_volume = type { i32 }
%struct.stat = type { i32, i32 }
@S_IFDIR = global i32 0
@S_IFREG = global i32 0
define i32 @appledouble_getattr(%struct.afp_volume* %0, i8* %1, %struct.stat* %2) {
%4 = alloca i32
%5 = alloca %struct.afp_volume*
%6 = alloca i8*
%7 = alloca %struct.stat*
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i32
%12 = alloca [768 x i8]
store %struct.afp_volume* %0, %struct.afp_volume** %5
store i8* %1, i8** %6
store %struct.stat* %2, %struct.stat** %7
%13 = load %struct.afp_volume*, %struct.afp_volume** %5
%14 = load i8*, i8** %6
%15 = call i32 @extra_translate(%struct.afp_volume* %13, i8* %14, i8** %9)
store i32 %15, i32* %8
%16 = load i32, i32* %8
switch i32 %16, label %79 [
i32 1, label %17
i32 2, label %22
i32 3, label %27
i32 4, label %39
i32 5, label %72
]
17: ; preds = %3
%18 = load %struct.afp_volume*, %struct.afp_volume** %5
%19 = load i8*, i8** %9
%20 = load %struct.stat*, %struct.stat** %7
%21 = call i32 @ll_getattr(%struct.afp_volume* %18, i8* %19, %struct.stat* %20, i32 1)
br label %80
22: ; preds = %3
%23 = load i32, i32* @S_IFDIR
%24 = or i32 448, %23
%25 = load %struct.stat*, %struct.stat** %7
%26 = getelementptr inbounds %struct.stat, %struct.stat* %25, i32 0, i32 0
store i32 %24, i32* %26
br label %80
27: ; preds = %3
%28 = load %struct.afp_volume*, %struct.afp_volume** %5
%29 = load i8*, i8** %9
%30 = load %struct.stat*, %struct.stat** %7
%31 = call i32 @ll_getattr(%struct.afp_volume* %28, i8* %29, %struct.stat* %30, i32 0)
%32 = load i32, i32* @S_IFREG
%33 = load %struct.stat*, %struct.stat** %7
%34 = getelementptr inbounds %struct.stat, %struct.stat* %33, i32 0, i32 0
%35 = load i32, i32* %34
%36 = or i32 %35, %32
store i32 %36, i32* %34
%37 = load %struct.stat*, %struct.stat** %7
%38 = getelementptr inbounds %struct.stat, %struct.stat* %37, i32 0, i32 1
store i32 32, i32* %38
br label %80
39: ; preds = %3
%40 = load %struct.afp_volume*, %struct.afp_volume** %5
%41 = load i8*, i8** %9
%42 = load %struct.stat*, %struct.stat** %7
%43 = call i32 @ll_getattr(%struct.afp_volume* %40, i8* %41, %struct.stat* %42, i32 0)
store i32 %43, i32* %10
%44 = load i32, i32* %10
%45 = icmp slt i32 %44, 0
br i1 %45, label %46, label %47
46: ; preds = %39
br label %83
47: ; preds = %39
%48 = load %struct.afp_volume*, %struct.afp_volume** %5
%49 = load i8*, i8** %9
%50 = getelementptr inbounds [768 x i8], [768 x i8]* %12, i64 0, i64 0
%51 = call i32 @get_dirid(%struct.afp_volume* %48, i8* %49, i8* %50, i32* %11)
store i32 %51, i32* %10
%52 = load i32, i32* %10
%53 = icmp slt i32 %52, 0
br i1 %53, label %54, label %55
54: ; preds = %47
br label %83
55: ; preds = %47
%56 = load %struct.afp_volume*, %struct.afp_volume** %5
%57 = getelementptr inbounds [768 x i8], [768 x i8]* %12, i64 0, i64 0
%58 = load i32, i32* %11
%59 = call i32 @get_comment_size(%struct.afp_volume* %56, i8* %57, i32 %58)
store i32 %59, i32* %10
%60 = load i32, i32* %10
%61 = icmp slt i32 %60, 0
br i1 %61, label %62, label %63
62: ; preds = %55
br label %83
63: ; preds = %55
%64 = load i32, i32* @S_IFREG
%65 = load %struct.stat*, %struct.stat** %7
%66 = getelementptr inbounds %struct.stat, %struct.stat* %65, i32 0, i32 0
%67 = load i32, i32* %66
%68 = or i32 %67, %64
store i32 %68, i32* %66
%69 = load i32, i32* %10
%70 = load %struct.stat*, %struct.stat** %7
%71 = getelementptr inbounds %struct.stat, %struct.stat* %70, i32 0, i32 1
store i32 %69, i32* %71
br label %80
72: ; preds = %3
%73 = load i32, i32* @S_IFREG
%74 = or i32 %73, 292
%75 = load %struct.stat*, %struct.stat** %7
%76 = getelementptr inbounds %struct.stat, %struct.stat* %75, i32 0, i32 0
store i32 %74, i32* %76
%77 = load %struct.stat*, %struct.stat** %7
%78 = getelementptr inbounds %struct.stat, %struct.stat* %77, i32 0, i32 1
store i32 256, i32* %78
br label %80
79: ; preds = %3
store i32 0, i32* %4
br label %87
80: ; preds = %72, %63, %27, %22, %17
%81 = load i8*, i8** %9
%82 = call i32 @free(i8* %81)
store i32 1, i32* %4
br label %87
83: ; preds = %62, %54, %46
%84 = load i8*, i8** %9
%85 = call i32 @free(i8* %84)
%86 = load i32, i32* %10
store i32 %86, i32* %4
br label %87
87: ; preds = %83, %80, %79
%88 = load i32, i32* %4
ret i32 %88
}

LLVM IR (-O2):
%struct.afp_volume = type { i32 }
%struct.stat = type { i32, i32 }
@S_IFDIR = global i32 0
@S_IFREG = global i32 0
define i32 @appledouble_getattr(%struct.afp_volume* %0, i8* %1, %struct.stat* %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca [768 x i8]
%7 = bitcast i8** %4 to i8*
%8 = call i32 @extra_translate(%struct.afp_volume* %0, i8* %1, i8** %4)
switch i32 %8, label %55 [
i32 1, label %9
i32 2, label %12
i32 3, label %16
i32 4, label %24
i32 5, label %44
]
9: ; preds = %3
%10 = load i8*, i8** %4
%11 = call i32 @ll_getattr(%struct.afp_volume* %0, i8* %10, %struct.stat* %2, i32 1)
br label %51
12: ; preds = %3
%13 = load i32, i32* @S_IFDIR
%14 = or i32 %13, 448
%15 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 0
store i32 %14, i32* %15
br label %51
16: ; preds = %3
%17 = load i8*, i8** %4
%18 = call i32 @ll_getattr(%struct.afp_volume* %0, i8* %17, %struct.stat* %2, i32 0)
%19 = load i32, i32* @S_IFREG
%20 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 0
%21 = load i32, i32* %20
%22 = or i32 %21, %19
store i32 %22, i32* %20
%23 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 1
store i32 32, i32* %23
br label %51
24: ; preds = %3
%25 = bitcast i32* %5 to i8*
%26 = getelementptr inbounds [768 x i8], [768 x i8]* %6, i64 0, i64 0
%27 = load i8*, i8** %4
%28 = call i32 @ll_getattr(%struct.afp_volume* %0, i8* %27, %struct.stat* %2, i32 0)
%29 = icmp slt i32 %28, 0
br i1 %29, label %49, label %30
30: ; preds = %24
%31 = load i8*, i8** %4
%32 = call i32 @get_dirid(%struct.afp_volume* %0, i8* %31, i8* %26, i32* %5)
%33 = icmp slt i32 %32, 0
br i1 %33, label %49, label %34
34: ; preds = %30
%35 = load i32, i32* %5
%36 = call i32 @get_comment_size(%struct.afp_volume* %0, i8* %26, i32 %35)
%37 = icmp slt i32 %36, 0
br i1 %37, label %49, label %38
38: ; preds = %34
%39 = load i32, i32* @S_IFREG
%40 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 0
%41 = load i32, i32* %40
%42 = or i32 %41, %39
store i32 %42, i32* %40
%43 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 1
store i32 %36, i32* %43
br label %51
44: ; preds = %3
%45 = load i32, i32* @S_IFREG
%46 = or i32 %45, 292
%47 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 0
store i32 %46, i32* %47
%48 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 1
store i32 256, i32* %48
br label %51
49: ; preds = %24, %30, %34
%50 = phi i32 [ %36, %34 ], [ %32, %30 ], [ %28, %24 ]
br label %51
51: ; preds = %9, %12, %16, %44, %38, %49
%52 = phi i32 [ %50, %49 ], [ 1, %38 ], [ 1, %44 ], [ 1, %16 ], [ 1, %12 ], [ 1, %9 ]
%53 = load i8*, i8** %4
%54 = call i32 @free(i8* %53)
br label %55
55: ; preds = %51, %3
%56 = phi i32 [ 0, %3 ], [ %52, %51 ]
ret i32 %56
}