#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*/ AF_APPLETALK;
int /*<<< orphan*/ AF_AX25;
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ AF_IPX;
int /*<<< orphan*/ SOCK_DGRAM;
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int sockets_open(void) {
  int sock;
  if ((sock = socket(AF_INET, SOCK_DGRAM, 0)) != -1)
    return sock;
  else if ((sock = socket(AF_IPX, SOCK_DGRAM, 0)) != -1)
    return sock;
  else if ((sock = socket(AF_AX25, SOCK_DGRAM, 0)) != -1)
    return sock;
  else
    return socket(AF_APPLETALK, SOCK_DGRAM, 0);
}


x86 assembly (clang, -O0):
<sockets_open>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2ec9(%rip),%rax
mov    (%rax),%edi
mov    0x2eb8(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1030 <socket@plt>
mov    %eax,-0x8(%rbp)
cmp    $0xffffffff,%eax
je     1148 <sockets_open+0x38>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11c4 <sockets_open+0xb4>
mov    0x2e71(%rip),%rax
mov    (%rax),%edi
mov    0x2e88(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1030 <socket@plt>
mov    %eax,-0x8(%rbp)
cmp    $0xffffffff,%eax
je     1178 <sockets_open+0x68>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11c4 <sockets_open+0xb4>
mov    0x2e49(%rip),%rax
mov    (%rax),%edi
mov    0x2e58(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1030 <socket@plt>
mov    %eax,-0x8(%rbp)
cmp    $0xffffffff,%eax
je     11a8 <sockets_open+0x98>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11c4 <sockets_open+0xb4>
mov    0x2e21(%rip),%rax
mov    (%rax),%edi
mov    0x2e28(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1030 <socket@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sockets_open>:
push   %rbx
mov    0x2ed0(%rip),%rax
mov    (%rax),%edi
mov    0x2ebf(%rip),%rbx
mov    (%rbx),%esi
xor    %edx,%edx
call   1030 <socket@plt>
cmp    $0xffffffff,%eax
jne    115d <sockets_open+0x4d>
mov    0x2e8a(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%esi
xor    %edx,%edx
call   1030 <socket@plt>
cmp    $0xffffffff,%eax
jne    115d <sockets_open+0x4d>
mov    0x2e7b(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%esi
xor    %edx,%edx
call   1030 <socket@plt>
cmp    $0xffffffff,%eax
je     115f <sockets_open+0x4f>
pop    %rbx
ret
mov    0x2e6a(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%esi
xor    %edx,%edx
pop    %rbx
jmp    1030 <socket@plt>

LLVM IR (-O0):
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@AF_IPX = global i32 0
@AF_AX25 = global i32 0
@AF_APPLETALK = global i32 0
define i32 @sockets_open() {
%1 = alloca i32
%2 = alloca i32
%3 = load i32, i32* @AF_INET
%4 = load i32, i32* @SOCK_DGRAM
%5 = call i32 @socket(i32 %3, i32 %4, i32 0)
store i32 %5, i32* %2
%6 = icmp ne i32 %5, -1
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = load i32, i32* %2
store i32 %8, i32* %1
br label %27
9: ; preds = %0
%10 = load i32, i32* @AF_IPX
%11 = load i32, i32* @SOCK_DGRAM
%12 = call i32 @socket(i32 %10, i32 %11, i32 0)
store i32 %12, i32* %2
%13 = icmp ne i32 %12, -1
br i1 %13, label %14, label %16
14: ; preds = %9
%15 = load i32, i32* %2
store i32 %15, i32* %1
br label %27
16: ; preds = %9
%17 = load i32, i32* @AF_AX25
%18 = load i32, i32* @SOCK_DGRAM
%19 = call i32 @socket(i32 %17, i32 %18, i32 0)
store i32 %19, i32* %2
%20 = icmp ne i32 %19, -1
br i1 %20, label %21, label %23
21: ; preds = %16
%22 = load i32, i32* %2
store i32 %22, i32* %1
br label %27
23: ; preds = %16
%24 = load i32, i32* @AF_APPLETALK
%25 = load i32, i32* @SOCK_DGRAM
%26 = call i32 @socket(i32 %24, i32 %25, i32 0)
store i32 %26, i32* %1
br label %27
27: ; preds = %23, %21, %14, %7
%28 = load i32, i32* %1
ret i32 %28
}

LLVM IR (-O2):
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@AF_IPX = global i32 0
@AF_AX25 = global i32 0
@AF_APPLETALK = global i32 0
define i32 @sockets_open() {
%1 = load i32, i32* @AF_INET
%2 = load i32, i32* @SOCK_DGRAM
%3 = tail call i32 @socket(i32 %1, i32 %2, i32 0)
%4 = icmp eq i32 %3, -1
br i1 %4, label %5, label %19
5: ; preds = %0
%6 = load i32, i32* @AF_IPX
%7 = load i32, i32* @SOCK_DGRAM
%8 = tail call i32 @socket(i32 %6, i32 %7, i32 0)
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %19
10: ; preds = %5
%11 = load i32, i32* @AF_AX25
%12 = load i32, i32* @SOCK_DGRAM
%13 = tail call i32 @socket(i32 %11, i32 %12, i32 0)
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %19
15: ; preds = %10
%16 = load i32, i32* @AF_APPLETALK
%17 = load i32, i32* @SOCK_DGRAM
%18 = tail call i32 @socket(i32 %16, i32 %17, i32 0)
br label %19
19: ; preds = %10, %5, %0, %15
%20 = phi i32 [ %18, %15 ], [ %3, %0 ], [ %8, %5 ], [ %13, %10 ]
ret i32 %20
}