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


x86 assembly (clang, -O0):
<brc_getrecord>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    $0x14,%edx
call   1040 <strlcpy@plt>
mov    -0x8(%rbp),%rax
add    $0x14,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movsbl (%rax),%eax
and    $0xff,%eax
mov    %eax,-0x24(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
shl    $0x2,%rcx
add    %rcx,%rax
mov    %rax,-0x30(%rbp)
cmpl   $0x3c,-0x24(%rbp)
jle    1194 <brc_getrecord+0x74>
movl   $0x3c,-0x24(%rbp)
mov    -0x24(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rsi
movslq -0x24(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edx
call   1030 <memcpy@plt>
mov    -0x30(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<brc_getrecord>:
push   %r15
push   %r14
push   %rbx
mov    %rcx,%r14
mov    %rdx,%r15
mov    %rdi,%rbx
mov    %rsi,%rdi
mov    %rbx,%rsi
mov    $0x14,%edx
call   1040 <strlcpy@plt>
lea    0x15(%rbx),%rsi
movzbl 0x14(%rbx),%eax
cmp    $0x3c,%rax
lea    0x15(%rbx,%rax,4),%rbx
mov    $0x3c,%edx
cmovb  %eax,%edx
mov    %edx,(%r15)
shl    $0x2,%edx
mov    %r14,%rdi
call   1030 <memcpy@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define i8* @brc_getrecord(i8* %0, i8* %1, i32* nocapture writeonly %2, i32* %3) {
%5 = tail call i32 @strlcpy(i8* %1, i8* %0, i32 20)
%6 = getelementptr inbounds i8, i8* %0, i64 20
%7 = getelementptr inbounds i8, i8* %0, i64 21
%8 = load i8, i8* %6
%9 = zext i8 %8 to i32
%10 = zext i8 %8 to i64
%11 = shl nuw nsw i64 %10, 2
%12 = getelementptr inbounds i8, i8* %7, i64 %11
%13 = icmp ult i32 %9, 60
%14 = select i1 %13, i32 %9, i32 60
store i32 %14, i32* %2
%15 = shl nuw nsw i32 %14, 2
%16 = tail call i32 @memcpy(i32* %3, i8* %7, i32 %15)
ret i8* %12
}