#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 scalar_t__ uint32_t;

/* Variables and functions */
int /*<<< orphan*/ ListDir(char *, char **, scalar_t__ *);
int /*<<< orphan*/ SendAll(int, char *, scalar_t__);
int /*<<< orphan*/ bzero(char *, scalar_t__);
int /*<<< orphan*/ free(char *);
scalar_t__ malloc(scalar_t__);
int /*<<< orphan*/ memcpy(char *, char *, scalar_t__);
int /*<<< orphan*/ printf(char *, char *, int /*<<< orphan*/);
char *readInt(char *, scalar_t__ *);
int /*<<< orphan*/ strlen(char *);
void DoList(int fd, char *data) {
  uint32_t targetLen = 0;
  data = readInt(data, &targetLen);
  char *dir = (char *)malloc(targetLen + 1);
  bzero(dir, targetLen + 1);
  memcpy(dir, data, targetLen);
  printf("request dir is %s, size %ldd\n", dir, strlen(dir));
  char *buf = NULL;
  uint32_t sendLen = 0;
  ListDir(dir, &buf, &sendLen);
  SendAll(fd, buf, sendLen);
  free(buf);
  free(dir);
}


x86 assembly (clang, -O0):
<DoList>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1070 <readInt@plt>
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%rdi
add    $0x1,%rdi
call   1090 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
add    $0x1,%rsi
call   10a0 <bzero@plt>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1080 <memcpy@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x38(%rbp),%rsi
mov    %eax,%edx
lea    0xdf7(%rip),%rdi
call   1050 <printf@plt>
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
mov    -0x20(%rbp),%rdi
lea    -0x28(%rbp),%rsi
lea    -0x30(%rbp),%rdx
call   1060 <ListDir@plt>
mov    -0x4(%rbp),%edi
mov    -0x28(%rbp),%rsi
mov    -0x30(%rbp),%rdx
call   10b0 <SendAll@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<DoList>:
push   %rbp
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %rsi,%rax
mov    %edi,%r14d
movq   $0x0,0x8(%rsp)
lea    0x8(%rsp),%rsi
mov    %rax,%rdi
call   1070 <readInt@plt>
mov    %rax,%rbp
mov    0x8(%rsp),%rdi
add    $0x1,%rdi
call   1090 <malloc@plt>
mov    %rax,%rbx
mov    0x8(%rsp),%rsi
add    $0x1,%rsi
mov    %rax,%rdi
call   10a0 <bzero@plt>
mov    0x8(%rsp),%rdx
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1080 <memcpy@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
lea    0xe08(%rip),%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1050 <printf@plt>
movq   $0x0,0x10(%rsp)
movq   $0x0,0x18(%rsp)
lea    0x10(%rsp),%rsi
lea    0x18(%rsp),%rdx
mov    %rbx,%rdi
call   1060 <ListDir@plt>
mov    0x10(%rsp),%rsi
mov    0x18(%rsp),%rdx
mov    %r14d,%edi
call   10b0 <SendAll@plt>
mov    0x10(%rsp),%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [30 x i8] c"request dir is %s, size %ldd\0A\00"
define void @DoList(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i64
store i32 %0, i32* %3
store i8* %1, i8** %4
store i64 0, i64* %5
%9 = load i8*, i8** %4
%10 = call i8* @readInt(i8* %9, i64* %5)
store i8* %10, i8** %4
%11 = load i64, i64* %5
%12 = add nsw i64 %11, 1
%13 = call i64 @malloc(i64 %12)
%14 = inttoptr i64 %13 to i8*
store i8* %14, i8** %6
%15 = load i8*, i8** %6
%16 = load i64, i64* %5
%17 = add nsw i64 %16, 1
%18 = call i32 @bzero(i8* %15, i64 %17)
%19 = load i8*, i8** %6
%20 = load i8*, i8** %4
%21 = load i64, i64* %5
%22 = call i32 @memcpy(i8* %19, i8* %20, i64 %21)
%23 = load i8*, i8** %6
%24 = load i8*, i8** %6
%25 = call i32 @strlen(i8* %24)
%26 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* %23, i32 %25)
store i8* null, i8** %7
store i64 0, i64* %8
%27 = load i8*, i8** %6
%28 = call i32 @ListDir(i8* %27, i8** %7, i64* %8)
%29 = load i32, i32* %3
%30 = load i8*, i8** %7
%31 = load i64, i64* %8
%32 = call i32 @SendAll(i32 %29, i8* %30, i64 %31)
%33 = load i8*, i8** %7
%34 = call i32 @free(i8* %33)
%35 = load i8*, i8** %6
%36 = call i32 @free(i8* %35)
ret void
}

LLVM IR (-O2):
@.str = [30 x i8] c"request dir is %s, size %ldd\0A\00"
define void @DoList(i32 %0, i8* %1) {
%3 = alloca i64
%4 = alloca i8*
%5 = alloca i64
%6 = bitcast i64* %3 to i8*
store i64 0, i64* %3
%7 = call i8* @readInt(i8* %1, i64* %3)
%8 = load i64, i64* %3
%9 = add nsw i64 %8, 1
%10 = call i64 @malloc(i64 %9)
%11 = inttoptr i64 %10 to i8*
%12 = load i64, i64* %3
%13 = add nsw i64 %12, 1
%14 = call i32 @bzero(i8* %11, i64 %13)
%15 = load i64, i64* %3
%16 = call i32 @memcpy(i8* %11, i8* %7, i64 %15)
%17 = call i32 @strlen(i8* %11)
%18 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* %11, i32 %17)
%19 = bitcast i8** %4 to i8*
store i8* null, i8** %4
%20 = bitcast i64* %5 to i8*
store i64 0, i64* %5
%21 = call i32 @ListDir(i8* %11, i8** %4, i64* %5)
%22 = load i8*, i8** %4
%23 = load i64, i64* %5
%24 = call i32 @SendAll(i32 %0, i8* %22, i64 %23)
%25 = load i8*, i8** %4
%26 = call i32 @free(i8* %25)
%27 = call i32 @free(i8* %11)
ret void
}