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

/* Variables and functions */
scalar_t__ DT_DIR;
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
int /*<<< orphan*/ *opendir(char *);
struct dirent *readdir(int /*<<< orphan*/ *);
int /*<<< orphan*/ sprintf(char *, char *, char *, char *);
scalar_t__ strcmp(char *, char *);
int getDeleteAllNum(char *path) {
  DIR *fd;
  struct dirent *dir;
  int ret;
  char buffer[512];
  int num = 0;
  fd = opendir(path);
  if (fd < 0) {
    return -1;
  }
  num++;
  while ((dir = readdir(fd)) != NULL) {
    if ((strcmp(dir->d_name, ".") == 0) || (strcmp(dir->d_name, "..") == 0)) {
      continue;
    }
    if (dir->d_type == DT_DIR) {
      sprintf(buffer, "%s/%s", path, dir->d_name);
      ret = getDeleteAllNum(buffer);
      if (ret >= 0) {
        num = num + ret;
      }
    } else {
      num++;
    }
  }
  closedir(fd);
  return num;
}


x86 assembly (clang, -O0):
<getDeleteAllNum>:
push   %rbp
mov    %rsp,%rbp
sub    $0x240,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x234(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <opendir@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jae    119d <getDeleteAllNum+0x3d>
movl   $0xffffffff,-0x4(%rbp)
jmp    128b <getDeleteAllNum+0x12b>
mov    -0x234(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x234(%rbp)
mov    -0x18(%rbp),%rdi
call   1060 <readdir@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     1279 <getDeleteAllNum+0x119>
mov    -0x20(%rbp),%rax
mov    (%rax),%rdi
lea    0xe30(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
je     11fd <getDeleteAllNum+0x9d>
mov    -0x20(%rbp),%rax
mov    (%rax),%rdi
lea    0xe12(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    1202 <getDeleteAllNum+0xa2>
jmp    11ac <getDeleteAllNum+0x4c>
mov    -0x20(%rbp),%rax
mov    0x8(%rax),%rax
mov    0x2dcf(%rip),%rcx
cmp    (%rcx),%rax
jne    1265 <getDeleteAllNum+0x105>
lea    -0x230(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    -0x20(%rbp),%rax
mov    (%rax),%rcx
lea    0xdd0(%rip),%rsi
call   1080 <sprintf@plt>
lea    -0x230(%rbp),%rdi
call   1070 <getDeleteAllNum@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jl     1260 <getDeleteAllNum+0x100>
mov    -0x234(%rbp),%eax
add    -0x24(%rbp),%eax
mov    %eax,-0x234(%rbp)
jmp    1274 <getDeleteAllNum+0x114>
mov    -0x234(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x234(%rbp)
jmp    11ac <getDeleteAllNum+0x4c>
mov    -0x18(%rbp),%rdi
call   1040 <closedir@plt>
mov    -0x234(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x240,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getDeleteAllNum>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x208,%rsp
mov    %rdi,%r14
call   1030 <opendir@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1060 <readdir@plt>
test   %rax,%rax
je     11a2 <getDeleteAllNum+0x42>
mov    %rax,%r13
mov    $0x1,%r15d
lea    0xe68(%rip),%rbp
lea    0xe60(%rip),%r12
jmp    11e0 <getDeleteAllNum+0x80>
mov    $0x1,%r15d
mov    %rbx,%rdi
call   1040 <closedir@plt>
mov    %r15d,%eax
add    $0x208,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
add    $0x1,%r15d
nopl   0x0(%rax)
mov    %rbx,%rdi
call   1060 <readdir@plt>
mov    %rax,%r13
test   %rax,%rax
je     11a8 <getDeleteAllNum+0x48>
mov    0x0(%r13),%rdi
mov    %rbp,%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
je     11d0 <getDeleteAllNum+0x70>
mov    0x0(%r13),%rdi
mov    %r12,%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
je     11d0 <getDeleteAllNum+0x70>
mov    0x8(%r13),%rax
mov    0x2dd3(%rip),%rcx
cmp    (%rcx),%rax
jne    11c5 <getDeleteAllNum+0x65>
mov    0x0(%r13),%rcx
mov    %rsp,%r13
mov    %r13,%rdi
lea    0xde0(%rip),%rsi
mov    %r14,%rdx
call   1080 <sprintf@plt>
mov    %r13,%rdi
call   1070 <getDeleteAllNum@plt>
test   %eax,%eax
mov    $0x0,%ecx
cmovs  %ecx,%eax
add    %eax,%r15d
jmp    11d0 <getDeleteAllNum+0x70>

LLVM IR (-O0):
%struct.dirent = type { i8*, i64 }
@.str = [2 x i8] c".\00"
@.str.1 = [3 x i8] c"..\00"
@DT_DIR = global i64 0
@.str.2 = [6 x i8] c"%s/%s\00"
define i32 @getDeleteAllNum(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca %struct.dirent*
%6 = alloca i32
%7 = alloca [512 x i8]
%8 = alloca i32
store i8* %0, i8** %3
store i32 0, i32* %8
%9 = load i8*, i8** %3
%10 = call i32* @opendir(i8* %9)
store i32* %10, i32** %4
%11 = load i32*, i32** %4
%12 = icmp ult i32* %11, null
br i1 %12, label %13, label %14
13: ; preds = %1
store i32 -1, i32* %2
br label %64
14: ; preds = %1
%15 = load i32, i32* %8
%16 = add nsw i32 %15, 1
store i32 %16, i32* %8
br label %17
17: ; preds = %59, %33, %14
%18 = load i32*, i32** %4
%19 = call %struct.dirent* @readdir(i32* %18)
store %struct.dirent* %19, %struct.dirent** %5
%20 = icmp ne %struct.dirent* %19, null
br i1 %20, label %21, label %60
21: ; preds = %17
%22 = load %struct.dirent*, %struct.dirent** %5
%23 = getelementptr inbounds %struct.dirent, %struct.dirent* %22, i32 0, i32 0
%24 = load i8*, i8** %23
%25 = call i64 @strcmp(i8* %24, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%26 = icmp eq i64 %25, 0
br i1 %26, label %33, label %27
27: ; preds = %21
%28 = load %struct.dirent*, %struct.dirent** %5
%29 = getelementptr inbounds %struct.dirent, %struct.dirent* %28, i32 0, i32 0
%30 = load i8*, i8** %29
%31 = call i64 @strcmp(i8* %30, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%32 = icmp eq i64 %31, 0
br i1 %32, label %33, label %34
33: ; preds = %27, %21
br label %17
34: ; preds = %27
%35 = load %struct.dirent*, %struct.dirent** %5
%36 = getelementptr inbounds %struct.dirent, %struct.dirent* %35, i32 0, i32 1
%37 = load i64, i64* %36
%38 = load i64, i64* @DT_DIR
%39 = icmp eq i64 %37, %38
br i1 %39, label %40, label %56
40: ; preds = %34
%41 = getelementptr inbounds [512 x i8], [512 x i8]* %7, i64 0, i64 0
%42 = load i8*, i8** %3
%43 = load %struct.dirent*, %struct.dirent** %5
%44 = getelementptr inbounds %struct.dirent, %struct.dirent* %43, i32 0, i32 0
%45 = load i8*, i8** %44
%46 = call i32 @sprintf(i8* %41, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %42, i8* %45)
%47 = getelementptr inbounds [512 x i8], [512 x i8]* %7, i64 0, i64 0
%48 = call i32 @getDeleteAllNum(i8* %47)
store i32 %48, i32* %6
%49 = load i32, i32* %6
%50 = icmp sge i32 %49, 0
br i1 %50, label %51, label %55
51: ; preds = %40
%52 = load i32, i32* %8
%53 = load i32, i32* %6
%54 = add nsw i32 %52, %53
store i32 %54, i32* %8
br label %55
55: ; preds = %51, %40
br label %59
56: ; preds = %34
%57 = load i32, i32* %8
%58 = add nsw i32 %57, 1
store i32 %58, i32* %8
br label %59
59: ; preds = %56, %55
br label %17
60: ; preds = %17
%61 = load i32*, i32** %4
%62 = call i32 @closedir(i32* %61)
%63 = load i32, i32* %8
store i32 %63, i32* %2
br label %64
64: ; preds = %60, %13
%65 = load i32, i32* %2
ret i32 %65
}

LLVM IR (-O2):
%struct.dirent = type { i8*, i64 }
@.str = [2 x i8] c".\00"
@.str.1 = [3 x i8] c"..\00"
@DT_DIR = global i64 0
@.str.2 = [6 x i8] c"%s/%s\00"
define i32 @getDeleteAllNum(i8* %0) {
%2 = alloca [512 x i8]
%3 = getelementptr inbounds [512 x i8], [512 x i8]* %2, i64 0, i64 0
%4 = tail call i32* @opendir(i8* %0)
%5 = call %struct.dirent* @readdir(i32* %4)
%6 = icmp eq %struct.dirent* %5, null
br i1 %6, label %41, label %7
7: ; preds = %1, %37
%8 = phi %struct.dirent* [ %39, %37 ], [ %5, %1 ]
%9 = phi i32 [ %38, %37 ], [ 1, %1 ]
br label %10
10: ; preds = %7, %20
%11 = phi %struct.dirent* [ %8, %7 ], [ %21, %20 ]
%12 = getelementptr inbounds %struct.dirent, %struct.dirent* %11, i64 0, i32 0
%13 = load i8*, i8** %12
%14 = call i64 @strcmp(i8* %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%15 = icmp eq i64 %14, 0
br i1 %15, label %20, label %16
16: ; preds = %10
%17 = load i8*, i8** %12
%18 = call i64 @strcmp(i8* %17, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %23
20: ; preds = %16, %10
%21 = call %struct.dirent* @readdir(i32* %4)
%22 = icmp eq %struct.dirent* %21, null
br i1 %22, label %41, label %10
23: ; preds = %16
%24 = getelementptr inbounds %struct.dirent, %struct.dirent* %11, i64 0, i32 1
%25 = load i64, i64* %24
%26 = load i64, i64* @DT_DIR
%27 = icmp eq i64 %25, %26
br i1 %27, label %28, label %35
28: ; preds = %23
%29 = load i8*, i8** %12
%30 = call i32 @sprintf(i8* %3, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %0, i8* %29)
%31 = call i32 @getDeleteAllNum(i8* %3)
%32 = icmp sgt i32 %31, 0
%33 = select i1 %32, i32 %31, i32 0
%34 = add nsw i32 %33, %9
br label %37
35: ; preds = %23
%36 = add nsw i32 %9, 1
br label %37
37: ; preds = %28, %35
%38 = phi i32 [ %36, %35 ], [ %34, %28 ]
%39 = call %struct.dirent* @readdir(i32* %4)
%40 = icmp eq %struct.dirent* %39, null
br i1 %40, label %41, label %7
41: ; preds = %37, %20, %1
%42 = phi i32 [ 1, %1 ], [ %9, %20 ], [ %38, %37 ]
%43 = call i32 @closedir(i32* %4)
ret i32 %42
}