#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*/ families;

/* Variables and functions */
#define AF_APPLETALK 131
#define AF_AX25 130
#define AF_INET 129
#define AF_IPX 128
int /*<<< orphan*/ SOCK_DGRAM;
int socket(int const, int /*<<< orphan*/, int /*<<< orphan*/);
int iw_sockets_open(void) {
  static const int families[] = {AF_INET, AF_IPX, AF_AX25, AF_APPLETALK};
  unsigned int i;
  int sock;
  for (i = 0; i < sizeof(families) / sizeof(int); ++i) {
    sock = socket(families[i], SOCK_DGRAM, 0);
    if (sock >= 0)
      return sock;
  }
  return -1;
}


x86 assembly (clang, -O0):
<iw_sockets_open>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    $0x4,%rax
jae    1176 <iw_sockets_open+0x66>
mov    -0x8(%rbp),%eax
mov    %eax,%ecx
lea    0xec8(%rip),%rax
mov    (%rax,%rcx,4),%edi
mov    0x2ea6(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1030 <socket@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jl     1163 <iw_sockets_open+0x53>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    117d <iw_sockets_open+0x6d>
jmp    1168 <iw_sockets_open+0x58>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    111f <iw_sockets_open+0xf>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<iw_sockets_open>:
push   %rbx
mov    0x2ed0(%rip),%rbx
mov    (%rbx),%esi
mov    $0x81,%edi
xor    %edx,%edx
call   1030 <socket@plt>
test   %eax,%eax
js     112c <iw_sockets_open+0x1c>
pop    %rbx
ret
mov    (%rbx),%esi
mov    $0x80,%edi
xor    %edx,%edx
call   1030 <socket@plt>
test   %eax,%eax
jns    112a <iw_sockets_open+0x1a>
mov    (%rbx),%esi
mov    $0x82,%edi
xor    %edx,%edx
call   1030 <socket@plt>
test   %eax,%eax
jns    112a <iw_sockets_open+0x1a>
mov    (%rbx),%esi
mov    $0x83,%edi
xor    %edx,%edx
call   1030 <socket@plt>
mov    %eax,%ecx
test   %eax,%eax
mov    $0xffffffff,%eax
cmovns %ecx,%eax
pop    %rbx
ret

LLVM IR (-O0):
@iw_sockets_open.families = internal constant [4 x i32] [i32 129, i32 128, i32 130, i32 131]
@SOCK_DGRAM = global i32 0
define i32 @iw_sockets_open() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
store i32 0, i32* %2
br label %4
4: ; preds = %20, %0
%5 = load i32, i32* %2
%6 = zext i32 %5 to i64
%7 = icmp ult i64 %6, 4
br i1 %7, label %8, label %23
8: ; preds = %4
%9 = load i32, i32* %2
%10 = zext i32 %9 to i64
%11 = getelementptr inbounds [4 x i32], [4 x i32]* @iw_sockets_open.families, i64 0, i64 %10
%12 = load i32, i32* %11
%13 = load i32, i32* @SOCK_DGRAM
%14 = call i32 @socket(i32 %12, i32 %13, i32 0)
store i32 %14, i32* %3
%15 = load i32, i32* %3
%16 = icmp sge i32 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %8
%18 = load i32, i32* %3
store i32 %18, i32* %1
br label %24
19: ; preds = %8
br label %20
20: ; preds = %19
%21 = load i32, i32* %2
%22 = add i32 %21, 1
store i32 %22, i32* %2
br label %4
23: ; preds = %4
store i32 -1, i32* %1
br label %24
24: ; preds = %23, %17
%25 = load i32, i32* %1
ret i32 %25
}

LLVM IR (-O2):
@SOCK_DGRAM = global i32 0
define i32 @iw_sockets_open() {
%1 = load i32, i32* @SOCK_DGRAM
%2 = tail call i32 @socket(i32 129, i32 %1, i32 0)
%3 = icmp sgt i32 %2, -1
br i1 %3, label %17, label %4
4: ; preds = %0
%5 = load i32, i32* @SOCK_DGRAM
%6 = tail call i32 @socket(i32 128, i32 %5, i32 0)
%7 = icmp sgt i32 %6, -1
br i1 %7, label %17, label %8
8: ; preds = %4
%9 = load i32, i32* @SOCK_DGRAM
%10 = tail call i32 @socket(i32 130, i32 %9, i32 0)
%11 = icmp sgt i32 %10, -1
br i1 %11, label %17, label %12
12: ; preds = %8
%13 = load i32, i32* @SOCK_DGRAM
%14 = tail call i32 @socket(i32 131, i32 %13, i32 0)
%15 = icmp sgt i32 %14, -1
%16 = select i1 %15, i32 %14, i32 -1
br label %17
17: ; preds = %12, %8, %4, %0
%18 = phi i32 [ %2, %0 ], [ %6, %4 ], [ %10, %8 ], [ %16, %12 ]
ret i32 %18
}