#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 EAGAIN;
int EPIPE;
int EWOULDBLOCK;
int errno;
int sanitize_read(int r) {
  switch (r) {
  case -1:
    return (((errno) == EAGAIN) || ((errno) == EWOULDBLOCK)) ? (errno = 0, 0)
                                                             : -1;
  case 0:
    return (errno = EPIPE, -1);
  default:
    return r;
  }
}


x86 assembly (clang, -O0):
<sanitize_read>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0xc(%rbp)
sub    $0xffffffff,%eax
je     112b <sanitize_read+0x2b>
jmp    111b <sanitize_read+0x1b>
mov    -0xc(%rbp),%eax
test   %eax,%eax
je     118a <sanitize_read+0x8a>
jmp    11a8 <sanitize_read+0xa8>
mov    0x2ea6(%rip),%rax
mov    (%rax),%eax
mov    0x2e85(%rip),%rcx
cmp    (%rcx),%eax
je     115b <sanitize_read+0x5b>
mov    0x2e8e(%rip),%rax
mov    (%rax),%eax
mov    0x2e7d(%rip),%rcx
cmp    (%rcx),%eax
jne    1172 <sanitize_read+0x72>
mov    0x2e76(%rip),%rax
movl   $0x0,(%rax)
xor    %eax,%eax
mov    %eax,-0x10(%rbp)
jmp    117f <sanitize_read+0x7f>
mov    $0xffffffff,%eax
mov    %eax,-0x10(%rbp)
jmp    117f <sanitize_read+0x7f>
mov    -0x10(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11ae <sanitize_read+0xae>
mov    0x2e4f(%rip),%rax
mov    (%rax),%ecx
mov    0x2e3e(%rip),%rax
mov    %ecx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    11ae <sanitize_read+0xae>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<sanitize_read>:
test   %edi,%edi
je     1137 <sanitize_read+0x37>
mov    %edi,%eax
cmp    $0xffffffff,%edi
jne    1136 <sanitize_read+0x36>
mov    0x2ec6(%rip),%rax
mov    (%rax),%esi
mov    0x2ea5(%rip),%rax
xor    %ecx,%ecx
cmp    (%rax),%esi
je     1147 <sanitize_read+0x47>
mov    0x2ea8(%rip),%rdi
mov    $0xffffffff,%eax
mov    $0x0,%edx
cmp    (%rdi),%esi
je     1149 <sanitize_read+0x49>
ret
mov    0x2ea2(%rip),%rax
mov    (%rax),%ecx
mov    $0xffffffff,%edx
jmp    1149 <sanitize_read+0x49>
xor    %edx,%edx
mov    0x2e88(%rip),%rax
mov    %ecx,(%rax)
mov    %edx,%eax
ret

LLVM IR (-O0):
@errno = global i32 0
@EAGAIN = global i32 0
@EWOULDBLOCK = global i32 0
@EPIPE = global i32 0
define i32 @sanitize_read(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %3
%4 = load i32, i32* %3
switch i32 %4, label %19 [
i32 -1, label %5
i32 0, label %17
]
5: ; preds = %1
%6 = load i32, i32* @errno
%7 = load i32, i32* @EAGAIN
%8 = icmp eq i32 %6, %7
br i1 %8, label %13, label %9
9: ; preds = %5
%10 = load i32, i32* @errno
%11 = load i32, i32* @EWOULDBLOCK
%12 = icmp eq i32 %10, %11
br i1 %12, label %13, label %14
13: ; preds = %9, %5
store i32 0, i32* @errno
br label %15
14: ; preds = %9
br label %15
15: ; preds = %14, %13
%16 = phi i32 [ 0, %13 ], [ -1, %14 ]
store i32 %16, i32* %2
br label %21
17: ; preds = %1
%18 = load i32, i32* @EPIPE
store i32 %18, i32* @errno
store i32 -1, i32* %2
br label %21
19: ; preds = %1
%20 = load i32, i32* %3
store i32 %20, i32* %2
br label %21
21: ; preds = %19, %17, %15
%22 = load i32, i32* %2
ret i32 %22
}

LLVM IR (-O2):
@errno = global i32 0
@EAGAIN = global i32 0
@EWOULDBLOCK = global i32 0
@EPIPE = global i32 0
define i32 @sanitize_read(i32 %0) {
switch i32 %0, label %14 [
i32 -1, label %2
i32 0, label %9
]
2: ; preds = %1
%3 = load i32, i32* @errno
%4 = load i32, i32* @EAGAIN
%5 = icmp eq i32 %3, %4
%6 = load i32, i32* @EWOULDBLOCK
%7 = icmp eq i32 %3, %6
%8 = select i1 %5, i1 true, i1 %7
br i1 %8, label %11, label %14
9: ; preds = %1
%10 = load i32, i32* @EPIPE
br label %11
11: ; preds = %2, %9
%12 = phi i32 [ %10, %9 ], [ 0, %2 ]
%13 = phi i32 [ -1, %9 ], [ 0, %2 ]
store i32 %12, i32* @errno
br label %14
14: ; preds = %11, %1, %2
%15 = phi i32 [ -1, %2 ], [ %0, %1 ], [ %13, %11 ]
ret i32 %15
}