#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*/ strcpy(char *, char const *);
int strlen(char const *);
int cerebro_copy_nodename(const char *node, char *buf, unsigned int buflen) {
  int len;
  if (!node || !buf || !buflen) {
    ;
    return -1;
  }
  len = strlen(node);
  if ((len + 1) > buflen) {
    ;
    return -1;
  }
  strcpy(buf, node);
  return 0;
}


x86 assembly (clang, -O0):
<cerebro_copy_nodename>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1153 <cerebro_copy_nodename+0x33>
cmpq   $0x0,-0x18(%rbp)
je     1153 <cerebro_copy_nodename+0x33>
cmpl   $0x0,-0x1c(%rbp)
jne    115f <cerebro_copy_nodename+0x3f>
movl   $0xffffffff,-0x4(%rbp)
jmp    119a <cerebro_copy_nodename+0x7a>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
cmp    -0x1c(%rbp),%eax
jbe    1186 <cerebro_copy_nodename+0x66>
movl   $0xffffffff,-0x4(%rbp)
jmp    119a <cerebro_copy_nodename+0x7a>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cerebro_copy_nodename>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    $0xffffffff,%r14d
test   %rdi,%rdi
je     115d <cerebro_copy_nodename+0x3d>
mov    %rsi,%r15
test   %rsi,%rsi
je     115d <cerebro_copy_nodename+0x3d>
mov    %edx,%ebp
test   %edx,%edx
je     115d <cerebro_copy_nodename+0x3d>
mov    %rdi,%rbx
call   1040 <strlen@plt>
add    $0x1,%eax
cmp    %ebp,%eax
ja     115d <cerebro_copy_nodename+0x3d>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
xor    %r14d,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @cerebro_copy_nodename(i8* %0, i8* %1, i32 %2) {
%4 = icmp ne i8* %0, null
%5 = icmp ne i8* %1, null
%6 = and i1 %4, %5
%7 = icmp ne i32 %2, 0
%8 = and i1 %6, %7
br i1 %8, label %9, label %15
9: ; preds = %3
%10 = tail call i32 @strlen(i8* %0)
%11 = add nsw i32 %10, 1
%12 = icmp ugt i32 %11, %2
br i1 %12, label %15, label %13
13: ; preds = %9
%14 = tail call i32 @strcpy(i8* %1, i8* %0)
br label %15
15: ; preds = %9, %3, %13
%16 = phi i32 [ 0, %13 ], [ -1, %3 ], [ -1, %9 ]
ret i32 %16
}