#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*/ UNLLog(int, char *, int, int, ...);
int /*<<< orphan*/ errno;
int read(int, void *, int);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
int afsocket_receive(void *c, int server_socket, int bytesToRead) {
  int length = 0;
  if ((length = read(server_socket, c, bytesToRead)) <= 0) {
    UNLLog(1,
           "Failed to receive data from local AF_UNIX (s=%i, l=%i): %s (%i)\n",
           server_socket, length, strerror(errno), length);
    return length;
  }
  UNLLog(5, "Received data from local AF_UNIX (s=%i, l=%i).\n", server_socket,
         length);
  return length;
}


x86 assembly (clang, -O0):
<afsocket_receive>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%edx
call   1030 <read@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jg     11a9 <afsocket_receive+0x79>
mov    -0x14(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    0x2e69(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
mov    -0x24(%rbp),%edx
mov    -0x20(%rbp),%ecx
mov    %eax,%r8d
mov    -0x1c(%rbp),%r9d
mov    $0x1,%edi
lea    0xe69(%rip),%rsi
mov    $0x0,%al
call   1040 <UNLLog@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11c8 <afsocket_receive+0x98>
mov    -0x14(%rbp),%edx
mov    -0x1c(%rbp),%ecx
mov    $0x5,%edi
lea    0xe86(%rip),%rsi
mov    $0x0,%al
call   1040 <UNLLog@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<afsocket_receive>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%rsi
mov    %ebp,%edi
call   1030 <read@plt>
mov    %eax,%ebx
test   %eax,%eax
jle    115e <afsocket_receive+0x2e>
lea    0xef5(%rip),%rsi
mov    $0x5,%edi
mov    %ebp,%edx
mov    %ebx,%ecx
xor    %eax,%eax
call   1040 <UNLLog@plt>
jmp    1189 <afsocket_receive+0x59>
mov    0x2e7b(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
lea    0xe8d(%rip),%rsi
mov    $0x1,%edi
mov    %ebp,%edx
mov    %ebx,%ecx
mov    %eax,%r8d
mov    %ebx,%r9d
xor    %eax,%eax
call   1040 <UNLLog@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [65 x i8] c"Failed to receive data from local AF_UNIX (s=%i, l=%i): %s (%i)\0A\00"
@errno = global i32 0
@.str.1 = [48 x i8] c"Received data from local AF_UNIX (s=%i, l=%i).\0A\00"
define i32 @afsocket_receive(i8* %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32 0, i32* %8
%9 = load i32, i32* %6
%10 = load i8*, i8** %5
%11 = load i32, i32* %7
%12 = call i32 @read(i32 %9, i8* %10, i32 %11)
store i32 %12, i32* %8
%13 = icmp sle i32 %12, 0
br i1 %13, label %14, label %22
14: ; preds = %3
%15 = load i32, i32* %6
%16 = load i32, i32* %8
%17 = load i32, i32* @errno
%18 = call i32 @strerror(i32 %17)
%19 = load i32, i32* %8
%20 = call i32 (i32, i8*, i32, i32, ...) @UNLLog(i32 1, i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str, i64 0, i64 0), i32 %15, i32 %16, i32 %18, i32 %19)
%21 = load i32, i32* %8
store i32 %21, i32* %4
br label %27
22: ; preds = %3
%23 = load i32, i32* %6
%24 = load i32, i32* %8
%25 = call i32 (i32, i8*, i32, i32, ...) @UNLLog(i32 5, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.1, i64 0, i64 0), i32 %23, i32 %24)
%26 = load i32, i32* %8
store i32 %26, i32* %4
br label %27
27: ; preds = %22, %14
%28 = load i32, i32* %4
ret i32 %28
}

LLVM IR (-O2):
@.str = [65 x i8] c"Failed to receive data from local AF_UNIX (s=%i, l=%i): %s (%i)\0A\00"
@errno = global i32 0
@.str.1 = [48 x i8] c"Received data from local AF_UNIX (s=%i, l=%i).\0A\00"
define i32 @afsocket_receive(i8* nocapture %0, i32 %1, i32 %2) {
%4 = tail call i32 @read(i32 %1, i8* %0, i32 %2)
%5 = icmp slt i32 %4, 1
br i1 %5, label %6, label %10
6: ; preds = %3
%7 = load i32, i32* @errno
%8 = tail call i32 @strerror(i32 %7)
%9 = tail call i32 (i32, i8*, i32, i32, ...) @UNLLog(i32 1, i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str, i64 0, i64 0), i32 %1, i32 %4, i32 %8, i32 %4)
br label %12
10: ; preds = %3
%11 = tail call i32 (i32, i8*, i32, i32, ...) @UNLLog(i32 5, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.1, i64 0, i64 0), i32 %1, i32 %4)
br label %12
12: ; preds = %10, %6
ret i32 %4
}