#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 /*<<< orphan*/ R_OK;
int fhandle_access(char *, int /*<<< orphan*/);
int fhandle_stat(char *, struct stat *);
int /*<<< orphan*/ sfree(char *);
char *string_fmt(char *, char const *);
int url_getfile(char *, char *);
char *url_gethashedfilename(char const *);
int url_statfcn(const char *path, struct stat *st_buf) {
  int err = 0;
  char *lpath = url_gethashedfilename(path);
  err = fhandle_access(lpath, R_OK);
  if (err) {
    char *rpath = string_fmt("http://%s", path);
    err = url_getfile(rpath, lpath);
    sfree(rpath);
  }
  if (err) {
    sfree(lpath);
    return err;
  }
  err = fhandle_stat(lpath, st_buf);
  sfree(lpath);
  return err;
}


x86 assembly (clang, -O0):
<url_statfcn>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
call   1080 <url_gethashedfilename@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    0x2e51(%rip),%rax
mov    (%rax),%esi
call   1070 <fhandle_access@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     11d0 <url_statfcn+0x70>
mov    -0x10(%rbp),%rsi
lea    0xe52(%rip),%rdi
call   1050 <string_fmt@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1060 <url_getfile@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x30(%rbp),%rdi
call   1040 <sfree@plt>
cmpl   $0x0,-0x1c(%rbp)
je     11ee <url_statfcn+0x8e>
mov    -0x28(%rbp),%rdi
call   1040 <sfree@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    120d <url_statfcn+0xad>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <fhandle_stat@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x28(%rbp),%rdi
call   1040 <sfree@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<url_statfcn>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
call   1080 <url_gethashedfilename@plt>
mov    %rax,%rbx
mov    0x2e64(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1070 <fhandle_access@plt>
test   %eax,%eax
je     11b5 <url_statfcn+0x55>
lea    0xe6f(%rip),%rdi
mov    %r15,%rsi
call   1050 <string_fmt@plt>
mov    %rax,%r15
mov    %rax,%rdi
mov    %rbx,%rsi
call   1060 <url_getfile@plt>
mov    %eax,%ebp
mov    %r15,%rdi
call   1040 <sfree@plt>
test   %ebp,%ebp
jne    11c2 <url_statfcn+0x62>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1030 <fhandle_stat@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1040 <sfree@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@R_OK = global i32 0
@.str = [10 x i8] c"http://%s\00"
define i32 @url_statfcn(i8* %0, %struct.stat* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca %struct.stat*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
store i8* %0, i8** %4
store %struct.stat* %1, %struct.stat** %5
store i32 0, i32* %6
%9 = load i8*, i8** %4
%10 = call i8* @url_gethashedfilename(i8* %9)
store i8* %10, i8** %7
%11 = load i8*, i8** %7
%12 = load i32, i32* @R_OK
%13 = call i32 @fhandle_access(i8* %11, i32 %12)
store i32 %13, i32* %6
%14 = load i32, i32* %6
%15 = icmp ne i32 %14, 0
br i1 %15, label %16, label %24
16: ; preds = %2
%17 = load i8*, i8** %4
%18 = call i8* @string_fmt(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* %17)
store i8* %18, i8** %8
%19 = load i8*, i8** %8
%20 = load i8*, i8** %7
%21 = call i32 @url_getfile(i8* %19, i8* %20)
store i32 %21, i32* %6
%22 = load i8*, i8** %8
%23 = call i32 @sfree(i8* %22)
br label %24
24: ; preds = %16, %2
%25 = load i32, i32* %6
%26 = icmp ne i32 %25, 0
br i1 %26, label %27, label %31
27: ; preds = %24
%28 = load i8*, i8** %7
%29 = call i32 @sfree(i8* %28)
%30 = load i32, i32* %6
store i32 %30, i32* %3
br label %38
31: ; preds = %24
%32 = load i8*, i8** %7
%33 = load %struct.stat*, %struct.stat** %5
%34 = call i32 @fhandle_stat(i8* %32, %struct.stat* %33)
store i32 %34, i32* %6
%35 = load i8*, i8** %7
%36 = call i32 @sfree(i8* %35)
%37 = load i32, i32* %6
store i32 %37, i32* %3
br label %38
38: ; preds = %31, %27
%39 = load i32, i32* %3
ret i32 %39
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@R_OK = global i32 0
@.str = [10 x i8] c"http://%s\00"
define i32 @url_statfcn(i8* %0, %struct.stat* %1) {
%3 = tail call i8* @url_gethashedfilename(i8* %0)
%4 = load i32, i32* @R_OK
%5 = tail call i32 @fhandle_access(i8* %3, i32 %4)
%6 = icmp eq i32 %5, 0
br i1 %6, label %12, label %7
7: ; preds = %2
%8 = tail call i8* @string_fmt(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* %0)
%9 = tail call i32 @url_getfile(i8* %8, i8* %3)
%10 = tail call i32 @sfree(i8* %8)
%11 = icmp eq i32 %9, 0
br i1 %11, label %12, label %14
12: ; preds = %2, %7
%13 = tail call i32 @fhandle_stat(i8* %3, %struct.stat* %1)
br label %14
14: ; preds = %7, %12
%15 = phi i32 [ %13, %12 ], [ %9, %7 ]
%16 = tail call i32 @sfree(i8* %3)
ret i32 %15
}