#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 /*<<< orphan*/ SHUT_RDWR;
int close(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int);
int shutdown(int, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int socket_close(int sockfd) {
  int r = shutdown(sockfd, SHUT_RDWR);
  if (r != 0) {
    fprintf(stderr, "edvs_net_close: socket shutdown error %d\n", r);
    return -1;
  }
  r = close(sockfd);
  if (r != 0) {
    fprintf(stderr, "edvs_net_close: socket close error %d\n", r);
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<socket_close>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2eab(%rip),%rax
mov    (%rax),%esi
call   1030 <shutdown@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     117d <socket_close+0x4d>
mov    0x2e78(%rip),%rax
mov    (%rax),%edi
mov    -0xc(%rbp),%edx
lea    0xe94(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11bd <socket_close+0x8d>
mov    -0x8(%rbp),%edi
call   1040 <close@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     11b6 <socket_close+0x86>
mov    0x2e3f(%rip),%rax
mov    (%rax),%edi
mov    -0xc(%rbp),%edx
lea    0xe85(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11bd <socket_close+0x8d>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<socket_close>:
push   %rbx
mov    %edi,%ebx
mov    0x2eb6(%rip),%rax
mov    (%rax),%esi
call   1030 <shutdown@plt>
test   %eax,%eax
je     1157 <socket_close+0x27>
mov    0x2e8c(%rip),%rcx
mov    (%rcx),%edi
lea    0xeab(%rip),%rsi
jmp    1172 <socket_close+0x42>
mov    %ebx,%edi
call   1040 <close@plt>
test   %eax,%eax
je     1180 <socket_close+0x50>
mov    0x2e6f(%rip),%rcx
mov    (%rcx),%edi
lea    0xeb8(%rip),%rsi
mov    %eax,%edx
call   1050 <fprintf@plt>
mov    $0xffffffff,%eax
pop    %rbx
ret
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@SHUT_RDWR = global i32 0
@stderr = global i32 0
@.str = [42 x i8] c"edvs_net_close: socket shutdown error %d\0A\00"
@.str.1 = [39 x i8] c"edvs_net_close: socket close error %d\0A\00"
define i32 @socket_close(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %3
%5 = load i32, i32* %3
%6 = load i32, i32* @SHUT_RDWR
%7 = call i32 @shutdown(i32 %5, i32 %6)
store i32 %7, i32* %4
%8 = load i32, i32* %4
%9 = icmp ne i32 %8, 0
br i1 %9, label %10, label %14
10: ; preds = %1
%11 = load i32, i32* @stderr
%12 = load i32, i32* %4
%13 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0), i32 %12)
store i32 -1, i32* %2
br label %24
14: ; preds = %1
%15 = load i32, i32* %3
%16 = call i32 @close(i32 %15)
store i32 %16, i32* %4
%17 = load i32, i32* %4
%18 = icmp ne i32 %17, 0
br i1 %18, label %19, label %23
19: ; preds = %14
%20 = load i32, i32* @stderr
%21 = load i32, i32* %4
%22 = call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0), i32 %21)
store i32 -1, i32* %2
br label %24
23: ; preds = %14
store i32 0, i32* %2
br label %24
24: ; preds = %23, %19, %10
%25 = load i32, i32* %2
ret i32 %25
}

LLVM IR (-O2):
@SHUT_RDWR = global i32 0
@stderr = global i32 0
@.str = [42 x i8] c"edvs_net_close: socket shutdown error %d\0A\00"
@.str.1 = [39 x i8] c"edvs_net_close: socket close error %d\0A\00"
define i32 @socket_close(i32 %0) {
%2 = load i32, i32* @SHUT_RDWR
%3 = tail call i32 @shutdown(i32 %0, i32 %2)
%4 = icmp eq i32 %3, 0
br i1 %4, label %8, label %5
5: ; preds = %1
%6 = load i32, i32* @stderr
%7 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0), i32 %3)
br label %14
8: ; preds = %1
%9 = tail call i32 @close(i32 %0)
%10 = icmp eq i32 %9, 0
br i1 %10, label %14, label %11
11: ; preds = %8
%12 = load i32, i32* @stderr
%13 = tail call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0), i32 %9)
br label %14
14: ; preds = %8, %11, %5
%15 = phi i32 [ -1, %5 ], [ -1, %11 ], [ 0, %8 ]
ret i32 %15
}