#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*/ croak(char *, int const, int);
int /*<<< orphan*/ memcpy(void *const, char *, int const);
void mrt_copy_next(char **src, void *const dst, int const sz, int *remain_len) {
  if (remain_len && *remain_len < sz)
    croak("Attempt to read %d bytes while buffer contain only %d", sz,
          *remain_len);
  *remain_len -= sz;
  memcpy(dst, *src, sz);
  *src = *src + sz;
  return;
}


x86 assembly (clang, -O0):
<mrt_copy_next>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1166 <mrt_copy_next+0x46>
mov    -0x20(%rbp),%rax
mov    (%rax),%eax
cmp    -0x14(%rbp),%eax
jge    1166 <mrt_copy_next+0x46>
mov    -0x14(%rbp),%esi
mov    -0x20(%rbp),%rax
mov    (%rax),%edx
lea    0xe9f(%rip),%rdi
call   1030 <croak@plt>
mov    -0x14(%rbp),%edx
mov    -0x20(%rbp),%rax
mov    (%rax),%ecx
sub    %edx,%ecx
mov    %ecx,(%rax)
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rax
mov    (%rax),%rsi
mov    -0x14(%rbp),%edx
call   1040 <memcpy@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%rcx
movslq -0x14(%rbp),%rax
add    %rax,%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mrt_copy_next>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r12
mov    %edx,%ebx
mov    %rsi,%r15
mov    %rdi,%r14
test   %rcx,%rcx
je     114e <mrt_copy_next+0x2e>
mov    (%r12),%edx
cmp    %ebx,%edx
jge    114e <mrt_copy_next+0x2e>
lea    0xeb9(%rip),%rdi
mov    %ebx,%esi
call   1030 <croak@plt>
sub    %ebx,(%r12)
mov    (%r14),%rsi
mov    %r15,%rdi
mov    %ebx,%edx
call   1040 <memcpy@plt>
movslq %ebx,%rax
add    %rax,(%r14)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [54 x i8] c"Attempt to read %d bytes while buffer contain only %d\00"
define void @mrt_copy_next(i8** %0, i8* %1, i32 %2, i32* %3) {
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32*
store i8** %0, i8*** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
store i32* %3, i32** %8
%9 = load i32*, i32** %8
%10 = icmp ne i32* %9, null
br i1 %10, label %11, label %21
11: ; preds = %4
%12 = load i32*, i32** %8
%13 = load i32, i32* %12
%14 = load i32, i32* %7
%15 = icmp slt i32 %13, %14
br i1 %15, label %16, label %21
16: ; preds = %11
%17 = load i32, i32* %7
%18 = load i32*, i32** %8
%19 = load i32, i32* %18
%20 = call i32 @croak(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str, i64 0, i64 0), i32 %17, i32 %19)
br label %21
21: ; preds = %16, %11, %4
%22 = load i32, i32* %7
%23 = load i32*, i32** %8
%24 = load i32, i32* %23
%25 = sub nsw i32 %24, %22
store i32 %25, i32* %23
%26 = load i8*, i8** %6
%27 = load i8**, i8*** %5
%28 = load i8*, i8** %27
%29 = load i32, i32* %7
%30 = call i32 @memcpy(i8* %26, i8* %28, i32 %29)
%31 = load i8**, i8*** %5
%32 = load i8*, i8** %31
%33 = load i32, i32* %7
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i8, i8* %32, i64 %34
%36 = load i8**, i8*** %5
store i8* %35, i8** %36
ret void
}

LLVM IR (-O2):
@.str = [54 x i8] c"Attempt to read %d bytes while buffer contain only %d\00"
define void @mrt_copy_next(i8** nocapture %0, i8* %1, i32 %2, i32* %3) {
%5 = icmp eq i32* %3, null
br i1 %5, label %11, label %6
6: ; preds = %4
%7 = load i32, i32* %3
%8 = icmp slt i32 %7, %2
br i1 %8, label %9, label %11
9: ; preds = %6
%10 = tail call i32 @croak(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str, i64 0, i64 0), i32 %2, i32 %7)
br label %11
11: ; preds = %9, %6, %4
%12 = load i32, i32* %3
%13 = sub nsw i32 %12, %2
store i32 %13, i32* %3
%14 = load i8*, i8** %0
%15 = tail call i32 @memcpy(i8* %1, i8* %14, i32 %2)
%16 = load i8*, i8** %0
%17 = sext i32 %2 to i64
%18 = getelementptr inbounds i8, i8* %16, i64 %17
store i8* %18, i8** %0
ret void
}