#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 EINVAL;
int ENOBUFS;
int /*<<< orphan*/ isprint(unsigned char);
int /*<<< orphan*/ memcpy(char *, char const *, unsigned int);
int copy_name(char *out, unsigned int outlen, const char *in,
              unsigned int inlen) {
  int i;
  if (inlen >= outlen) {
    return -ENOBUFS;
  }
  for (i = 0; i < inlen; i++) {
    if (!isprint((unsigned char)in[i])) {
      return -EINVAL;
    }
  }
  memcpy(out, in, inlen);
  out[inlen] = '\0';
  return 0;
}


x86 assembly (clang, -O0):
<copy_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x14(%rbp),%eax
jb     1155 <copy_name+0x35>
xor    %eax,%eax
mov    0x2ead(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    11ca <copy_name+0xaa>
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x24(%rbp),%eax
jae    11a8 <copy_name+0x88>
mov    -0x20(%rbp),%rax
movslq -0x28(%rbp),%rcx
movzbl (%rax,%rcx,1),%edi
call   1040 <isprint@plt>
cmp    $0x0,%eax
jne    1195 <copy_name+0x75>
xor    %eax,%eax
mov    0x2e4d(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    11ca <copy_name+0xaa>
jmp    119a <copy_name+0x7a>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    115c <copy_name+0x3c>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x24(%rbp),%edx
call   1030 <memcpy@plt>
mov    -0x10(%rbp),%rax
mov    -0x24(%rbp),%ecx
movb   $0x0,(%rax,%rcx,1)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<copy_name>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
cmp    %esi,%ecx
jae    116a <copy_name+0x4a>
mov    %ecx,%r12d
mov    %rdx,%r13
mov    %rdi,%r14
xor    %r15d,%r15d
test   %ecx,%ecx
je     1173 <copy_name+0x53>
mov    %r12d,%ebp
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movzbl 0x0(%r13,%rbx,1),%edi
call   1040 <isprint@plt>
test   %eax,%eax
je     118a <copy_name+0x6a>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1150 <copy_name+0x30>
jmp    1175 <copy_name+0x55>
mov    0x2e87(%rip),%rax
jmp    1191 <copy_name+0x71>
xor    %ebp,%ebp
mov    %r14,%rdi
mov    %r13,%rsi
mov    %r12d,%edx
call   1030 <memcpy@plt>
movb   $0x0,(%r14,%rbp,1)
jmp    1197 <copy_name+0x77>
mov    0x2e47(%rip),%rax
xor    %r15d,%r15d
sub    (%rax),%r15d
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@ENOBUFS = global i32 0
@EINVAL = global i32 0
define i32 @copy_name(i8* %0, i32 %1, i8* %2, i32 %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
store i8* %0, i8** %6
store i32 %1, i32* %7
store i8* %2, i8** %8
store i32 %3, i32* %9
%11 = load i32, i32* %9
%12 = load i32, i32* %7
%13 = icmp uge i32 %11, %12
br i1 %13, label %14, label %17
14: ; preds = %4
%15 = load i32, i32* @ENOBUFS
%16 = sub nsw i32 0, %15
store i32 %16, i32* %5
br label %46
17: ; preds = %4
store i32 0, i32* %10
br label %18
18: ; preds = %34, %17
%19 = load i32, i32* %10
%20 = load i32, i32* %9
%21 = icmp ult i32 %19, %20
br i1 %21, label %22, label %37
22: ; preds = %18
%23 = load i8*, i8** %8
%24 = load i32, i32* %10
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8, i8* %23, i64 %25
%27 = load i8, i8* %26
%28 = call i32 @isprint(i8 zeroext %27)
%29 = icmp ne i32 %28, 0
br i1 %29, label %33, label %30
30: ; preds = %22
%31 = load i32, i32* @EINVAL
%32 = sub nsw i32 0, %31
store i32 %32, i32* %5
br label %46
33: ; preds = %22
br label %34
34: ; preds = %33
%35 = load i32, i32* %10
%36 = add nsw i32 %35, 1
store i32 %36, i32* %10
br label %18
37: ; preds = %18
%38 = load i8*, i8** %6
%39 = load i8*, i8** %8
%40 = load i32, i32* %9
%41 = call i32 @memcpy(i8* %38, i8* %39, i32 %40)
%42 = load i8*, i8** %6
%43 = load i32, i32* %9
%44 = zext i32 %43 to i64
%45 = getelementptr inbounds i8, i8* %42, i64 %44
store i8 0, i8* %45
store i32 0, i32* %5
br label %46
46: ; preds = %37, %30, %14
%47 = load i32, i32* %5
ret i32 %47
}

LLVM IR (-O2):
@ENOBUFS = global i32 0
@EINVAL = global i32 0
define i32 @copy_name(i8* %0, i32 %1, i8* %2, i32 %3) {
%5 = icmp ult i32 %3, %1
br i1 %5, label %6, label %10
6: ; preds = %4
%7 = icmp eq i32 %3, 0
br i1 %7, label %25, label %8
8: ; preds = %6
%9 = zext i32 %3 to i64
br label %15
10: ; preds = %4
%11 = load i32, i32* @ENOBUFS
%12 = sub nsw i32 0, %11
br label %29
13: ; preds = %15
%14 = icmp eq i64 %21, %9
br i1 %14, label %25, label %15
15: ; preds = %8, %13
%16 = phi i64 [ 0, %8 ], [ %21, %13 ]
%17 = getelementptr inbounds i8, i8* %2, i64 %16
%18 = load i8, i8* %17
%19 = tail call i32 @isprint(i8 zeroext %18)
%20 = icmp eq i32 %19, 0
%21 = add nuw nsw i64 %16, 1
br i1 %20, label %22, label %13
22: ; preds = %15
%23 = load i32, i32* @EINVAL
%24 = sub nsw i32 0, %23
br label %29
25: ; preds = %13, %6
%26 = phi i64 [ 0, %6 ], [ %9, %13 ]
%27 = tail call i32 @memcpy(i8* %0, i8* %2, i32 %3)
%28 = getelementptr inbounds i8, i8* %0, i64 %26
store i8 0, i8* %28
br label %29
29: ; preds = %25, %22, %10
%30 = phi i32 [ %12, %10 ], [ %24, %22 ], [ 0, %25 ]
ret i32 %30
}