#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__ errno;
int /*<<< orphan*/ ltr_int_my_perror(char *);
scalar_t__ read(int, void *, size_t);
ssize_t ltr_int_socket_receive(int socket, void *buf, size_t size) {
  ssize_t num_read = read(socket, buf, size);
  if (num_read > 0) {
    return num_read;
  } else if (num_read < 0) {
    ltr_int_my_perror("read@socket_receive");
    return -errno;
  }
  return 0;
}


x86 assembly (clang, -O0):
<ltr_int_socket_receive>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0xc(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0xc(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1030 <read@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jle    115f <ltr_int_socket_receive+0x3f>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1198 <ltr_int_socket_receive+0x78>
cmpq   $0x0,-0x28(%rbp)
jge    118b <ltr_int_socket_receive+0x6b>
lea    0xe8f(%rip),%rdi
call   1040 <ltr_int_my_perror@plt>
xor    %eax,%eax
mov    0x2e61(%rip),%rcx
sub    (%rcx),%rax
mov    %rax,-0x8(%rbp)
jmp    1198 <ltr_int_socket_receive+0x78>
jmp    1190 <ltr_int_socket_receive+0x70>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ltr_int_socket_receive>:
push   %rax
call   1030 <read@plt>
test   %rax,%rax
jle    112d <ltr_int_socket_receive+0xd>
pop    %rcx
ret
js     1133 <ltr_int_socket_receive+0x13>
xor    %eax,%eax
pop    %rcx
ret
lea    0xec6(%rip),%rdi
call   1040 <ltr_int_my_perror@plt>
mov    0x2e9a(%rip),%rcx
xor    %eax,%eax
sub    (%rcx),%rax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [20 x i8] c"read@socket_receive\00"
@errno = global i64 0
define i64 @ltr_int_socket_receive(i32 %0, i8* %1, i64 %2) {
%4 = alloca i64
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i64
store i32 %0, i32* %5
store i8* %1, i8** %6
store i64 %2, i64* %7
%9 = load i32, i32* %5
%10 = load i8*, i8** %6
%11 = load i64, i64* %7
%12 = call i64 @read(i32 %9, i8* %10, i64 %11)
store i64 %12, i64* %8
%13 = load i64, i64* %8
%14 = icmp sgt i64 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %3
%16 = load i64, i64* %8
store i64 %16, i64* %4
br label %26
17: ; preds = %3
%18 = load i64, i64* %8
%19 = icmp slt i64 %18, 0
br i1 %19, label %20, label %24
20: ; preds = %17
%21 = call i32 @ltr_int_my_perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%22 = load i64, i64* @errno
%23 = sub nsw i64 0, %22
store i64 %23, i64* %4
br label %26
24: ; preds = %17
br label %25
25: ; preds = %24
store i64 0, i64* %4
br label %26
26: ; preds = %25, %20, %15
%27 = load i64, i64* %4
ret i64 %27
}

LLVM IR (-O2):
@.str = [20 x i8] c"read@socket_receive\00"
@errno = global i64 0
define i64 @ltr_int_socket_receive(i32 %0, i8* nocapture %1, i64 %2) {
%4 = tail call i64 @read(i32 %0, i8* %1, i64 %2)
%5 = icmp sgt i64 %4, 0
br i1 %5, label %12, label %6
6: ; preds = %3
%7 = icmp slt i64 %4, 0
br i1 %7, label %8, label %12
8: ; preds = %6
%9 = tail call i32 @ltr_int_my_perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%10 = load i64, i64* @errno
%11 = sub nsw i64 0, %10
br label %12
12: ; preds = %6, %3, %8
%13 = phi i64 [ %11, %8 ], [ %4, %3 ], [ 0, %6 ]
ret i64 %13
}