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

/* Variables and functions */
scalar_t__ ENOENT;
scalar_t__ S_ISREG(int /*<<< orphan*/);
scalar_t__ errno;
int stat(char const *, struct stat *);
int is_regular_file(const char *filename) {
  struct stat st;
  if (stat(filename, &st) == -1) {
    if (errno == ENOENT)
      return 1;
    return 0;
  }
  if (S_ISREG(st.st_mode))
    return 1;
  return 0;
}


x86 assembly (clang, -O0):
<is_regular_file>:
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    $0xffffffff,%eax
jne    1174 <is_regular_file+0x54>
mov    0x2e97(%rip),%rax
mov    (%rax),%rax
mov    0x2e7d(%rip),%rcx
cmp    (%rcx),%rax
jne    1168 <is_regular_file+0x48>
movl   $0x1,-0x4(%rbp)
jmp    1199 <is_regular_file+0x79>
movl   $0x0,-0x4(%rbp)
jmp    1199 <is_regular_file+0x79>
mov    -0x18(%rbp),%edi
call   1040 <S_ISREG@plt>
cmp    $0x0,%rax
je     1192 <is_regular_file+0x72>
movl   $0x1,-0x4(%rbp)
jmp    1199 <is_regular_file+0x79>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<is_regular_file>:
push   %rax
mov    %rsp,%rsi
call   1030 <stat@plt>
cmp    $0xffffffff,%eax
je     113e <is_regular_file+0x1e>
mov    (%rsp),%edi
call   1040 <S_ISREG@plt>
test   %rax,%rax
setne  %al
jmp    1155 <is_regular_file+0x35>
mov    0x2e9b(%rip),%rax
mov    (%rax),%rax
mov    0x2e81(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
movzbl %al,%eax
pop    %rcx
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@errno = global i64 0
@ENOENT = global i64 0
define i32 @is_regular_file(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 %8, label %14
8: ; preds = %1
%9 = load i64, i64* @errno
%10 = load i64, i64* @ENOENT
%11 = icmp eq i64 %9, %10
br i1 %11, label %12, label %13
12: ; preds = %8
store i32 1, i32* %2
br label %21
13: ; preds = %8
store i32 0, i32* %2
br label %21
14: ; preds = %1
%15 = getelementptr inbounds %struct.stat, %struct.stat* %4, i32 0, i32 0
%16 = load i32, i32* %15
%17 = call i64 @S_ISREG(i32 %16)
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %20
19: ; preds = %14
store i32 1, i32* %2
br label %21
20: ; preds = %14
store i32 0, i32* %2
br label %21
21: ; preds = %20, %19, %13, %12
%22 = load i32, i32* %2
ret i32 %22
}

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