#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*/ d_storeub(unsigned char **, unsigned int);
int /*<<< orphan*/ memcpy(unsigned char *, char const *, unsigned int);
int /*<<< orphan*/ memset(unsigned char *, int /*<<< orphan*/, unsigned int);
unsigned int strlen(char const *);
void d_storestr(unsigned char **ptr, const char *src, unsigned size) {
  unsigned len;
  len = strlen(src);
  if (len > --size)
    len = 0;
  d_storeub(ptr, len);
  memcpy(*ptr, src, len);
  memset(*ptr + len, 0, size - len);
  *ptr += size;
}


x86 assembly (clang, -O0):
<d_storestr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    -0x14(%rbp),%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x14(%rbp)
cmp    %ecx,%eax
jbe    117a <d_storestr+0x3a>
movl   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%esi
call   1060 <d_storeub@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%edx
call   1050 <memcpy@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
mov    -0x18(%rbp),%eax
add    %rax,%rdi
mov    -0x14(%rbp),%edx
sub    -0x18(%rbp),%edx
xor    %esi,%esi
call   1040 <memset@plt>
mov    -0x14(%rbp),%edx
mov    -0x8(%rbp),%rax
mov    (%rax),%rcx
mov    %edx,%edx
add    %rdx,%rcx
mov    %rcx,(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<d_storestr>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %edx,%r12d
mov    %rsi,%r15
mov    %rdi,%r14
mov    %rsi,%rdi
call   1030 <strlen@plt>
mov    %eax,%ebx
add    $0xffffffff,%r12d
xor    %eax,%eax
cmp    %r12d,%ebx
cmova  %eax,%ebx
mov    %r14,%rdi
mov    %ebx,%esi
call   1060 <d_storeub@plt>
mov    (%r14),%rdi
mov    %r15,%rsi
mov    %ebx,%edx
call   1050 <memcpy@plt>
mov    (%r14),%rdi
add    %rbx,%rdi
mov    %r12d,%edx
sub    %ebx,%edx
xor    %esi,%esi
call   1040 <memset@plt>
add    %r12,(%r14)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define void @d_storestr(i8** %0, i8* %1, i32 %2) {
%4 = tail call i32 @strlen(i8* %1)
%5 = add i32 %2, -1
%6 = icmp ugt i32 %4, %5
%7 = select i1 %6, i32 0, i32 %4
%8 = tail call i32 @d_storeub(i8** %0, i32 %7)
%9 = load i8*, i8** %0
%10 = tail call i32 @memcpy(i8* %9, i8* %1, i32 %7)
%11 = load i8*, i8** %0
%12 = zext i32 %7 to i64
%13 = getelementptr inbounds i8, i8* %11, i64 %12
%14 = sub i32 %5, %7
%15 = tail call i32 @memset(i8* %13, i32 0, i32 %14)
%16 = load i8*, i8** %0
%17 = zext i32 %5 to i64
%18 = getelementptr inbounds i8, i8* %16, i64 %17
store i8* %18, i8** %0
ret void
}