#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 */
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ socklen_t;
typedef int /*<<< orphan*/ one;

/* Variables and functions */
int PF_INET6;
int SOL_IP;
int SOL_IPV6;
scalar_t__ bind(int, struct sockaddr *, int /*<<< orphan*/);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ error(int, int /*<<< orphan*/, char *, ...);
scalar_t__ setsockopt(int, int, int, int *, int);
int socket(int, int, int);
int socket_rx(int domain, int type, int protocol, struct sockaddr *addr,
              socklen_t alen) {
  int fd, level, optname, one = 1;
  fd = socket(domain, type, protocol);
  if (fd == -1)
    error(1, errno, "socket");
  if (domain == PF_INET6) {
    level = SOL_IPV6;
    optname = 77;
  } else {
    level = SOL_IP;
    optname = 25;
  }
  if (setsockopt(fd, level, optname, &one, sizeof(one)))
    error(1, errno, "setsockopt recvfragsize (%u.%u)", level, optname);
  if (bind(fd, addr, alen))
    error(1, errno, "bind");
  return fd;
}


x86 assembly (clang, -O0):
<socket_rx>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    %rcx,-0x18(%rbp)
mov    %r8d,-0x1c(%rbp)
movl   $0x1,-0x2c(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
call   1060 <socket@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0xffffffff,-0x20(%rbp)
jne    1197 <socket_rx+0x57>
mov    0x2e46(%rip),%rax
mov    (%rax),%esi
mov    $0x1,%edi
lea    0xe70(%rip),%rdx
mov    $0x0,%al
call   1050 <error@plt>
mov    -0x4(%rbp),%eax
mov    0x2e37(%rip),%rcx
cmp    (%rcx),%eax
jne    11c1 <socket_rx+0x81>
mov    0x2e38(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
movl   $0x4d,-0x28(%rbp)
jmp    11d4 <socket_rx+0x94>
mov    0x2e30(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
movl   $0x19,-0x28(%rbp)
mov    -0x20(%rbp),%edi
mov    -0x24(%rbp),%esi
mov    -0x28(%rbp),%edx
lea    -0x2c(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
cmp    $0x0,%rax
je     1219 <socket_rx+0xd9>
mov    0x2dcb(%rip),%rax
mov    (%rax),%esi
mov    -0x24(%rbp),%ecx
mov    -0x28(%rbp),%r8d
mov    $0x1,%edi
lea    0xdf5(%rip),%rdx
mov    $0x0,%al
call   1050 <error@plt>
mov    -0x20(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1040 <bind@plt>
cmp    $0x0,%rax
je     124e <socket_rx+0x10e>
mov    0x2d8f(%rip),%rax
mov    (%rax),%esi
mov    $0x1,%edi
lea    0xde0(%rip),%rdx
mov    $0x0,%al
call   1050 <error@plt>
mov    -0x20(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<socket_rx>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %r8d,%r14d
mov    %rcx,%r15
mov    %edi,%ebp
movl   $0x1,0xc(%rsp)
call   1060 <socket@plt>
mov    %eax,%r12d
cmp    $0xffffffff,%eax
jne    1185 <socket_rx+0x45>
mov    0x2e58(%rip),%rax
mov    (%rax),%esi
lea    0xe87(%rip),%rdx
mov    $0x1,%edi
xor    %eax,%eax
call   1050 <error@plt>
mov    0x2e4c(%rip),%rax
cmp    %ebp,(%rax)
mov    $0x4d,%eax
mov    $0x19,%ebp
cmove  %eax,%ebp
mov    0x2e56(%rip),%rax
cmove  0x2e3e(%rip),%rax
mov    (%rax),%ebx
lea    0xc(%rsp),%rcx
mov    %r12d,%edi
mov    %ebx,%esi
mov    %ebp,%edx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
test   %rax,%rax
je     11e9 <socket_rx+0xa9>
mov    0x2df9(%rip),%rax
mov    (%rax),%esi
lea    0xe2f(%rip),%rdx
mov    $0x1,%edi
mov    %ebx,%ecx
mov    %ebp,%r8d
xor    %eax,%eax
call   1050 <error@plt>
mov    %r12d,%edi
mov    %r15,%rsi
mov    %r14d,%edx
call   1040 <bind@plt>
test   %rax,%rax
je     1218 <socket_rx+0xd8>
mov    0x2dc5(%rip),%rax
mov    (%rax),%esi
lea    0xe1b(%rip),%rdx
mov    $0x1,%edi
xor    %eax,%eax
call   1050 <error@plt>
mov    %r12d,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr = type { i32 }
@errno = global i32 0
@.str = [7 x i8] c"socket\00"
@PF_INET6 = global i32 0
@SOL_IPV6 = global i32 0
@SOL_IP = global i32 0
@.str.1 = [32 x i8] c"setsockopt recvfragsize (%u.%u)\00"
@.str.2 = [5 x i8] c"bind\00"
define i32 @socket_rx(i32 %0, i32 %1, i32 %2, %struct.sockaddr* %3, i32 %4) {
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca %struct.sockaddr*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
store i32 %0, i32* %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store %struct.sockaddr* %3, %struct.sockaddr** %9
store i32 %4, i32* %10
store i32 1, i32* %14
%15 = load i32, i32* %6
%16 = load i32, i32* %7
%17 = load i32, i32* %8
%18 = call i32 @socket(i32 %15, i32 %16, i32 %17)
store i32 %18, i32* %11
%19 = load i32, i32* %11
%20 = icmp eq i32 %19, -1
br i1 %20, label %21, label %24
21: ; preds = %5
%22 = load i32, i32* @errno
%23 = call i32 (i32, i32, i8*, ...) @error(i32 1, i32 %22, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %24
24: ; preds = %21, %5
%25 = load i32, i32* %6
%26 = load i32, i32* @PF_INET6
%27 = icmp eq i32 %25, %26
br i1 %27, label %28, label %30
28: ; preds = %24
%29 = load i32, i32* @SOL_IPV6
store i32 %29, i32* %12
store i32 77, i32* %13
br label %32
30: ; preds = %24
%31 = load i32, i32* @SOL_IP
store i32 %31, i32* %12
store i32 25, i32* %13
br label %32
32: ; preds = %30, %28
%33 = load i32, i32* %11
%34 = load i32, i32* %12
%35 = load i32, i32* %13
%36 = call i64 @setsockopt(i32 %33, i32 %34, i32 %35, i32* %14, i32 4)
%37 = icmp ne i64 %36, 0
br i1 %37, label %38, label %43
38: ; preds = %32
%39 = load i32, i32* @errno
%40 = load i32, i32* %12
%41 = load i32, i32* %13
%42 = call i32 (i32, i32, i8*, ...) @error(i32 1, i32 %39, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i32 %40, i32 %41)
br label %43
43: ; preds = %38, %32
%44 = load i32, i32* %11
%45 = load %struct.sockaddr*, %struct.sockaddr** %9
%46 = load i32, i32* %10
%47 = call i64 @bind(i32 %44, %struct.sockaddr* %45, i32 %46)
%48 = icmp ne i64 %47, 0
br i1 %48, label %49, label %52
49: ; preds = %43
%50 = load i32, i32* @errno
%51 = call i32 (i32, i32, i8*, ...) @error(i32 1, i32 %50, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
br label %52
52: ; preds = %49, %43
%53 = load i32, i32* %11
ret i32 %53
}

LLVM IR (-O2):
%struct.sockaddr = type { i32 }
@errno = global i32 0
@.str = [7 x i8] c"socket\00"
@PF_INET6 = global i32 0
@SOL_IPV6 = global i32 0
@SOL_IP = global i32 0
@.str.1 = [32 x i8] c"setsockopt recvfragsize (%u.%u)\00"
@.str.2 = [5 x i8] c"bind\00"
define i32 @socket_rx(i32 %0, i32 %1, i32 %2, %struct.sockaddr* %3, i32 %4) {
%6 = alloca i32
%7 = bitcast i32* %6 to i8*
store i32 1, i32* %6
%8 = tail call i32 @socket(i32 %0, i32 %1, i32 %2)
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %13
10: ; preds = %5
%11 = load i32, i32* @errno
%12 = tail call i32 (i32, i32, i8*, ...) @error(i32 1, i32 %11, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %13
13: ; preds = %10, %5
%14 = load i32, i32* @PF_INET6
%15 = icmp eq i32 %14, %0
%16 = select i1 %15, i32 77, i32 25
%17 = load i32, i32* @SOL_IPV6
%18 = load i32, i32* @SOL_IP
%19 = select i1 %15, i32 %17, i32 %18
%20 = call i64 @setsockopt(i32 %8, i32 %19, i32 %16, i32* %6, i32 4)
%21 = icmp eq i64 %20, 0
br i1 %21, label %25, label %22
22: ; preds = %13
%23 = load i32, i32* @errno
%24 = call i32 (i32, i32, i8*, ...) @error(i32 1, i32 %23, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i32 %19, i32 %16)
br label %25
25: ; preds = %22, %13
%26 = call i64 @bind(i32 %8, %struct.sockaddr* %3, i32 %4)
%27 = icmp eq i64 %26, 0
br i1 %27, label %31, label %28
28: ; preds = %25
%29 = load i32, i32* @errno
%30 = call i32 (i32, i32, i8*, ...) @error(i32 1, i32 %29, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
br label %31
31: ; preds = %28, %25
ret i32 %8
}