#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 */
struct szl_interp {
  int dummy;
};
typedef scalar_t__ ssize_t;

/* Variables and functions */
scalar_t__ EAGAIN;
scalar_t__ EWOULDBLOCK;
scalar_t__ errno;
int /*<<< orphan*/ szl_set_last_strerror(struct szl_interp *, scalar_t__);
ssize_t szl_socket_read_common(struct szl_interp *interp, const ssize_t out,
                               int *more) {
  if (out < 0) {
    if ((errno == EAGAIN) || (errno == EWOULDBLOCK))
      return 0;
    szl_set_last_strerror(interp, errno);
  } else if (out == 0)
    *more = 0;
  return out;
}


x86 assembly (clang, -O0):
<szl_socket_read_common>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
cmpq   $0x0,-0x18(%rbp)
jge    1188 <szl_socket_read_common+0x78>
mov    0x2eaa(%rip),%rax
mov    (%rax),%rax
mov    0x2e88(%rip),%rcx
cmp    (%rcx),%rax
je     1163 <szl_socket_read_common+0x53>
mov    0x2e90(%rip),%rax
mov    (%rax),%rax
mov    0x2e7e(%rip),%rcx
cmp    (%rcx),%rax
jne    1170 <szl_socket_read_common+0x60>
movq   $0x0,-0x8(%rbp)
jmp    11aa <szl_socket_read_common+0x9a>
mov    -0x10(%rbp),%rdi
mov    0x2e65(%rip),%rax
mov    (%rax),%rsi
call   1030 <szl_set_last_strerror@plt>
jmp    11a2 <szl_socket_read_common+0x92>
cmpq   $0x0,-0x18(%rbp)
jne    119d <szl_socket_read_common+0x8d>
mov    -0x20(%rbp),%rax
movl   $0x0,(%rax)
jmp    11a2 <szl_socket_read_common+0x92>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<szl_socket_read_common>:
push   %rbx
mov    %rsi,%rbx
test   %rsi,%rsi
js     1120 <szl_socket_read_common+0x10>
mov    %rbx,%rax
je     114e <szl_socket_read_common+0x3e>
pop    %rbx
ret
mov    0x2eb9(%rip),%rax
mov    (%rax),%rsi
mov    0x2e97(%rip),%rcx
xor    %eax,%eax
cmp    (%rcx),%rsi
je     111e <szl_socket_read_common+0xe>
mov    0x2e99(%rip),%rcx
cmp    (%rcx),%rsi
je     111e <szl_socket_read_common+0xe>
call   1030 <szl_set_last_strerror@plt>
mov    %rbx,%rax
pop    %rbx
ret
movl   $0x0,(%rdx)
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
%struct.szl_interp = type { i32 }
@errno = global i64 0
@EAGAIN = global i64 0
@EWOULDBLOCK = global i64 0
define i64 @szl_socket_read_common(%struct.szl_interp* %0, i64 %1, i32* %2) {
%4 = alloca i64
%5 = alloca %struct.szl_interp*
%6 = alloca i64
%7 = alloca i32*
store %struct.szl_interp* %0, %struct.szl_interp** %5
store i64 %1, i64* %6
store i32* %2, i32** %7
%8 = load i64, i64* %6
%9 = icmp slt i64 %8, 0
br i1 %9, label %10, label %23
10: ; preds = %3
%11 = load i64, i64* @errno
%12 = load i64, i64* @EAGAIN
%13 = icmp eq i64 %11, %12
br i1 %13, label %18, label %14
14: ; preds = %10
%15 = load i64, i64* @errno
%16 = load i64, i64* @EWOULDBLOCK
%17 = icmp eq i64 %15, %16
br i1 %17, label %18, label %19
18: ; preds = %14, %10
store i64 0, i64* %4
br label %31
19: ; preds = %14
%20 = load %struct.szl_interp*, %struct.szl_interp** %5
%21 = load i64, i64* @errno
%22 = call i32 @szl_set_last_strerror(%struct.szl_interp* %20, i64 %21)
br label %29
23: ; preds = %3
%24 = load i64, i64* %6
%25 = icmp eq i64 %24, 0
br i1 %25, label %26, label %28
26: ; preds = %23
%27 = load i32*, i32** %7
store i32 0, i32* %27
br label %28
28: ; preds = %26, %23
br label %29
29: ; preds = %28, %19
%30 = load i64, i64* %6
store i64 %30, i64* %4
br label %31
31: ; preds = %29, %18
%32 = load i64, i64* %4
ret i64 %32
}

LLVM IR (-O2):
%struct.szl_interp = type { i32 }
@errno = global i64 0
@EAGAIN = global i64 0
@EWOULDBLOCK = global i64 0
define i64 @szl_socket_read_common(%struct.szl_interp* %0, i64 %1, i32* nocapture writeonly %2) {
%4 = icmp slt i64 %1, 0
br i1 %4, label %5, label %14
5: ; preds = %3
%6 = load i64, i64* @errno
%7 = load i64, i64* @EAGAIN
%8 = icmp eq i64 %6, %7
%9 = load i64, i64* @EWOULDBLOCK
%10 = icmp eq i64 %6, %9
%11 = select i1 %8, i1 true, i1 %10
br i1 %11, label %17, label %12
12: ; preds = %5
%13 = tail call i32 @szl_set_last_strerror(%struct.szl_interp* %0, i64 %6)
br label %17
14: ; preds = %3
%15 = icmp eq i64 %1, 0
br i1 %15, label %16, label %17
16: ; preds = %14
store i32 0, i32* %2
br label %17
17: ; preds = %12, %16, %14, %5
%18 = phi i64 [ 0, %5 ], [ %1, %14 ], [ 0, %16 ], [ %1, %12 ]
ret i64 %18
}