#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 read(int, void *, int);
int scbuf_get_fd(void *dstbuf, int *psrcfd, int len) {
  int n;
  assert(dstbuf != NULL);
  assert(psrcfd != NULL);
  assert(*psrcfd >= 0);
  assert(len > 0);
  do {
    n = read(*psrcfd, dstbuf, len);
  } while ((n < 0) && (errno == EINTR));
  return (n);
}


x86 assembly (clang, -O0):
<scbuf_get_fd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
cmpq   $0x0,-0x8(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
cmpq   $0x0,-0x10(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x10(%rbp),%rax
cmpl   $0x0,(%rax)
setge  %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
cmpl   $0x0,-0x14(%rbp)
setg   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1030 <read@plt>
mov    %eax,-0x18(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x18(%rbp)
mov    %al,-0x19(%rbp)
jge    11ba <scbuf_get_fd+0x9a>
mov    0x2e39(%rip),%rax
mov    (%rax),%rax
mov    0x2e27(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    117c <scbuf_get_fd+0x5c>
mov    -0x18(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<scbuf_get_fd>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edx,%r14d
mov    %rsi,%rbx
mov    %rdi,%rbp
xor    %edi,%edi
test   %rbp,%rbp
setne  %dil
call   1040 <assert@plt>
xor    %edi,%edi
test   %rbx,%rbx
setne  %dil
call   1040 <assert@plt>
mov    (%rbx),%edi
not    %edi
shr    $0x1f,%edi
call   1040 <assert@plt>
xor    %edi,%edi
test   %r14d,%r14d
setg   %dil
call   1040 <assert@plt>
mov    0x2e72(%rip),%r15
mov    0x2e63(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
nop
mov    (%rbx),%edi
mov    %rbp,%rsi
mov    %r14d,%edx
call   1030 <read@plt>
test   %eax,%eax
jns    119a <scbuf_get_fd+0x7a>
mov    (%r12),%rcx
cmp    %rcx,(%r15)
je     1180 <scbuf_get_fd+0x60>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@errno = global i64 0
@EINTR = global i64 0
define i32 @scbuf_get_fd(i8* %0, i32* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %4
store i32* %1, i32** %5
store i32 %2, i32* %6
%8 = load i8*, i8** %4
%9 = icmp ne i8* %8, null
%10 = zext i1 %9 to i32
%11 = call i32 @assert(i32 %10)
%12 = load i32*, i32** %5
%13 = icmp ne i32* %12, null
%14 = zext i1 %13 to i32
%15 = call i32 @assert(i32 %14)
%16 = load i32*, i32** %5
%17 = load i32, i32* %16
%18 = icmp sge i32 %17, 0
%19 = zext i1 %18 to i32
%20 = call i32 @assert(i32 %19)
%21 = load i32, i32* %6
%22 = icmp sgt i32 %21, 0
%23 = zext i1 %22 to i32
%24 = call i32 @assert(i32 %23)
br label %25
25: ; preds = %38, %3
%26 = load i32*, i32** %5
%27 = load i32, i32* %26
%28 = load i8*, i8** %4
%29 = load i32, i32* %6
%30 = call i32 @read(i32 %27, i8* %28, i32 %29)
store i32 %30, i32* %7
br label %31
31: ; preds = %25
%32 = load i32, i32* %7
%33 = icmp slt i32 %32, 0
br i1 %33, label %34, label %38
34: ; preds = %31
%35 = load i64, i64* @errno
%36 = load i64, i64* @EINTR
%37 = icmp eq i64 %35, %36
br label %38
38: ; preds = %34, %31
%39 = phi i1 [ false, %31 ], [ %37, %34 ]
br i1 %39, label %25, label %40
40: ; preds = %38
%41 = load i32, i32* %7
ret i32 %41
}

LLVM IR (-O2):
@errno = global i64 0
@EINTR = global i64 0
define i32 @scbuf_get_fd(i8* %0, i32* %1, i32 %2) {
%4 = icmp ne i8* %0, null
%5 = zext i1 %4 to i32
%6 = tail call i32 @assert(i32 %5)
%7 = icmp ne i32* %1, null
%8 = zext i1 %7 to i32
%9 = tail call i32 @assert(i32 %8)
%10 = load i32, i32* %1
%11 = xor i32 %10, -1
%12 = lshr i32 %11, 31
%13 = tail call i32 @assert(i32 %12)
%14 = icmp sgt i32 %2, 0
%15 = zext i1 %14 to i32
%16 = tail call i32 @assert(i32 %15)
br label %17
17: ; preds = %17, %3
%18 = load i32, i32* %1
%19 = tail call i32 @read(i32 %18, i8* %0, i32 %2)
%20 = icmp slt i32 %19, 0
%21 = load i64, i64* @errno
%22 = load i64, i64* @EINTR
%23 = icmp eq i64 %21, %22
%24 = select i1 %20, i1 %23, i1 false
br i1 %24, label %17, label %25
25: ; preds = %17
ret i32 %19
}