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

/* Variables and functions */
int /*<<< orphan*/ free(struct addrinfo *);
void __freeaddrinfo(struct addrinfo *ai) {
  struct addrinfo *ai_next;
  while (ai != NULL) {
    ai_next = ai->ai_next;
    if (ai->ai_addr != NULL) {
      free(ai->ai_addr);
      ai->ai_addr = NULL;
    }
    if (ai->ai_canonname) {
      free(ai->ai_canonname);
      ai->ai_canonname = NULL;
    }
    free(ai);
    ai = ai_next;
  }
}


x86 assembly (clang, -O0):
<__freeaddrinfo>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     1196 <__freeaddrinfo+0x86>
mov    -0x8(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
cmpq   $0x0,0x8(%rax)
je     115b <__freeaddrinfo+0x4b>
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%rdi
call   1030 <free@plt>
mov    -0x8(%rbp),%rax
movq   $0x0,0x8(%rax)
mov    -0x8(%rbp),%rax
cmpq   $0x0,(%rax)
je     1180 <__freeaddrinfo+0x70>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
call   1030 <free@plt>
mov    -0x8(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x8(%rbp),%rdi
call   1030 <free@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    111c <__freeaddrinfo+0xc>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__freeaddrinfo>:
push   %r14
push   %rbx
push   %rax
test   %rdi,%rdi
je     1160 <__freeaddrinfo+0x50>
mov    %rdi,%rbx
jmp    1130 <__freeaddrinfo+0x20>
xchg   %ax,%ax
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r14,%rbx
test   %r14,%r14
je     1160 <__freeaddrinfo+0x50>
mov    0x8(%rbx),%rdi
mov    0x10(%rbx),%r14
test   %rdi,%rdi
je     114a <__freeaddrinfo+0x3a>
call   1030 <free@plt>
movq   $0x0,0x8(%rbx)
mov    (%rbx),%rdi
test   %rdi,%rdi
je     1120 <__freeaddrinfo+0x10>
call   1030 <free@plt>
movq   $0x0,(%rbx)
jmp    1120 <__freeaddrinfo+0x10>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

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