#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 */
char *cpu_info_strval(char *);
int strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
void cpu_info_strcpy(char *ptr, char *buf, int len) {
  int slen;
  ptr = cpu_info_strval(ptr);
  if (!ptr) {
    return;
  }
  slen = strlen(ptr);
  strncpy(buf, ptr, len);
  buf[len] = '\0';
  if (slen < len) {
    buf[slen - 1] = '\0';
  }
}


x86 assembly (clang, -O0):
<cpu_info_strcpy>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <cpu_info_strval@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    1160 <cpu_info_strcpy+0x30>
jmp    11a5 <cpu_info_strcpy+0x75>
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1030 <strncpy@plt>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11a5 <cpu_info_strcpy+0x75>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cpu_info_strcpy>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%ebp
mov    %rsi,%r15
call   1050 <cpu_info_strval@plt>
test   %rax,%rax
je     1177 <cpu_info_strcpy+0x47>
mov    %rax,%rbx
mov    %rax,%rdi
call   1040 <strlen@plt>
mov    %eax,%r14d
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %ebp,%edx
call   1030 <strncpy@plt>
movslq %ebp,%rax
movb   $0x0,(%r15,%rax,1)
cmp    %eax,%r14d
jge    1177 <cpu_info_strcpy+0x47>
movslq %r14d,%rax
movb   $0x0,-0x1(%rax,%r15,1)
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @cpu_info_strcpy(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%8 = load i8*, i8** %4
%9 = call i8* @cpu_info_strval(i8* %8)
store i8* %9, i8** %4
%10 = load i8*, i8** %4
%11 = icmp ne i8* %10, null
br i1 %11, label %13, label %12
12: ; preds = %3
br label %33
13: ; preds = %3
%14 = load i8*, i8** %4
%15 = call i32 @strlen(i8* %14)
store i32 %15, i32* %7
%16 = load i8*, i8** %5
%17 = load i8*, i8** %4
%18 = load i32, i32* %6
%19 = call i32 @strncpy(i8* %16, i8* %17, i32 %18)
%20 = load i8*, i8** %5
%21 = load i32, i32* %6
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %20, i64 %22
store i8 0, i8* %23
%24 = load i32, i32* %7
%25 = load i32, i32* %6
%26 = icmp slt i32 %24, %25
br i1 %26, label %27, label %33
27: ; preds = %13
%28 = load i8*, i8** %5
%29 = load i32, i32* %7
%30 = sub nsw i32 %29, 1
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8, i8* %28, i64 %31
store i8 0, i8* %32
br label %33
33: ; preds = %12, %27, %13
ret void
}

LLVM IR (-O2):
define void @cpu_info_strcpy(i8* %0, i8* %1, i32 %2) {
%4 = tail call i8* @cpu_info_strval(i8* %0)
%5 = icmp eq i8* %4, null
br i1 %5, label %16, label %6
6: ; preds = %3
%7 = tail call i32 @strlen(i8* %4)
%8 = tail call i32 @strncpy(i8* %1, i8* %4, i32 %2)
%9 = sext i32 %2 to i64
%10 = getelementptr inbounds i8, i8* %1, i64 %9
store i8 0, i8* %10
%11 = icmp slt i32 %7, %2
br i1 %11, label %12, label %16
12: ; preds = %6
%13 = add nsw i32 %7, -1
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds i8, i8* %1, i64 %14
store i8 0, i8* %15
br label %16
16: ; preds = %6, %12, %3
ret void
}