#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 addrinfo {
  int ai_flags;
  scalar_t__ ai_family;
  int ai_socktype;
  int ai_protocol;
  scalar_t__ ai_next;
  scalar_t__ ai_canonname;
  scalar_t__ ai_addr;
  scalar_t__ ai_addrlen;
};

/* Variables and functions */
scalar_t__ AF_INET;
scalar_t__ AF_UNSPEC;
int AI_CANONNAME;
int AI_NUMERICHOST;
int AI_NUMERICSERV;
int AI_PASSIVE;
int EAI_BADFLAGS;
int EAI_FAMILY;
int EAI_SOCKTYPE;
int EAI_SYSTEM;
int /*<<< orphan*/ EINVAL;
#define SOCK_DGRAM 129
#define SOCK_STREAM 128
int /*<<< orphan*/ assert(int *);
int /*<<< orphan*/ errno;
int getaddrinfo_parse_hints(const struct addrinfo *hints, int *flags,
                            int *socktype, int *protocol) {
  assert(flags);
  assert(socktype);
  if (!hints) {
    *flags = 0;
    *socktype = 0;
    *protocol = 0;
    return 0;
  }
  if (hints->ai_addrlen || hints->ai_addr || hints->ai_canonname ||
      hints->ai_next) {
    errno = EINVAL;
    return EAI_SYSTEM;
  }
  *flags = hints->ai_flags;
  if (*flags & ~(AI_PASSIVE | AI_CANONNAME | AI_NUMERICHOST | AI_NUMERICSERV))
    return EAI_BADFLAGS;
  if (hints->ai_family != AF_UNSPEC && hints->ai_family != AF_INET)
    return EAI_FAMILY;
  *socktype = hints->ai_socktype;
  switch (*socktype) {
  case 0:
  case SOCK_STREAM:
  case SOCK_DGRAM:
    break;
  default:
    return EAI_SOCKTYPE;
  }
  *protocol = hints->ai_protocol;
  return 0;
}


