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

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


x86 assembly (clang, -O0):
<freeaddrinfo>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     1180 <freeaddrinfo+0x70>
mov    -0x8(%rbp),%rax
cmpq   $0x0,0x10(%rax)
je     1143 <freeaddrinfo+0x33>
mov    -0x8(%rbp),%rax
mov    0x10(%rax),%rdi
call   1030 <free@plt>
mov    -0x8(%rbp),%rax
cmpq   $0x0,0x8(%rax)
je     115f <freeaddrinfo+0x4f>
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%rdi
call   1030 <free@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x10(%rbp)
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     1151 <freeaddrinfo+0x41>
mov    %rdi,%rbx
jmp    1133 <freeaddrinfo+0x23>
xchg   %ax,%ax
mov    (%rbx),%r14
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r14,%rbx
test   %r14,%r14
je     1151 <freeaddrinfo+0x41>
mov    0x10(%rbx),%rdi
test   %rdi,%rdi
je     1141 <freeaddrinfo+0x31>
call   1030 <free@plt>
mov    0x8(%rbx),%rdi
test   %rdi,%rdi
je     1120 <freeaddrinfo+0x10>
call   1030 <free@plt>
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 = %33, %1
%5 = load %struct.addrinfo*, %struct.addrinfo** %2
%6 = icmp ne %struct.addrinfo* %5, null
br i1 %6, label %7, label %35
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
%11 = icmp ne %struct.addrinfo* %10, null
br i1 %11, label %12, label %17
12: ; preds = %7
%13 = load %struct.addrinfo*, %struct.addrinfo** %2
%14 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %13, i32 0, i32 2
%15 = load %struct.addrinfo*, %struct.addrinfo** %14
%16 = call i32 @free(%struct.addrinfo* %15)
br label %17
17: ; preds = %12, %7
%18 = load %struct.addrinfo*, %struct.addrinfo** %2
%19 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %18, i32 0, i32 1
%20 = load %struct.addrinfo*, %struct.addrinfo** %19
%21 = icmp ne %struct.addrinfo* %20, null
br i1 %21, label %22, label %27
22: ; preds = %17
%23 = load %struct.addrinfo*, %struct.addrinfo** %2
%24 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %23, i32 0, i32 1
%25 = load %struct.addrinfo*, %struct.addrinfo** %24
%26 = call i32 @free(%struct.addrinfo* %25)
br label %27
27: ; preds = %22, %17
%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
store %struct.addrinfo* %30, %struct.addrinfo** %3
%31 = load %struct.addrinfo*, %struct.addrinfo** %2
%32 = call i32 @free(%struct.addrinfo* %31)
br label %33
33: ; preds = %27
%34 = load %struct.addrinfo*, %struct.addrinfo** %3
store %struct.addrinfo* %34, %struct.addrinfo** %2
br label %4
35: ; 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, %16
%4 = phi %struct.addrinfo* [ %18, %16 ], [ %0, %1 ]
%5 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %4, i64 0, i32 2
%6 = load %struct.addrinfo*, %struct.addrinfo** %5
%7 = icmp eq %struct.addrinfo* %6, null
br i1 %7, label %10, label %8
8: ; preds = %3
%9 = tail call i32 @free(%struct.addrinfo* %6)
br label %10
10: ; preds = %8, %3
%11 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %4, i64 0, i32 1
%12 = load %struct.addrinfo*, %struct.addrinfo** %11
%13 = icmp eq %struct.addrinfo* %12, null
br i1 %13, label %16, label %14
14: ; preds = %10
%15 = tail call i32 @free(%struct.addrinfo* %12)
br label %16
16: ; preds = %14, %10
%17 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %4, i64 0, i32 0
%18 = load %struct.addrinfo*, %struct.addrinfo** %17
%19 = tail call i32 @free(%struct.addrinfo* %4)
%20 = icmp eq %struct.addrinfo* %18, null
br i1 %20, label %21, label %3
21: ; preds = %16, %1
ret void
}