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

/* Variables and functions */
scalar_t__ read(int, ...);
int receive_response(int sfd, size_t *size, char *response) {
  ssize_t ret;
  ret = read(sfd, size, sizeof(size_t));
  if (ret <= 0)
    return -1;
  ret = read(sfd, response, *size);
  if (ret <= 0)
    return -1;
  return 0;
}


x86 assembly (clang, -O0):
<receive_response>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    $0x8,%edx
mov    $0x0,%al
call   1030 <read@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jg     1151 <receive_response+0x41>
movl   $0xffffffff,-0x4(%rbp)
jmp    1188 <receive_response+0x78>
mov    -0x8(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
mov    $0x0,%al
call   1030 <read@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jg     1181 <receive_response+0x71>
movl   $0xffffffff,-0x4(%rbp)
jmp    1188 <receive_response+0x78>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<receive_response>:
push   %rbp
push   %r14
push   %rbx
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %edi,%ebp
mov    $0x8,%edx
xor    %eax,%eax
call   1030 <read@plt>
test   %rax,%rax
jle    114b <receive_response+0x3b>
mov    (%rbx),%rdx
mov    %ebp,%edi
mov    %r14,%rsi
xor    %eax,%eax
call   1030 <read@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
setle  %al
neg    %eax
jmp    1150 <receive_response+0x40>
mov    $0xffffffff,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @receive_response(i32 %0, i64* %1, i8* %2) {
%4 = tail call i64 (i32, ...) @read(i32 %0, i64* %1, i64 8)
%5 = icmp slt i64 %4, 1
br i1 %5, label %11, label %6
6: ; preds = %3
%7 = load i64, i64* %1
%8 = tail call i64 (i32, ...) @read(i32 %0, i8* %2, i64 %7)
%9 = icmp slt i64 %8, 1
%10 = sext i1 %9 to i32
br label %11
11: ; preds = %6, %3
%12 = phi i32 [ -1, %3 ], [ %10, %6 ]
ret i32 %12
}