x86 assembly (clang, -O0):
<getaddrinfo_parse_hints>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <assert@plt>
mov    -0x20(%rbp),%rdi
call   1030 <assert@plt>
cmpq   $0x0,-0x10(%rbp)
jne    116f <getaddrinfo_parse_hints+0x5f>
mov    -0x18(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x20(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x28(%rbp),%rax
movl   $0x0,(%rax)
movl   $0x0,-0x4(%rbp)
jmp    12c5 <getaddrinfo_parse_hints+0x1b5>
mov    -0x10(%rbp),%rax
cmpq   $0x0,0x30(%rax)
jne    11ab <getaddrinfo_parse_hints+0x9b>
mov    -0x10(%rbp),%rax
cmpq   $0x0,0x28(%rax)
jne    11ab <getaddrinfo_parse_hints+0x9b>
mov    -0x10(%rbp),%rax
cmpq   $0x0,0x20(%rax)
jne    11ab <getaddrinfo_parse_hints+0x9b>
mov    -0x10(%rbp),%rax
cmpq   $0x0,0x18(%rax)
je     11ce <getaddrinfo_parse_hints+0xbe>
mov    0x2dd6(%rip),%rax
mov    (%rax),%ecx
mov    0x2dd5(%rip),%rax
mov    %ecx,(%rax)
mov    0x2dec(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    12c5 <getaddrinfo_parse_hints+0x1b5>
mov    -0x10(%rbp),%rax
mov    (%rax),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
mov    0x2df1(%rip),%rcx
mov    (%rcx),%ecx
mov    0x2dc8(%rip),%rdx
or     (%rdx),%ecx
mov    0x2dc7(%rip),%rdx
or     (%rdx),%ecx
mov    0x2df6(%rip),%rdx
or     (%rdx),%ecx
xor    $0xffffffff,%ecx
and    %ecx,%eax
cmp    $0x0,%eax
je     1223 <getaddrinfo_parse_hints+0x113>
mov    0x2d8f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    12c5 <getaddrinfo_parse_hints+0x1b5>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    0x2d96(%rip),%rcx
cmp    (%rcx),%rax
je     1264 <getaddrinfo_parse_hints+0x154>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    0x2d86(%rip),%rcx
cmp    (%rcx),%rax
je     1264 <getaddrinfo_parse_hints+0x154>
mov    0x2d46(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    12c5 <getaddrinfo_parse_hints+0x1b5>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x20(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
test   %eax,%eax
je     129b <getaddrinfo_parse_hints+0x18b>
jmp    1287 <getaddrinfo_parse_hints+0x177>
mov    -0x2c(%rbp),%eax
add    $0xffffff80,%eax
sub    $0x1,%eax
ja     12a0 <getaddrinfo_parse_hints+0x190>
jmp    129b <getaddrinfo_parse_hints+0x18b>
jmp    12b1 <getaddrinfo_parse_hints+0x1a1>
mov    0x2d41(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    12c5 <getaddrinfo_parse_hints+0x1b5>
mov    -0x10(%rbp),%rax
mov    0x14(%rax),%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getaddrinfo_parse_hints>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r14
mov    %rdx,%r15
mov    %rsi,%rbx
mov    %rdi,%r12
mov    %rsi,%rdi
call   1030 <assert@plt>
mov    %r15,%rdi
call   1030 <assert@plt>
test   %r12,%r12
je     1176 <getaddrinfo_parse_hints+0x66>
cmpq   $0x0,0x30(%r12)
jne    1159 <getaddrinfo_parse_hints+0x49>
cmpq   $0x0,0x28(%r12)
jne    1159 <getaddrinfo_parse_hints+0x49>
cmpq   $0x0,0x20(%r12)
jne    1159 <getaddrinfo_parse_hints+0x49>
cmpq   $0x0,0x18(%r12)
je     1198 <getaddrinfo_parse_hints+0x88>
mov    0x2e28(%rip),%rax
mov    (%rax),%eax
mov    0x2e27(%rip),%rcx
mov    %eax,(%rcx)
mov    0x2e3e(%rip),%rax
mov    (%rax),%eax
jmp    118c <getaddrinfo_parse_hints+0x7c>
movl   $0x0,(%rbx)
movl   $0x0,(%r15)
movl   $0x0,(%r14)
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    (%r12),%eax
mov    %eax,(%rbx)
mov    0x2e33(%rip),%rcx
mov    0x2e0c(%rip),%rdx
mov    (%rdx),%edx
or     (%rcx),%edx
mov    0x2e09(%rip),%rcx
or     (%rcx),%edx
mov    0x2e38(%rip),%rcx
or     (%rcx),%edx
not    %edx
test   %edx,%eax
je     11d3 <getaddrinfo_parse_hints+0xc3>
mov    0x2dd9(%rip),%rax
mov    (%rax),%eax
jmp    118c <getaddrinfo_parse_hints+0x7c>
mov    0x8(%r12),%rax
mov    0x2de9(%rip),%rcx
cmp    (%rcx),%rax
je     11fb <getaddrinfo_parse_hints+0xeb>
mov    0x2de5(%rip),%rcx
cmp    (%rcx),%rax
je     11fb <getaddrinfo_parse_hints+0xeb>
mov    0x2da9(%rip),%rax
mov    (%rax),%eax
jmp    118c <getaddrinfo_parse_hints+0x7c>
mov    0x10(%r12),%eax
mov    %eax,(%r15)
lea    -0x80(%rax),%ecx
cmp    $0x2,%ecx
jb     120f <getaddrinfo_parse_hints+0xff>
test   %eax,%eax
jne    121c <getaddrinfo_parse_hints+0x10c>
mov    0x14(%r12),%eax
mov    %eax,(%r14)
jmp    118a <getaddrinfo_parse_hints+0x7a>
mov    0x2dc5(%rip),%rax
mov    (%rax),%eax
jmp    118c <getaddrinfo_parse_hints+0x7c>

LLVM IR (-O0):
%struct.addrinfo = type { i32, i64, i32, i32, i64, i64, i64, i64 }
@EINVAL = global i32 0
@errno = global i32 0
@EAI_SYSTEM = global i32 0
@AI_PASSIVE = global i32 0
@AI_CANONNAME = global i32 0
@AI_NUMERICHOST = global i32 0
@AI_NUMERICSERV = global i32 0
@EAI_BADFLAGS = global i32 0
@AF_UNSPEC = global i64 0
@AF_INET = global i64 0
@EAI_FAMILY = global i32 0
@EAI_SOCKTYPE = global i32 0
define i32 @getaddrinfo_parse_hints(%struct.addrinfo* %0, i32* %1, i32* %2, i32* %3) {
%5 = alloca i32
%6 = alloca %struct.addrinfo*
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i32*
store %struct.addrinfo* %0, %struct.addrinfo** %6
store i32* %1, i32** %7
store i32* %2, i32** %8
store i32* %3, i32** %9
%10 = load i32*, i32** %7
%11 = call i32 @assert(i32* %10)
%12 = load i32*, i32** %8
%13 = call i32 @assert(i32* %12)
%14 = load %struct.addrinfo*, %struct.addrinfo** %6
%15 = icmp ne %struct.addrinfo* %14, null
br i1 %15, label %20, label %16
16: ; preds = %4
%17 = load i32*, i32** %7
store i32 0, i32* %17
%18 = load i32*, i32** %8
store i32 0, i32* %18
%19 = load i32*, i32** %9
store i32 0, i32* %19
store i32 0, i32* %5
br label %91
20: ; preds = %4
%21 = load %struct.addrinfo*, %struct.addrinfo** %6
%22 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %21, i32 0, i32 7
%23 = load i64, i64* %22
%24 = icmp ne i64 %23, 0
br i1 %24, label %40, label %25
25: ; preds = %20
%26 = load %struct.addrinfo*, %struct.addrinfo** %6
%27 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %26, i32 0, i32 6
%28 = load i64, i64* %27
%29 = icmp ne i64 %28, 0
br i1 %29, label %40, label %30
30: ; preds = %25
%31 = load %struct.addrinfo*, %struct.addrinfo** %6
%32 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %31, i32 0, i32 5
%33 = load i64, i64* %32
%34 = icmp ne i64 %33, 0
br i1 %34, label %40, label %35
35: ; preds = %30
%36 = load %struct.addrinfo*, %struct.addrinfo** %6
%37 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %36, i32 0, i32 4
%38 = load i64, i64* %37
%39 = icmp ne i64 %38, 0
br i1 %39, label %40, label %43
40: ; preds = %35, %30, %25, %20
%41 = load i32, i32* @EINVAL
store i32 %41, i32* @errno
%42 = load i32, i32* @EAI_SYSTEM
store i32 %42, i32* %5
br label %91
43: ; preds = %35
%44 = load %struct.addrinfo*, %struct.addrinfo** %6
%45 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %44, i32 0, i32 0
%46 = load i32, i32* %45
%47 = load i32*, i32** %7
store i32 %46, i32* %47
%48 = load i32*, i32** %7
%49 = load i32, i32* %48
%50 = load i32, i32* @AI_PASSIVE
%51 = load i32, i32* @AI_CANONNAME
%52 = or i32 %50, %51
%53 = load i32, i32* @AI_NUMERICHOST
%54 = or i32 %52, %53
%55 = load i32, i32* @AI_NUMERICSERV
%56 = or i32 %54, %55
%57 = xor i32 %56, -1
%58 = and i32 %49, %57
%59 = icmp ne i32 %58, 0
br i1 %59, label %60, label %62
60: ; preds = %43
%61 = load i32, i32* @EAI_BADFLAGS
store i32 %61, i32* %5
br label %91
62: ; preds = %43
%63 = load %struct.addrinfo*, %struct.addrinfo** %6
%64 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %63, i32 0, i32 1
%65 = load i64, i64* %64
%66 = load i64, i64* @AF_UNSPEC
%67 = icmp ne i64 %65, %66
br i1 %67, label %68, label %76
68: ; preds = %62
%69 = load %struct.addrinfo*, %struct.addrinfo** %6
%70 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %69, i32 0, i32 1
%71 = load i64, i64* %70
%72 = load i64, i64* @AF_INET
%73 = icmp ne i64 %71, %72
br i1 %73, label %74, label %76
74: ; preds = %68
%75 = load i32, i32* @EAI_FAMILY
store i32 %75, i32* %5
br label %91
76: ; preds = %68, %62
%77 = load %struct.addrinfo*, %struct.addrinfo** %6
%78 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %77, i32 0, i32 2
%79 = load i32, i32* %78
%80 = load i32*, i32** %8
store i32 %79, i32* %80
%81 = load i32*, i32** %8
%82 = load i32, i32* %81
switch i32 %82, label %84 [
i32 0, label %83
i32 128, label %83
i32 129, label %83
]
83: ; preds = %76, %76, %76
br label %86
84: ; preds = %76
%85 = load i32, i32* @EAI_SOCKTYPE
store i32 %85, i32* %5
br label %91
86: ; preds = %83
%87 = load %struct.addrinfo*, %struct.addrinfo** %6
%88 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %87, i32 0, i32 3
%89 = load i32, i32* %88
%90 = load i32*, i32** %9
store i32 %89, i32* %90
store i32 0, i32* %5
br label %91
91: ; preds = %86, %84, %74, %60, %40, %16
%92 = load i32, i32* %5
ret i32 %92
}

LLVM IR (-O2):
%struct.addrinfo = type { i32, i64, i32, i32, i64, i64, i64, i64 }
@EINVAL = global i32 0
@errno = global i32 0
@EAI_SYSTEM = global i32 0
@AI_PASSIVE = global i32 0
@AI_CANONNAME = global i32 0
@AI_NUMERICHOST = global i32 0
@AI_NUMERICSERV = global i32 0
@EAI_BADFLAGS = global i32 0
@AF_UNSPEC = global i64 0
@AF_INET = global i64 0
@EAI_FAMILY = global i32 0
@EAI_SOCKTYPE = global i32 0
define i32 @getaddrinfo_parse_hints(%struct.addrinfo* %0, i32* %1, i32* %2, i32* nocapture writeonly %3) {
%5 = tail call i32 @assert(i32* %1)
%6 = tail call i32 @assert(i32* %2)
%7 = icmp eq %struct.addrinfo* %0, null
br i1 %7, label %8, label %9
8: ; preds = %4
store i32 0, i32* %1
store i32 0, i32* %2
store i32 0, i32* %3
br label %61
9: ; preds = %4
%10 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %0, i64 0, i32 7
%11 = load i64, i64* %10
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %25
13: ; preds = %9
%14 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %0, i64 0, i32 6
%15 = load i64, i64* %14
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %25
17: ; preds = %13
%18 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %0, i64 0, i32 5
%19 = load i64, i64* %18
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %25
21: ; preds = %17
%22 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %0, i64 0, i32 4
%23 = load i64, i64* %22
%24 = icmp eq i64 %23, 0
br i1 %24, label %28, label %25
25: ; preds = %21, %17, %13, %9
%26 = load i32, i32* @EINVAL
store i32 %26, i32* @errno
%27 = load i32, i32* @EAI_SYSTEM
br label %61
28: ; preds = %21
%29 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %0, i64 0, i32 0
%30 = load i32, i32* %29
store i32 %30, i32* %1
%31 = load i32, i32* @AI_PASSIVE
%32 = load i32, i32* @AI_CANONNAME
%33 = or i32 %32, %31
%34 = load i32, i32* @AI_NUMERICHOST
%35 = or i32 %33, %34
%36 = load i32, i32* @AI_NUMERICSERV
%37 = or i32 %35, %36
%38 = xor i32 %37, -1
%39 = and i32 %30, %38
%40 = icmp eq i32 %39, 0
br i1 %40, label %43, label %41
41: ; preds = %28
%42 = load i32, i32* @EAI_BADFLAGS
br label %61
43: ; preds = %28
%44 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %0, i64 0, i32 1
%45 = load i64, i64* %44
%46 = load i64, i64* @AF_UNSPEC
%47 = icmp eq i64 %45, %46
%48 = load i64, i64* @AF_INET
%49 = icmp eq i64 %45, %48
%50 = select i1 %47, i1 true, i1 %49
br i1 %50, label %53, label %51
51: ; preds = %43
%52 = load i32, i32* @EAI_FAMILY
br label %61
53: ; preds = %43
%54 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %0, i64 0, i32 2
%55 = load i32, i32* %54
store i32 %55, i32* %2
switch i32 %55, label %56 [
i32 0, label %58
i32 128, label %58
i32 129, label %58
]
56: ; preds = %53
%57 = load i32, i32* @EAI_SOCKTYPE
br label %61
58: ; preds = %53, %53, %53
%59 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %0, i64 0, i32 3
%60 = load i32, i32* %59
store i32 %60, i32* %3
br label %61
61: ; preds = %58, %56, %51, %41, %25, %8
%62 = phi i32 [ %27, %25 ], [ %42, %41 ], [ %52, %51 ], [ %57, %56 ], [ 0, %58 ], [ 0, %8 ]
ret i32 %62
}