#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 */
int /*<<< orphan*/ LOG_ERR;
int S_ISDIR(int /*<<< orphan*/);
int /*<<< orphan*/ errno;
scalar_t__ lstat(char *, struct stat *);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
int /*<<< orphan*/ syslog(int /*<<< orphan*/, char *, char *,
                          int /*<<< orphan*/);
int is_dir(char *dirName) {
  struct stat buf;
  if (lstat(dirName, &buf)) {
    syslog(LOG_ERR, "FAILED: lstat(%s): \n\tcause:%s", dirName,
           strerror(errno));
    return -1;
  }
  return S_ISDIR(buf.st_mode);
}


x86 assembly (clang, -O0):
<is_dir>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1040 <lstat@plt>
cmp    $0x0,%rax
je     11a6 <is_dir+0x66>
mov    0x2e66(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    0x2e62(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    -0x24(%rbp),%edi
mov    -0x20(%rbp),%rdx
mov    %eax,%ecx
lea    0xe6b(%rip),%rsi
call   1050 <syslog@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b1 <is_dir+0x71>
mov    -0x18(%rbp),%edi
call   1030 <S_ISDIR@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<is_dir>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    %rsp,%rsi
call   1040 <lstat@plt>
test   %rax,%rax
je     1189 <is_dir+0x49>
mov    0x2e76(%rip),%rax
mov    (%rax),%ebp
mov    0x2e7d(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
lea    0xe8f(%rip),%rsi
mov    %ebp,%edi
mov    %rbx,%rdx
mov    %eax,%ecx
call   1050 <syslog@plt>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
mov    (%rsp),%edi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1030 <S_ISDIR@plt>

LLVM IR (-O0):
%struct.stat = type { i32 }
@LOG_ERR = global i32 0
@.str = [30 x i8] c"FAILED: lstat(%s): \0A\09cause:%s\00"
@errno = global i32 0
define i32 @is_dir(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 @lstat(i8* %5, %struct.stat* %4)
%7 = icmp ne i64 %6, 0
br i1 %7, label %8, label %14
8: ; preds = %1
%9 = load i32, i32* @LOG_ERR
%10 = load i8*, i8** %3
%11 = load i32, i32* @errno
%12 = call i32 @strerror(i32 %11)
%13 = call i32 @syslog(i32 %9, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* %10, i32 %12)
store i32 -1, i32* %2
br label %18
14: ; preds = %1
%15 = getelementptr inbounds %struct.stat, %struct.stat* %4, i32 0, i32 0
%16 = load i32, i32* %15
%17 = call i32 @S_ISDIR(i32 %16)
store i32 %17, i32* %2
br label %18
18: ; preds = %14, %8
%19 = load i32, i32* %2
ret i32 %19
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@LOG_ERR = global i32 0
@.str = [30 x i8] c"FAILED: lstat(%s): \0A\09cause:%s\00"
@errno = global i32 0
define i32 @is_dir(i8* %0) {
%2 = alloca %struct.stat
%3 = bitcast %struct.stat* %2 to i8*
%4 = call i64 @lstat(i8* %0, %struct.stat* %2)
%5 = icmp eq i64 %4, 0
br i1 %5, label %11, label %6
6: ; preds = %1
%7 = load i32, i32* @LOG_ERR
%8 = load i32, i32* @errno
%9 = tail call i32 @strerror(i32 %8)
%10 = tail call i32 @syslog(i32 %7, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* %0, i32 %9)
br label %15
11: ; preds = %1
%12 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 0
%13 = load i32, i32* %12
%14 = tail call i32 @S_ISDIR(i32 %13)
br label %15
15: ; preds = %11, %6
%16 = phi i32 [ -1, %6 ], [ %14, %11 ]
ret i32 %16
}