#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*/ SOCK_STREAM;
int /*<<< orphan*/ anetSetError(char *, char *, int /*<<< orphan*/);
int anetSetReuseAddr(char *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ errno;
int socket(int, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
int anetCreateSocket(char *err, int domain) {
  int s;
  if ((s = socket(domain, SOCK_STREAM, 0)) == -1) {
    anetSetError(err, "creating socket: %s", strerror(errno));
    return -1;
  }
  if (anetSetReuseAddr(err, s) == -1) {
    close(s);
    return -1;
  }
  return s;
}


x86 assembly (clang, -O0):
<anetCreateSocket>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x14(%rbp),%edi
mov    0x2e77(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1070 <socket@plt>
mov    %eax,-0x18(%rbp)
cmp    $0xffffffff,%eax
jne    11b2 <anetCreateSocket+0x62>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    0x2e4b(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    -0x20(%rbp),%rdi
mov    %eax,%edx
lea    0xe5f(%rip),%rsi
call   1040 <anetSetError@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e1 <anetCreateSocket+0x91>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%esi
call   1050 <anetSetReuseAddr@plt>
cmp    $0xffffffff,%eax
jne    11db <anetCreateSocket+0x8b>
mov    -0x18(%rbp),%edi
call   1030 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e1 <anetCreateSocket+0x91>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<anetCreateSocket>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%eax
mov    %rdi,%rbx
mov    0x2e81(%rip),%rcx
mov    (%rcx),%esi
mov    %eax,%edi
xor    %edx,%edx
call   1070 <socket@plt>
cmp    $0xffffffff,%eax
je     1189 <anetCreateSocket+0x39>
mov    %eax,%ebp
mov    %rbx,%rdi
mov    %eax,%esi
call   1050 <anetSetReuseAddr@plt>
cmp    $0xffffffff,%eax
jne    11ad <anetCreateSocket+0x5d>
mov    %ebp,%edi
call   1030 <close@plt>
jmp    11a8 <anetCreateSocket+0x58>
mov    0x2e48(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
lea    0xe62(%rip),%rsi
mov    %rbx,%rdi
mov    %eax,%edx
call   1040 <anetSetError@plt>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@SOCK_STREAM = global i32 0
@.str = [20 x i8] c"creating socket: %s\00"
@errno = global i32 0
define i32 @anetCreateSocket(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
%7 = load i32, i32* %5
%8 = load i32, i32* @SOCK_STREAM
%9 = call i32 @socket(i32 %7, i32 %8, i32 0)
store i32 %9, i32* %6
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %16
11: ; preds = %2
%12 = load i8*, i8** %4
%13 = load i32, i32* @errno
%14 = call i32 @strerror(i32 %13)
%15 = call i32 @anetSetError(i8* %12, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 %14)
store i32 -1, i32* %3
br label %26
16: ; preds = %2
%17 = load i8*, i8** %4
%18 = load i32, i32* %6
%19 = call i32 @anetSetReuseAddr(i8* %17, i32 %18)
%20 = icmp eq i32 %19, -1
br i1 %20, label %21, label %24
21: ; preds = %16
%22 = load i32, i32* %6
%23 = call i32 @close(i32 %22)
store i32 -1, i32* %3
br label %26
24: ; preds = %16
%25 = load i32, i32* %6
store i32 %25, i32* %3
br label %26
26: ; preds = %24, %21, %11
%27 = load i32, i32* %3
ret i32 %27
}

LLVM IR (-O2):
@SOCK_STREAM = global i32 0
@.str = [20 x i8] c"creating socket: %s\00"
@errno = global i32 0
define i32 @anetCreateSocket(i8* %0, i32 %1) {
%3 = load i32, i32* @SOCK_STREAM
%4 = tail call i32 @socket(i32 %1, i32 %3, i32 0)
%5 = icmp eq i32 %4, -1
br i1 %5, label %6, label %10
6: ; preds = %2
%7 = load i32, i32* @errno
%8 = tail call i32 @strerror(i32 %7)
%9 = tail call i32 @anetSetError(i8* %0, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 %8)
br label %15
10: ; preds = %2
%11 = tail call i32 @anetSetReuseAddr(i8* %0, i32 %4)
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %15
13: ; preds = %10
%14 = tail call i32 @close(i32 %4)
br label %15
15: ; preds = %10, %13, %6
%16 = phi i32 [ -1, %6 ], [ -1, %13 ], [ %4, %10 ]
ret i32 %16
}