#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;
};
struct dirent {
  char *d_name;
};

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int S_ISREG(int /*<<< orphan*/);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ memset(struct stat *, int /*<<< orphan*/, int);
scalar_t__ stat(char *, struct stat *);
int /*<<< orphan*/ stderr;
int nebula_regular_file(struct dirent *e) {
  struct stat sta;
  memset(&sta, 0, sizeof(struct stat));
  if (stat(e->d_name, &sta) != 0) {
    fprintf(stderr, "Error - Unable to get file status for %s: %m.\n",
            e->d_name);
    exit(EXIT_FAILURE);
  }
  return (S_ISREG(sta.st_mode));
}


x86 assembly (clang, -O0):
<nebula_regular_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0x10(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1030 <memset@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
lea    -0x10(%rbp),%rsi
call   1050 <stat@plt>
cmp    $0x0,%rax
je     11b0 <nebula_regular_file+0x60>
mov    0x2e53(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rax
mov    (%rax),%rdx
lea    0xe63(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2e2f(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    -0x10(%rbp),%edi
call   1060 <S_ISREG@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<nebula_regular_file>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    %rsp,%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1030 <memset@plt>
mov    (%rbx),%rdi
mov    %r14,%rsi
call   1050 <stat@plt>
test   %rax,%rax
jne    1189 <nebula_regular_file+0x39>
mov    (%rsp),%edi
call   1060 <S_ISREG@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    0x2e50(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xe64(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2e30(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

LLVM IR (-O0):
%struct.dirent = type { i8* }
%struct.stat = type { i32 }
@stderr = global i32 0
@.str = [47 x i8] c"Error - Unable to get file status for %s: %m.\0A\00"
@EXIT_FAILURE = global i32 0
define i32 @nebula_regular_file(%struct.dirent* %0) {
%2 = alloca %struct.dirent*
%3 = alloca %struct.stat
store %struct.dirent* %0, %struct.dirent** %2
%4 = call i32 @memset(%struct.stat* %3, i32 0, i32 4)
%5 = load %struct.dirent*, %struct.dirent** %2
%6 = getelementptr inbounds %struct.dirent, %struct.dirent* %5, i32 0, i32 0
%7 = load i8*, i8** %6
%8 = call i64 @stat(i8* %7, %struct.stat* %3)
%9 = icmp ne i64 %8, 0
br i1 %9, label %10, label %18
10: ; preds = %1
%11 = load i32, i32* @stderr
%12 = load %struct.dirent*, %struct.dirent** %2
%13 = getelementptr inbounds %struct.dirent, %struct.dirent* %12, i32 0, i32 0
%14 = load i8*, i8** %13
%15 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0), i8* %14)
%16 = load i32, i32* @EXIT_FAILURE
%17 = call i32 @exit(i32 %16)
unreachable
18: ; preds = %1
%19 = getelementptr inbounds %struct.stat, %struct.stat* %3, i32 0, i32 0
%20 = load i32, i32* %19
%21 = call i32 @S_ISREG(i32 %20)
ret i32 %21
}

LLVM IR (-O2):
%struct.dirent = type { i8* }
%struct.stat = type { i32 }
@stderr = global i32 0
@.str = [47 x i8] c"Error - Unable to get file status for %s: %m.\0A\00"
@EXIT_FAILURE = global i32 0
define i32 @nebula_regular_file(%struct.dirent* nocapture %0) {
%2 = alloca %struct.stat
%3 = bitcast %struct.stat* %2 to i8*
%4 = call i32 @memset(%struct.stat* %2, i32 0, i32 4)
%5 = getelementptr inbounds %struct.dirent, %struct.dirent* %0, i64 0, i32 0
%6 = load i8*, i8** %5
%7 = call i64 @stat(i8* %6, %struct.stat* %2)
%8 = icmp eq i64 %7, 0
br i1 %8, label %15, label %9
9: ; preds = %1
%10 = load i32, i32* @stderr
%11 = load i8*, i8** %5
%12 = call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0), i8* %11)
%13 = load i32, i32* @EXIT_FAILURE
%14 = call i32 @exit(i32 %13)
unreachable
15: ; preds = %1
%16 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 0
%17 = load i32, i32* %16
%18 = call i32 @S_ISREG(i32 %17)
ret i32 %18
}