#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*/ uint32_t;

/* Variables and functions */
int /*<<< orphan*/ SendAll(int, char *, int /*<<< orphan*/);
int /*<<< orphan*/ WriteFileEnd(char *, char *, char **, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ printf(char *, char *, char *);
char *readString(char *, char **);
void DoPutFileEnd(int fd, char *data) {
  char *fileName = NULL;
  data = readString(data, &fileName);
  char *md5 = NULL;
  data = readString(data, &md5);
  printf("DoPutFileEnd, filename: %s, md5: %s\n", fileName, md5);
  char *buf = NULL;
  uint32_t sendLen = 0;
  WriteFileEnd(fileName, md5, &buf, &sendLen);
  SendAll(fd, buf, sendLen);
  free(buf);
  free(fileName);
  free(md5);
}


x86 assembly (clang, -O0):
<DoPutFileEnd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1050 <readString@plt>
mov    %rax,-0x10(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1050 <readString@plt>
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
lea    0xe60(%rip),%rdi
call   1040 <printf@plt>
movq   $0x0,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
lea    -0x28(%rbp),%rdx
lea    -0x2c(%rbp),%rcx
call   1060 <WriteFileEnd@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>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<DoPutFileEnd>:
push   %rbx
sub    $0x20,%rsp
mov    %rsi,%rax
mov    %edi,%ebx
movq   $0x0,0x10(%rsp)
lea    0x10(%rsp),%rsi
mov    %rax,%rdi
call   1050 <readString@plt>
movq   $0x0,0x8(%rsp)
lea    0x8(%rsp),%rsi
mov    %rax,%rdi
call   1050 <readString@plt>
mov    0x10(%rsp),%rsi
mov    0x8(%rsp),%rdx
lea    0xe69(%rip),%rdi
call   1040 <printf@plt>
movq   $0x0,0x18(%rsp)
movl   $0x0,0x4(%rsp)
mov    0x10(%rsp),%rdi
mov    0x8(%rsp),%rsi
lea    0x18(%rsp),%rdx
lea    0x4(%rsp),%rcx
call   1060 <WriteFileEnd@plt>
mov    0x18(%rsp),%rsi
mov    0x4(%rsp),%edx
mov    %ebx,%edi
call   1070 <SendAll@plt>
mov    0x18(%rsp),%rdi
call   1030 <free@plt>
mov    0x10(%rsp),%rdi
call   1030 <free@plt>
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [37 x i8] c"DoPutFileEnd, filename: %s, md5: %s\0A\00"
define void @DoPutFileEnd(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
store i32 %0, i32* %3
store i8* %1, i8** %4
store i8* null, i8** %5
%9 = load i8*, i8** %4
%10 = call i8* @readString(i8* %9, i8** %5)
store i8* %10, i8** %4
store i8* null, i8** %6
%11 = load i8*, i8** %4
%12 = call i8* @readString(i8* %11, i8** %6)
store i8* %12, i8** %4
%13 = load i8*, i8** %5
%14 = load i8*, i8** %6
%15 = call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i8* %13, i8* %14)
store i8* null, i8** %7
store i32 0, i32* %8
%16 = load i8*, i8** %5
%17 = load i8*, i8** %6
%18 = call i32 @WriteFileEnd(i8* %16, i8* %17, i8** %7, i32* %8)
%19 = load i32, i32* %3
%20 = load i8*, i8** %7
%21 = load i32, i32* %8
%22 = call i32 @SendAll(i32 %19, i8* %20, i32 %21)
%23 = load i8*, i8** %7
%24 = call i32 @free(i8* %23)
%25 = load i8*, i8** %5
%26 = call i32 @free(i8* %25)
%27 = load i8*, i8** %6
%28 = call i32 @free(i8* %27)
ret void
}

LLVM IR (-O2):
@.str = [37 x i8] c"DoPutFileEnd, filename: %s, md5: %s\0A\00"
define void @DoPutFileEnd(i32 %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = bitcast i8** %3 to i8*
store i8* null, i8** %3
%8 = call i8* @readString(i8* %1, i8** %3)
%9 = bitcast i8** %4 to i8*
store i8* null, i8** %4
%10 = call i8* @readString(i8* %8, i8** %4)
%11 = load i8*, i8** %3
%12 = load i8*, i8** %4
%13 = call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i8* %11, i8* %12)
%14 = bitcast i8** %5 to i8*
store i8* null, i8** %5
%15 = bitcast i32* %6 to i8*
store i32 0, i32* %6
%16 = load i8*, i8** %3
%17 = load i8*, i8** %4
%18 = call i32 @WriteFileEnd(i8* %16, i8* %17, i8** %5, i32* %6)
%19 = load i8*, i8** %5
%20 = load i32, i32* %6
%21 = call i32 @SendAll(i32 %0, i8* %19, i32 %20)
%22 = load i8*, i8** %5
%23 = call i32 @free(i8* %22)
%24 = load i8*, i8** %3
%25 = call i32 @free(i8* %24)
%26 = load i8*, i8** %4
%27 = call i32 @free(i8* %26)
ret void
}