char *brc_getrecord(ptr, name, pnum, list)
char *ptr, *name;
int *pnum, *list;
{
  int num;
  char *tmp;
  strncpy(name, ptr, 15);
  ptr += 15;
  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    $0xf,%edx
call   1030 <strncpy@plt>
mov    -0x8(%rbp),%rax
add    $0xf,%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),%rdx
shl    $0x2,%rdx
call   1040 <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    $0xf,%edx
mov    %rsi,%rdi
mov    %rbx,%rsi
call   1030 <strncpy@plt>
lea    0x10(%rbx),%rsi
movzbl 0xf(%rbx),%eax
cmp    $0x3c,%rax
lea    0x10(%rbx,%rax,4),%rbx
mov    $0x3c,%edx
cmovb  %eax,%edx
mov    %edx,(%r15)
shl    $0x2,%edx
mov    %r14,%rdi
call   1040 <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 i8* @strncpy(i8* %11, i8* %12, i64 15)
%14 = load i8*, i8** %5
%15 = getelementptr inbounds i8, i8* %14, i64 15
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 = bitcast i32* %32 to i8*
%34 = load i8*, i8** %5
%35 = load i32, i32* %9
%36 = sext i32 %35 to i64
%37 = mul i64 %36, 4
%38 = load i8*, i8** %10
ret i8* %38
}

LLVM IR (-O2):
define i8* @brc_getrecord(i8* %0, i8* %1, i32* nocapture writeonly %2, i32* nocapture writeonly %3) {
%5 = tail call i8* @strncpy(i8* dereferenceable(1) %1, i8* dereferenceable(1) %0, i64 15)
%6 = getelementptr inbounds i8, i8* %0, i64 15
%7 = getelementptr inbounds i8, i8* %0, i64 16
%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 = bitcast i32* %3 to i8*
%16 = shl nuw nsw i32 %14, 2
%17 = zext i32 %16 to i64
tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 4 %15, i8* align 1 %7, i64 %17, i1 false)
ret i8* %12
}