#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 afp_volume {
  int dummy;
};
typedef int /*<<< orphan*/ mode_t;

/* Variables and functions */
int EBADF;
int EPERM;
int extra_translate(struct afp_volume *, char const *, char **);
int /*<<< orphan*/ free(char *);
int appledouble_creat(struct afp_volume *volume, const char *path,
                      mode_t mode) {
  int resource;
  char *newpath;
  resource = extra_translate(volume, path, &newpath);
  switch (resource) {
  case 1:
    free(newpath);
    return 1;
  case 2:
    free(newpath);
    return -EBADF;
  case 5:
    return -EPERM;
    return 1;
  case 3:
    free(newpath);
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<appledouble_creat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
lea    -0x28(%rbp),%rdx
call   1040 <extra_translate@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,%ecx
mov    %rcx,-0x30(%rbp)
sub    $0x4,%eax
ja     11c9 <appledouble_creat+0xa9>
mov    -0x30(%rbp),%rax
lea    0xe99(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movl   $0x1,-0x4(%rbp)
jmp    11d0 <appledouble_creat+0xb0>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
mov    0x2e49(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    11d0 <appledouble_creat+0xb0>
xor    %eax,%eax
mov    0x2e26(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    11d0 <appledouble_creat+0xb0>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movl   $0x1,-0x4(%rbp)
jmp    11d0 <appledouble_creat+0xb0>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<appledouble_creat>:
push   %rax
mov    %rsp,%rdx
call   1040 <extra_translate@plt>
mov    %eax,%ecx
xor    %eax,%eax
add    $0xffffffff,%ecx
cmp    $0x4,%ecx
ja     1153 <appledouble_creat+0x33>
lea    0xec4(%rip),%rdx
movslq (%rdx,%rcx,4),%rcx
add    %rdx,%rcx
jmp    *%rcx
mov    (%rsp),%rdi
call   1030 <free@plt>
mov    $0x1,%eax
pop    %rcx
ret
mov    (%rsp),%rdi
call   1030 <free@plt>
mov    0x2e7b(%rip),%rcx
jmp    116e <appledouble_creat+0x4e>
mov    0x2e62(%rip),%rcx
xor    %eax,%eax
sub    (%rcx),%eax
pop    %rcx
ret

LLVM IR (-O0):
%struct.afp_volume = type { i32 }
@EBADF = global i32 0
@EPERM = global i32 0
define i32 @appledouble_creat(%struct.afp_volume* %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca %struct.afp_volume*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
store %struct.afp_volume* %0, %struct.afp_volume** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
%10 = load %struct.afp_volume*, %struct.afp_volume** %5
%11 = load i8*, i8** %6
%12 = call i32 @extra_translate(%struct.afp_volume* %10, i8* %11, i8** %9)
store i32 %12, i32* %8
%13 = load i32, i32* %8
switch i32 %13, label %28 [
i32 1, label %14
i32 2, label %17
i32 5, label %22
i32 3, label %25
]
14: ; preds = %3
%15 = load i8*, i8** %9
%16 = call i32 @free(i8* %15)
store i32 1, i32* %4
br label %29
17: ; preds = %3
%18 = load i8*, i8** %9
%19 = call i32 @free(i8* %18)
%20 = load i32, i32* @EBADF
%21 = sub nsw i32 0, %20
store i32 %21, i32* %4
br label %29
22: ; preds = %3
%23 = load i32, i32* @EPERM
%24 = sub nsw i32 0, %23
store i32 %24, i32* %4
br label %29
25: ; preds = %3
%26 = load i8*, i8** %9
%27 = call i32 @free(i8* %26)
store i32 1, i32* %4
br label %29
28: ; preds = %3
store i32 0, i32* %4
br label %29
29: ; preds = %28, %25, %22, %17, %14
%30 = load i32, i32* %4
ret i32 %30
}

LLVM IR (-O2):
%struct.afp_volume = type { i32 }
@EBADF = global i32 0
@EPERM = global i32 0
define i32 @appledouble_creat(%struct.afp_volume* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = bitcast i8** %4 to i8*
%6 = call i32 @extra_translate(%struct.afp_volume* %0, i8* %1, i8** %4)
switch i32 %6, label %21 [
i32 1, label %7
i32 2, label %10
i32 5, label %15
i32 3, label %18
]
7: ; preds = %3
%8 = load i8*, i8** %4
%9 = call i32 @free(i8* %8)
br label %21
10: ; preds = %3
%11 = load i8*, i8** %4
%12 = call i32 @free(i8* %11)
%13 = load i32, i32* @EBADF
%14 = sub nsw i32 0, %13
br label %21
15: ; preds = %3
%16 = load i32, i32* @EPERM
%17 = sub nsw i32 0, %16
br label %21
18: ; preds = %3
%19 = load i8*, i8** %4
%20 = call i32 @free(i8* %19)
br label %21
21: ; preds = %3, %18, %15, %10, %7
%22 = phi i32 [ 1, %18 ], [ %17, %15 ], [ %14, %10 ], [ 1, %7 ], [ 0, %3 ]
ret i32 %22
}