#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*/ noctrl(char *);
char *skip_ws(char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
char *copy_string(char *y, char *x, int len) {
  x = skip_ws(x);
  noctrl(x);
  len -= 2;
  if (strlen(x) >= len)
    x[len] = 0;
  if (y != x)
    strcpy(y, x);
  return (y);
}


x86 assembly (clang, -O0):
<copy_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <skip_ws@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <noctrl@plt>
mov    -0x14(%rbp),%eax
sub    $0x2,%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
cmp    -0x14(%rbp),%eax
jl     1190 <copy_string+0x50>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x8(%rbp),%rax
cmp    -0x10(%rbp),%rax
je     11ab <copy_string+0x6b>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<copy_string>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%ebp
mov    %rdi,%r14
mov    %rsi,%rdi
call   1060 <skip_ws@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1050 <noctrl@plt>
movslq %ebp,%rbp
add    $0xfffffffffffffffe,%rbp
mov    %rbx,%rdi
call   1040 <strlen@plt>
cmp    %ebp,%eax
jl     1173 <copy_string+0x33>
movb   $0x0,(%rbx,%rbp,1)
cmp    %r14,%rbx
je     1183 <copy_string+0x43>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %rbp
ret

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

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