#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 */
typedef int /*<<< orphan*/ SSL;

/* Variables and functions */
scalar_t__ EINTR;
int SSL_read(int /*<<< orphan*/ *, char *, int);
scalar_t__ errno;
int read(int, char *, int);
int slow(SSL *ssl, int fd, char *p, int cnt) {
  int n;
  while ((n = ssl ? SSL_read(ssl, p, cnt) : read(fd, p, cnt)) < 0)
    if (errno != EINTR)
      return 0;
  return n;
}


x86 assembly (clang, -O0):
<slow>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1159 <slow+0x39>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x24(%rbp),%edx
call   1030 <SSL_read@plt>
mov    %eax,-0x2c(%rbp)
jmp    116b <slow+0x4b>
mov    -0x14(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    -0x24(%rbp),%edx
call   1040 <read@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
mov    %eax,-0x28(%rbp)
cmp    $0x0,%eax
jge    11a5 <slow+0x85>
mov    0x2e5f(%rip),%rax
mov    (%rax),%rax
mov    0x2e4d(%rip),%rcx
cmp    (%rcx),%rax
je     11a0 <slow+0x80>
movl   $0x0,-0x4(%rbp)
jmp    11ab <slow+0x8b>
jmp    1136 <slow+0x16>
mov    -0x28(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<slow>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %ecx,%r15d
mov    %rdx,%rbx
mov    %esi,%r14d
mov    %rdi,%rbp
mov    0x2ea2(%rip),%r12
mov    0x2e93(%rip),%r13
cs nopw 0x0(%rax,%rax,1)
nop
test   %rbp,%rbp
je     1170 <slow+0x50>
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    %r15d,%edx
call   1030 <SSL_read@plt>
test   %eax,%eax
js     1182 <slow+0x62>
jmp    118e <slow+0x6e>
nopl   0x0(%rax)
mov    %r14d,%edi
mov    %rbx,%rsi
mov    %r15d,%edx
call   1040 <read@plt>
test   %eax,%eax
jns    118e <slow+0x6e>
mov    (%r12),%rax
cmp    0x0(%r13),%rax
je     1150 <slow+0x30>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@errno = global i64 0
@EINTR = global i64 0
define i32 @slow(i32* %0, i32 %1, i8* %2, i32 %3) {
%5 = icmp eq i32* %0, null
br label %6
6: ; preds = %14, %4
br i1 %5, label %9, label %7
7: ; preds = %6
%8 = tail call i32 @SSL_read(i32* %0, i8* %2, i32 %3)
br label %11
9: ; preds = %6
%10 = tail call i32 @read(i32 %1, i8* %2, i32 %3)
br label %11
11: ; preds = %9, %7
%12 = phi i32 [ %8, %7 ], [ %10, %9 ]
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %18
14: ; preds = %11
%15 = load i64, i64* @errno
%16 = load i64, i64* @EINTR
%17 = icmp eq i64 %15, %16
br i1 %17, label %6, label %18
18: ; preds = %11, %14
%19 = phi i32 [ 0, %14 ], [ %12, %11 ]
ret i32 %19
}