#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 {
  scalar_t__ ai_family;
  struct addrinfo *ai_next;
};

/* Variables and functions */
scalar_t__ AF_INET;
scalar_t__ AF_INET6;
struct addrinfo *select_resolved_host(struct addrinfo *ai, char use_ipv6) {
  struct addrinfo *p = ai;
  while (p) {
    if (p->ai_family == AF_INET6 && use_ipv6)
      return p;
    if (p->ai_family == AF_INET)
      return p;
    p = p->ai_next;
  }
  return NULL;
}


x86 assembly (clang, -O0):
<select_resolved_host>:
push   %rbp
mov    %rsp,%rbp
mov    %sil,%al
mov    %rdi,-0x10(%rbp)
mov    %al,-0x11(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1187 <select_resolved_host+0x87>
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
mov    0x2eb1(%rip),%rcx
cmp    (%rcx),%rax
jne    1152 <select_resolved_host+0x52>
movsbl -0x11(%rbp),%eax
cmp    $0x0,%eax
je     1152 <select_resolved_host+0x52>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    118f <select_resolved_host+0x8f>
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
mov    0x2e88(%rip),%rcx
cmp    (%rcx),%rax
jne    1176 <select_resolved_host+0x76>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    118f <select_resolved_host+0x8f>
mov    -0x20(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x20(%rbp)
jmp    1116 <select_resolved_host+0x16>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<select_resolved_host>:
test   %rdi,%rdi
je     1141 <select_resolved_host+0x41>
mov    %rdi,%rax
mov    0x2ed1(%rip),%rcx
mov    (%rcx),%r8
mov    0x2ecf(%rip),%rdx
mov    (%rdx),%r9
nopl   0x0(%rax)
test   %sil,%sil
setne  %cl
mov    (%rax),%rdi
cmp    %r8,%rdi
sete   %dl
test   %dl,%cl
jne    1143 <select_resolved_host+0x43>
cmp    %r9,%rdi
je     1143 <select_resolved_host+0x43>
mov    0x8(%rax),%rax
test   %rax,%rax
jne    1120 <select_resolved_host+0x20>
xor    %eax,%eax
ret

LLVM IR (-O0):
%struct.addrinfo = type { i64, %struct.addrinfo* }
@AF_INET6 = global i64 0
@AF_INET = global i64 0
define %struct.addrinfo* @select_resolved_host(%struct.addrinfo* %0, i8 signext %1) {
%3 = alloca %struct.addrinfo*
%4 = alloca %struct.addrinfo*
%5 = alloca i8
%6 = alloca %struct.addrinfo*
store %struct.addrinfo* %0, %struct.addrinfo** %4
store i8 %1, i8* %5
%7 = load %struct.addrinfo*, %struct.addrinfo** %4
store %struct.addrinfo* %7, %struct.addrinfo** %6
br label %8
8: ; preds = %31, %2
%9 = load %struct.addrinfo*, %struct.addrinfo** %6
%10 = icmp ne %struct.addrinfo* %9, null
br i1 %10, label %11, label %35
11: ; preds = %8
%12 = load %struct.addrinfo*, %struct.addrinfo** %6
%13 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %12, i32 0, i32 0
%14 = load i64, i64* %13
%15 = load i64, i64* @AF_INET6
%16 = icmp eq i64 %14, %15
br i1 %16, label %17, label %23
17: ; preds = %11
%18 = load i8, i8* %5
%19 = sext i8 %18 to i32
%20 = icmp ne i32 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %17
%22 = load %struct.addrinfo*, %struct.addrinfo** %6
store %struct.addrinfo* %22, %struct.addrinfo** %3
br label %36
23: ; preds = %17, %11
%24 = load %struct.addrinfo*, %struct.addrinfo** %6
%25 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %24, i32 0, i32 0
%26 = load i64, i64* %25
%27 = load i64, i64* @AF_INET
%28 = icmp eq i64 %26, %27
br i1 %28, label %29, label %31
29: ; preds = %23
%30 = load %struct.addrinfo*, %struct.addrinfo** %6
store %struct.addrinfo* %30, %struct.addrinfo** %3
br label %36
31: ; preds = %23
%32 = load %struct.addrinfo*, %struct.addrinfo** %6
%33 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %32, i32 0, i32 1
%34 = load %struct.addrinfo*, %struct.addrinfo** %33
store %struct.addrinfo* %34, %struct.addrinfo** %6
br label %8
35: ; preds = %8
store %struct.addrinfo* null, %struct.addrinfo** %3
br label %36
36: ; preds = %35, %29, %21
%37 = load %struct.addrinfo*, %struct.addrinfo** %3
ret %struct.addrinfo* %37
}

LLVM IR (-O2):
%struct.addrinfo = type { i64, %struct.addrinfo* }
@AF_INET6 = global i64 0
@AF_INET = global i64 0
define %struct.addrinfo* @select_resolved_host(%struct.addrinfo* %0, i8 signext %1) {
%3 = icmp eq %struct.addrinfo* %0, null
br i1 %3, label %20, label %4
4: ; preds = %2
%5 = load i64, i64* @AF_INET6
%6 = icmp ne i8 %1, 0
%7 = load i64, i64* @AF_INET
br label %8
8: ; preds = %4, %16
%9 = phi %struct.addrinfo* [ %0, %4 ], [ %18, %16 ]
%10 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %9, i64 0, i32 0
%11 = load i64, i64* %10
%12 = icmp eq i64 %11, %5
%13 = and i1 %6, %12
%14 = icmp eq i64 %11, %7
%15 = select i1 %13, i1 true, i1 %14
br i1 %15, label %20, label %16
16: ; preds = %8
%17 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %9, i64 0, i32 1
%18 = load %struct.addrinfo*, %struct.addrinfo** %17
%19 = icmp eq %struct.addrinfo* %18, null
br i1 %19, label %20, label %8
20: ; preds = %8, %16, %2
%21 = phi %struct.addrinfo* [ null, %2 ], [ null, %16 ], [ %9, %8 ]
ret %struct.addrinfo* %21
}