#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*/ memcpy(unsigned char *, unsigned char *, unsigned int);
unsigned int codec_binary_encode(unsigned char *input, unsigned int in_len,
                                 unsigned char *output, unsigned int *out_len,
                                 unsigned int max_out_len) {
  if (max_out_len > in_len) {
    memcpy(output, input, in_len);
    *out_len = in_len;
    return in_len;
  } else {
    memcpy(output, input, max_out_len);
    *out_len = max_out_len;
    return max_out_len;
  }
}


x86 assembly (clang, -O0):
<codec_binary_encode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8d,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jbe    115b <codec_binary_encode+0x4b>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1030 <memcpy@plt>
mov    -0x14(%rbp),%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    117a <codec_binary_encode+0x6a>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x2c(%rbp),%edx
call   1030 <memcpy@plt>
mov    -0x2c(%rbp),%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<codec_binary_encode>:
push   %r14
push   %rbx
push   %rax
mov    %r8d,%ebx
mov    %rcx,%r14
mov    %rdi,%rax
cmp    %esi,%r8d
cmova  %esi,%ebx
mov    %rdx,%rdi
mov    %rax,%rsi
mov    %ebx,%edx
call   1030 <memcpy@plt>
mov    %ebx,(%r14)
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i32 @codec_binary_encode(i8* %0, i32 %1, i8* %2, i32* %3, i32 %4) {
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i32*
%11 = alloca i32
store i8* %0, i8** %7
store i32 %1, i32* %8
store i8* %2, i8** %9
store i32* %3, i32** %10
store i32 %4, i32* %11
%12 = load i32, i32* %11
%13 = load i32, i32* %8
%14 = icmp ugt i32 %12, %13
br i1 %14, label %15, label %23
15: ; preds = %5
%16 = load i8*, i8** %9
%17 = load i8*, i8** %7
%18 = load i32, i32* %8
%19 = call i32 @memcpy(i8* %16, i8* %17, i32 %18)
%20 = load i32, i32* %8
%21 = load i32*, i32** %10
store i32 %20, i32* %21
%22 = load i32, i32* %8
store i32 %22, i32* %6
br label %31
23: ; preds = %5
%24 = load i8*, i8** %9
%25 = load i8*, i8** %7
%26 = load i32, i32* %11
%27 = call i32 @memcpy(i8* %24, i8* %25, i32 %26)
%28 = load i32, i32* %11
%29 = load i32*, i32** %10
store i32 %28, i32* %29
%30 = load i32, i32* %11
store i32 %30, i32* %6
br label %31
31: ; preds = %23, %15
%32 = load i32, i32* %6
ret i32 %32
}

LLVM IR (-O2):
define i32 @codec_binary_encode(i8* %0, i32 %1, i8* %2, i32* nocapture writeonly %3, i32 %4) {
%6 = icmp ugt i32 %4, %1
%7 = select i1 %6, i32 %1, i32 %4
%8 = tail call i32 @memcpy(i8* %2, i8* %0, i32 %7)
store i32 %7, i32* %3
ret i32 %7
}