#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 /*<<< orphan*/ st_mode;
};

/* Variables and functions */
scalar_t__ S_ISREG(int /*<<< orphan*/);
scalar_t__ stat(char *, struct stat *);
int flott_file_exists_not_empty(char *filename) {
  int ret_val = 0;
  struct stat info;
  if (stat(filename, &info) == 0 && S_ISREG(info.st_mode)) {
    ret_val = (info.st_size > 0);
  }
  return ret_val;
}


x86 assembly (clang, -O0):
<flott_file_exists_not_empty>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1030 <stat@plt>
cmp    $0x0,%rax
jne    116c <flott_file_exists_not_empty+0x4c>
mov    -0x18(%rbp),%edi
call   1040 <S_ISREG@plt>
cmp    $0x0,%rax
je     116c <flott_file_exists_not_empty+0x4c>
cmpq   $0x0,-0x20(%rbp)
setg   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<flott_file_exists_not_empty>:
push   %rbx
sub    $0x10,%rsp
mov    %rsp,%rsi
call   1030 <stat@plt>
xor    %ebx,%ebx
test   %rax,%rax
jne    114c <flott_file_exists_not_empty+0x2c>
mov    0x8(%rsp),%edi
call   1040 <S_ISREG@plt>
test   %rax,%rax
je     114c <flott_file_exists_not_empty+0x2c>
xor    %ebx,%ebx
cmpq   $0x0,(%rsp)
setg   %bl
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
ret

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

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