#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 */
typedef int /*<<< orphan*/ DIR;

/* Variables and functions */
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
char *malloc(int);
int /*<<< orphan*/ *opendir(char *);
int /*<<< orphan*/ snprintf(char *, int, char *, char *, char *);
scalar_t__ strcmp(char *, char *);
int strlen(char *);
int is_directory(char *relpath, char *dirname) {
  if (strcmp(dirname, "..") != 0 && strcmp(dirname, ".") != 0) {
    int len = strlen(relpath) + strlen(dirname) + 1;
    char *fullpath = malloc(len + 1);
    if (fullpath != NULL) {
      snprintf(fullpath, len + 1, "%s/%s", relpath, dirname);
      DIR *dirp = opendir(fullpath);
      if (dirp != NULL) {
        closedir(dirp);
        free(fullpath);
        return 1;
      } else
        free(fullpath);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<is_directory>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe75(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
je     1257 <is_directory+0xe7>
mov    -0x18(%rbp),%rdi
lea    0xe5c(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
je     1257 <is_directory+0xe7>
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x34(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x34(%rbp),%eax
add    %ecx,%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%edi
add    $0x1,%edi
call   1090 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     1252 <is_directory+0xe2>
mov    -0x28(%rbp),%rdi
mov    -0x1c(%rbp),%esi
add    $0x1,%esi
mov    -0x10(%rbp),%rcx
mov    -0x18(%rbp),%r8
lea    0xdfa(%rip),%rdx
call   1060 <snprintf@plt>
mov    -0x28(%rbp),%rdi
call   1040 <opendir@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     1244 <is_directory+0xd4>
mov    -0x30(%rbp),%rdi
call   1070 <closedir@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movl   $0x1,-0x4(%rbp)
jmp    125e <is_directory+0xee>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
jmp    1252 <is_directory+0xe2>
jmp    1257 <is_directory+0xe7>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<is_directory>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%rbx
mov    %rdi,%r14
lea    0xe7b(%rip),%rsi
mov    %rbx,%rdi
call   1080 <strcmp@plt>
xor    %ebp,%ebp
test   %rax,%rax
je     1211 <is_directory+0xa1>
lea    0xe66(%rip),%rsi
mov    %rbx,%rdi
call   1080 <strcmp@plt>
test   %rax,%rax
je     1211 <is_directory+0xa1>
mov    %r14,%rdi
call   1050 <strlen@plt>
mov    %eax,%r15d
mov    %rbx,%rdi
call   1050 <strlen@plt>
lea    (%r15,%rax,1),%r12d
add    $0x2,%r12d
mov    %r12d,%edi
call   1090 <malloc@plt>
test   %rax,%rax
je     1211 <is_directory+0xa1>
mov    %rax,%r15
lea    0xe29(%rip),%rdx
mov    %rax,%rdi
mov    %r12d,%esi
mov    %r14,%rcx
mov    %rbx,%r8
call   1060 <snprintf@plt>
mov    %r15,%rdi
call   1040 <opendir@plt>
test   %rax,%rax
je     1207 <is_directory+0x97>
mov    %rax,%rdi
call   1070 <closedir@plt>
mov    $0x1,%ebp
jmp    1209 <is_directory+0x99>
xor    %ebp,%ebp
mov    %r15,%rdi
call   1030 <free@plt>
mov    %ebp,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"..\00"
@.str.1 = [2 x i8] c".\00"
@.str.2 = [6 x i8] c"%s/%s\00"
define i32 @is_directory(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32*
store i8* %0, i8** %4
store i8* %1, i8** %5
%9 = load i8*, i8** %5
%10 = call i64 @strcmp(i8* %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%11 = icmp ne i64 %10, 0
br i1 %11, label %12, label %49
12: ; preds = %2
%13 = load i8*, i8** %5
%14 = call i64 @strcmp(i8* %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %49
16: ; preds = %12
%17 = load i8*, i8** %4
%18 = call i32 @strlen(i8* %17)
%19 = load i8*, i8** %5
%20 = call i32 @strlen(i8* %19)
%21 = add nsw i32 %18, %20
%22 = add nsw i32 %21, 1
store i32 %22, i32* %6
%23 = load i32, i32* %6
%24 = add nsw i32 %23, 1
%25 = call i8* @malloc(i32 %24)
store i8* %25, i8** %7
%26 = load i8*, i8** %7
%27 = icmp ne i8* %26, null
br i1 %27, label %28, label %48
28: ; preds = %16
%29 = load i8*, i8** %7
%30 = load i32, i32* %6
%31 = add nsw i32 %30, 1
%32 = load i8*, i8** %4
%33 = load i8*, i8** %5
%34 = call i32 @snprintf(i8* %29, i32 %31, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %32, i8* %33)
%35 = load i8*, i8** %7
%36 = call i32* @opendir(i8* %35)
store i32* %36, i32** %8
%37 = load i32*, i32** %8
%38 = icmp ne i32* %37, null
br i1 %38, label %39, label %44
39: ; preds = %28
%40 = load i32*, i32** %8
%41 = call i32 @closedir(i32* %40)
%42 = load i8*, i8** %7
%43 = call i32 @free(i8* %42)
store i32 1, i32* %3
br label %50
44: ; preds = %28
%45 = load i8*, i8** %7
%46 = call i32 @free(i8* %45)
br label %47
47: ; preds = %44
br label %48
48: ; preds = %47, %16
br label %49
49: ; preds = %48, %12, %2
store i32 0, i32* %3
br label %50
50: ; preds = %49, %39
%51 = load i32, i32* %3
ret i32 %51
}

LLVM IR (-O2):
@.str = [3 x i8] c"..\00"
@.str.1 = [2 x i8] c".\00"
@.str.2 = [6 x i8] c"%s/%s\00"
define i32 @is_directory(i8* %0, i8* %1) {
%3 = tail call i64 @strcmp(i8* %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i64 %3, 0
br i1 %4, label %24, label %5
5: ; preds = %2
%6 = tail call i64 @strcmp(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%7 = icmp eq i64 %6, 0
br i1 %7, label %24, label %8
8: ; preds = %5
%9 = tail call i32 @strlen(i8* %0)
%10 = tail call i32 @strlen(i8* %1)
%11 = add i32 %9, 2
%12 = add i32 %11, %10
%13 = tail call i8* @malloc(i32 %12)
%14 = icmp eq i8* %13, null
br i1 %14, label %24, label %15
15: ; preds = %8
%16 = tail call i32 @snprintf(i8* %13, i32 %12, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %0, i8* %1)
%17 = tail call i32* @opendir(i8* %13)
%18 = icmp eq i32* %17, null
br i1 %18, label %21, label %19
19: ; preds = %15
%20 = tail call i32 @closedir(i32* %17)
br label %21
21: ; preds = %15, %19
%22 = phi i32 [ 1, %19 ], [ 0, %15 ]
%23 = tail call i32 @free(i8* %13)
br label %24
24: ; preds = %21, %8, %2, %5
%25 = phi i32 [ 0, %5 ], [ 0, %2 ], [ 0, %8 ], [ %22, %21 ]
ret i32 %25
}