#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 stat64 {
  int dummy;
};
struct file_cache {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ cached_name(struct file_cache *, char const *, char *);
scalar_t__ stat64(char *, struct stat64 *);
scalar_t__ wait_for_running_txn(struct file_cache *, char const *);
int file_cache_stat(struct file_cache *c, const char *path, char *lpath,
                    struct stat64 *info) {
  cached_name(c, path, lpath);
  if (stat64(lpath, info) == 0)
    return 0;
  if (wait_for_running_txn(c, path)) {
    if (stat64(lpath, info) == 0)
      return 0;
  }
  return -1;
}


x86 assembly (clang, -O0):
<file_cache_stat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1050 <cached_name@plt>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1040 <stat64@plt>
cmp    $0x0,%rax
jne    117c <file_cache_stat+0x4c>
movl   $0x0,-0x4(%rbp)
jmp    11c2 <file_cache_stat+0x92>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <wait_for_running_txn@plt>
cmp    $0x0,%rax
je     11bb <file_cache_stat+0x8b>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1040 <stat64@plt>
cmp    $0x0,%rax
jne    11b6 <file_cache_stat+0x86>
movl   $0x0,-0x4(%rbp)
jmp    11c2 <file_cache_stat+0x92>
jmp    11bb <file_cache_stat+0x8b>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<file_cache_stat>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rcx,%r14
mov    %rdx,%rbx
mov    %rsi,%r12
mov    %rdi,%rbp
call   1050 <cached_name@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <stat64@plt>
xor    %r15d,%r15d
test   %rax,%rax
je     1182 <file_cache_stat+0x52>
mov    %rbp,%rdi
mov    %r12,%rsi
call   1030 <wait_for_running_txn@plt>
test   %rax,%rax
je     117c <file_cache_stat+0x4c>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <stat64@plt>
test   %rax,%rax
je     1182 <file_cache_stat+0x52>
mov    $0xffffffff,%r15d
mov    %r15d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.file_cache = type { i32 }
%struct.stat64 = type { i32 }
define i32 @file_cache_stat(%struct.file_cache* %0, i8* %1, i8* %2, %struct.stat64* %3) {
%5 = alloca i32
%6 = alloca %struct.file_cache*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca %struct.stat64*
store %struct.file_cache* %0, %struct.file_cache** %6
store i8* %1, i8** %7
store i8* %2, i8** %8
store %struct.stat64* %3, %struct.stat64** %9
%10 = load %struct.file_cache*, %struct.file_cache** %6
%11 = load i8*, i8** %7
%12 = load i8*, i8** %8
%13 = call i32 @cached_name(%struct.file_cache* %10, i8* %11, i8* %12)
%14 = load i8*, i8** %8
%15 = load %struct.stat64*, %struct.stat64** %9
%16 = call i64 @stat64(i8* %14, %struct.stat64* %15)
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %19
18: ; preds = %4
store i32 0, i32* %5
br label %32
19: ; preds = %4
%20 = load %struct.file_cache*, %struct.file_cache** %6
%21 = load i8*, i8** %7
%22 = call i64 @wait_for_running_txn(%struct.file_cache* %20, i8* %21)
%23 = icmp ne i64 %22, 0
br i1 %23, label %24, label %31
24: ; preds = %19
%25 = load i8*, i8** %8
%26 = load %struct.stat64*, %struct.stat64** %9
%27 = call i64 @stat64(i8* %25, %struct.stat64* %26)
%28 = icmp eq i64 %27, 0
br i1 %28, label %29, label %30
29: ; preds = %24
store i32 0, i32* %5
br label %32
30: ; preds = %24
br label %31
31: ; preds = %30, %19
store i32 -1, i32* %5
br label %32
32: ; preds = %31, %29, %18
%33 = load i32, i32* %5
ret i32 %33
}

LLVM IR (-O2):
%struct.file_cache = type { i32 }
%struct.stat64 = type { i32 }
define i32 @file_cache_stat(%struct.file_cache* %0, i8* %1, i8* %2, %struct.stat64* nocapture %3) {
%5 = tail call i32 @cached_name(%struct.file_cache* %0, i8* %1, i8* %2)
%6 = tail call i64 @stat64(i8* %2, %struct.stat64* %3)
%7 = icmp eq i64 %6, 0
br i1 %7, label %15, label %8
8: ; preds = %4
%9 = tail call i64 @wait_for_running_txn(%struct.file_cache* %0, i8* %1)
%10 = icmp eq i64 %9, 0
br i1 %10, label %14, label %11
11: ; preds = %8
%12 = tail call i64 @stat64(i8* %2, %struct.stat64* %3)
%13 = icmp eq i64 %12, 0
br i1 %13, label %15, label %14
14: ; preds = %11, %8
br label %15
15: ; preds = %11, %4, %14
%16 = phi i32 [ -1, %14 ], [ 0, %4 ], [ 0, %11 ]
ret i32 %16
}