#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 EIO;
int EPERM;
int W_OK;
int X_OK;
int fhandle_access(char *, int);
int /*<<< orphan*/ sfree(char *);
char *string_fmt(char *, char const *);
int url_getfile(char *, char *);
char *url_gethashedfilename(char const *);
int url_accessfcn(const char *path, int amode) {
  char *rpath = string_fmt("http://%s", path);
  char *lpath = url_gethashedfilename(path);
  int err;
  if (amode & W_OK) {
    sfree(lpath);
    sfree(rpath);
    return -EIO;
  }
  if (amode & X_OK) {
    sfree(lpath);
    sfree(rpath);
    return -EPERM;
  }
  err = fhandle_access(lpath, amode);
  if (!err) {
    sfree(lpath);
    sfree(rpath);
    return 0;
  }
  err = url_getfile(rpath, lpath);
  return err;
}


x86 assembly (clang, -O0):
<url_accessfcn>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xe96(%rip),%rdi
call   1040 <string_fmt@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1070 <url_gethashedfilename@plt>
mov    %rax,-0x28(%rbp)
mov    -0x14(%rbp),%eax
mov    0x2e5e(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     11ba <url_accessfcn+0x6a>
mov    -0x28(%rbp),%rdi
call   1030 <sfree@plt>
mov    -0x20(%rbp),%rdi
call   1030 <sfree@plt>
xor    %eax,%eax
mov    0x2e20(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    1241 <url_accessfcn+0xf1>
mov    -0x14(%rbp),%eax
mov    0x2e1c(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     11f4 <url_accessfcn+0xa4>
mov    -0x28(%rbp),%rdi
call   1030 <sfree@plt>
mov    -0x20(%rbp),%rdi
call   1030 <sfree@plt>
xor    %eax,%eax
mov    0x2dd6(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    1241 <url_accessfcn+0xf1>
mov    -0x28(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1060 <fhandle_access@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jne    122b <url_accessfcn+0xdb>
mov    -0x28(%rbp),%rdi
call   1030 <sfree@plt>
mov    -0x20(%rbp),%rdi
call   1030 <sfree@plt>
movl   $0x0,-0x4(%rbp)
jmp    1241 <url_accessfcn+0xf1>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1050 <url_getfile@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<url_accessfcn>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%ebp
mov    %rdi,%rbx
lea    0xea0(%rip),%rdi
mov    %rbx,%rsi
call   1040 <string_fmt@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1070 <url_gethashedfilename@plt>
mov    %rax,%rbx
mov    0x2e6b(%rip),%rax
test   %ebp,(%rax)
je     119a <url_accessfcn+0x4a>
mov    %rbx,%rdi
call   1030 <sfree@plt>
mov    %r14,%rdi
call   1030 <sfree@plt>
mov    0x2e38(%rip),%rcx
jmp    11bc <url_accessfcn+0x6c>
mov    0x2e3f(%rip),%rax
test   %ebp,(%rax)
je     11c5 <url_accessfcn+0x75>
mov    %rbx,%rdi
call   1030 <sfree@plt>
mov    %r14,%rdi
call   1030 <sfree@plt>
mov    0x2e04(%rip),%rcx
xor    %eax,%eax
sub    (%rcx),%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    %rbx,%rdi
mov    %ebp,%esi
call   1060 <fhandle_access@plt>
test   %eax,%eax
je     11e2 <url_accessfcn+0x92>
mov    %r14,%rdi
mov    %rbx,%rsi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1050 <url_getfile@plt>
mov    %rbx,%rdi
call   1030 <sfree@plt>
mov    %r14,%rdi
call   1030 <sfree@plt>
xor    %eax,%eax
jmp    11c0 <url_accessfcn+0x70>

LLVM IR (-O0):
@.str = [10 x i8] c"http://%s\00"
@W_OK = global i32 0
@EIO = global i32 0
@X_OK = global i32 0
@EPERM = global i32 0
define i32 @url_accessfcn(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
%9 = load i8*, i8** %4
%10 = call i8* @string_fmt(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* %9)
store i8* %10, i8** %6
%11 = load i8*, i8** %4
%12 = call i8* @url_gethashedfilename(i8* %11)
store i8* %12, i8** %7
%13 = load i32, i32* %5
%14 = load i32, i32* @W_OK
%15 = and i32 %13, %14
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %24
17: ; preds = %2
%18 = load i8*, i8** %7
%19 = call i32 @sfree(i8* %18)
%20 = load i8*, i8** %6
%21 = call i32 @sfree(i8* %20)
%22 = load i32, i32* @EIO
%23 = sub nsw i32 0, %22
store i32 %23, i32* %3
br label %52
24: ; preds = %2
%25 = load i32, i32* %5
%26 = load i32, i32* @X_OK
%27 = and i32 %25, %26
%28 = icmp ne i32 %27, 0
br i1 %28, label %29, label %36
29: ; preds = %24
%30 = load i8*, i8** %7
%31 = call i32 @sfree(i8* %30)
%32 = load i8*, i8** %6
%33 = call i32 @sfree(i8* %32)
%34 = load i32, i32* @EPERM
%35 = sub nsw i32 0, %34
store i32 %35, i32* %3
br label %52
36: ; preds = %24
%37 = load i8*, i8** %7
%38 = load i32, i32* %5
%39 = call i32 @fhandle_access(i8* %37, i32 %38)
store i32 %39, i32* %8
%40 = load i32, i32* %8
%41 = icmp ne i32 %40, 0
br i1 %41, label %47, label %42
42: ; preds = %36
%43 = load i8*, i8** %7
%44 = call i32 @sfree(i8* %43)
%45 = load i8*, i8** %6
%46 = call i32 @sfree(i8* %45)
store i32 0, i32* %3
br label %52
47: ; preds = %36
%48 = load i8*, i8** %6
%49 = load i8*, i8** %7
%50 = call i32 @url_getfile(i8* %48, i8* %49)
store i32 %50, i32* %8
%51 = load i32, i32* %8
store i32 %51, i32* %3
br label %52
52: ; preds = %47, %42, %29, %17
%53 = load i32, i32* %3
ret i32 %53
}

LLVM IR (-O2):
@.str = [10 x i8] c"http://%s\00"
@W_OK = global i32 0
@EIO = global i32 0
@X_OK = global i32 0
@EPERM = global i32 0
define i32 @url_accessfcn(i8* %0, i32 %1) {
%3 = tail call i8* @string_fmt(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* %0)
%4 = tail call i8* @url_gethashedfilename(i8* %0)
%5 = load i32, i32* @W_OK
%6 = and i32 %5, %1
%7 = icmp eq i32 %6, 0
br i1 %7, label %13, label %8
8: ; preds = %2
%9 = tail call i32 @sfree(i8* %4)
%10 = tail call i32 @sfree(i8* %3)
%11 = load i32, i32* @EIO
%12 = sub nsw i32 0, %11
br label %30
13: ; preds = %2
%14 = load i32, i32* @X_OK
%15 = and i32 %14, %1
%16 = icmp eq i32 %15, 0
br i1 %16, label %22, label %17
17: ; preds = %13
%18 = tail call i32 @sfree(i8* %4)
%19 = tail call i32 @sfree(i8* %3)
%20 = load i32, i32* @EPERM
%21 = sub nsw i32 0, %20
br label %30
22: ; preds = %13
%23 = tail call i32 @fhandle_access(i8* %4, i32 %1)
%24 = icmp eq i32 %23, 0
br i1 %24, label %25, label %28
25: ; preds = %22
%26 = tail call i32 @sfree(i8* %4)
%27 = tail call i32 @sfree(i8* %3)
br label %30
28: ; preds = %22
%29 = tail call i32 @url_getfile(i8* %3, i8* %4)
br label %30
30: ; preds = %28, %25, %17, %8
%31 = phi i32 [ %12, %8 ], [ %21, %17 ], [ %29, %28 ], [ 0, %25 ]
ret i32 %31
}