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

/* Variables and functions */
int /*<<< orphan*/ EraseFileIndex(char *);
char *GetRealPath(char *);
int /*<<< orphan*/ Lock();
int /*<<< orphan*/ UnLock();
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ free(char *);
char *malloc(int);
int strlen(char *);
int unlink(char *);
char *writeInt(char *, int);
char *writeString(char *, char *, int);
int DeleteFile(char *fileName, char **buf, uint32_t *sendLen) {
  int err = 0;
  char *errStr = "";
  char *filePath = GetRealPath(fileName);
  uint32_t totalLen = 0;
  char *writeIndex = NULL;
  do {
    err = unlink(filePath);
    assert(err == 0);
    Lock();
    EraseFileIndex(fileName);
    UnLock();
  } while (0);
  totalLen += 4 + 4 + strlen(errStr);
  *buf = malloc(totalLen + 4);
  writeIndex = *buf;
  *sendLen = totalLen + 4;
  writeIndex = writeInt(writeIndex, totalLen);
  writeIndex = writeInt(writeIndex, err);
  writeIndex = writeString(writeIndex, errStr, strlen(errStr));
  if (filePath != NULL) {
    free(filePath);
  }
  return err;
}


x86 assembly (clang, -O0):
<DeleteFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
lea    0xe2e(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
call   10d0 <GetRealPath@plt>
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
movq   $0x0,-0x40(%rbp)
mov    -0x30(%rbp),%rdi
call   1050 <unlink@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
mov    $0x0,%al
call   1080 <Lock@plt>
mov    -0x8(%rbp),%rdi
call   10b0 <EraseFileIndex@plt>
mov    $0x0,%al
call   10c0 <UnLock@plt>
mov    -0x28(%rbp),%rdi
call   1060 <strlen@plt>
add    $0x8,%eax
add    -0x34(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x34(%rbp),%edi
add    $0x4,%edi
call   10a0 <malloc@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x40(%rbp)
mov    -0x34(%rbp),%ecx
add    $0x4,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x40(%rbp),%rdi
mov    -0x34(%rbp),%esi
call   1030 <writeInt@plt>
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1030 <writeInt@plt>
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x28(%rbp),%rdi
call   1060 <strlen@plt>
mov    -0x50(%rbp),%rdi
mov    -0x48(%rbp),%rsi
mov    %eax,%edx
call   1090 <writeString@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     12c4 <DeleteFile+0x114>
mov    -0x30(%rbp),%rdi
call   1040 <free@plt>
mov    -0x1c(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<DeleteFile>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,(%rsp)
mov    %rsi,%r15
mov    %rdi,%rbx
call   10d0 <GetRealPath@plt>
mov    %rax,%r13
mov    %rax,%rdi
call   1050 <unlink@plt>
mov    %eax,%ebp
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1070 <assert@plt>
xor    %eax,%eax
call   1080 <Lock@plt>
mov    %rbx,%rdi
call   10b0 <EraseFileIndex@plt>
xor    %eax,%eax
call   10c0 <UnLock@plt>
lea    0xdff(%rip),%r12
mov    %r12,%rdi
call   1060 <strlen@plt>
mov    %eax,%ebx
lea    0x8(%rbx),%r14d
add    $0xc,%ebx
mov    %ebx,%edi
call   10a0 <malloc@plt>
mov    %rax,(%r15)
mov    (%rsp),%rcx
mov    %ebx,(%rcx)
mov    %rax,%rdi
mov    %r14d,%esi
call   1030 <writeInt@plt>
mov    %rax,%rdi
mov    %ebp,%esi
call   1030 <writeInt@plt>
mov    %rax,%rbx
mov    %r12,%rdi
call   1060 <strlen@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %eax,%edx
call   1090 <writeString@plt>
test   %r13,%r13
je     125c <DeleteFile+0xac>
mov    %r13,%rdi
call   1040 <free@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [1 x i8] zeroinitializer
define i32 @DeleteFile(i8* %0, i8** %1, i32* %2) {
%4 = alloca i8*
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i8*
store i8* %0, i8** %4
store i8** %1, i8*** %5
store i32* %2, i32** %6
store i32 0, i32* %7
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8** %8
%12 = load i8*, i8** %4
%13 = call i8* @GetRealPath(i8* %12)
store i8* %13, i8** %9
store i32 0, i32* %10
store i8* null, i8** %11
br label %14
14: ; preds = %3
%15 = load i8*, i8** %9
%16 = call i32 @unlink(i8* %15)
store i32 %16, i32* %7
%17 = load i32, i32* %7
%18 = icmp eq i32 %17, 0
%19 = zext i1 %18 to i32
%20 = call i32 @assert(i32 %19)
%21 = call i32 (...) @Lock()
%22 = load i8*, i8** %4
%23 = call i32 @EraseFileIndex(i8* %22)
%24 = call i32 (...) @UnLock()
br label %25
25: ; preds = %14
%26 = load i8*, i8** %8
%27 = call i32 @strlen(i8* %26)
%28 = add nsw i32 8, %27
%29 = load i32, i32* %10
%30 = add nsw i32 %29, %28
store i32 %30, i32* %10
%31 = load i32, i32* %10
%32 = add nsw i32 %31, 4
%33 = call i8* @malloc(i32 %32)
%34 = load i8**, i8*** %5
store i8* %33, i8** %34
%35 = load i8**, i8*** %5
%36 = load i8*, i8** %35
store i8* %36, i8** %11
%37 = load i32, i32* %10
%38 = add nsw i32 %37, 4
%39 = load i32*, i32** %6
store i32 %38, i32* %39
%40 = load i8*, i8** %11
%41 = load i32, i32* %10
%42 = call i8* @writeInt(i8* %40, i32 %41)
store i8* %42, i8** %11
%43 = load i8*, i8** %11
%44 = load i32, i32* %7
%45 = call i8* @writeInt(i8* %43, i32 %44)
store i8* %45, i8** %11
%46 = load i8*, i8** %11
%47 = load i8*, i8** %8
%48 = load i8*, i8** %8
%49 = call i32 @strlen(i8* %48)
%50 = call i8* @writeString(i8* %46, i8* %47, i32 %49)
store i8* %50, i8** %11
%51 = load i8*, i8** %9
%52 = icmp ne i8* %51, null
br i1 %52, label %53, label %56
53: ; preds = %25
%54 = load i8*, i8** %9
%55 = call i32 @free(i8* %54)
br label %56
56: ; preds = %53, %25
%57 = load i32, i32* %7
ret i32 %57
}

LLVM IR (-O2):
@.str = [1 x i8] zeroinitializer
define i32 @DeleteFile(i8* %0, i8** nocapture writeonly %1, i32* nocapture writeonly %2) {
%4 = tail call i8* @GetRealPath(i8* %0)
%5 = tail call i32 @unlink(i8* %4)
%6 = icmp eq i32 %5, 0
%7 = zext i1 %6 to i32
%8 = tail call i32 @assert(i32 %7)
%9 = tail call i32 (...) @Lock()
%10 = tail call i32 @EraseFileIndex(i8* %0)
%11 = tail call i32 (...) @UnLock()
%12 = tail call i32 @strlen(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%13 = add nsw i32 %12, 8
%14 = add nsw i32 %12, 12
%15 = tail call i8* @malloc(i32 %14)
store i8* %15, i8** %1
store i32 %14, i32* %2
%16 = tail call i8* @writeInt(i8* %15, i32 %13)
%17 = tail call i8* @writeInt(i8* %16, i32 %5)
%18 = tail call i32 @strlen(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%19 = tail call i8* @writeString(i8* %17, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i32 %18)
%20 = icmp eq i8* %4, null
br i1 %20, label %23, label %21
21: ; preds = %3
%22 = tail call i32 @free(i8* %4)
br label %23
23: ; preds = %21, %3
ret i32 %5
}