#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 */
int /*<<< orphan*/ exit(int);
char *malloc(int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int read(int, char *, int);
char *fromFVM(int outP[], int len) {
  char *buf = malloc(len);
  if (NULL == buf) {
    perror("malloc");
    printf("function: fromFVM\n");
    return NULL;
  }
  memset(buf, 0, len);
  int cnt = read(outP[0], buf, len);
  if (-1 == cnt) {
    perror("read from pipe");
    exit(-1);
  }
  return buf;
}


x86 assembly (clang, -O0):
<fromFVM>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x14(%rbp),%edi
call   1060 <malloc@plt>
mov    %rax,-0x20(%rbp)
xor    %eax,%eax
cmp    -0x20(%rbp),%rax
jne    11ac <fromFVM+0x4c>
lea    0xe72(%rip),%rdi
call   1070 <perror@plt>
lea    0xe6d(%rip),%rdi
call   1030 <printf@plt>
movq   $0x0,-0x8(%rbp)
jmp    11fb <fromFVM+0x9b>
mov    -0x20(%rbp),%rdi
mov    -0x14(%rbp),%edx
xor    %esi,%esi
call   1040 <memset@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1050 <read@plt>
mov    %eax,-0x24(%rbp)
mov    $0xffffffff,%eax
cmp    -0x24(%rbp),%eax
jne    11f3 <fromFVM+0x93>
lea    0xe36(%rip),%rdi
call   1070 <perror@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fromFVM>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%ebp
mov    %rdi,%r14
mov    %esi,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
test   %rax,%rax
je     119e <fromFVM+0x3e>
mov    %rbx,%rdi
xor    %esi,%esi
mov    %ebp,%edx
call   1040 <memset@plt>
mov    (%r14),%edi
mov    %rbx,%rsi
mov    %ebp,%edx
call   1050 <read@plt>
cmp    $0xffffffff,%eax
je     11b8 <fromFVM+0x58>
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xe5b(%rip),%rdi
call   1070 <perror@plt>
lea    0xe65(%rip),%rdi
call   1030 <puts@plt>
jmp    1196 <fromFVM+0x36>
lea    0xe48(%rip),%rdi
call   1070 <perror@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [7 x i8] c"malloc\00"
@.str.1 = [19 x i8] c"function: fromFVM\0A\00"
@.str.2 = [15 x i8] c"read from pipe\00"
define i8* @fromFVM(i32* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
store i32* %0, i32** %4
store i32 %1, i32* %5
%8 = load i32, i32* %5
%9 = call i8* @malloc(i32 %8)
store i8* %9, i8** %6
%10 = load i8*, i8** %6
%11 = icmp eq i8* null, %10
br i1 %11, label %12, label %15
12: ; preds = %2
%13 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%14 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
store i8* null, i8** %3
br label %32
15: ; preds = %2
%16 = load i8*, i8** %6
%17 = load i32, i32* %5
%18 = call i32 @memset(i8* %16, i32 0, i32 %17)
%19 = load i32*, i32** %4
%20 = getelementptr inbounds i32, i32* %19, i64 0
%21 = load i32, i32* %20
%22 = load i8*, i8** %6
%23 = load i32, i32* %5
%24 = call i32 @read(i32 %21, i8* %22, i32 %23)
store i32 %24, i32* %7
%25 = load i32, i32* %7
%26 = icmp eq i32 -1, %25
br i1 %26, label %27, label %30
27: ; preds = %15
%28 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
%29 = call i32 @exit(i32 -1)
unreachable
30: ; preds = %15
%31 = load i8*, i8** %6
store i8* %31, i8** %3
br label %32
32: ; preds = %30, %12
%33 = load i8*, i8** %3
ret i8* %33
}

LLVM IR (-O2):
@.str = [7 x i8] c"malloc\00"
@.str.2 = [15 x i8] c"read from pipe\00"
@str = [18 x i8] c"function: fromFVM\00"
define i8* @fromFVM(i32* nocapture %0, i32 %1) {
%3 = tail call i8* @malloc(i32 %1)
%4 = icmp eq i8* %3, null
br i1 %4, label %5, label %8
5: ; preds = %2
%6 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str, i64 0, i64 0))
br label %16
8: ; preds = %2
%9 = tail call i32 @memset(i8* %3, i32 0, i32 %1)
%10 = load i32, i32* %0
%11 = tail call i32 @read(i32 %10, i8* %3, i32 %1)
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %16
13: ; preds = %8
%14 = tail call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
%15 = tail call i32 @exit(i32 -1)
unreachable
16: ; preds = %8, %5
ret i8* %3
}