#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 evl_checkBufSpace(size_t, size_t, size_t);
int /*<<< orphan*/ memcpy(char *, char const *, size_t);
int strlen(char const *);
int evl_packString(char *d, const char *s, size_t buf_maxlen,
                   size_t total_used_len, size_t *tk_len_added) {
  size_t slen = strlen(s) + 1;
  size_t va_len = 0;
  int status = evl_checkBufSpace(buf_maxlen, total_used_len, slen);
  if (status == 0) {
    memcpy(d, s, slen);
    va_len = slen;
  } else {
    return status;
  }
  *tk_len_added = va_len;
  return 0;
}


x86 assembly (clang, -O0):
<evl_packString>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
add    $0x1,%eax
cltq
mov    %rax,-0x38(%rbp)
movq   $0x0,-0x40(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x38(%rbp),%rdx
call   1050 <evl_checkBufSpace@plt>
mov    %eax,-0x44(%rbp)
cmpl   $0x0,-0x44(%rbp)
jne    11a2 <evl_packString+0x72>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x38(%rbp),%rdx
call   1040 <memcpy@plt>
mov    -0x38(%rbp),%rax
mov    %rax,-0x40(%rbp)
jmp    11ad <evl_packString+0x7d>
mov    -0x44(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11bf <evl_packString+0x8f>
mov    -0x40(%rbp),%rcx
mov    -0x30(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<evl_packString>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r8,%r14
mov    %rcx,%r13
mov    %rdx,%rbp
mov    %rsi,%r12
mov    %rdi,%r15
mov    %rsi,%rdi
call   1030 <strlen@plt>
add    $0x1,%eax
movslq %eax,%rbx
mov    %rbp,%rdi
mov    %r13,%rsi
mov    %rbx,%rdx
call   1050 <evl_checkBufSpace@plt>
mov    %eax,%ebp
test   %eax,%eax
jne    117d <evl_packString+0x4d>
mov    %r15,%rdi
mov    %r12,%rsi
mov    %rbx,%rdx
call   1040 <memcpy@plt>
mov    %rbx,(%r14)
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @evl_packString(i8* %0, i8* %1, i64 %2, i64 %3, i64* nocapture writeonly %4) {
%6 = tail call i32 @strlen(i8* %1)
%7 = add nsw i32 %6, 1
%8 = sext i32 %7 to i64
%9 = tail call i32 @evl_checkBufSpace(i64 %2, i64 %3, i64 %8)
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %5
%12 = tail call i32 @memcpy(i8* %0, i8* %1, i64 %8)
store i64 %8, i64* %4
br label %13
13: ; preds = %5, %11
ret i32 %9
}