#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 {
  scalar_t__ st_size;
  int st_mode;
};
typedef int int8_t;

/* Variables and functions */
int S_IFMT;
int S_IFREG;
int stat(char const *, struct stat *);
int8_t file_exists_readable(const char *fpath) {
  struct stat file_stat;
  if (stat(fpath, &file_stat) == -1 || file_stat.st_size == 0 ||
      (file_stat.st_mode & S_IFMT) != S_IFREG)
    return 0;
  return 1;
}


x86 assembly (clang, -O0):
<file_exists_readable>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1030 <stat@plt>
cmp    $0xffffffff,%eax
je     1158 <file_exists_readable+0x48>
cmpq   $0x0,-0x20(%rbp)
je     1158 <file_exists_readable+0x48>
mov    -0x18(%rbp),%eax
mov    0x2e91(%rip),%rcx
and    (%rcx),%eax
mov    0x2e98(%rip),%rcx
cmp    (%rcx),%eax
je     1164 <file_exists_readable+0x54>
movl   $0x0,-0x4(%rbp)
jmp    116b <file_exists_readable+0x5b>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<file_exists_readable>:
sub    $0x18,%rsp
lea    0x8(%rsp),%rsi
call   1030 <stat@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0xffffffff,%ecx
je     114a <file_exists_readable+0x3a>
cmpq   $0x0,0x8(%rsp)
je     114a <file_exists_readable+0x3a>
mov    0x2ea2(%rip),%rax
mov    (%rax),%ecx
and    0x10(%rsp),%ecx
mov    0x2ea5(%rip),%rdx
xor    %eax,%eax
cmp    (%rdx),%ecx
sete   %al
add    $0x18,%rsp
ret

LLVM IR (-O0):
%struct.stat = type { i64, i32 }
@S_IFMT = global i32 0
@S_IFREG = global i32 0
define i32 @file_exists_readable(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca %struct.stat
store i8* %0, i8** %3
%5 = load i8*, i8** %3
%6 = call i32 @stat(i8* %5, %struct.stat* %4)
%7 = icmp eq i32 %6, -1
br i1 %7, label %19, label %8
8: ; preds = %1
%9 = getelementptr inbounds %struct.stat, %struct.stat* %4, i32 0, i32 0
%10 = load i64, i64* %9
%11 = icmp eq i64 %10, 0
br i1 %11, label %19, label %12
12: ; preds = %8
%13 = getelementptr inbounds %struct.stat, %struct.stat* %4, i32 0, i32 1
%14 = load i32, i32* %13
%15 = load i32, i32* @S_IFMT
%16 = and i32 %14, %15
%17 = load i32, i32* @S_IFREG
%18 = icmp ne i32 %16, %17
br i1 %18, label %19, label %20
19: ; preds = %12, %8, %1
store i32 0, i32* %2
br label %21
20: ; preds = %12
store i32 1, i32* %2
br label %21
21: ; preds = %20, %19
%22 = load i32, i32* %2
ret i32 %22
}

LLVM IR (-O2):
%struct.stat = type { i64, i32 }
@S_IFMT = global i32 0
@S_IFREG = global i32 0
define i32 @file_exists_readable(i8* nocapture %0) {
%2 = alloca %struct.stat
%3 = bitcast %struct.stat* %2 to i8*
%4 = call i32 @stat(i8* %0, %struct.stat* %2)
%5 = icmp eq i32 %4, -1
%6 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 0
%7 = load i64, i64* %6
%8 = icmp eq i64 %7, 0
%9 = select i1 %5, i1 true, i1 %8
br i1 %9, label %18, label %10
10: ; preds = %1
%11 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 1
%12 = load i32, i32* %11
%13 = load i32, i32* @S_IFMT
%14 = and i32 %13, %12
%15 = load i32, i32* @S_IFREG
%16 = icmp eq i32 %14, %15
%17 = zext i1 %16 to i32
br label %18
18: ; preds = %10, %1
%19 = phi i32 [ 0, %1 ], [ %17, %10 ]
ret i32 %19
}