#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*/ PF_INET6;
int /*<<< orphan*/ PF_PACKET;
int /*<<< orphan*/ SOCK_DGRAM;
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int xsocket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int get_ctl_fd(void) {
  int fd;
  fd = socket(PF_INET, SOCK_DGRAM, 0);
  if (fd >= 0)
    return fd;
  fd = socket(PF_PACKET, SOCK_DGRAM, 0);
  if (fd >= 0)
    return fd;
  return xsocket(PF_INET6, SOCK_DGRAM, 0);
}


x86 assembly (clang, -O0):
<get_ctl_fd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2e99(%rip),%rax
mov    (%rax),%edi
mov    0x2ea0(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1040 <socket@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jl     1159 <get_ctl_fd+0x39>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11a6 <get_ctl_fd+0x86>
mov    0x2e90(%rip),%rax
mov    (%rax),%edi
mov    0x2e6f(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1040 <socket@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jl     118a <get_ctl_fd+0x6a>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11a6 <get_ctl_fd+0x86>
mov    0x2e4f(%rip),%rax
mov    (%rax),%edi
mov    0x2e3e(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1030 <xsocket@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_ctl_fd>:
push   %rbx
mov    0x2ea0(%rip),%rax
mov    (%rax),%edi
mov    0x2ea7(%rip),%rbx
mov    (%rbx),%esi
xor    %edx,%edx
call   1040 <socket@plt>
test   %eax,%eax
jns    1154 <get_ctl_fd+0x34>
mov    0x2eab(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%esi
xor    %edx,%edx
call   1040 <socket@plt>
test   %eax,%eax
js     1156 <get_ctl_fd+0x36>
pop    %rbx
ret
mov    0x2e83(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%esi
xor    %edx,%edx
pop    %rbx
jmp    1030 <xsocket@plt>

LLVM IR (-O0):
@PF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@PF_PACKET = global i32 0
@PF_INET6 = global i32 0
define i32 @get_ctl_fd() {
%1 = alloca i32
%2 = alloca i32
%3 = load i32, i32* @PF_INET
%4 = load i32, i32* @SOCK_DGRAM
%5 = call i32 @socket(i32 %3, i32 %4, i32 0)
store i32 %5, i32* %2
%6 = load i32, i32* %2
%7 = icmp sge i32 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %0
%9 = load i32, i32* %2
store i32 %9, i32* %1
br label %22
10: ; preds = %0
%11 = load i32, i32* @PF_PACKET
%12 = load i32, i32* @SOCK_DGRAM
%13 = call i32 @socket(i32 %11, i32 %12, i32 0)
store i32 %13, i32* %2
%14 = load i32, i32* %2
%15 = icmp sge i32 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %10
%17 = load i32, i32* %2
store i32 %17, i32* %1
br label %22
18: ; preds = %10
%19 = load i32, i32* @PF_INET6
%20 = load i32, i32* @SOCK_DGRAM
%21 = call i32 @xsocket(i32 %19, i32 %20, i32 0)
store i32 %21, i32* %1
br label %22
22: ; preds = %18, %16, %8
%23 = load i32, i32* %1
ret i32 %23
}

LLVM IR (-O2):
@PF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@PF_PACKET = global i32 0
@PF_INET6 = global i32 0
define i32 @get_ctl_fd() {
%1 = load i32, i32* @PF_INET
%2 = load i32, i32* @SOCK_DGRAM
%3 = tail call i32 @socket(i32 %1, i32 %2, i32 0)
%4 = icmp sgt i32 %3, -1
br i1 %4, label %14, label %5
5: ; preds = %0
%6 = load i32, i32* @PF_PACKET
%7 = load i32, i32* @SOCK_DGRAM
%8 = tail call i32 @socket(i32 %6, i32 %7, i32 0)
%9 = icmp sgt i32 %8, -1
br i1 %9, label %14, label %10
10: ; preds = %5
%11 = load i32, i32* @PF_INET6
%12 = load i32, i32* @SOCK_DGRAM
%13 = tail call i32 @xsocket(i32 %11, i32 %12, i32 0)
br label %14
14: ; preds = %5, %0, %10
%15 = phi i32 [ %13, %10 ], [ %3, %0 ], [ %8, %5 ]
ret i32 %15
}