#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 EXIT_FAILURE;
int EXIT_SUCCESS;
scalar_t__ calloc(size_t, int);
int /*<<< orphan*/ memcpy(char *, char *, size_t);
size_t strlen(char *);
int ragasm_clone_comment(char **dst_p, char *src) {
  int ret = EXIT_FAILURE;
  char *duplicate;
  size_t len;
  len = strlen(src);
  if (len > 0 && (duplicate = (char *)calloc((len + 1), sizeof(char)))) {
    memcpy(duplicate, src, len);
    duplicate[len - 1] = '@';
    duplicate[len] = '\0';
    *dst_p = duplicate;
    ret = EXIT_SUCCESS;
  }
  return ret;
}


x86 assembly (clang, -O0):
<ragasm_clone_comment>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e99(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jbe    11c8 <ragasm_clone_comment+0x98>
mov    -0x28(%rbp),%rdi
add    $0x1,%rdi
mov    $0x1,%esi
call   1040 <calloc@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     11c8 <ragasm_clone_comment+0x98>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1050 <memcpy@plt>
mov    -0x20(%rbp),%rax
mov    -0x28(%rbp),%rcx
sub    $0x1,%rcx
movb   $0x40,(%rax,%rcx,1)
mov    -0x20(%rbp),%rax
mov    -0x28(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x20(%rbp),%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
mov    0x2e15(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ragasm_clone_comment>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r15
mov    %rdi,%r14
mov    0x2e9b(%rip),%rax
mov    (%rax),%r12d
mov    %rsi,%rdi
call   1030 <strlen@plt>
test   %rax,%rax
je     1190 <ragasm_clone_comment+0x60>
mov    %rax,%rbx
lea    0x1(%rax),%rdi
mov    $0x1,%esi
call   1040 <calloc@plt>
test   %rax,%rax
je     1190 <ragasm_clone_comment+0x60>
mov    %rax,%rbp
mov    %rax,%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
call   1050 <memcpy@plt>
movw   $0x40,-0x1(%rbx,%rbp,1)
mov    %rbp,(%r14)
mov    0x2e4b(%rip),%rax
mov    (%rax),%r12d
mov    %r12d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@EXIT_FAILURE = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @ragasm_clone_comment(i8** %0, i8* %1) {
%3 = alloca i8**
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i64
store i8** %0, i8*** %3
store i8* %1, i8** %4
%8 = load i32, i32* @EXIT_FAILURE
store i32 %8, i32* %5
%9 = load i8*, i8** %4
%10 = call i64 @strlen(i8* %9)
store i64 %10, i64* %7
%11 = load i64, i64* %7
%12 = icmp ugt i64 %11, 0
br i1 %12, label %13, label %34
13: ; preds = %2
%14 = load i64, i64* %7
%15 = add i64 %14, 1
%16 = call i64 @calloc(i64 %15, i32 1)
%17 = inttoptr i64 %16 to i8*
store i8* %17, i8** %6
%18 = icmp ne i8* %17, null
br i1 %18, label %19, label %34
19: ; preds = %13
%20 = load i8*, i8** %6
%21 = load i8*, i8** %4
%22 = load i64, i64* %7
%23 = call i32 @memcpy(i8* %20, i8* %21, i64 %22)
%24 = load i8*, i8** %6
%25 = load i64, i64* %7
%26 = sub i64 %25, 1
%27 = getelementptr inbounds i8, i8* %24, i64 %26
store i8 64, i8* %27
%28 = load i8*, i8** %6
%29 = load i64, i64* %7
%30 = getelementptr inbounds i8, i8* %28, i64 %29
store i8 0, i8* %30
%31 = load i8*, i8** %6
%32 = load i8**, i8*** %3
store i8* %31, i8** %32
%33 = load i32, i32* @EXIT_SUCCESS
store i32 %33, i32* %5
br label %34
34: ; preds = %19, %13, %2
%35 = load i32, i32* %5
ret i32 %35
}

LLVM IR (-O2):
@EXIT_FAILURE = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @ragasm_clone_comment(i8** nocapture writeonly %0, i8* %1) {
%3 = load i32, i32* @EXIT_FAILURE
%4 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%5 = icmp eq i64 %4, 0
br i1 %5, label %17, label %6
6: ; preds = %2
%7 = add i64 %4, 1
%8 = tail call i64 @calloc(i64 %7, i32 1)
%9 = inttoptr i64 %8 to i8*
%10 = icmp eq i64 %8, 0
br i1 %10, label %17, label %11
11: ; preds = %6
%12 = tail call i32 @memcpy(i8* %9, i8* %1, i64 %4)
%13 = add i64 %4, -1
%14 = getelementptr inbounds i8, i8* %9, i64 %13
store i8 64, i8* %14
%15 = getelementptr inbounds i8, i8* %9, i64 %4
store i8 0, i8* %15
store i8* %9, i8** %0
%16 = load i32, i32* @EXIT_SUCCESS
br label %17
17: ; preds = %11, %6, %2
%18 = phi i32 [ %16, %11 ], [ %3, %6 ], [ %3, %2 ]
ret i32 %18
}