#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 EINVAL;
int errno;
int shutdown(int, int);
int os_shutdown_socket(int fd, int r, int w) {
  int what, err;
  if (r && w)
    what = 2;
  else if (r)
    what = 0;
  else if (w)
    what = 1;
  else
    return -EINVAL;
  err = shutdown(fd, what);
  if (err < 0)
    return -errno;
  return 0;
}


x86 assembly (clang, -O0):
<os_shutdown_socket>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     1141 <os_shutdown_socket+0x31>
cmpl   $0x0,-0x10(%rbp)
je     1141 <os_shutdown_socket+0x31>
movl   $0x2,-0x14(%rbp)
jmp    118a <os_shutdown_socket+0x7a>
cmpl   $0x0,-0xc(%rbp)
je     1157 <os_shutdown_socket+0x47>
movl   $0x0,-0x14(%rbp)
jmp    1185 <os_shutdown_socket+0x75>
cmpl   $0x0,-0x10(%rbp)
je     116d <os_shutdown_socket+0x5d>
movl   $0x1,-0x14(%rbp)
jmp    1180 <os_shutdown_socket+0x70>
xor    %eax,%eax
mov    0x2e62(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    11bc <os_shutdown_socket+0xac>
jmp    1185 <os_shutdown_socket+0x75>
jmp    118a <os_shutdown_socket+0x7a>
mov    -0x8(%rbp),%edi
mov    -0x14(%rbp),%esi
call   1030 <shutdown@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    11b5 <os_shutdown_socket+0xa5>
xor    %eax,%eax
mov    0x2e35(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    11bc <os_shutdown_socket+0xac>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<os_shutdown_socket>:
push   %rax
mov    %edx,%eax
or     %esi,%eax
je     1141 <os_shutdown_socket+0x31>
test   %esi,%esi
setne  %al
test   %edx,%edx
setne  %cl
and    %al,%cl
movzbl %cl,%eax
add    %eax,%eax
test   %esi,%esi
mov    $0x1,%esi
cmovne %eax,%esi
call   1030 <shutdown@plt>
mov    %eax,%ecx
xor    %eax,%eax
test   %ecx,%ecx
js     114a <os_shutdown_socket+0x3a>
pop    %rcx
ret
mov    0x2e90(%rip),%rcx
jmp    1151 <os_shutdown_socket+0x41>
mov    0x2e8f(%rip),%rcx
xor    %eax,%eax
sub    (%rcx),%eax
pop    %rcx
ret

LLVM IR (-O0):
@EINVAL = global i32 0
@errno = global i32 0
define i32 @os_shutdown_socket(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32 %2, i32* %7
%10 = load i32, i32* %6
%11 = icmp ne i32 %10, 0
br i1 %11, label %12, label %16
12: ; preds = %3
%13 = load i32, i32* %7
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %16
15: ; preds = %12
store i32 2, i32* %8
br label %29
16: ; preds = %12, %3
%17 = load i32, i32* %6
%18 = icmp ne i32 %17, 0
br i1 %18, label %19, label %20
19: ; preds = %16
store i32 0, i32* %8
br label %28
20: ; preds = %16
%21 = load i32, i32* %7
%22 = icmp ne i32 %21, 0
br i1 %22, label %23, label %24
23: ; preds = %20
store i32 1, i32* %8
br label %27
24: ; preds = %20
%25 = load i32, i32* @EINVAL
%26 = sub nsw i32 0, %25
store i32 %26, i32* %4
br label %39
27: ; preds = %23
br label %28
28: ; preds = %27, %19
br label %29
29: ; preds = %28, %15
%30 = load i32, i32* %5
%31 = load i32, i32* %8
%32 = call i32 @shutdown(i32 %30, i32 %31)
store i32 %32, i32* %9
%33 = load i32, i32* %9
%34 = icmp slt i32 %33, 0
br i1 %34, label %35, label %38
35: ; preds = %29
%36 = load i32, i32* @errno
%37 = sub nsw i32 0, %36
store i32 %37, i32* %4
br label %39
38: ; preds = %29
store i32 0, i32* %4
br label %39
39: ; preds = %38, %35, %24
%40 = load i32, i32* %4
ret i32 %40
}

LLVM IR (-O2):
@EINVAL = global i32 0
@errno = global i32 0
define i32 @os_shutdown_socket(i32 %0, i32 %1, i32 %2) {
%4 = icmp ne i32 %1, 0
%5 = or i32 %2, %1
%6 = icmp eq i32 %5, 0
br i1 %6, label %7, label %10
7: ; preds = %3
%8 = load i32, i32* @EINVAL
%9 = sub nsw i32 0, %8
br label %20
10: ; preds = %3
%11 = icmp ne i32 %2, 0
%12 = and i1 %4, %11
%13 = select i1 %12, i32 2, i32 0
%14 = select i1 %4, i32 %13, i32 1
%15 = tail call i32 @shutdown(i32 %0, i32 %14)
%16 = icmp slt i32 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %10
%18 = load i32, i32* @errno
%19 = sub nsw i32 0, %18
br label %20
20: ; preds = %10, %17, %7
%21 = phi i32 [ %19, %17 ], [ %9, %7 ], [ 0, %10 ]
ret i32 %21
}