#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 */
typedef int /*<<< orphan*/ on;

/* Variables and functions */
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_REUSEADDR;
int setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/, int *, int);
int socket(int, int /*<<< orphan*/, int /*<<< orphan*/);
int createSocket(char *err, int domain) {
  int s, on = 1;
  if ((s = socket(domain, SOCK_STREAM, 0)) == -1) {
    return -1;
  }
  if (setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on)) == -1) {
    return -1;
  }
  return s;
}


x86 assembly (clang, -O0):
<createSocket>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
movl   $0x1,-0x1c(%rbp)
mov    -0x14(%rbp),%edi
mov    0x2e98(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1040 <socket@plt>
mov    %eax,-0x18(%rbp)
cmp    $0xffffffff,%eax
jne    1161 <createSocket+0x41>
movl   $0xffffffff,-0x4(%rbp)
jmp    11a0 <createSocket+0x80>
mov    -0x18(%rbp),%edi
mov    0x2e7d(%rip),%rax
mov    (%rax),%esi
mov    0x2e5c(%rip),%rax
mov    (%rax),%edx
lea    -0x1c(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
cmp    $0xffffffff,%eax
jne    119a <createSocket+0x7a>
movl   $0xffffffff,-0x4(%rbp)
jmp    11a0 <createSocket+0x80>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<createSocket>:
push   %rbx
sub    $0x10,%rsp
mov    %esi,%edi
movl   $0x1,0xc(%rsp)
mov    0x2ea2(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1040 <socket@plt>
cmp    $0xffffffff,%eax
je     1172 <createSocket+0x52>
mov    %eax,%ebx
mov    0x2e9b(%rip),%rax
mov    (%rax),%esi
mov    0x2e7a(%rip),%rax
mov    (%rax),%edx
lea    0xc(%rsp),%rcx
mov    %ebx,%edi
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
cmp    $0xffffffff,%eax
cmove  %eax,%ebx
jmp    1177 <createSocket+0x57>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
ret

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

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