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

/* Variables and functions */
int fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ memmove(char *, char *, int);
int strlen(char *);
int update_pepxml_buffer(char *buffer, char *bufpos, FILE *file_handle,
                         int buffersize) {
  int residu, read;
  residu = strlen(bufpos);
  if (residu <= 0)
    return 0;
  memmove(buffer, bufpos, residu);
  read = fread(buffer + residu, sizeof(char), buffersize - (residu + 1),
               file_handle);
  buffer[residu + read + 1] = '\0';
  bufpos = buffer;
  return read;
}


x86 assembly (clang, -O0):
<update_pepxml_buffer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
jg     1169 <update_pepxml_buffer+0x39>
movl   $0x0,-0x4(%rbp)
jmp    11c2 <update_pepxml_buffer+0x92>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x28(%rbp),%edx
call   1050 <memmove@plt>
mov    -0x10(%rbp),%rdi
movslq -0x28(%rbp),%rax
add    %rax,%rdi
mov    -0x24(%rbp),%edx
mov    -0x28(%rbp),%eax
add    $0x1,%eax
sub    %eax,%edx
mov    -0x20(%rbp),%rcx
mov    $0x1,%esi
call   1030 <fread@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x28(%rbp),%ecx
add    -0x2c(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<update_pepxml_buffer>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %ecx,%r12d
mov    %rdx,%r14
mov    %rsi,%rbp
mov    %rdi,%r15
mov    %rsi,%rdi
call   1040 <strlen@plt>
test   %eax,%eax
jle    1188 <update_pepxml_buffer+0x58>
mov    %eax,%ebx
mov    %r15,%rdi
mov    %rbp,%rsi
mov    %eax,%edx
call   1050 <memmove@plt>
mov    %ebx,%edi
add    %r15,%rdi
mov    %ebx,%edx
not    %edx
add    %r12d,%edx
mov    $0x1,%esi
mov    %r14,%rcx
call   1030 <fread@plt>
lea    (%rbx,%rax,1),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%r15,%rcx,1)
jmp    118a <update_pepxml_buffer+0x5a>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @update_pepxml_buffer(i8* %0, i8* %1, i32* %2, i32 %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i8* %0, i8** %6
store i8* %1, i8** %7
store i32* %2, i32** %8
store i32 %3, i32* %9
%12 = load i8*, i8** %7
%13 = call i32 @strlen(i8* %12)
store i32 %13, i32* %10
%14 = load i32, i32* %10
%15 = icmp sle i32 %14, 0
br i1 %15, label %16, label %17
16: ; preds = %4
store i32 0, i32* %5
br label %41
17: ; preds = %4
%18 = load i8*, i8** %6
%19 = load i8*, i8** %7
%20 = load i32, i32* %10
%21 = call i32 @memmove(i8* %18, i8* %19, i32 %20)
%22 = load i8*, i8** %6
%23 = load i32, i32* %10
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %22, i64 %24
%26 = load i32, i32* %9
%27 = load i32, i32* %10
%28 = add nsw i32 %27, 1
%29 = sub nsw i32 %26, %28
%30 = load i32*, i32** %8
%31 = call i32 @fread(i8* %25, i32 1, i32 %29, i32* %30)
store i32 %31, i32* %11
%32 = load i8*, i8** %6
%33 = load i32, i32* %10
%34 = load i32, i32* %11
%35 = add nsw i32 %33, %34
%36 = add nsw i32 %35, 1
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i8, i8* %32, i64 %37
store i8 0, i8* %38
%39 = load i8*, i8** %6
store i8* %39, i8** %7
%40 = load i32, i32* %11
store i32 %40, i32* %5
br label %41
41: ; preds = %17, %16
%42 = load i32, i32* %5
ret i32 %42
}

LLVM IR (-O2):
define i32 @update_pepxml_buffer(i8* %0, i8* %1, i32* nocapture %2, i32 %3) {
%5 = tail call i32 @strlen(i8* %1)
%6 = icmp slt i32 %5, 1
br i1 %6, label %18, label %7
7: ; preds = %4
%8 = tail call i32 @memmove(i8* %0, i8* %1, i32 %5)
%9 = zext i32 %5 to i64
%10 = getelementptr inbounds i8, i8* %0, i64 %9
%11 = xor i32 %5, -1
%12 = add i32 %11, %3
%13 = tail call i32 @fread(i8* %10, i32 1, i32 %12, i32* %2)
%14 = add nuw i32 %5, 1
%15 = add i32 %14, %13
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i8, i8* %0, i64 %16
store i8 0, i8* %17
br label %18
18: ; preds = %4, %7
%19 = phi i32 [ %13, %7 ], [ 0, %4 ]
ret i32 %19
}