#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*/ delete_directory(char *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ join_strings(char **, int, char *, char *);
int /*<<< orphan*/ *opendir(char *);
int delete_temp_directory(char *path) {
  DIR *Dp;
  join_strings(&path, 2, path, "_mnemontempdir_/");
  Dp = opendir(path);
  if (Dp == NULL) {
    free(path);
    return -1;
  }
  closedir(Dp);
  delete_directory(path);
  free(path);
  return 0;
}


x86 assembly (clang, -O0):
<delete_temp_directory>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdx
lea    -0x10(%rbp),%rdi
mov    $0x2,%esi
lea    0xe90(%rip),%rcx
call   1070 <join_strings@plt>
mov    -0x10(%rbp),%rdi
call   1040 <opendir@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11a2 <delete_temp_directory+0x52>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c4 <delete_temp_directory+0x74>
mov    -0x18(%rbp),%rdi
call   1050 <closedir@plt>
mov    -0x10(%rbp),%rdi
call   1060 <delete_directory@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<delete_temp_directory>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rdx
mov    %rdi,0x8(%rsp)
lea    0xe9c(%rip),%rcx
lea    0x8(%rsp),%rdi
mov    $0x2,%esi
call   1070 <join_strings@plt>
mov    0x8(%rsp),%rdi
call   1040 <opendir@plt>
test   %rax,%rax
je     1198 <delete_temp_directory+0x48>
mov    %rax,%rdi
call   1050 <closedir@plt>
mov    0x8(%rsp),%rdi
call   1060 <delete_directory@plt>
xor    %ebx,%ebx
jmp    119d <delete_temp_directory+0x4d>
mov    $0xffffffff,%ebx
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [17 x i8] c"_mnemontempdir_/\00"
define i32 @delete_temp_directory(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32*
store i8* %0, i8** %3
%5 = load i8*, i8** %3
%6 = call i32 @join_strings(i8** %3, i32 2, i8* %5, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%7 = load i8*, i8** %3
%8 = call i32* @opendir(i8* %7)
store i32* %8, i32** %4
%9 = load i32*, i32** %4
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %14
11: ; preds = %1
%12 = load i8*, i8** %3
%13 = call i32 @free(i8* %12)
store i32 -1, i32* %2
br label %21
14: ; preds = %1
%15 = load i32*, i32** %4
%16 = call i32 @closedir(i32* %15)
%17 = load i8*, i8** %3
%18 = call i32 @delete_directory(i8* %17)
%19 = load i8*, i8** %3
%20 = call i32 @free(i8* %19)
store i32 0, i32* %2
br label %21
21: ; preds = %14, %11
%22 = load i32, i32* %2
ret i32 %22
}

LLVM IR (-O2):
@.str = [17 x i8] c"_mnemontempdir_/\00"
define i32 @delete_temp_directory(i8* %0) {
%2 = alloca i8*
store i8* %0, i8** %2
%3 = call i32 @join_strings(i8** %2, i32 2, i8* %0, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%4 = load i8*, i8** %2
%5 = call i32* @opendir(i8* %4)
%6 = icmp eq i32* %5, null
br i1 %6, label %11, label %7
7: ; preds = %1
%8 = call i32 @closedir(i32* %5)
%9 = load i8*, i8** %2
%10 = call i32 @delete_directory(i8* %9)
br label %11
11: ; preds = %1, %7
%12 = phi i32 [ 0, %7 ], [ -1, %1 ]
%13 = load i8*, i8** %2
%14 = call i32 @free(i8* %13)
ret i32 %12
}