#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 */
scalar_t__ EINTR;
int /*<<< orphan*/ assert(int);
scalar_t__ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int read(int, void *, int);
int /*<<< orphan*/ stderr;
char *strerror(scalar_t__);
void block_readpipe(int pipefd, void *buffer, int sz) {
  for (;;) {
    int n = read(pipefd, buffer, sz);
    if (n < 0) {
      if (errno == EINTR)
        continue;
      fprintf(stderr, "socket-server : read pipe error %s.\n", strerror(errno));
      return;
    }
    assert(n == sz);
    return;
  }
}


x86 assembly (clang, -O0):
<block_readpipe>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1030 <read@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    11bf <block_readpipe+0x7f>
mov    0x2e63(%rip),%rax
mov    (%rax),%rax
mov    0x2e51(%rip),%rcx
cmp    (%rcx),%rax
jne    118d <block_readpipe+0x4d>
jmp    1152 <block_readpipe+0x12>
mov    0x2e4c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    0x2e38(%rip),%rax
mov    (%rax),%rdi
call   1060 <strerror@plt>
mov    -0x1c(%rbp),%edi
mov    %rax,%rdx
lea    0xe4b(%rip),%rsi
call   1050 <fprintf@plt>
jmp    11d2 <block_readpipe+0x92>
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<block_readpipe>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edx,%r14d
mov    %rsi,%rbx
mov    %edi,%ebp
mov    0x2e81(%rip),%r15
mov    0x2e72(%rip),%r12
xchg   %ax,%ax
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r14d,%edx
call   1030 <read@plt>
test   %eax,%eax
jns    11a1 <block_readpipe+0x61>
mov    (%r15),%rdi
cmp    (%r12),%rdi
je     1160 <block_readpipe+0x20>
mov    0x2e5f(%rip),%rax
mov    (%rax),%ebx
call   1060 <strerror@plt>
lea    0xe71(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <fprintf@plt>
xor    %edi,%edi
cmp    %r14d,%eax
sete   %dil
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <assert@plt>

LLVM IR (-O0):
@errno = global i64 0
@EINTR = global i64 0
@stderr = global i32 0
@.str = [37 x i8] c"socket-server : read pipe error %s.\0A\00"
define void @block_readpipe(i32 %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %4
store i8* %1, i8** %5
store i32 %2, i32* %6
br label %8
8: ; preds = %19, %3
%9 = load i32, i32* %4
%10 = load i8*, i8** %5
%11 = load i32, i32* %6
%12 = call i32 @read(i32 %9, i8* %10, i32 %11)
store i32 %12, i32* %7
%13 = load i32, i32* %7
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %25
15: ; preds = %8
%16 = load i64, i64* @errno
%17 = load i64, i64* @EINTR
%18 = icmp eq i64 %16, %17
br i1 %18, label %19, label %20
19: ; preds = %15
br label %8
20: ; preds = %15
%21 = load i32, i32* @stderr
%22 = load i64, i64* @errno
%23 = call i8* @strerror(i64 %22)
%24 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i8* %23)
br label %31
25: ; preds = %8
%26 = load i32, i32* %7
%27 = load i32, i32* %6
%28 = icmp eq i32 %26, %27
%29 = zext i1 %28 to i32
%30 = call i32 @assert(i32 %29)
br label %31
31: ; preds = %25, %20
ret void
}

LLVM IR (-O2):
@errno = global i64 0
@EINTR = global i64 0
@stderr = global i32 0
@.str = [37 x i8] c"socket-server : read pipe error %s.\0A\00"
define void @block_readpipe(i32 %0, i8* nocapture %1, i32 %2) {
br label %4
4: ; preds = %7, %3
%5 = tail call i32 @read(i32 %0, i8* %1, i32 %2)
%6 = icmp slt i32 %5, 0
br i1 %6, label %7, label %15
7: ; preds = %4
%8 = load i64, i64* @errno
%9 = load i64, i64* @EINTR
%10 = icmp eq i64 %8, %9
br i1 %10, label %4, label %11
11: ; preds = %7
%12 = load i32, i32* @stderr
%13 = tail call i8* @strerror(i64 %8)
%14 = tail call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i8* %13)
br label %19
15: ; preds = %4
%16 = icmp eq i32 %5, %2
%17 = zext i1 %16 to i32
%18 = tail call i32 @assert(i32 %17)
br label %19
19: ; preds = %11, %15
ret void
}