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

/* Variables and functions */
scalar_t__ DT_DIR;
scalar_t__ DT_REG;
int PATH_MAX;
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 server_attr *, char *, int, int);
void upload_recursive(struct server_attr *attr, char *path,
                      int dir_name_length) {
  DIR *dirp;
  struct dirent entry, *result;
  char tmp[PATH_MAX];
  ;
  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) {
      upload_recursive(attr, tmp, dir_name_length);
    }
  }
  closedir(dirp);
}


x86 assembly (clang, -O0):
<upload_recursive>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    0x2e46(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x40(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x58(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x48(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <opendir@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    11f2 <upload_recursive+0x62>
movl   $0x1,-0x4c(%rbp)
jmp    1324 <upload_recursive+0x194>
jmp    11f7 <upload_recursive+0x67>
mov    -0x20(%rbp),%rdi
lea    -0x30(%rbp),%rsi
lea    -0x38(%rbp),%rdx
call   1050 <readdir_r@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x59(%rbp)
jne    1225 <upload_recursive+0x95>
cmpq   $0x0,-0x38(%rbp)
setne  %al
mov    %al,-0x59(%rbp)
mov    -0x59(%rbp),%al
test   $0x1,%al
jne    1235 <upload_recursive+0xa5>
jmp    1314 <upload_recursive+0x184>
mov    -0x30(%rbp),%rsi
lea    0xdc1(%rip),%rdi
call   1090 <strcmp@plt>
cmp    $0x0,%rax
je     1269 <upload_recursive+0xd9>
mov    -0x30(%rbp),%rsi
lea    0xda6(%rip),%rdi
call   1090 <strcmp@plt>
cmp    $0x0,%rax
jne    126e <upload_recursive+0xde>
jmp    11f7 <upload_recursive+0x67>
mov    -0x58(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x58(%rbp),%rdi
call   1070 <strlen@plt>
mov    %eax,%ecx
mov    -0x58(%rbp),%rax
movslq %ecx,%rcx
movsbl -0x1(%rax,%rcx,1),%eax
cmp    $0x2f,%eax
je     12ab <upload_recursive+0x11b>
mov    -0x58(%rbp),%rdi
lea    0xd5d(%rip),%rsi
call   10b0 <strcat@plt>
mov    -0x58(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   10b0 <strcat@plt>
mov    -0x28(%rbp),%rax
mov    0x2d15(%rip),%rcx
cmp    (%rcx),%rax
jne    12e6 <upload_recursive+0x156>
mov    -0x58(%rbp),%rsi
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%edx
mov    $0x1,%ecx
call   10a0 <transmit@plt>
jmp    130f <upload_recursive+0x17f>
mov    -0x28(%rbp),%rax
mov    0x2cdf(%rip),%rcx
cmp    (%rcx),%rax
jne    130a <upload_recursive+0x17a>
mov    -0x58(%rbp),%rsi
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%edx
call   1040 <upload_recursive@plt>
jmp    130f <upload_recursive+0x17f>
jmp    11f7 <upload_recursive+0x67>
mov    -0x20(%rbp),%rdi
call   1080 <closedir@plt>
movl   $0x0,-0x4c(%rbp)
mov    -0x40(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<upload_recursive>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %edx,-0x2c(%rbp)
mov    %rdi,-0x40(%rbp)
mov    %rsp,%r14
mov    0x2e3e(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %rsi,-0x60(%rbp)
mov    %rsi,%rdi
call   1060 <opendir@plt>
test   %rax,%rax
je     12fa <upload_recursive+0x16a>
mov    %rax,%r13
mov    %r14,-0x58(%rbp)
lea    -0x50(%rbp),%rsi
lea    -0x38(%rbp),%rdx
mov    %rax,%rdi
call   1050 <readdir_r@plt>
test   %rax,%rax
jne    12ee <upload_recursive+0x15e>
cmpq   $0x0,-0x38(%rbp)
je     12ee <upload_recursive+0x15e>
lea    0xdf5(%rip),%r14
lea    -0x50(%rbp),%r15
lea    -0x38(%rbp),%r12
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    -0x50(%rbp),%rsi
mov    %r14,%rdi
call   1090 <strcmp@plt>
test   %rax,%rax
je     12d0 <upload_recursive+0x140>
mov    -0x50(%rbp),%rsi
lea    0xdc0(%rip),%rdi
call   1090 <strcmp@plt>
test   %rax,%rax
je     12d0 <upload_recursive+0x140>
mov    %rbx,%rdi
mov    -0x60(%rbp),%rsi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
call   1070 <strlen@plt>
cltq
cmpb   $0x2f,-0x1(%rbx,%rax,1)
je     127a <upload_recursive+0xea>
mov    %rbx,%rdi
lea    0xd8e(%rip),%rsi
call   10b0 <strcat@plt>
mov    -0x50(%rbp),%rsi
mov    %rbx,%rdi
call   10b0 <strcat@plt>
mov    -0x48(%rbp),%rax
mov    0x2d47(%rip),%rcx
cmp    (%rcx),%rax
jne    12ac <upload_recursive+0x11c>
mov    -0x40(%rbp),%rdi
mov    %rbx,%rsi
mov    -0x2c(%rbp),%edx
mov    $0x1,%ecx
call   10a0 <transmit@plt>
jmp    12d0 <upload_recursive+0x140>
mov    0x2d1d(%rip),%rcx
cmp    (%rcx),%rax
jne    12d0 <upload_recursive+0x140>
mov    -0x40(%rbp),%rdi
mov    %rbx,%rsi
mov    -0x2c(%rbp),%edx
call   1040 <upload_recursive@plt>
nopw   0x0(%rax,%rax,1)
mov    %r13,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
call   1050 <readdir_r@plt>
test   %rax,%rax
jne    12ee <upload_recursive+0x15e>
cmpq   $0x0,-0x38(%rbp)
jne    1220 <upload_recursive+0x90>
mov    %r13,%rdi
call   1080 <closedir@plt>
mov    -0x58(%rbp),%r14
mov    %r14,%rsp
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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