#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;

/* Variables and functions */
char *flb_malloc(size_t);
int /*<<< orphan*/ memcpy(char *, int /*<<< orphan*/ const *, size_t);
char *get_null_terminated(size_t size, const uint8_t **data,
                          size_t *total_data_size) {
  char *tmp = flb_malloc(size + 1);
  memcpy(tmp, *data, size);
  tmp[size] = '\0';
  *total_data_size -= size;
  *data += size;
  return tmp;
}


x86 assembly (clang, -O0):
<get_null_terminated>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
add    $0x1,%rdi
call   1040 <flb_malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
mov    -0x8(%rbp),%rdx
call   1030 <memcpy@plt>
mov    -0x20(%rbp),%rax
mov    -0x8(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x8(%rbp),%rdx
mov    -0x18(%rbp),%rax
mov    (%rax),%rcx
sub    %rdx,%rcx
mov    %rcx,(%rax)
mov    -0x8(%rbp),%rcx
mov    -0x10(%rbp),%rax
shl    $0x2,%rcx
add    (%rax),%rcx
mov    %rcx,(%rax)
mov    -0x20(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_null_terminated>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
add    $0x1,%rdi
call   1040 <flb_malloc@plt>
mov    %rax,%r12
mov    (%r15),%rsi
mov    %rax,%rdi
mov    %rbx,%rdx
call   1030 <memcpy@plt>
movb   $0x0,(%r12,%rbx,1)
sub    %rbx,(%r14)
shl    $0x2,%rbx
add    %rbx,(%r15)
mov    %r12,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @get_null_terminated(i64 %0, i32** %1, i64* %2) {
%4 = alloca i64
%5 = alloca i32**
%6 = alloca i64*
%7 = alloca i8*
store i64 %0, i64* %4
store i32** %1, i32*** %5
store i64* %2, i64** %6
%8 = load i64, i64* %4
%9 = add i64 %8, 1
%10 = call i8* @flb_malloc(i64 %9)
store i8* %10, i8** %7
%11 = load i8*, i8** %7
%12 = load i32**, i32*** %5
%13 = load i32*, i32** %12
%14 = load i64, i64* %4
%15 = call i32 @memcpy(i8* %11, i32* %13, i64 %14)
%16 = load i8*, i8** %7
%17 = load i64, i64* %4
%18 = getelementptr inbounds i8, i8* %16, i64 %17
store i8 0, i8* %18
%19 = load i64, i64* %4
%20 = load i64*, i64** %6
%21 = load i64, i64* %20
%22 = sub i64 %21, %19
store i64 %22, i64* %20
%23 = load i64, i64* %4
%24 = load i32**, i32*** %5
%25 = load i32*, i32** %24
%26 = getelementptr inbounds i32, i32* %25, i64 %23
store i32* %26, i32** %24
%27 = load i8*, i8** %7
ret i8* %27
}

LLVM IR (-O2):
define i8* @get_null_terminated(i64 %0, i32** nocapture %1, i64* nocapture %2) {
%4 = add i64 %0, 1
%5 = tail call i8* @flb_malloc(i64 %4)
%6 = load i32*, i32** %1
%7 = tail call i32 @memcpy(i8* %5, i32* %6, i64 %0)
%8 = getelementptr inbounds i8, i8* %5, i64 %0
store i8 0, i8* %8
%9 = load i64, i64* %2
%10 = sub i64 %9, %0
store i64 %10, i64* %2
%11 = load i32*, i32** %1
%12 = getelementptr inbounds i32, i32* %11, i64 %0
store i32* %12, i32** %1
ret i8* %5
}