#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;
};
struct client_attr {
  int dummy;
};
typedef int /*<<< orphan*/ DIR;

/* Variables and functions */
scalar_t__ DT_DIR;
scalar_t__ DT_REG;
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
int /*<<< orphan*/ *opendir(char *);
scalar_t__ readdir_r(int /*<<< orphan*/ *, struct dirent *, struct dirent **);
int /*<<< orphan*/ strcat(char *, char *);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
int /*<<< orphan*/ transmit(struct client_attr *, char *, int, int);
void download_recursive(struct client_attr *attr, char *path,
                        int dir_name_length) {
  DIR *dirp;
  struct dirent entry, *result;
  char tmp[4096];
  ;
  if ((dirp = opendir(path)) == NULL) {
    return;
  }
  while ((readdir_r(dirp, &entry, &result) == 0) && result) {
    if (strcmp(".", entry.d_name) == 0 || strcmp("..", entry.d_name) == 0)
      continue;
    strcpy(tmp, path);
    if (*(tmp + strlen(tmp) - 1) != '/')
      strcat(tmp, "/");
    strcat(tmp, entry.d_name);
    if (entry.d_type == DT_REG) {
      transmit(attr, tmp, dir_name_length, 0x01);
    } else if (entry.d_type == DT_DIR) {
      download_recursive(attr, tmp, dir_name_length);
    }
  }
  closedir(dirp);
}


