#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*/ fprintf(int /*<<< orphan*/, char *, char *, int, char *);
int read(int, char *, int);
int /*<<< orphan*/ stderr;
int chat_client_read(int socket_fd, char buf[], int buflen) {
  int ret;
  if ((ret = read(socket_fd, buf, buflen)) < 0) {
    fprintf(stderr, "%s:%d >> Error: %s\n",
            "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
            "2022-01-22/02-19-57/repos/dorneanu/rsachat/refs/heads/master/src/"
            "client.c",
            124, "Error reading from socket");
    return -1;
  } else {
    return ret;
  }
}


x86 assembly (clang, -O0):
<chat_client_read>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1030 <read@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
jge    1181 <chat_client_read+0x61>
mov    0x2e8c(%rip),%rax
mov    (%rax),%edi
lea    0xea3(%rip),%rsi
lea    0xeb0(%rip),%rdx
mov    $0x7c,%ecx
lea    0xf2e(%rip),%r8
call   1040 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1187 <chat_client_read+0x67>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<chat_client_read>:
push   %rax
call   1030 <read@plt>
test   %eax,%eax
js     112c <chat_client_read+0xc>
pop    %rcx
ret
mov    0x2ead(%rip),%rax
mov    (%rax),%edi
lea    0xec4(%rip),%rsi
lea    0xed1(%rip),%rdx
lea    0xf54(%rip),%r8
mov    $0x7c,%ecx
call   1040 <fprintf@plt>
mov    $0xffffffff,%eax
pop    %rcx
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [20 x i8] c"%s:%d >> Error: %s\0A\00"
@.str.1 = [138 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/dorneanu/rsachat/refs/heads/master/src/client.c\00"
@.str.2 = [26 x i8] c"Error reading from socket\00"
define i32 @chat_client_read(i32 %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %5
store i8* %1, i8** %6
store i32 %2, i32* %7
%9 = load i32, i32* %5
%10 = load i8*, i8** %6
%11 = load i32, i32* %7
%12 = call i32 @read(i32 %9, i8* %10, i32 %11)
store i32 %12, i32* %8
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %3
%15 = load i32, i32* @stderr
%16 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([138 x i8], [138 x i8]* @.str.1, i64 0, i64 0), i32 124, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %4
br label %19
17: ; preds = %3
%18 = load i32, i32* %8
store i32 %18, i32* %4
br label %19
19: ; preds = %17, %14
%20 = load i32, i32* %4
ret i32 %20
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [20 x i8] c"%s:%d >> Error: %s\0A\00"
@.str.1 = [138 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/dorneanu/rsachat/refs/heads/master/src/client.c\00"
@.str.2 = [26 x i8] c"Error reading from socket\00"
define i32 @chat_client_read(i32 %0, i8* nocapture %1, i32 %2) {
%4 = tail call i32 @read(i32 %0, i8* %1, i32 %2)
%5 = icmp slt i32 %4, 0
br i1 %5, label %6, label %9
6: ; preds = %3
%7 = load i32, i32* @stderr
%8 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([138 x i8], [138 x i8]* @.str.1, i64 0, i64 0), i32 124, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
br label %9
9: ; preds = %3, %6
%10 = phi i32 [ -1, %6 ], [ %4, %3 ]
ret i32 %10
}