#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 int /*<<< orphan*/ uint64_t;
typedef int /*<<< orphan*/ uint32_t;

/* Variables and functions */
int /*<<< orphan*/ ReadData(char *, int /*<<< orphan*/, int /*<<< orphan*/,
                            char **, int /*<<< orphan*/ *);
int /*<<< orphan*/ SendAll(int, char *, int /*<<< orphan*/);
int /*<<< orphan*/ free(char *);
char *read64Int(char *, int /*<<< orphan*/ *);
char *readInt(char *, int /*<<< orphan*/ *);
char *readString(char *, char **);
void DoRead(int fd, char *data) {
  char *fileName;
  data = readString(data, &fileName);
  uint64_t offset = 0;
  data = read64Int(data, &offset);
  uint32_t size = 0;
  data = readInt(data, &size);
  char *buf = NULL;
  uint32_t sendLen = 0;
  ReadData(fileName, offset, size, &buf, &sendLen);
  SendAll(fd, buf, sendLen);
  free(buf);
  free(fileName);
}


x86 assembly (clang, -O0):
<DoRead>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1060 <readString@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x1c(%rbp),%rsi
call   1040 <read64Int@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1050 <readInt@plt>
mov    %rax,-0x10(%rbp)
movq   $0x0,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    -0x20(%rbp),%edx
lea    -0x28(%rbp),%rcx
lea    -0x2c(%rbp),%r8
call   1080 <ReadData@plt>
mov    -0x4(%rbp),%edi
mov    -0x28(%rbp),%rsi
mov    -0x2c(%rbp),%edx
call   1070 <SendAll@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<DoRead>:
push   %rbx
sub    $0x20,%rsp
mov    %rsi,%rax
mov    %edi,%ebx
lea    0x18(%rsp),%rsi
mov    %rax,%rdi
call   1060 <readString@plt>
movl   $0x0,0xc(%rsp)
lea    0xc(%rsp),%rsi
mov    %rax,%rdi
call   1040 <read64Int@plt>
movl   $0x0,0x8(%rsp)
lea    0x8(%rsp),%rsi
mov    %rax,%rdi
call   1050 <readInt@plt>
movq   $0x0,0x10(%rsp)
movl   $0x0,0x4(%rsp)
mov    0x18(%rsp),%rdi
mov    0xc(%rsp),%esi
mov    0x8(%rsp),%edx
lea    0x10(%rsp),%rcx
lea    0x4(%rsp),%r8
call   1080 <ReadData@plt>
mov    0x10(%rsp),%rsi
mov    0x4(%rsp),%edx
mov    %ebx,%edi
call   1070 <SendAll@plt>
mov    0x10(%rsp),%rdi
call   1030 <free@plt>
mov    0x18(%rsp),%rdi
call   1030 <free@plt>
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define void @DoRead(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
store i32 %0, i32* %3
store i8* %1, i8** %4
%10 = load i8*, i8** %4
%11 = call i8* @readString(i8* %10, i8** %5)
store i8* %11, i8** %4
store i32 0, i32* %6
%12 = load i8*, i8** %4
%13 = call i8* @read64Int(i8* %12, i32* %6)
store i8* %13, i8** %4
store i32 0, i32* %7
%14 = load i8*, i8** %4
%15 = call i8* @readInt(i8* %14, i32* %7)
store i8* %15, i8** %4
store i8* null, i8** %8
store i32 0, i32* %9
%16 = load i8*, i8** %5
%17 = load i32, i32* %6
%18 = load i32, i32* %7
%19 = call i32 @ReadData(i8* %16, i32 %17, i32 %18, i8** %8, i32* %9)
%20 = load i32, i32* %3
%21 = load i8*, i8** %8
%22 = load i32, i32* %9
%23 = call i32 @SendAll(i32 %20, i8* %21, i32 %22)
%24 = load i8*, i8** %8
%25 = call i32 @free(i8* %24)
%26 = load i8*, i8** %5
%27 = call i32 @free(i8* %26)
ret void
}

LLVM IR (-O2):
define void @DoRead(i32 %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = bitcast i8** %3 to i8*
%9 = call i8* @readString(i8* %1, i8** %3)
%10 = bitcast i32* %4 to i8*
store i32 0, i32* %4
%11 = call i8* @read64Int(i8* %9, i32* %4)
%12 = bitcast i32* %5 to i8*
store i32 0, i32* %5
%13 = call i8* @readInt(i8* %11, i32* %5)
%14 = bitcast i8** %6 to i8*
store i8* null, i8** %6
%15 = bitcast i32* %7 to i8*
store i32 0, i32* %7
%16 = load i8*, i8** %3
%17 = load i32, i32* %4
%18 = load i32, i32* %5
%19 = call i32 @ReadData(i8* %16, i32 %17, i32 %18, i8** %6, i32* %7)
%20 = load i8*, i8** %6
%21 = load i32, i32* %7
%22 = call i32 @SendAll(i32 %0, i8* %20, i32 %21)
%23 = load i8*, i8** %6
%24 = call i32 @free(i8* %23)
%25 = load i8*, i8** %3
%26 = call i32 @free(i8* %25)
ret void
}