#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*/ SendAll(int, char *, int /*<<< orphan*/);
int /*<<< orphan*/ WriteFile(char *, char *, int /*<<< orphan*/, char *,
                             int /*<<< orphan*/, char **, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
char *read64Int(char *, int /*<<< orphan*/ *);
char *readInt(char *, int /*<<< orphan*/ *);
char *readString(char *, char **);
void DoWrite(int fd, char *data) {
  char *fileName = NULL;
  data = readString(data, &fileName);
  char *md5 = NULL;
  data = readString(data, &md5);
  uint64_t offset = 0;
  data = read64Int(data, &offset);
  uint32_t dataLen = 0;
  data = readInt(data, &dataLen);
  char *buf = NULL;
  uint32_t sendLen = 0;
  WriteFile(fileName, md5, offset, data, dataLen, &buf, &sendLen);
  SendAll(fd, buf, sendLen);
  free(buf);
  free(fileName);
  free(md5);
}


x86 assembly (clang, -O0):
<DoWrite>:
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 <readString@plt>
mov    %rax,-0x10(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1070 <readString@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x24(%rbp),%rsi
call   1040 <read64Int@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   1050 <readInt@plt>
mov    %rax,-0x10(%rbp)
movq   $0x0,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x24(%rbp),%edx
mov    -0x10(%rbp),%rcx
mov    -0x28(%rbp),%r8d
lea    -0x30(%rbp),%r9
lea    -0x34(%rbp),%rax
mov    %rax,(%rsp)
call   1060 <WriteFile@plt>
mov    -0x4(%rbp),%edi
mov    -0x30(%rbp),%rsi
mov    -0x34(%rbp),%edx
call   1080 <SendAll@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<DoWrite>:
push   %rbx
sub    $0x30,%rsp
mov    %rsi,%rax
mov    %edi,%ebx
movq   $0x0,0x28(%rsp)
lea    0x28(%rsp),%rsi
mov    %rax,%rdi
call   1070 <readString@plt>
movq   $0x0,0x20(%rsp)
lea    0x20(%rsp),%rsi
mov    %rax,%rdi
call   1070 <readString@plt>
movl   $0x0,0x14(%rsp)
lea    0x14(%rsp),%rsi
mov    %rax,%rdi
call   1040 <read64Int@plt>
movl   $0x0,0x10(%rsp)
lea    0x10(%rsp),%rsi
mov    %rax,%rdi
call   1050 <readInt@plt>
movq   $0x0,0x18(%rsp)
movl   $0x0,0xc(%rsp)
mov    0x28(%rsp),%rdi
mov    0x20(%rsp),%rsi
mov    0x14(%rsp),%edx
mov    0x10(%rsp),%r8d
lea    0xc(%rsp),%rcx
mov    %rcx,(%rsp)
lea    0x18(%rsp),%r9
mov    %rax,%rcx
call   1060 <WriteFile@plt>
mov    0x18(%rsp),%rsi
mov    0xc(%rsp),%edx
mov    %ebx,%edi
call   1080 <SendAll@plt>
mov    0x18(%rsp),%rdi
call   1030 <free@plt>
mov    0x28(%rsp),%rdi
call   1030 <free@plt>
mov    0x20(%rsp),%rdi
call   1030 <free@plt>
add    $0x30,%rsp
pop    %rbx
ret

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

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