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

/* Variables and functions */
int S_IFMT;
int S_IFREG;
scalar_t__ stat(char *, struct stat *);
int isxfile(char *filename) {
  struct stat buf;
  if (stat(filename, &buf) != 0)
    return 0;
  if (!(((buf.st_mode) & S_IFMT) == S_IFREG))
    return 0;
  if ((buf.st_mode & 0111) == 0)
    return 0;
  return 1;
}


x86 assembly (clang, -O0):
<isxfile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1030 <stat@plt>
cmp    $0x0,%rax
je     113f <isxfile+0x2f>
movl   $0x0,-0x4(%rbp)
jmp    1188 <isxfile+0x78>
mov    -0x18(%rbp),%eax
mov    0x2e8f(%rip),%rcx
and    (%rcx),%eax
mov    0x2e96(%rip),%rcx
cmp    (%rcx),%eax
je     1166 <isxfile+0x56>
movl   $0x0,-0x4(%rbp)
jmp    1188 <isxfile+0x78>
mov    -0x18(%rbp),%eax
and    $0x49,%eax
cmp    $0x0,%eax
jne    1181 <isxfile+0x71>
movl   $0x0,-0x4(%rbp)
jmp    1188 <isxfile+0x78>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<isxfile>:
push   %rax
mov    %rsp,%rsi
call   1030 <stat@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
je     1125 <isxfile+0x15>
pop    %rcx
ret
mov    (%rsp),%ecx
mov    0x2ea9(%rip),%rdx
mov    (%rdx),%edx
and    %ecx,%edx
mov    0x2eae(%rip),%rsi
cmp    (%rsi),%edx
jne    1123 <isxfile+0x13>
xor    %eax,%eax
test   $0x49,%cl
setne  %al
pop    %rcx
ret

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

LLVM IR (-O2):
%struct.stat = type { i32 }
@S_IFMT = global i32 0
@S_IFREG = global i32 0
define i32 @isxfile(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 %17
6: ; preds = %1
%7 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 0
%8 = load i32, i32* %7
%9 = load i32, i32* @S_IFMT
%10 = and i32 %9, %8
%11 = load i32, i32* @S_IFREG
%12 = icmp eq i32 %10, %11
br i1 %12, label %13, label %17
13: ; preds = %6
%14 = and i32 %8, 73
%15 = icmp ne i32 %14, 0
%16 = zext i1 %15 to i32
br label %17
17: ; preds = %13, %6, %1
%18 = phi i32 [ 0, %1 ], [ 0, %6 ], [ %16, %13 ]
ret i32 %18
}