char *path_str(struct dlist_root *self) {
  int length = path_length(self);
  char *alloc = (char *)malloc(length + 1);
  assert(alloc);
  int pos = path_write(self, alloc);
  assert(pos == length + 1);
  return alloc;
}


x86 assembly (clang, -O0):
<path_str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x0,%al
call   1040 <path_length@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
movslq %eax,%rdi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    $0x0,%al
call   1050 <assert@plt>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    $0x0,%al
call   1030 <path_write@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    -0xc(%rbp),%ecx
add    $0x1,%ecx
cmp    %ecx,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
mov    $0x0,%al
call   1050 <assert@plt>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<path_str>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
xor    %eax,%eax
call   1040 <path_length@plt>
add    $0x1,%eax
movslq %eax,%r15
mov    %r15,%rdi
call   1060 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
xor    %eax,%eax
call   1050 <assert@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1030 <path_write@plt>
xor    %edi,%edi
cmp    %r15d,%eax
sete   %dil
xor    %eax,%eax
call   1050 <assert@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.dlist_root = type opaque
define i8* @path_str(%struct.dlist_root* %0) {
%2 = alloca %struct.dlist_root*
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
store %struct.dlist_root* %0, %struct.dlist_root** %2
%6 = load %struct.dlist_root*, %struct.dlist_root** %2
%7 = call i32 (%struct.dlist_root*, ...) bitcast (i32 (...)* @path_length to i32 (%struct.dlist_root*, ...)*)(%struct.dlist_root* %6)
store i32 %7, i32* %3
%8 = load i32, i32* %3
%9 = add nsw i32 %8, 1
%10 = sext i32 %9 to i64
%11 = call i8* @malloc(i64 %10)
store i8* %11, i8** %4
%12 = load i8*, i8** %4
%13 = call i32 (i8*, ...) bitcast (i32 (...)* @assert to i32 (i8*, ...)*)(i8* %12)
%14 = load %struct.dlist_root*, %struct.dlist_root** %2
%15 = load i8*, i8** %4
%16 = call i32 (%struct.dlist_root*, i8*, ...) bitcast (i32 (...)* @path_write to i32 (%struct.dlist_root*, i8*, ...)*)(%struct.dlist_root* %14, i8* %15)
store i32 %16, i32* %5
%17 = load i32, i32* %5
%18 = load i32, i32* %3
%19 = add nsw i32 %18, 1
%20 = icmp eq i32 %17, %19
%21 = zext i1 %20 to i32
%22 = call i32 (i32, ...) bitcast (i32 (...)* @assert to i32 (i32, ...)*)(i32 %21)
%23 = load i8*, i8** %4
ret i8* %23
}

LLVM IR (-O2):
%struct.dlist_root = type opaque
define i8* @path_str(%struct.dlist_root* %0) {
%2 = tail call i32 (%struct.dlist_root*, ...) bitcast (i32 (...)* @path_length to i32 (%struct.dlist_root*, ...)*)(%struct.dlist_root* %0)
%3 = add nsw i32 %2, 1
%4 = sext i32 %3 to i64
%5 = tail call i8* @malloc(i64 %4)
%6 = tail call i32 (i8*, ...) bitcast (i32 (...)* @assert to i32 (i8*, ...)*)(i8* %5)
%7 = tail call i32 (%struct.dlist_root*, i8*, ...) bitcast (i32 (...)* @path_write to i32 (%struct.dlist_root*, i8*, ...)*)(%struct.dlist_root* %0, i8* %5)
%8 = icmp eq i32 %7, %3
%9 = zext i1 %8 to i32
%10 = tail call i32 (i32, ...) bitcast (i32 (...)* @assert to i32 (i32, ...)*)(i32 %9)
ret i8* %5
}