#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 ECONNRESET;
int errno;
int shutdown(int, int);
int ruby_shutdown(int s, int how) {
  int err = errno;
  errno = 0;
  s = shutdown(s, how);
  if (errno == ECONNRESET) {
    errno = 0;
    s = 0;
  } else if (errno == 0)
    errno = err;
  return s;
}


x86 assembly (clang, -O0):
<ruby_shutdown>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    0x2eb3(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
mov    0x2ea7(%rip),%rax
movl   $0x0,(%rax)
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
call   1030 <shutdown@plt>
mov    %eax,-0x4(%rbp)
mov    0x2e8c(%rip),%rax
mov    (%rax),%eax
mov    0x2e8b(%rip),%rcx
cmp    (%rcx),%eax
jne    1176 <ruby_shutdown+0x66>
mov    0x2e74(%rip),%rax
movl   $0x0,(%rax)
movl   $0x0,-0x4(%rbp)
jmp    1197 <ruby_shutdown+0x87>
mov    0x2e5b(%rip),%rax
cmpl   $0x0,(%rax)
jne    1192 <ruby_shutdown+0x82>
mov    -0xc(%rbp),%ecx
mov    0x2e48(%rip),%rax
mov    %ecx,(%rax)
jmp    1197 <ruby_shutdown+0x87>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ruby_shutdown>:
push   %rbp
push   %rbx
push   %rax
mov    0x2ebe(%rip),%rbx
mov    (%rbx),%ebp
movl   $0x0,(%rbx)
call   1030 <shutdown@plt>
mov    (%rbx),%edx
mov    0x2eb0(%rip),%rdi
xor    %ecx,%ecx
mov    $0x0,%esi
cmp    (%rdi),%edx
je     1143 <ruby_shutdown+0x33>
mov    %ebp,%ecx
mov    %eax,%esi
test   %edx,%edx
jne    1147 <ruby_shutdown+0x37>
mov    %ecx,(%rbx)
mov    %esi,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@errno = global i32 0
@ECONNRESET = global i32 0
define i32 @ruby_shutdown(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%6 = load i32, i32* @errno
store i32 %6, i32* %5
store i32 0, i32* @errno
%7 = load i32, i32* %3
%8 = load i32, i32* %4
%9 = call i32 @shutdown(i32 %7, i32 %8)
store i32 %9, i32* %3
%10 = load i32, i32* @errno
%11 = load i32, i32* @ECONNRESET
%12 = icmp eq i32 %10, %11
br i1 %12, label %13, label %14
13: ; preds = %2
store i32 0, i32* @errno
store i32 0, i32* %3
br label %20
14: ; preds = %2
%15 = load i32, i32* @errno
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %14
%18 = load i32, i32* %5
store i32 %18, i32* @errno
br label %19
19: ; preds = %17, %14
br label %20
20: ; preds = %19, %13
%21 = load i32, i32* %3
ret i32 %21
}

LLVM IR (-O2):
@errno = global i32 0
@ECONNRESET = global i32 0
define i32 @ruby_shutdown(i32 %0, i32 %1) {
%3 = load i32, i32* @errno
store i32 0, i32* @errno
%4 = tail call i32 @shutdown(i32 %0, i32 %1)
%5 = load i32, i32* @errno
%6 = load i32, i32* @ECONNRESET
%7 = icmp eq i32 %5, %6
br i1 %7, label %10, label %8
8: ; preds = %2
%9 = icmp eq i32 %5, 0
br i1 %9, label %10, label %13
10: ; preds = %8, %2
%11 = phi i32 [ 0, %2 ], [ %3, %8 ]
%12 = phi i32 [ 0, %2 ], [ %4, %8 ]
store i32 %11, i32* @errno
br label %13
13: ; preds = %10, %8
%14 = phi i32 [ %4, %8 ], [ %12, %10 ]
ret i32 %14
}