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

/* Variables and functions */
int /*<<< orphan*/ *opendir(char *);
struct dirent *readdir(int /*<<< orphan*/ *);
int /*<<< orphan*/ remove(int /*<<< orphan*/);
int /*<<< orphan*/ rmdir(char *);
int /*<<< orphan*/ strcmp(int /*<<< orphan*/, char *);
int del_dir(char *dir_name) {
  struct dirent *dentry;
  DIR *dp;
  if (!(dp = opendir(dir_name)))
    return -1;
  while ((dentry = readdir(dp))) {
    if (!strcmp(dentry->d_name, "."))
      continue;
    if (!strcmp(dentry->d_name, ".."))
      continue;
    remove(dentry->d_name);
  }
  rmdir(dir_name);
  return 0;
}


x86 assembly (clang, -O0):
<del_dir>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <opendir@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    117f <del_dir+0x2f>
movl   $0xffffffff,-0x4(%rbp)
jmp    11fb <del_dir+0xab>
jmp    1184 <del_dir+0x34>
mov    -0x20(%rbp),%rdi
call   1070 <readdir@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     11eb <del_dir+0x9b>
mov    -0x18(%rbp),%rax
mov    (%rax),%edi
lea    0xe59(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%eax
jne    11bb <del_dir+0x6b>
jmp    1184 <del_dir+0x34>
mov    -0x18(%rbp),%rax
mov    (%rax),%edi
lea    0xe38(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%eax
jne    11db <del_dir+0x8b>
jmp    1184 <del_dir+0x34>
mov    -0x18(%rbp),%rax
mov    (%rax),%edi
call   1030 <remove@plt>
jmp    1184 <del_dir+0x34>
mov    -0x10(%rbp),%rdi
call   1050 <rmdir@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<del_dir>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdi,%r14
call   1040 <opendir@plt>
test   %rax,%rax
je     11d1 <del_dir+0x81>
mov    %rax,%r13
mov    %rax,%rdi
call   1070 <readdir@plt>
test   %rax,%rax
je     11c5 <del_dir+0x75>
mov    %rax,%rbx
lea    0xe81(%rip),%r15
lea    0xe79(%rip),%r12
jmp    11a0 <del_dir+0x50>
nopl   0x0(%rax)
mov    %r13,%rdi
call   1070 <readdir@plt>
mov    %rax,%rbx
test   %rax,%rax
je     11c5 <del_dir+0x75>
mov    (%rbx),%edi
mov    %r15,%rsi
call   1060 <strcmp@plt>
test   %eax,%eax
je     1190 <del_dir+0x40>
mov    (%rbx),%edi
mov    %r12,%rsi
call   1060 <strcmp@plt>
test   %eax,%eax
je     1190 <del_dir+0x40>
mov    (%rbx),%edi
call   1030 <remove@plt>
jmp    1190 <del_dir+0x40>
mov    %r14,%rdi
call   1050 <rmdir@plt>
xor    %eax,%eax
jmp    11d6 <del_dir+0x86>
mov    $0xffffffff,%eax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.dirent = type { i32 }
@.str = [2 x i8] c".\00"
@.str.1 = [3 x i8] c"..\00"
define i32 @del_dir(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca %struct.dirent*
%5 = alloca i32*
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = call i32* @opendir(i8* %6)
store i32* %7, i32** %5
%8 = icmp ne i32* %7, null
br i1 %8, label %10, label %9
9: ; preds = %1
store i32 -1, i32* %2
br label %37
10: ; preds = %1
br label %11
11: ; preds = %29, %28, %21, %10
%12 = load i32*, i32** %5
%13 = call %struct.dirent* @readdir(i32* %12)
store %struct.dirent* %13, %struct.dirent** %4
%14 = icmp ne %struct.dirent* %13, null
br i1 %14, label %15, label %34
15: ; preds = %11
%16 = load %struct.dirent*, %struct.dirent** %4
%17 = getelementptr inbounds %struct.dirent, %struct.dirent* %16, i32 0, i32 0
%18 = load i32, i32* %17
%19 = call i32 @strcmp(i32 %18, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%20 = icmp ne i32 %19, 0
br i1 %20, label %22, label %21
21: ; preds = %15
br label %11
22: ; preds = %15
%23 = load %struct.dirent*, %struct.dirent** %4
%24 = getelementptr inbounds %struct.dirent, %struct.dirent* %23, i32 0, i32 0
%25 = load i32, i32* %24
%26 = call i32 @strcmp(i32 %25, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%27 = icmp ne i32 %26, 0
br i1 %27, label %29, label %28
28: ; preds = %22
br label %11
29: ; preds = %22
%30 = load %struct.dirent*, %struct.dirent** %4
%31 = getelementptr inbounds %struct.dirent, %struct.dirent* %30, i32 0, i32 0
%32 = load i32, i32* %31
%33 = call i32 @remove(i32 %32)
br label %11
34: ; preds = %11
%35 = load i8*, i8** %3
%36 = call i32 @rmdir(i8* %35)
store i32 0, i32* %2
br label %37
37: ; preds = %34, %9
%38 = load i32, i32* %2
ret i32 %38
}

LLVM IR (-O2):
%struct.dirent = type { i32 }
@.str = [2 x i8] c".\00"
@.str.1 = [3 x i8] c"..\00"
define i32 @del_dir(i8* nocapture %0) {
%2 = tail call i32* @opendir(i8* %0)
%3 = icmp eq i32* %2, null
br i1 %3, label %25, label %4
4: ; preds = %1
%5 = tail call %struct.dirent* @readdir(i32* %2)
%6 = icmp eq %struct.dirent* %5, null
br i1 %6, label %23, label %7
7: ; preds = %4, %20
%8 = phi %struct.dirent* [ %21, %20 ], [ %5, %4 ]
%9 = getelementptr inbounds %struct.dirent, %struct.dirent* %8, i64 0, i32 0
%10 = load i32, i32* %9
%11 = tail call i32 @strcmp(i32 %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%12 = icmp eq i32 %11, 0
br i1 %12, label %20, label %13
13: ; preds = %7
%14 = load i32, i32* %9
%15 = tail call i32 @strcmp(i32 %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%16 = icmp eq i32 %15, 0
br i1 %16, label %20, label %17
17: ; preds = %13
%18 = load i32, i32* %9
%19 = tail call i32 @remove(i32 %18)
br label %20
20: ; preds = %17, %7, %13
%21 = tail call %struct.dirent* @readdir(i32* %2)
%22 = icmp eq %struct.dirent* %21, null
br i1 %22, label %23, label %7
23: ; preds = %20, %4
%24 = tail call i32 @rmdir(i8* %0)
br label %25
25: ; preds = %1, %23
%26 = phi i32 [ 0, %23 ], [ -1, %1 ]
ret i32 %26
}