#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 */
char *CR_EnsureCapacity(char *, int /*<<< orphan*/);
int /*<<< orphan*/ memcpy(char *, char const *, size_t);
int /*<<< orphan*/ sSizeAdd(size_t, int);
size_t strlen(char const *);
size_t pathBuilderSet(char **buffer_ptr, const char *path) {
  size_t length = strlen(path);
  *buffer_ptr = CR_EnsureCapacity(*buffer_ptr, sSizeAdd(length, 1));
  memcpy(*buffer_ptr, path, length);
  (*buffer_ptr)[length] = '\0';
  return length;
}


x86 assembly (clang, -O0):
<pathBuilderSet>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
mov    $0x1,%esi
call   1060 <sSizeAdd@plt>
mov    -0x20(%rbp),%rdi
mov    %eax,%esi
call   1050 <CR_EnsureCapacity@plt>
mov    %rax,%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1040 <memcpy@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    -0x18(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pathBuilderSet>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
mov    %rsi,%rdi
call   1030 <strlen@plt>
mov    %rax,%rbx
mov    (%r15),%r12
mov    %rax,%rdi
mov    $0x1,%esi
call   1060 <sSizeAdd@plt>
mov    %r12,%rdi
mov    %eax,%esi
call   1050 <CR_EnsureCapacity@plt>
mov    %rax,(%r15)
mov    %rax,%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
call   1040 <memcpy@plt>
mov    (%r15),%rax
movb   $0x0,(%rax,%rbx,1)
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i64 @pathBuilderSet(i8** %0, i8* %1) {
%3 = alloca i8**
%4 = alloca i8*
%5 = alloca i64
store i8** %0, i8*** %3
store i8* %1, i8** %4
%6 = load i8*, i8** %4
%7 = call i64 @strlen(i8* %6)
store i64 %7, i64* %5
%8 = load i8**, i8*** %3
%9 = load i8*, i8** %8
%10 = load i64, i64* %5
%11 = call i32 @sSizeAdd(i64 %10, i32 1)
%12 = call i8* @CR_EnsureCapacity(i8* %9, i32 %11)
%13 = load i8**, i8*** %3
store i8* %12, i8** %13
%14 = load i8**, i8*** %3
%15 = load i8*, i8** %14
%16 = load i8*, i8** %4
%17 = load i64, i64* %5
%18 = call i32 @memcpy(i8* %15, i8* %16, i64 %17)
%19 = load i8**, i8*** %3
%20 = load i8*, i8** %19
%21 = load i64, i64* %5
%22 = getelementptr inbounds i8, i8* %20, i64 %21
store i8 0, i8* %22
%23 = load i64, i64* %5
ret i64 %23
}

LLVM IR (-O2):
define i64 @pathBuilderSet(i8** nocapture %0, i8* %1) {
%3 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%4 = load i8*, i8** %0
%5 = tail call i32 @sSizeAdd(i64 %3, i32 1)
%6 = tail call i8* @CR_EnsureCapacity(i8* %4, i32 %5)
store i8* %6, i8** %0
%7 = tail call i32 @memcpy(i8* %6, i8* %1, i64 %3)
%8 = load i8*, i8** %0
%9 = getelementptr inbounds i8, i8* %8, i64 %3
store i8 0, i8* %9
ret i64 %3
}