#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;
scalar_t__ close(int);
int /*<<< orphan*/ perror(char *);
scalar_t__ shutdown(int, int /*<<< orphan*/);
int sock_close(int fd) {
  if (shutdown(fd, SHUT_RDWR) < 0) {
    perror("sock_close: (err) shutdown");
    return -1;
  }
  if (close(fd) < 0) {
    perror("sock_close: (err) close");
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<sock_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>
cmp    $0x0,%rax
jge    116e <sock_close+0x3e>
lea    0xea3(%rip),%rdi
call   1050 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    119f <sock_close+0x6f>
mov    -0x8(%rbp),%edi
call   1040 <close@plt>
cmp    $0x0,%rax
jge    1198 <sock_close+0x68>
lea    0xe94(%rip),%rdi
call   1050 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    119f <sock_close+0x6f>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sock_close>:
push   %rbx
mov    %edi,%ebx
mov    0x2eb6(%rip),%rax
mov    (%rax),%esi
call   1030 <shutdown@plt>
test   %rax,%rax
js     1159 <sock_close+0x29>
mov    %ebx,%edi
call   1040 <close@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
js     1162 <sock_close+0x32>
pop    %rbx
ret
lea    0xea0(%rip),%rdi
jmp    1169 <sock_close+0x39>
lea    0xeb2(%rip),%rdi
call   1050 <perror@plt>
mov    $0xffffffff,%eax
pop    %rbx
ret

LLVM IR (-O0):
@SHUT_RDWR = global i32 0
@.str = [27 x i8] c"sock_close: (err) shutdown\00"
@.str.1 = [24 x i8] c"sock_close: (err) close\00"
define i32 @sock_close(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %3
%4 = load i32, i32* %3
%5 = load i32, i32* @SHUT_RDWR
%6 = call i64 @shutdown(i32 %4, i32 %5)
%7 = icmp slt i64 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %1
%9 = call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %2
br label %17
10: ; preds = %1
%11 = load i32, i32* %3
%12 = call i64 @close(i32 %11)
%13 = icmp slt i64 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %10
%15 = call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %2
br label %17
16: ; preds = %10
store i32 0, i32* %2
br label %17
17: ; preds = %16, %14, %8
%18 = load i32, i32* %2
ret i32 %18
}

LLVM IR (-O2):
@SHUT_RDWR = global i32 0
@.str = [27 x i8] c"sock_close: (err) shutdown\00"
@.str.1 = [24 x i8] c"sock_close: (err) close\00"
define i32 @sock_close(i32 %0) {
%2 = load i32, i32* @SHUT_RDWR
%3 = tail call i64 @shutdown(i32 %0, i32 %2)
%4 = icmp slt i64 %3, 0
br i1 %4, label %8, label %5
5: ; preds = %1
%6 = tail call i64 @close(i32 %0)
%7 = icmp slt i64 %6, 0
br i1 %7, label %8, label %11
8: ; preds = %5, %1
%9 = phi i8* [ getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), %1 ], [ getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), %5 ]
%10 = tail call i32 @perror(i8* %9)
br label %11
11: ; preds = %8, %5
%12 = phi i32 [ 0, %5 ], [ -1, %8 ]
ret i32 %12
}