#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_family;
  struct addrinfo *ai_next;
};

/* Variables and functions */
int /*<<< orphan*/ freeaddrinfo(struct addrinfo *);
void addrinfo_remove(int familyToRemove, struct addrinfo **aip) {
  struct addrinfo *ai;
  while ((ai = *aip)) {
    if (ai->ai_family == familyToRemove) {
      *aip = ai->ai_next;
      ai->ai_next = NULL;
      freeaddrinfo(ai);
    } else {
      aip = &ai->ai_next;
    }
  }
}


x86 assembly (clang, -O0):
<addrinfo_remove>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     117d <addrinfo_remove+0x6d>
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
cmp    -0x4(%rbp),%eax
jne    116c <addrinfo_remove+0x5c>
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rax
movq   $0x0,0x8(%rax)
mov    -0x18(%rbp),%rdi
call   1030 <freeaddrinfo@plt>
jmp    1178 <addrinfo_remove+0x68>
mov    -0x18(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x10(%rbp)
jmp    111f <addrinfo_remove+0xf>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<addrinfo_remove>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebp
mov    (%rsi),%rdi
test   %rdi,%rdi
je     1159 <addrinfo_remove+0x49>
mov    %rsi,%rbx
jmp    114c <addrinfo_remove+0x3c>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    0x8(%rdi),%rax
mov    %rax,(%rbx)
movq   $0x0,0x8(%rdi)
call   1030 <freeaddrinfo@plt>
mov    (%rbx),%rdi
test   %rdi,%rdi
je     1159 <addrinfo_remove+0x49>
cmp    %ebp,(%rdi)
je     1130 <addrinfo_remove+0x20>
add    $0x8,%rdi
mov    %rdi,%rbx
jmp    1144 <addrinfo_remove+0x34>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.addrinfo = type { i32, %struct.addrinfo* }
define void @addrinfo_remove(i32 %0, %struct.addrinfo** %1) {
%3 = alloca i32
%4 = alloca %struct.addrinfo**
%5 = alloca %struct.addrinfo*
store i32 %0, i32* %3
store %struct.addrinfo** %1, %struct.addrinfo*** %4
br label %6
6: ; preds = %28, %2
%7 = load %struct.addrinfo**, %struct.addrinfo*** %4
%8 = load %struct.addrinfo*, %struct.addrinfo** %7
store %struct.addrinfo* %8, %struct.addrinfo** %5
%9 = icmp ne %struct.addrinfo* %8, null
br i1 %9, label %10, label %29
10: ; preds = %6
%11 = load %struct.addrinfo*, %struct.addrinfo** %5
%12 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %11, i32 0, i32 0
%13 = load i32, i32* %12
%14 = load i32, i32* %3
%15 = icmp eq i32 %13, %14
br i1 %15, label %16, label %25
16: ; preds = %10
%17 = load %struct.addrinfo*, %struct.addrinfo** %5
%18 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %17, i32 0, i32 1
%19 = load %struct.addrinfo*, %struct.addrinfo** %18
%20 = load %struct.addrinfo**, %struct.addrinfo*** %4
store %struct.addrinfo* %19, %struct.addrinfo** %20
%21 = load %struct.addrinfo*, %struct.addrinfo** %5
%22 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %21, i32 0, i32 1
store %struct.addrinfo* null, %struct.addrinfo** %22
%23 = load %struct.addrinfo*, %struct.addrinfo** %5
%24 = call i32 @freeaddrinfo(%struct.addrinfo* %23)
br label %28
25: ; preds = %10
%26 = load %struct.addrinfo*, %struct.addrinfo** %5
%27 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %26, i32 0, i32 1
store %struct.addrinfo** %27, %struct.addrinfo*** %4
br label %28
28: ; preds = %25, %16
br label %6
29: ; preds = %6
ret void
}

LLVM IR (-O2):
%struct.addrinfo = type { i32, %struct.addrinfo* }
define void @addrinfo_remove(i32 %0, %struct.addrinfo** nocapture %1) {
%3 = load %struct.addrinfo*, %struct.addrinfo** %1
%4 = icmp eq %struct.addrinfo* %3, null
br i1 %4, label %19, label %5
5: ; preds = %2, %15
%6 = phi %struct.addrinfo* [ %17, %15 ], [ %3, %2 ]
%7 = phi %struct.addrinfo** [ %16, %15 ], [ %1, %2 ]
%8 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %6, i64 0, i32 0
%9 = load i32, i32* %8
%10 = icmp eq i32 %9, %0
%11 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %6, i64 0, i32 1
br i1 %10, label %12, label %15
12: ; preds = %5
%13 = load %struct.addrinfo*, %struct.addrinfo** %11
store %struct.addrinfo* %13, %struct.addrinfo** %7
store %struct.addrinfo* null, %struct.addrinfo** %11
%14 = tail call i32 @freeaddrinfo(%struct.addrinfo* %6)
br label %15
15: ; preds = %5, %12
%16 = phi %struct.addrinfo** [ %7, %12 ], [ %11, %5 ]
%17 = load %struct.addrinfo*, %struct.addrinfo** %16
%18 = icmp eq %struct.addrinfo* %17, null
br i1 %18, label %19, label %5
19: ; preds = %15, %2
ret void
}