#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 */
typedef int /*<<< orphan*/ uint8_t;
typedef scalar_t__ uint16_t;

/* Variables and functions */
scalar_t__ get_name_size(int /*<<< orphan*/ const *,
                         int /*<<< orphan*/ const *);
char *malloc(scalar_t__);
int /*<<< orphan*/ parse_name(int /*<<< orphan*/ const *,
                              int /*<<< orphan*/ const *, char *);
char *new_name(const uint8_t *msg, const uint8_t *pstart, uint16_t *len) {
  char *name;
  uint16_t name_len;
  name_len = get_name_size(msg, pstart);
  if (name_len == 0) {
    name = NULL;
  } else {
    name = malloc(name_len);
    parse_name(msg, pstart, name);
  }
  if (len != NULL) {
    *len = name_len;
  }
  return name;
}


x86 assembly (clang, -O0):
<new_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <get_name_size@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    116d <new_name+0x3d>
movq   $0x0,-0x20(%rbp)
jmp    118b <new_name+0x5b>
mov    -0x28(%rbp),%rdi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1030 <parse_name@plt>
cmpq   $0x0,-0x18(%rbp)
je     11a1 <new_name+0x71>
mov    -0x28(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x20(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<new_name>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdx,%r14
mov    %rsi,%r12
mov    %rdi,%rbx
call   1040 <get_name_size@plt>
mov    %rax,%r13
test   %rax,%rax
je     117d <new_name+0x4d>
mov    %r13,%rdi
call   1050 <malloc@plt>
mov    %rax,%r15
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %rax,%rdx
call   1030 <parse_name@plt>
test   %r14,%r14
je     1170 <new_name+0x40>
mov    %r13,(%r14)
mov    %r15,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
xor    %r15d,%r15d
test   %r14,%r14
jne    116d <new_name+0x3d>
jmp    1170 <new_name+0x40>

LLVM IR (-O0):
define i8* @new_name(i32* %0, i32* %1, i64* %2) {
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i64*
%7 = alloca i8*
%8 = alloca i64
store i32* %0, i32** %4
store i32* %1, i32** %5
store i64* %2, i64** %6
%9 = load i32*, i32** %4
%10 = load i32*, i32** %5
%11 = call i64 @get_name_size(i32* %9, i32* %10)
store i64 %11, i64* %8
%12 = load i64, i64* %8
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %15
14: ; preds = %3
store i8* null, i8** %7
br label %22
15: ; preds = %3
%16 = load i64, i64* %8
%17 = call i8* @malloc(i64 %16)
store i8* %17, i8** %7
%18 = load i32*, i32** %4
%19 = load i32*, i32** %5
%20 = load i8*, i8** %7
%21 = call i32 @parse_name(i32* %18, i32* %19, i8* %20)
br label %22
22: ; preds = %15, %14
%23 = load i64*, i64** %6
%24 = icmp ne i64* %23, null
br i1 %24, label %25, label %28
25: ; preds = %22
%26 = load i64, i64* %8
%27 = load i64*, i64** %6
store i64 %26, i64* %27
br label %28
28: ; preds = %25, %22
%29 = load i8*, i8** %7
ret i8* %29
}

LLVM IR (-O2):
define i8* @new_name(i32* %0, i32* %1, i64* writeonly %2) {
%4 = tail call i64 @get_name_size(i32* %0, i32* %1)
%5 = icmp eq i64 %4, 0
br i1 %5, label %9, label %6
6: ; preds = %3
%7 = tail call i8* @malloc(i64 %4)
%8 = tail call i32 @parse_name(i32* %0, i32* %1, i8* %7)
br label %9
9: ; preds = %3, %6
%10 = phi i8* [ %7, %6 ], [ null, %3 ]
%11 = icmp eq i64* %2, null
br i1 %11, label %13, label %12
12: ; preds = %9
store i64 %4, i64* %2
br label %13
13: ; preds = %12, %9
ret i8* %10
}