#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 */
typedef int /*<<< orphan*/ dst;

/* Variables and functions */
scalar_t__ ECANCELED;
scalar_t__ EINVAL;
scalar_t__ EOVERFLOW;
int INT_MAX;
scalar_t__ errno;
int eslib_string_copy(char *, char const *, int, unsigned int *);
unsigned int strlen(char const *);
int test_copy() {
  char dst[16];
  const char good_msg[] = "1234567890";
  const char bad_msg[] = "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB";
  unsigned int len;
  if (eslib_string_copy(dst, good_msg, sizeof(dst), &len))
    return -1;
  if (len != strlen(good_msg))
    return -1;
  if (eslib_string_copy(dst, bad_msg, sizeof(dst), &len) == 0)
    return -1;
  if (errno != EOVERFLOW || dst[0] != 'B')
    return -1;
  if (eslib_string_copy(dst, "", sizeof(dst), &len) == 0)
    return -1;
  if (errno != ECANCELED || len != 0)
    return -1;
  if (dst[0] != '\0')
    return -1;
  if (eslib_string_copy(dst, good_msg, INT_MAX, NULL) != -1)
    return -1;
  if (errno != EINVAL)
    return -1;
  if (dst[0] != '\0')
    return -1;
  return 0;
}


x86 assembly (clang, -O0):
<test_copy>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    0xec1(%rip),%rax
mov    %rax,-0x2b(%rbp)
mov    0xebe(%rip),%ax
mov    %ax,-0x23(%rbp)
mov    0xeb6(%rip),%al
mov    %al,-0x21(%rbp)
lea    -0x60(%rbp),%rdi
lea    0xeae(%rip),%rsi
mov    $0x2c,%edx
call   1040 <memcpy@plt>
lea    -0x20(%rbp),%rdi
lea    -0x2b(%rbp),%rsi
mov    $0x10,%edx
lea    -0x64(%rbp),%rcx
call   1050 <eslib_string_copy@plt>
cmp    $0x0,%eax
je     1197 <test_copy+0x67>
movl   $0xffffffff,-0x4(%rbp)
jmp    1309 <test_copy+0x1d9>
mov    -0x64(%rbp),%eax
mov    %eax,-0x68(%rbp)
lea    -0x2b(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x68(%rbp),%eax
cmp    %ecx,%eax
je     11bf <test_copy+0x8f>
movl   $0xffffffff,-0x4(%rbp)
jmp    1309 <test_copy+0x1d9>
lea    -0x20(%rbp),%rdi
lea    -0x60(%rbp),%rsi
mov    $0x10,%edx
lea    -0x64(%rbp),%rcx
call   1050 <eslib_string_copy@plt>
cmp    $0x0,%eax
jne    11ea <test_copy+0xba>
movl   $0xffffffff,-0x4(%rbp)
jmp    1309 <test_copy+0x1d9>
mov    0x2dd7(%rip),%rax
mov    (%rax),%rax
mov    0x2df5(%rip),%rcx
cmp    (%rcx),%rax
jne    1211 <test_copy+0xe1>
movsbl -0x20(%rbp),%eax
cmp    $0x42,%eax
je     121d <test_copy+0xed>
movl   $0xffffffff,-0x4(%rbp)
jmp    1309 <test_copy+0x1d9>
lea    -0x20(%rbp),%rdi
lea    0xde2(%rip),%rsi
mov    $0x10,%edx
lea    -0x64(%rbp),%rcx
call   1050 <eslib_string_copy@plt>
cmp    $0x0,%eax
jne    124b <test_copy+0x11b>
movl   $0xffffffff,-0x4(%rbp)
jmp    1309 <test_copy+0x1d9>
mov    0x2d76(%rip),%rax
mov    (%rax),%rax
mov    0x2d84(%rip),%rcx
cmp    (%rcx),%rax
jne    126f <test_copy+0x13f>
cmpl   $0x0,-0x64(%rbp)
je     127b <test_copy+0x14b>
movl   $0xffffffff,-0x4(%rbp)
jmp    1309 <test_copy+0x1d9>
movsbl -0x20(%rbp),%eax
cmp    $0x0,%eax
je     1294 <test_copy+0x164>
movl   $0xffffffff,-0x4(%rbp)
jmp    1309 <test_copy+0x1d9>
lea    -0x20(%rbp),%rdi
lea    -0x2b(%rbp),%rsi
mov    0x2d35(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%ecx
call   1050 <eslib_string_copy@plt>
cmp    $0xffffffff,%eax
je     12c3 <test_copy+0x193>
movl   $0xffffffff,-0x4(%rbp)
jmp    1309 <test_copy+0x1d9>
mov    0x2cfe(%rip),%rax
mov    (%rax),%rax
mov    0x2cec(%rip),%rcx
cmp    (%rcx),%rax
je     12e9 <test_copy+0x1b9>
movl   $0xffffffff,-0x4(%rbp)
jmp    1309 <test_copy+0x1d9>
movsbl -0x20(%rbp),%eax
cmp    $0x0,%eax
je     1302 <test_copy+0x1d2>
movl   $0xffffffff,-0x4(%rbp)
jmp    1309 <test_copy+0x1d9>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_copy>:
push   %rbp
push   %r14
push   %rbx
sub    $0x60,%rsp
movabs $0x3837363534333231,%rax
36 37 38
mov    %rax,0x10(%rsp)
movl   $0x303938,0x17(%rsp)
movups 0xee6(%rip),%xmm0
movups %xmm0,0x4c(%rsp)
movaps 0xece(%rip),%xmm0
movaps %xmm0,0x40(%rsp)
movaps 0xeb2(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
lea    0x20(%rsp),%rdi
lea    0x10(%rsp),%rsi
lea    0xc(%rsp),%rcx
mov    $0x10,%edx
call   1040 <eslib_string_copy@plt>
mov    $0xffffffff,%ebx
test   %eax,%eax
jne    124f <test_copy+0x12f>
mov    0xc(%rsp),%ebp
lea    0x10(%rsp),%rdi
call   1030 <strlen@plt>
cmp    %eax,%ebp
jne    124f <test_copy+0x12f>
lea    0x20(%rsp),%rdi
lea    0x30(%rsp),%rsi
lea    0xc(%rsp),%rcx
mov    $0x10,%edx
call   1040 <eslib_string_copy@plt>
test   %eax,%eax
je     124f <test_copy+0x12f>
mov    0x2e01(%rip),%r14
mov    (%r14),%rax
mov    0x2e1f(%rip),%rcx
cmp    (%rcx),%rax
jne    124f <test_copy+0x12f>
cmpb   $0x42,0x20(%rsp)
jne    124f <test_copy+0x12f>
lea    0xe26(%rip),%rsi
lea    0x20(%rsp),%rdi
lea    0xc(%rsp),%rcx
mov    $0x10,%edx
call   1040 <eslib_string_copy@plt>
test   %eax,%eax
je     124f <test_copy+0x12f>
mov    (%r14),%rax
mov    0x2dda(%rip),%rcx
cmp    (%rcx),%rax
jne    124f <test_copy+0x12f>
cmpl   $0x0,0xc(%rsp)
jne    124f <test_copy+0x12f>
cmpb   $0x0,0x20(%rsp)
jne    124f <test_copy+0x12f>
mov    0x2db8(%rip),%rax
mov    (%rax),%edx
lea    0x20(%rsp),%rdi
lea    0x10(%rsp),%rsi
xor    %ecx,%ecx
call   1040 <eslib_string_copy@plt>
cmp    $0xffffffff,%eax
jne    124f <test_copy+0x12f>
mov    (%r14),%rax
mov    0x2d7e(%rip),%rcx
cmp    (%rcx),%rax
jne    124f <test_copy+0x12f>
xor    %eax,%eax
cmp    0x20(%rsp),%al
sbb    %ebx,%ebx
mov    %ebx,%eax
add    $0x60,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@__const.test_copy.good_msg = [11 x i8] c"1234567890\00"
@__const.test_copy.bad_msg = [44 x i8] c"BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\00"
@errno = global i64 0
@EOVERFLOW = global i64 0
@.str = [1 x i8] zeroinitializer
@ECANCELED = global i64 0
@INT_MAX = global i32 0
@EINVAL = global i64 0
define i32 @test_copy() {
%1 = alloca i32
%2 = alloca [16 x i8]
%3 = alloca [11 x i8]
%4 = alloca [44 x i8]
%5 = alloca i32
%6 = bitcast [11 x i8]* %3 to i8*
%7 = bitcast [44 x i8]* %4 to i8*
%8 = getelementptr inbounds [16 x i8], [16 x i8]* %2, i64 0, i64 0
%9 = getelementptr inbounds [11 x i8], [11 x i8]* %3, i64 0, i64 0
%10 = call i32 @eslib_string_copy(i8* %8, i8* %9, i32 16, i32* %5)
%11 = icmp ne i32 %10, 0
br i1 %11, label %12, label %13
12: ; preds = %0
store i32 -1, i32* %1
br label %73
13: ; preds = %0
%14 = load i32, i32* %5
%15 = getelementptr inbounds [11 x i8], [11 x i8]* %3, i64 0, i64 0
%16 = call i32 @strlen(i8* %15)
%17 = icmp ne i32 %14, %16
br i1 %17, label %18, label %19
18: ; preds = %13
store i32 -1, i32* %1
br label %73
19: ; preds = %13
%20 = getelementptr inbounds [16 x i8], [16 x i8]* %2, i64 0, i64 0
%21 = getelementptr inbounds [44 x i8], [44 x i8]* %4, i64 0, i64 0
%22 = call i32 @eslib_string_copy(i8* %20, i8* %21, i32 16, i32* %5)
%23 = icmp eq i32 %22, 0
br i1 %23, label %24, label %25
24: ; preds = %19
store i32 -1, i32* %1
br label %73
25: ; preds = %19
%26 = load i64, i64* @errno
%27 = load i64, i64* @EOVERFLOW
%28 = icmp ne i64 %26, %27
br i1 %28, label %34, label %29
29: ; preds = %25
%30 = getelementptr inbounds [16 x i8], [16 x i8]* %2, i64 0, i64 0
%31 = load i8, i8* %30
%32 = sext i8 %31 to i32
%33 = icmp ne i32 %32, 66
br i1 %33, label %34, label %35
34: ; preds = %29, %25
store i32 -1, i32* %1
br label %73
35: ; preds = %29
%36 = getelementptr inbounds [16 x i8], [16 x i8]* %2, i64 0, i64 0
%37 = call i32 @eslib_string_copy(i8* %36, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i32 16, i32* %5)
%38 = icmp eq i32 %37, 0
br i1 %38, label %39, label %40
39: ; preds = %35
store i32 -1, i32* %1
br label %73
40: ; preds = %35
%41 = load i64, i64* @errno
%42 = load i64, i64* @ECANCELED
%43 = icmp ne i64 %41, %42
br i1 %43, label %47, label %44
44: ; preds = %40
%45 = load i32, i32* %5
%46 = icmp ne i32 %45, 0
br i1 %46, label %47, label %48
47: ; preds = %44, %40
store i32 -1, i32* %1
br label %73
48: ; preds = %44
%49 = getelementptr inbounds [16 x i8], [16 x i8]* %2, i64 0, i64 0
%50 = load i8, i8* %49
%51 = sext i8 %50 to i32
%52 = icmp ne i32 %51, 0
br i1 %52, label %53, label %54
53: ; preds = %48
store i32 -1, i32* %1
br label %73
54: ; preds = %48
%55 = getelementptr inbounds [16 x i8], [16 x i8]* %2, i64 0, i64 0
%56 = getelementptr inbounds [11 x i8], [11 x i8]* %3, i64 0, i64 0
%57 = load i32, i32* @INT_MAX
%58 = call i32 @eslib_string_copy(i8* %55, i8* %56, i32 %57, i32* null)
%59 = icmp ne i32 %58, -1
br i1 %59, label %60, label %61
60: ; preds = %54
store i32 -1, i32* %1
br label %73
61: ; preds = %54
%62 = load i64, i64* @errno
%63 = load i64, i64* @EINVAL
%64 = icmp ne i64 %62, %63
br i1 %64, label %65, label %66
65: ; preds = %61
store i32 -1, i32* %1
br label %73
66: ; preds = %61
%67 = getelementptr inbounds [16 x i8], [16 x i8]* %2, i64 0, i64 0
%68 = load i8, i8* %67
%69 = sext i8 %68 to i32
%70 = icmp ne i32 %69, 0
br i1 %70, label %71, label %72
71: ; preds = %66
store i32 -1, i32* %1
br label %73
72: ; preds = %66
store i32 0, i32* %1
br label %73
73: ; preds = %72, %71, %65, %60, %53, %47, %39, %34, %24, %18, %12
%74 = load i32, i32* %1
ret i32 %74
}

LLVM IR (-O2):
@__const.test_copy.good_msg = [11 x i8] c"1234567890\00"
@__const.test_copy.bad_msg = [44 x i8] c"BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\00"
@errno = global i64 0
@EOVERFLOW = global i64 0
@.str = [1 x i8] zeroinitializer
@ECANCELED = global i64 0
@INT_MAX = global i32 0
@EINVAL = global i64 0
define i32 @test_copy() {
%1 = alloca [16 x i8]
%2 = alloca [11 x i8]
%3 = alloca [44 x i8]
%4 = alloca i32
%5 = getelementptr inbounds [16 x i8], [16 x i8]* %1, i64 0, i64 0
%6 = getelementptr inbounds [11 x i8], [11 x i8]* %2, i64 0, i64 0
%7 = getelementptr inbounds [44 x i8], [44 x i8]* %3, i64 0, i64 0
%8 = bitcast i32* %4 to i8*
%9 = call i32 @eslib_string_copy(i8* %5, i8* %6, i32 16, i32* %4)
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %50
11: ; preds = %0
%12 = load i32, i32* %4
%13 = call i32 @strlen(i8* %6)
%14 = icmp eq i32 %12, %13
br i1 %14, label %15, label %50
15: ; preds = %11
%16 = call i32 @eslib_string_copy(i8* %5, i8* %7, i32 16, i32* %4)
%17 = icmp eq i32 %16, 0
br i1 %17, label %50, label %18
18: ; preds = %15
%19 = load i64, i64* @errno
%20 = load i64, i64* @EOVERFLOW
%21 = icmp ne i64 %19, %20
%22 = load i8, i8* %5
%23 = icmp ne i8 %22, 66
%24 = select i1 %21, i1 true, i1 %23
br i1 %24, label %50, label %25
25: ; preds = %18
%26 = call i32 @eslib_string_copy(i8* %5, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i32 16, i32* %4)
%27 = icmp eq i32 %26, 0
br i1 %27, label %50, label %28
28: ; preds = %25
%29 = load i64, i64* @errno
%30 = load i64, i64* @ECANCELED
%31 = icmp eq i64 %29, %30
%32 = load i32, i32* %4
%33 = icmp eq i32 %32, 0
%34 = select i1 %31, i1 %33, i1 false
%35 = load i8, i8* %5
%36 = icmp eq i8 %35, 0
%37 = select i1 %34, i1 %36, i1 false
br i1 %37, label %38, label %50
38: ; preds = %28
%39 = load i32, i32* @INT_MAX
%40 = call i32 @eslib_string_copy(i8* %5, i8* %6, i32 %39, i32* null)
%41 = icmp eq i32 %40, -1
br i1 %41, label %42, label %50
42: ; preds = %38
%43 = load i64, i64* @errno
%44 = load i64, i64* @EINVAL
%45 = icmp eq i64 %43, %44
br i1 %45, label %46, label %50
46: ; preds = %42
%47 = load i8, i8* %5
%48 = icmp ne i8 %47, 0
%49 = sext i1 %48 to i32
br label %50
50: ; preds = %46, %42, %38, %28, %25, %18, %15, %11, %0
%51 = phi i32 [ -1, %0 ], [ -1, %11 ], [ -1, %15 ], [ -1, %18 ], [ -1, %25 ], [ -1, %28 ], [ -1, %38 ], [ -1, %42 ], [ %49, %46 ]
ret i32 %51
}