#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 *);
scalar_t__ malloc(scalar_t__);
int /*<<< orphan*/ *opendir(char *);
int /*<<< orphan*/ strcat(char *, char const *);
int /*<<< orphan*/ strcpy(char *, char const *);
scalar_t__ strlen(char const *);
bool is_dir(const char *name1, const char *name2) {
  char *name;
  DIR *directory;
  name = (char *)malloc(strlen(name1) + strlen(name2) + 1);
  strcpy(name, name1);
  strcat(name, name2);
  directory = opendir(name);
  free(name);
  if (directory) {
    closedir(directory);
    return true;
  } else
    return false;
}


x86 assembly (clang, -O0):
<is_dir>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <strlen@plt>
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
call   1060 <strlen@plt>
mov    -0x30(%rbp),%rdi
add    %rax,%rdi
add    $0x1,%rdi
call   1080 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1090 <strcat@plt>
mov    -0x20(%rbp),%rdi
call   1050 <opendir@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
cmpq   $0x0,-0x28(%rbp)
je     11fa <is_dir+0x8a>
mov    -0x28(%rbp),%rdi
call   1070 <closedir@plt>
movl   $0x1,-0x4(%rbp)
jmp    1201 <is_dir+0x91>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<is_dir>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r12
call   1060 <strlen@plt>
mov    %rax,%r15
mov    %r14,%rdi
call   1060 <strlen@plt>
lea    (%r15,%rax,1),%rdi
add    $0x1,%rdi
call   1080 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r12,%rsi
call   1040 <strcpy@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1090 <strcat@plt>
mov    %rbx,%rdi
call   1050 <opendir@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1030 <free@plt>
test   %r14,%r14
je     11db <is_dir+0x6b>
mov    %r14,%rdi
call   1070 <closedir@plt>
mov    $0x1,%eax
jmp    11dd <is_dir+0x6d>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @is_dir(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32*
store i8* %0, i8** %4
store i8* %1, i8** %5
%8 = load i8*, i8** %4
%9 = call i64 @strlen(i8* %8)
%10 = load i8*, i8** %5
%11 = call i64 @strlen(i8* %10)
%12 = add nsw i64 %9, %11
%13 = add nsw i64 %12, 1
%14 = call i64 @malloc(i64 %13)
%15 = inttoptr i64 %14 to i8*
store i8* %15, i8** %6
%16 = load i8*, i8** %6
%17 = load i8*, i8** %4
%18 = call i32 @strcpy(i8* %16, i8* %17)
%19 = load i8*, i8** %6
%20 = load i8*, i8** %5
%21 = call i32 @strcat(i8* %19, i8* %20)
%22 = load i8*, i8** %6
%23 = call i32* @opendir(i8* %22)
store i32* %23, i32** %7
%24 = load i8*, i8** %6
%25 = call i32 @free(i8* %24)
%26 = load i32*, i32** %7
%27 = icmp ne i32* %26, null
br i1 %27, label %28, label %31
28: ; preds = %2
%29 = load i32*, i32** %7
%30 = call i32 @closedir(i32* %29)
store i32 1, i32* %3
br label %32
31: ; preds = %2
store i32 0, i32* %3
br label %32
32: ; preds = %31, %28
%33 = load i32, i32* %3
ret i32 %33
}

LLVM IR (-O2):
define i32 @is_dir(i8* %0, i8* %1) {
%3 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%4 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%5 = add i64 %3, 1
%6 = add i64 %5, %4
%7 = tail call i64 @malloc(i64 %6)
%8 = inttoptr i64 %7 to i8*
%9 = tail call i32 @strcpy(i8* %8, i8* %0)
%10 = tail call i32 @strcat(i8* %8, i8* %1)
%11 = tail call i32* @opendir(i8* %8)
%12 = tail call i32 @free(i8* %8)
%13 = icmp eq i32* %11, null
br i1 %13, label %16, label %14
14: ; preds = %2
%15 = tail call i32 @closedir(i32* %11)
br label %16
16: ; preds = %2, %14
%17 = phi i32 [ 1, %14 ], [ 0, %2 ]
ret i32 %17
}