#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 */
struct nlattr {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ memcpy(void *, int /*<<< orphan*/, int);
int /*<<< orphan*/ nla_data(struct nlattr const *);
int nla_len(struct nlattr const *);
int nla_memcpy(void *dest, const struct nlattr *src, int count) {
  int minlen = ({
    int __min1 = (count);
    int __min2 = (nla_len(src));
    __min1 < __min2 ? __min1 : __min2;
  });
  memcpy(dest, nla_data(src), minlen);
  return minlen;
}


x86 assembly (clang, -O0):
<nla_memcpy>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <nla_len@plt>
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x20(%rbp),%eax
jge    116c <nla_memcpy+0x3c>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x28(%rbp)
jmp    1172 <nla_memcpy+0x42>
mov    -0x20(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <nla_data@plt>
mov    -0x30(%rbp),%rdi
mov    %eax,%esi
mov    -0x18(%rbp),%edx
call   1050 <memcpy@plt>
mov    -0x18(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<nla_memcpy>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%ebx
mov    %rsi,%r14
mov    %rdi,%r15
mov    %rsi,%rdi
call   1030 <nla_len@plt>
mov    %eax,%ebp
cmp    %ebx,%eax
cmovg  %ebx,%ebp
mov    %r14,%rdi
call   1040 <nla_data@plt>
mov    %r15,%rdi
mov    %eax,%esi
mov    %ebp,%edx
call   1050 <memcpy@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.nlattr = type { i32 }
define i32 @nla_memcpy(i8* %0, %struct.nlattr* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca %struct.nlattr*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i8* %0, i8** %4
store %struct.nlattr* %1, %struct.nlattr** %5
store i32 %2, i32* %6
%11 = load i32, i32* %6
store i32 %11, i32* %8
%12 = load %struct.nlattr*, %struct.nlattr** %5
%13 = call i32 @nla_len(%struct.nlattr* %12)
store i32 %13, i32* %9
%14 = load i32, i32* %8
%15 = load i32, i32* %9
%16 = icmp slt i32 %14, %15
br i1 %16, label %17, label %19
17: ; preds = %3
%18 = load i32, i32* %8
br label %21
19: ; preds = %3
%20 = load i32, i32* %9
br label %21
21: ; preds = %19, %17
%22 = phi i32 [ %18, %17 ], [ %20, %19 ]
store i32 %22, i32* %10
%23 = load i32, i32* %10
store i32 %23, i32* %7
%24 = load i8*, i8** %4
%25 = load %struct.nlattr*, %struct.nlattr** %5
%26 = call i32 @nla_data(%struct.nlattr* %25)
%27 = load i32, i32* %7
%28 = call i32 @memcpy(i8* %24, i32 %26, i32 %27)
%29 = load i32, i32* %7
ret i32 %29
}

LLVM IR (-O2):
%struct.nlattr = type { i32 }
define i32 @nla_memcpy(i8* %0, %struct.nlattr* %1, i32 %2) {
%4 = tail call i32 @nla_len(%struct.nlattr* %1)
%5 = icmp sgt i32 %4, %2
%6 = select i1 %5, i32 %2, i32 %4
%7 = tail call i32 @nla_data(%struct.nlattr* %1)
%8 = tail call i32 @memcpy(i8* %0, i32 %7, i32 %6)
ret i32 %6
}