#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 */
scalar_t__ EINVAL;
int /*<<< orphan*/ PF_INET;
int /*<<< orphan*/ PF_INET6;
int /*<<< orphan*/ SOCK_DGRAM;
scalar_t__ errno;
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int socket_udp6(void) {
  int s;
  s = socket(PF_INET6, SOCK_DGRAM, 0);
  if (s == -1) {
    if (errno == EINVAL)
      s = socket(PF_INET, SOCK_DGRAM, 0);
  }
  return s;
}


x86 assembly (clang, -O0):
<socket_udp6>:
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,-0x4(%rbp)
cmpl   $0xffffffff,-0x4(%rbp)
jne    1179 <socket_udp6+0x69>
mov    0x2e8b(%rip),%rax
mov    (%rax),%rax
mov    0x2e71(%rip),%rcx
cmp    (%rcx),%rax
jne    1174 <socket_udp6+0x64>
mov    0x2e69(%rip),%rax
mov    (%rax),%edi
mov    0x2e78(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1030 <socket@plt>
mov    %eax,-0x4(%rbp)
jmp    1179 <socket_udp6+0x69>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<socket_udp6>:
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 <socket_udp6+0x4d>
mov    0x2e9a(%rip),%rax
mov    (%rax),%rcx
mov    0x2e80(%rip),%rdx
mov    $0xffffffff,%eax
cmp    (%rdx),%rcx
jne    115d <socket_udp6+0x4d>
mov    0x2e77(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%esi
xor    %edx,%edx
pop    %rbx
jmp    1030 <socket@plt>
pop    %rbx
ret

LLVM IR (-O0):
@PF_INET6 = global i32 0
@SOCK_DGRAM = global i32 0
@errno = global i64 0
@EINVAL = global i64 0
@PF_INET = global i32 0
define i32 @socket_udp6() {
%1 = alloca i32
%2 = load i32, i32* @PF_INET6
%3 = load i32, i32* @SOCK_DGRAM
%4 = call i32 @socket(i32 %2, i32 %3, i32 0)
store i32 %4, i32* %1
%5 = load i32, i32* %1
%6 = icmp eq i32 %5, -1
br i1 %6, label %7, label %16
7: ; preds = %0
%8 = load i64, i64* @errno
%9 = load i64, i64* @EINVAL
%10 = icmp eq i64 %8, %9
br i1 %10, label %11, label %15
11: ; preds = %7
%12 = load i32, i32* @PF_INET
%13 = load i32, i32* @SOCK_DGRAM
%14 = call i32 @socket(i32 %12, i32 %13, i32 0)
store i32 %14, i32* %1
br label %15
15: ; preds = %11, %7
br label %16
16: ; preds = %15, %0
%17 = load i32, i32* %1
ret i32 %17
}

LLVM IR (-O2):
@PF_INET6 = global i32 0
@SOCK_DGRAM = global i32 0
@errno = global i64 0
@EINVAL = global i64 0
@PF_INET = global i32 0
define i32 @socket_udp6() {
%1 = load i32, i32* @PF_INET6
%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 %13
5: ; preds = %0
%6 = load i64, i64* @errno
%7 = load i64, i64* @EINVAL
%8 = icmp eq i64 %6, %7
br i1 %8, label %9, label %13
9: ; preds = %5
%10 = load i32, i32* @PF_INET
%11 = load i32, i32* @SOCK_DGRAM
%12 = tail call i32 @socket(i32 %10, i32 %11, i32 0)
br label %13
13: ; preds = %5, %9, %0
%14 = phi i32 [ %12, %9 ], [ -1, %5 ], [ %3, %0 ]
ret i32 %14
}