x86 assembly (clang, -O0):
<download_recursive>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1050,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <opendir@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    11c2 <download_recursive+0x32>
jmp    1304 <download_recursive+0x174>
jmp    11c7 <download_recursive+0x37>
mov    -0x20(%rbp),%rdi
lea    -0x30(%rbp),%rsi
lea    -0x38(%rbp),%rdx
call   1040 <readdir_r@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x1041(%rbp)
jne    11fb <download_recursive+0x6b>
cmpq   $0x0,-0x38(%rbp)
setne  %al
mov    %al,-0x1041(%rbp)
mov    -0x1041(%rbp),%al
test   $0x1,%al
jne    120e <download_recursive+0x7e>
jmp    12fb <download_recursive+0x16b>
mov    -0x30(%rbp),%rsi
lea    0xde8(%rip),%rdi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
je     1242 <download_recursive+0xb2>
mov    -0x30(%rbp),%rsi
lea    0xdcd(%rip),%rdi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
jne    1247 <download_recursive+0xb7>
jmp    11c7 <download_recursive+0x37>
lea    -0x1040(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
lea    -0x1040(%rbp),%rdi
call   1060 <strlen@plt>
cltq
movsbl -0x1041(%rbp,%rax,1),%eax
ff
cmp    $0x2f,%eax
je     1289 <download_recursive+0xf9>
lea    -0x1040(%rbp),%rdi
lea    0xd7f(%rip),%rsi
call   10b0 <strcat@plt>
lea    -0x1040(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   10b0 <strcat@plt>
mov    -0x28(%rbp),%rax
mov    0x2d3c(%rip),%rcx
cmp    (%rcx),%rax
jne    12ca <download_recursive+0x13a>
mov    -0x8(%rbp),%rdi
lea    -0x1040(%rbp),%rsi
mov    -0x14(%rbp),%edx
mov    $0x1,%ecx
call   10a0 <transmit@plt>
jmp    12f6 <download_recursive+0x166>
mov    -0x28(%rbp),%rax
mov    0x2d03(%rip),%rcx
cmp    (%rcx),%rax
jne    12f1 <download_recursive+0x161>
mov    -0x8(%rbp),%rdi
lea    -0x1040(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1090 <download_recursive@plt>
jmp    12f6 <download_recursive+0x166>
jmp    11c7 <download_recursive+0x37>
mov    -0x20(%rbp),%rdi
call   1070 <closedir@plt>
add    $0x1050,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<download_recursive>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1038,%rsp
mov    %edx,0xc(%rsp)
mov    %rsi,%r12
mov    %rdi,0x18(%rsp)
mov    %rsi,%rdi
call   1050 <opendir@plt>
test   %rax,%rax
je     12d7 <download_recursive+0x147>
mov    %rax,%rbp
lea    0x20(%rsp),%rsi
lea    0x10(%rsp),%rdx
mov    %rax,%rdi
call   1040 <readdir_r@plt>
test   %rax,%rax
jne    12cf <download_recursive+0x13f>
cmpq   $0x0,0x10(%rsp)
je     12cf <download_recursive+0x13f>
lea    0xe12(%rip),%r13
lea    0x20(%rsp),%rbx
lea    0x10(%rsp),%r14
lea    0x30(%rsp),%r15
xchg   %ax,%ax
mov    0x20(%rsp),%rsi
mov    %r13,%rdi
call   1080 <strcmp@plt>
test   %rax,%rax
je     12b0 <download_recursive+0x120>
mov    0x20(%rsp),%rsi
lea    0xdde(%rip),%rdi
call   1080 <strcmp@plt>
test   %rax,%rax
je     12b0 <download_recursive+0x120>
mov    %r15,%rdi
mov    %r12,%rsi
call   1030 <strcpy@plt>
mov    %r15,%rdi
call   1060 <strlen@plt>
cltq
cmpb   $0x2f,0x2f(%rsp,%rax,1)
je     125b <download_recursive+0xcb>
mov    %r15,%rdi
lea    0xdad(%rip),%rsi
call   10b0 <strcat@plt>
mov    0x20(%rsp),%rsi
mov    %r15,%rdi
call   10b0 <strcat@plt>
mov    0x28(%rsp),%rax
mov    0x2d6c(%rip),%rcx
cmp    (%rcx),%rax
jne    1291 <download_recursive+0x101>
mov    0x18(%rsp),%rdi
mov    %r15,%rsi
mov    0xc(%rsp),%edx
mov    $0x1,%ecx
call   10a0 <transmit@plt>
jmp    12b0 <download_recursive+0x120>
mov    0x2d40(%rip),%rcx
cmp    (%rcx),%rax
jne    12b0 <download_recursive+0x120>
mov    0x18(%rsp),%rdi
mov    %r15,%rsi
mov    0xc(%rsp),%edx
call   1090 <download_recursive@plt>
xchg   %ax,%ax
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1040 <readdir_r@plt>
test   %rax,%rax
jne    12cf <download_recursive+0x13f>
cmpq   $0x0,0x10(%rsp)
jne    1200 <download_recursive+0x70>
mov    %rbp,%rdi
call   1070 <closedir@plt>
add    $0x1038,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.client_attr = type { i32 }
%struct.dirent = type { i8*, i64 }
@.str = [2 x i8] c".\00"
@.str.1 = [3 x i8] c"..\00"
@.str.2 = [2 x i8] c"/\00"
@DT_REG = global i64 0
@DT_DIR = global i64 0
define void @download_recursive(%struct.client_attr* %0, i8* %1, i32 %2) {
%4 = alloca %struct.client_attr*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32*
%8 = alloca %struct.dirent
%9 = alloca %struct.dirent*
%10 = alloca [4096 x i8]
store %struct.client_attr* %0, %struct.client_attr** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%11 = load i8*, i8** %5
%12 = call i32* @opendir(i8* %11)
store i32* %12, i32** %7
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %15
14: ; preds = %3
br label %80
15: ; preds = %3
br label %16
16: ; preds = %76, %35, %15
%17 = load i32*, i32** %7
%18 = call i64 @readdir_r(i32* %17, %struct.dirent* %8, %struct.dirent** %9)
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %23
20: ; preds = %16
%21 = load %struct.dirent*, %struct.dirent** %9
%22 = icmp ne %struct.dirent* %21, null
br label %23
23: ; preds = %20, %16
%24 = phi i1 [ false, %16 ], [ %22, %20 ]
br i1 %24, label %25, label %77
25: ; preds = %23
%26 = getelementptr inbounds %struct.dirent, %struct.dirent* %8, i32 0, i32 0
%27 = load i8*, i8** %26
%28 = call i64 @strcmp(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8* %27)
%29 = icmp eq i64 %28, 0
br i1 %29, label %35, label %30
30: ; preds = %25
%31 = getelementptr inbounds %struct.dirent, %struct.dirent* %8, i32 0, i32 0
%32 = load i8*, i8** %31
%33 = call i64 @strcmp(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %32)
%34 = icmp eq i64 %33, 0
br i1 %34, label %35, label %36
35: ; preds = %30, %25
br label %16
36: ; preds = %30
%37 = getelementptr inbounds [4096 x i8], [4096 x i8]* %10, i64 0, i64 0
%38 = load i8*, i8** %5
%39 = call i32 @strcpy(i8* %37, i8* %38)
%40 = getelementptr inbounds [4096 x i8], [4096 x i8]* %10, i64 0, i64 0
%41 = getelementptr inbounds [4096 x i8], [4096 x i8]* %10, i64 0, i64 0
%42 = call i32 @strlen(i8* %41)
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds i8, i8* %40, i64 %43
%45 = getelementptr inbounds i8, i8* %44, i64 -1
%46 = load i8, i8* %45
%47 = sext i8 %46 to i32
%48 = icmp ne i32 %47, 47
br i1 %48, label %49, label %52
49: ; preds = %36
%50 = getelementptr inbounds [4096 x i8], [4096 x i8]* %10, i64 0, i64 0
%51 = call i32 @strcat(i8* %50, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %52
52: ; preds = %49, %36
%53 = getelementptr inbounds [4096 x i8], [4096 x i8]* %10, i64 0, i64 0
%54 = getelementptr inbounds %struct.dirent, %struct.dirent* %8, i32 0, i32 0
%55 = load i8*, i8** %54
%56 = call i32 @strcat(i8* %53, i8* %55)
%57 = getelementptr inbounds %struct.dirent, %struct.dirent* %8, i32 0, i32 1
%58 = load i64, i64* %57
%59 = load i64, i64* @DT_REG
%60 = icmp eq i64 %58, %59
br i1 %60, label %61, label %66
61: ; preds = %52
%62 = load %struct.client_attr*, %struct.client_attr** %4
%63 = getelementptr inbounds [4096 x i8], [4096 x i8]* %10, i64 0, i64 0
%64 = load i32, i32* %6
%65 = call i32 @transmit(%struct.client_attr* %62, i8* %63, i32 %64, i32 1)
br label %76
66: ; preds = %52
%67 = getelementptr inbounds %struct.dirent, %struct.dirent* %8, i32 0, i32 1
%68 = load i64, i64* %67
%69 = load i64, i64* @DT_DIR
%70 = icmp eq i64 %68, %69
br i1 %70, label %71, label %75
71: ; preds = %66
%72 = load %struct.client_attr*, %struct.client_attr** %4
%73 = getelementptr inbounds [4096 x i8], [4096 x i8]* %10, i64 0, i64 0
%74 = load i32, i32* %6
br label %75
75: ; preds = %71, %66
br label %76
76: ; preds = %75, %61
br label %16
77: ; preds = %23
%78 = load i32*, i32** %7
%79 = call i32 @closedir(i32* %78)
br label %80
80: ; preds = %77, %14
ret void
}

LLVM IR (-O2):
%struct.client_attr = type { i32 }
%struct.dirent = type { i8*, i64 }
@.str = [2 x i8] c".\00"
@.str.1 = [3 x i8] c"..\00"
@.str.2 = [2 x i8] c"/\00"
@DT_REG = global i64 0
@DT_DIR = global i64 0
define void @download_recursive(%struct.client_attr* %0, i8* %1, i32 %2) {
%4 = alloca %struct.dirent
%5 = alloca %struct.dirent*
%6 = alloca [4096 x i8]
%7 = bitcast %struct.dirent* %4 to i8*
%8 = bitcast %struct.dirent** %5 to i8*
%9 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%10 = tail call i32* @opendir(i8* %1)
%11 = icmp eq i32* %10, null
br i1 %11, label %59, label %12
12: ; preds = %3
%13 = call i64 @readdir_r(i32* %10, %struct.dirent* %4, %struct.dirent** %5)
%14 = icmp eq i64 %13, 0
%15 = load %struct.dirent*, %struct.dirent** %5
%16 = icmp ne %struct.dirent* %15, null
%17 = select i1 %14, i1 %16, i1 false
br i1 %17, label %18, label %57
18: ; preds = %12
%19 = getelementptr inbounds %struct.dirent, %struct.dirent* %4, i64 0, i32 0
%20 = getelementptr inbounds %struct.dirent, %struct.dirent* %4, i64 0, i32 1
br label %21
21: ; preds = %18, %29
%22 = load i8*, i8** %19
%23 = call i64 @strcmp(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8* %22)
%24 = icmp eq i64 %23, 0
br i1 %24, label %29, label %25
25: ; preds = %21
%26 = load i8*, i8** %19
%27 = call i64 @strcmp(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %26)
%28 = icmp eq i64 %27, 0
br i1 %28, label %29, label %35
29: ; preds = %51, %56, %53, %21, %25
%30 = call i64 @readdir_r(i32* %10, %struct.dirent* %4, %struct.dirent** %5)
%31 = icmp eq i64 %30, 0
%32 = load %struct.dirent*, %struct.dirent** %5
%33 = icmp ne %struct.dirent* %32, null
%34 = select i1 %31, i1 %33, i1 false
br i1 %34, label %21, label %57
35: ; preds = %25
%36 = call i32 @strcpy(i8* %9, i8* %1)
%37 = call i32 @strlen(i8* %9)
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 %38
%40 = getelementptr inbounds i8, i8* %39, i64 -1
%41 = load i8, i8* %40
%42 = icmp eq i8 %41, 47
br i1 %42, label %45, label %43
43: ; preds = %35
%44 = call i32 @strcat(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %45
45: ; preds = %43, %35
%46 = load i8*, i8** %19
%47 = call i32 @strcat(i8* %9, i8* %46)
%48 = load i64, i64* %20
%49 = load i64, i64* @DT_REG
%50 = icmp eq i64 %48, %49
br i1 %50, label %51, label %53
51: ; preds = %45
%52 = call i32 @transmit(%struct.client_attr* %0, i8* %9, i32 %2, i32 1)
br label %29
53: ; preds = %45
%54 = load i64, i64* @DT_DIR
%55 = icmp eq i64 %48, %54
br i1 %55, label %56, label %29
56: ; preds = %53
br label %29
57: ; preds = %29, %12
%58 = call i32 @closedir(i32* %10)
br label %59
59: ; preds = %3, %57
ret void
}