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

/* Variables and functions */
int getFileSize(char *);
int /*<<< orphan*/ printf(char *, ...);
int truncate(char *, int);
void deleteLast(char *pValidFilePath, int pSizeOfData) {
  printf("start deleteLast Function\n");
  int Thefilesize = getFileSize(pValidFilePath);
  if (pSizeOfData < Thefilesize) {
    int result = truncate(pValidFilePath, Thefilesize - pSizeOfData);
    if (result == 0) {
      printf("successfully deleted %d bytes from file %s\n", pSizeOfData,
             pValidFilePath);
    } else {
      printf("could not delete %d bytes from file %s\n", pSizeOfData,
             pValidFilePath);
    }
  } else {
    printf("filesize smaller than size of data to delete\n");
  }
  printf("end deleteLast Function\n");
}


x86 assembly (clang, -O0):
<deleteLast>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
lea    0xeba(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%rdi
call   1040 <getFileSize@plt>
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    11b5 <deleteLast+0x85>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%esi
sub    -0xc(%rbp),%esi
call   1050 <truncate@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    119b <deleteLast+0x6b>
mov    -0xc(%rbp),%esi
mov    -0x8(%rbp),%rdx
lea    0xe8c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11b0 <deleteLast+0x80>
mov    -0xc(%rbp),%esi
mov    -0x8(%rbp),%rdx
lea    0xe9e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11c3 <deleteLast+0x93>
lea    0xeb3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xed3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<deleteLast>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%rbx
lea    0xf05(%rip),%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
call   1050 <getFileSize@plt>
sub    %ebp,%eax
jle    1177 <deleteLast+0x37>
mov    %rbx,%rdi
mov    %eax,%esi
call   1060 <truncate@plt>
test   %eax,%eax
je     1185 <deleteLast+0x45>
lea    0xeb7(%rip),%rdi
jmp    118c <deleteLast+0x4c>
lea    0xef0(%rip),%rdi
call   1030 <puts@plt>
jmp    1198 <deleteLast+0x58>
lea    0xe74(%rip),%rdi
mov    %ebp,%esi
mov    %rbx,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xefc(%rip),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1030 <puts@plt>

LLVM IR (-O0):
@.str = [27 x i8] c"start deleteLast Function\0A\00"
@.str.1 = [44 x i8] c"successfully deleted %d bytes from file %s\0A\00"
@.str.2 = [40 x i8] c"could not delete %d bytes from file %s\0A\00"
@.str.3 = [46 x i8] c"filesize smaller than size of data to delete\0A\00"
@.str.4 = [25 x i8] c"end deleteLast Function\0A\00"
define void @deleteLast(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%8 = load i8*, i8** %3
%9 = call i32 @getFileSize(i8* %8)
store i32 %9, i32* %5
%10 = load i32, i32* %4
%11 = load i32, i32* %5
%12 = icmp slt i32 %10, %11
br i1 %12, label %13, label %30
13: ; preds = %2
%14 = load i8*, i8** %3
%15 = load i32, i32* %5
%16 = load i32, i32* %4
%17 = sub nsw i32 %15, %16
%18 = call i32 @truncate(i8* %14, i32 %17)
store i32 %18, i32* %6
%19 = load i32, i32* %6
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %25
21: ; preds = %13
%22 = load i32, i32* %4
%23 = load i8*, i8** %3
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.1, i64 0, i64 0), i32 %22, i8* %23)
br label %29
25: ; preds = %13
%26 = load i32, i32* %4
%27 = load i8*, i8** %3
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0), i32 %26, i8* %27)
br label %29
29: ; preds = %25, %21
br label %32
30: ; preds = %2
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.3, i64 0, i64 0))
br label %32
32: ; preds = %30, %29
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str.1 = [44 x i8] c"successfully deleted %d bytes from file %s\0A\00"
@.str.2 = [40 x i8] c"could not delete %d bytes from file %s\0A\00"
@str = [26 x i8] c"start deleteLast Function\00"
@str.5 = [45 x i8] c"filesize smaller than size of data to delete\00"
@str.6 = [24 x i8] c"end deleteLast Function\00"
define void @deleteLast(i8* %0, i32 %1) {
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str, i64 0, i64 0))
%4 = tail call i32 @getFileSize(i8* %0)
%5 = icmp sgt i32 %4, %1
br i1 %5, label %6, label %14
6: ; preds = %2
%7 = sub nsw i32 %4, %1
%8 = tail call i32 @truncate(i8* %0, i32 %7)
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %6
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @.str.1, i64 0, i64 0), i32 %1, i8* %0)
br label %16
12: ; preds = %6
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0), i32 %1, i8* %0)
br label %16
14: ; preds = %2
%15 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @str.5, i64 0, i64 0))
br label %16
16: ; preds = %10, %12, %14
%17 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str.6, i64 0, i64 0))
ret void
}