#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__ S_ISDIR(int /*<<< orphan*/);
int /*<<< orphan*/ free(char *);
char *shell_unquote(char *);
int stat(char *, struct stat *);
int is_dir(char *filename) {
  int isdir = 0;
  int r;
  struct stat statbuf;
  filename = shell_unquote(filename);
  r = stat(filename, &statbuf);
  isdir = (r >= 0 && S_ISDIR(statbuf.st_mode));
  free(filename);
  return (isdir);
}


x86 assembly (clang, -O0):
<is_dir>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <shell_unquote@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1060 <stat@plt>
mov    %eax,-0x10(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x10(%rbp)
mov    %al,-0x19(%rbp)
jl     1191 <is_dir+0x51>
mov    -0x18(%rbp),%edi
call   1040 <S_ISDIR@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <free@plt>
mov    -0xc(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<is_dir>:
push   %rbp
push   %rbx
push   %rax
call   1050 <shell_unquote@plt>
mov    %rax,%rbx
mov    %rsp,%rsi
mov    %rax,%rdi
call   1060 <stat@plt>
test   %eax,%eax
js     116d <is_dir+0x2d>
mov    (%rsp),%edi
call   1040 <S_ISDIR@plt>
xor    %ebp,%ebp
test   %rax,%rax
setne  %bpl
jmp    116f <is_dir+0x2f>
xor    %ebp,%ebp
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
define i32 @is_dir(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca %struct.stat
store i8* %0, i8** %2
store i32 0, i32* %3
%6 = load i8*, i8** %2
%7 = call i8* @shell_unquote(i8* %6)
store i8* %7, i8** %2
%8 = load i8*, i8** %2
%9 = call i32 @stat(i8* %8, %struct.stat* %5)
store i32 %9, i32* %4
%10 = load i32, i32* %4
%11 = icmp sge i32 %10, 0
br i1 %11, label %12, label %17
12: ; preds = %1
%13 = getelementptr inbounds %struct.stat, %struct.stat* %5, i32 0, i32 0
%14 = load i32, i32* %13
%15 = call i64 @S_ISDIR(i32 %14)
%16 = icmp ne i64 %15, 0
br label %17
17: ; preds = %12, %1
%18 = phi i1 [ false, %1 ], [ %16, %12 ]
%19 = zext i1 %18 to i32
store i32 %19, i32* %3
%20 = load i8*, i8** %2
%21 = call i32 @free(i8* %20)
%22 = load i32, i32* %3
ret i32 %22
}

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