#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*/ PF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_REUSEADDR;
int /*<<< orphan*/ close(int);
int setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/, int *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int net_createSocket() {
  int fd, yes = 1;
  fd = socket(PF_INET, SOCK_STREAM, 0);
  if (fd < 0)
    return -1;
  if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(int)) == -1) {
    close(fd);
    return -1;
  }
  return fd;
}


x86 assembly (clang, -O0):
<net_createSocket>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x1,-0xc(%rbp)
mov    0x2e8a(%rip),%rax
mov    (%rax),%edi
mov    0x2e89(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1050 <socket@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    1171 <net_createSocket+0x41>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b8 <net_createSocket+0x88>
mov    -0x8(%rbp),%edi
mov    0x2e6d(%rip),%rax
mov    (%rax),%esi
mov    0x2e44(%rip),%rax
mov    (%rax),%edx
lea    -0xc(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
cmp    $0xffffffff,%eax
jne    11b2 <net_createSocket+0x82>
mov    -0x8(%rbp),%edi
call   1040 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b8 <net_createSocket+0x88>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<net_createSocket>:
push   %rbp
push   %rbx
push   %rax
movl   $0x1,0x4(%rsp)
mov    0x2e8e(%rip),%rax
mov    (%rax),%edi
mov    0x2e8d(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1050 <socket@plt>
mov    $0xffffffff,%ebx
test   %eax,%eax
js     1193 <net_createSocket+0x63>
mov    %eax,%ebp
mov    0x2e82(%rip),%rax
mov    (%rax),%esi
mov    0x2e59(%rip),%rax
mov    (%rax),%edx
lea    0x4(%rsp),%rcx
mov    %ebp,%edi
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
cmp    $0xffffffff,%eax
je     118c <net_createSocket+0x5c>
mov    %ebp,%ebx
jmp    1193 <net_createSocket+0x63>
mov    %ebp,%edi
call   1040 <close@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
define i32 @net_createSocket() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
store i32 1, i32* %3
%4 = load i32, i32* @PF_INET
%5 = load i32, i32* @SOCK_STREAM
%6 = call i32 @socket(i32 %4, i32 %5, i32 0)
store i32 %6, i32* %2
%7 = load i32, i32* %2
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %10
9: ; preds = %0
store i32 -1, i32* %1
br label %21
10: ; preds = %0
%11 = load i32, i32* %2
%12 = load i32, i32* @SOL_SOCKET
%13 = load i32, i32* @SO_REUSEADDR
%14 = call i32 @setsockopt(i32 %11, i32 %12, i32 %13, i32* %3, i32 4)
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %19
16: ; preds = %10
%17 = load i32, i32* %2
%18 = call i32 @close(i32 %17)
store i32 -1, i32* %1
br label %21
19: ; preds = %10
%20 = load i32, i32* %2
store i32 %20, i32* %1
br label %21
21: ; preds = %19, %16, %9
%22 = load i32, i32* %1
ret i32 %22
}

LLVM IR (-O2):
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
define i32 @net_createSocket() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
store i32 1, i32* %1
%3 = load i32, i32* @PF_INET
%4 = load i32, i32* @SOCK_STREAM
%5 = tail call i32 @socket(i32 %3, i32 %4, i32 0)
%6 = icmp slt i32 %5, 0
br i1 %6, label %14, label %7
7: ; preds = %0
%8 = load i32, i32* @SOL_SOCKET
%9 = load i32, i32* @SO_REUSEADDR
%10 = call i32 @setsockopt(i32 %5, i32 %8, i32 %9, i32* %1, i32 4)
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %14
12: ; preds = %7
%13 = call i32 @close(i32 %5)
br label %14
14: ; preds = %7, %0, %12
%15 = phi i32 [ -1, %12 ], [ -1, %0 ], [ %5, %7 ]
ret i32 %15
}