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

/* Variables and functions */
char *calloc(scalar_t__, int);
int /*<<< orphan*/ free(char *);
scalar_t__ read_FP(int /*<<< orphan*/ *, char *, scalar_t__);
scalar_t__ uint32ReadFromFP(int /*<<< orphan*/ *, scalar_t__ *);
size_t astringReadFromFP(FILE *fp, char **data) {
  size_t count = 0;
  uint32_t length;
  count += uint32ReadFromFP(fp, &length);
  if (*data != NULL)
    free(*data);
  *data = calloc(length + 1, sizeof(char));
  count += read_FP(fp, *data, length);
  return count;
}


x86 assembly (clang, -O0):
<astringReadFromFP>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1050 <uint32ReadFromFP@plt>
add    -0x18(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
je     1187 <astringReadFromFP+0x47>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1040 <free@plt>
mov    -0x20(%rbp),%rdi
add    $0x1,%rdi
mov    $0x1,%esi
call   1060 <calloc@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
mov    -0x20(%rbp),%rdx
call   1030 <read_FP@plt>
add    -0x18(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<astringReadFromFP>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
mov    %rdi,%r15
lea    0x8(%rsp),%rsi
call   1050 <uint32ReadFromFP@plt>
mov    %rax,%r14
mov    (%rbx),%rdi
test   %rdi,%rdi
je     1169 <astringReadFromFP+0x29>
call   1040 <free@plt>
mov    0x8(%rsp),%rdi
add    $0x1,%rdi
mov    $0x1,%esi
call   1060 <calloc@plt>
mov    %rax,(%rbx)
mov    0x8(%rsp),%rdx
mov    %r15,%rdi
mov    %rax,%rsi
call   1030 <read_FP@plt>
add    %r14,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define i64 @astringReadFromFP(i32* %0, i8** nocapture %1) {
%3 = alloca i64
%4 = bitcast i64* %3 to i8*
%5 = call i64 @uint32ReadFromFP(i32* %0, i64* %3)
%6 = load i8*, i8** %1
%7 = icmp eq i8* %6, null
br i1 %7, label %10, label %8
8: ; preds = %2
%9 = call i32 @free(i8* %6)
br label %10
10: ; preds = %8, %2
%11 = load i64, i64* %3
%12 = add nsw i64 %11, 1
%13 = call i8* @calloc(i64 %12, i32 1)
store i8* %13, i8** %1
%14 = load i64, i64* %3
%15 = call i64 @read_FP(i32* %0, i8* %13, i64 %14)
%16 = add i64 %15, %5
ret i64 %16
}