#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*/ memcpy(char *, char *, size_t);
char *redislite_malloc(int);
int redislite_echo(char *src_name, size_t src_length, char **dst_name,
                   size_t *dst_length) {
  if (src_length > 0 && dst_name && dst_length) {
    char *dst = redislite_malloc(sizeof(char) * src_length);
    if (dst == NULL) {
      return -2;
    }
    memcpy(dst, src_name, src_length);
    *dst_name = dst;
    *dst_length = src_length;
    return 0;
  }
  return -1;
}


x86 assembly (clang, -O0):
<redislite_echo>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
cmpq   $0x0,-0x18(%rbp)
jbe    11b6 <redislite_echo+0x96>
cmpq   $0x0,-0x20(%rbp)
je     11b6 <redislite_echo+0x96>
cmpq   $0x0,-0x28(%rbp)
je     11b6 <redislite_echo+0x96>
mov    -0x18(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edi
call   1030 <redislite_malloc@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1183 <redislite_echo+0x63>
movl   $0xfffffffe,-0x4(%rbp)
jmp    11bd <redislite_echo+0x9d>
mov    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1040 <memcpy@plt>
mov    -0x30(%rbp),%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rcx
mov    -0x28(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x0,-0x4(%rbp)
jmp    11bd <redislite_echo+0x9d>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<redislite_echo>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    $0xffffffff,%eax
test   %rsi,%rsi
je     1175 <redislite_echo+0x55>
mov    %rdx,%r15
test   %rdx,%rdx
je     1175 <redislite_echo+0x55>
mov    %rcx,%r14
test   %rcx,%rcx
je     1175 <redislite_echo+0x55>
mov    %rsi,%rbx
mov    %rdi,%r12
mov    %ebx,%edi
call   1030 <redislite_malloc@plt>
test   %rax,%rax
je     1170 <redislite_echo+0x50>
mov    %rax,%r13
mov    %rax,%rdi
mov    %r12,%rsi
mov    %rbx,%rdx
call   1040 <memcpy@plt>
mov    %r13,(%r15)
mov    %rbx,(%r14)
xor    %eax,%eax
jmp    1175 <redislite_echo+0x55>
mov    $0xfffffffe,%eax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @redislite_echo(i8* %0, i64 %1, i8** %2, i64* %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i8**
%9 = alloca i64*
%10 = alloca i8*
store i8* %0, i8** %6
store i64 %1, i64* %7
store i8** %2, i8*** %8
store i64* %3, i64** %9
%11 = load i64, i64* %7
%12 = icmp ugt i64 %11, 0
br i1 %12, label %13, label %36
13: ; preds = %4
%14 = load i8**, i8*** %8
%15 = icmp ne i8** %14, null
br i1 %15, label %16, label %36
16: ; preds = %13
%17 = load i64*, i64** %9
%18 = icmp ne i64* %17, null
br i1 %18, label %19, label %36
19: ; preds = %16
%20 = load i64, i64* %7
%21 = mul i64 1, %20
%22 = trunc i64 %21 to i32
%23 = call i8* @redislite_malloc(i32 %22)
store i8* %23, i8** %10
%24 = load i8*, i8** %10
%25 = icmp eq i8* %24, null
br i1 %25, label %26, label %27
26: ; preds = %19
store i32 -2, i32* %5
br label %37
27: ; preds = %19
%28 = load i8*, i8** %10
%29 = load i8*, i8** %6
%30 = load i64, i64* %7
%31 = call i32 @memcpy(i8* %28, i8* %29, i64 %30)
%32 = load i8*, i8** %10
%33 = load i8**, i8*** %8
store i8* %32, i8** %33
%34 = load i64, i64* %7
%35 = load i64*, i64** %9
store i64 %34, i64* %35
store i32 0, i32* %5
br label %37
36: ; preds = %16, %13, %4
store i32 -1, i32* %5
br label %37
37: ; preds = %36, %27, %26
%38 = load i32, i32* %5
ret i32 %38
}

LLVM IR (-O2):
define i32 @redislite_echo(i8* %0, i64 %1, i8** writeonly %2, i64* writeonly %3) {
%5 = icmp ne i64 %1, 0
%6 = icmp ne i8** %2, null
%7 = and i1 %5, %6
%8 = icmp ne i64* %3, null
%9 = and i1 %7, %8
br i1 %9, label %10, label %16
10: ; preds = %4
%11 = trunc i64 %1 to i32
%12 = tail call i8* @redislite_malloc(i32 %11)
%13 = icmp eq i8* %12, null
br i1 %13, label %16, label %14
14: ; preds = %10
%15 = tail call i32 @memcpy(i8* %12, i8* %0, i64 %1)
store i8* %12, i8** %2
store i64 %1, i64* %3
br label %16
16: ; preds = %4, %14, %10
%17 = phi i32 [ 0, %14 ], [ -2, %10 ], [ -1, %4 ]
ret i32 %17
}