#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 /*<<< orphan*/ free(char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ memcpy(char *, char *, int);
void truncatemem(char **recvbuf, int *recvbuflen, int offset) {
  char *tmp;
  int newsize = *recvbuflen - offset;
  tmp = (char *)malloc(newsize * sizeof(char));
  memcpy(tmp, *recvbuf + offset, newsize);
  free(*recvbuf);
  *recvbuf = tmp;
  *recvbuflen = newsize;
}


x86 assembly (clang, -O0):
<truncatemem>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
sub    -0x14(%rbp),%eax
mov    %eax,-0x24(%rbp)
movslq -0x24(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rax
mov    (%rax),%rsi
movslq -0x14(%rbp),%rax
add    %rax,%rsi
mov    -0x24(%rbp),%edx
call   1040 <memcpy@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x24(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<truncatemem>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edx,%ebx
mov    %rsi,%r14
mov    %rdi,%r15
mov    (%rsi),%ebp
sub    %edx,%ebp
mov    %ebp,%edi
call   1050 <malloc@plt>
mov    %rax,%r12
movslq %ebx,%rsi
add    (%r15),%rsi
mov    %rax,%rdi
mov    %ebp,%edx
call   1040 <memcpy@plt>
mov    (%r15),%rdi
call   1030 <free@plt>
mov    %r12,(%r15)
mov    %ebp,(%r14)
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @truncatemem(i8** %0, i32* %1, i32 %2) {
%4 = alloca i8**
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
store i8** %0, i8*** %4
store i32* %1, i32** %5
store i32 %2, i32* %6
%9 = load i32*, i32** %5
%10 = load i32, i32* %9
%11 = load i32, i32* %6
%12 = sub nsw i32 %10, %11
store i32 %12, i32* %8
%13 = load i32, i32* %8
%14 = sext i32 %13 to i64
%15 = mul i64 %14, 1
%16 = trunc i64 %15 to i32
%17 = call i64 @malloc(i32 %16)
%18 = inttoptr i64 %17 to i8*
store i8* %18, i8** %7
%19 = load i8*, i8** %7
%20 = load i8**, i8*** %4
%21 = load i8*, i8** %20
%22 = load i32, i32* %6
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %21, i64 %23
%25 = load i32, i32* %8
%26 = call i32 @memcpy(i8* %19, i8* %24, i32 %25)
%27 = load i8**, i8*** %4
%28 = load i8*, i8** %27
%29 = call i32 @free(i8* %28)
%30 = load i8*, i8** %7
%31 = load i8**, i8*** %4
store i8* %30, i8** %31
%32 = load i32, i32* %8
%33 = load i32*, i32** %5
store i32 %32, i32* %33
ret void
}

LLVM IR (-O2):
define void @truncatemem(i8** nocapture %0, i32* nocapture %1, i32 %2) {
%4 = load i32, i32* %1
%5 = sub nsw i32 %4, %2
%6 = tail call i64 @malloc(i32 %5)
%7 = inttoptr i64 %6 to i8*
%8 = load i8*, i8** %0
%9 = sext i32 %2 to i64
%10 = getelementptr inbounds i8, i8* %8, i64 %9
%11 = tail call i32 @memcpy(i8* %7, i8* %10, i32 %5)
%12 = load i8*, i8** %0
%13 = tail call i32 @free(i8* %12)
store i8* %7, i8** %0
store i32 %5, i32* %1
ret void
}