#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(char *, int *, int);
int /*<<< orphan*/ strlcpy(char *, char *, int);
char *brc_putrecord(char *ptr, char *name, int num, int *list) {
  if (num > 0) {
    if (num > 60)
      num = 60;
    strlcpy(ptr, name, 20);
    ptr += 20;
    *ptr++ = num;
    memcpy(ptr, list, num * sizeof(int));
    ptr += num * sizeof(int);
  }
  return ptr;
}


x86 assembly (clang, -O0):
<brc_putrecord>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
cmpl   $0x0,-0x14(%rbp)
jle    11ad <brc_putrecord+0x8d>
cmpl   $0x3c,-0x14(%rbp)
jle    1152 <brc_putrecord+0x32>
movl   $0x3c,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0x14,%edx
call   1040 <strlcpy@plt>
mov    -0x8(%rbp),%rax
add    $0x14,%rax
mov    %rax,-0x8(%rbp)
mov    -0x14(%rbp),%eax
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x8(%rbp)
mov    %cl,(%rax)
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rsi
movslq -0x14(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edx
call   1030 <memcpy@plt>
movslq -0x14(%rbp),%rax
shl    $0x2,%rax
add    -0x8(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<brc_putrecord>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r15
test   %edx,%edx
jle    1163 <brc_putrecord+0x43>
mov    %rcx,%r14
cmp    $0x3c,%edx
mov    $0x3c,%ebx
cmovb  %edx,%ebx
mov    %r15,%rdi
mov    $0x14,%edx
call   1040 <strlcpy@plt>
lea    0x15(%r15),%rdi
mov    %bl,0x14(%r15)
shl    $0x2,%ebx
mov    %r14,%rsi
mov    %ebx,%edx
call   1030 <memcpy@plt>
add    %rbx,%r15
add    $0x15,%r15
mov    %r15,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @brc_putrecord(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* %7
%10 = icmp sgt i32 %9, 0
br i1 %10, label %11, label %37
11: ; preds = %4
%12 = load i32, i32* %7
%13 = icmp sgt i32 %12, 60
br i1 %13, label %14, label %15
14: ; preds = %11
store i32 60, i32* %7
br label %15
15: ; preds = %14, %11
%16 = load i8*, i8** %5
%17 = load i8*, i8** %6
%18 = call i32 @strlcpy(i8* %16, i8* %17, i32 20)
%19 = load i8*, i8** %5
%20 = getelementptr inbounds i8, i8* %19, i64 20
store i8* %20, i8** %5
%21 = load i32, i32* %7
%22 = trunc i32 %21 to i8
%23 = load i8*, i8** %5
%24 = getelementptr inbounds i8, i8* %23, i32 1
store i8* %24, i8** %5
store i8 %22, i8* %23
%25 = load i8*, i8** %5
%26 = load i32*, i32** %8
%27 = load i32, i32* %7
%28 = sext i32 %27 to i64
%29 = mul i64 %28, 4
%30 = trunc i64 %29 to i32
%31 = call i32 @memcpy(i8* %25, i32* %26, i32 %30)
%32 = load i32, i32* %7
%33 = sext i32 %32 to i64
%34 = mul i64 %33, 4
%35 = load i8*, i8** %5
%36 = getelementptr inbounds i8, i8* %35, i64 %34
store i8* %36, i8** %5
br label %37
37: ; preds = %15, %4
%38 = load i8*, i8** %5
ret i8* %38
}

LLVM IR (-O2):
define i8* @brc_putrecord(i8* %0, i8* %1, i32 %2, i32* %3) {
%5 = icmp sgt i32 %2, 0
br i1 %5, label %6, label %17
6: ; preds = %4
%7 = icmp ult i32 %2, 60
%8 = select i1 %7, i32 %2, i32 60
%9 = tail call i32 @strlcpy(i8* %0, i8* %1, i32 20)
%10 = getelementptr inbounds i8, i8* %0, i64 20
%11 = trunc i32 %8 to i8
%12 = getelementptr inbounds i8, i8* %0, i64 21
store i8 %11, i8* %10
%13 = shl nuw nsw i32 %8, 2
%14 = zext i32 %13 to i64
%15 = tail call i32 @memcpy(i8* %12, i32* %3, i32 %13)
%16 = getelementptr inbounds i8, i8* %12, i64 %14
br label %17
17: ; preds = %6, %4
%18 = phi i8* [ %16, %6 ], [ %0, %4 ]
ret i8* %18
}