#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_next;
};

/* Variables and functions */
int /*<<< orphan*/ free(struct addrinfo *);
void qn_freeaddrinfo(struct addrinfo *ai) {
  if (ai == NULL) {
    return;
  }
  struct addrinfo *next;
  do {
    next = ai->ai_next;
    if (ai->ai_canonname)
      free(ai->ai_canonname);
    free(ai);
    ai = next;
  } while (ai);
}


x86 assembly (clang, -O0):
<qn_freeaddrinfo>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    112c <qn_freeaddrinfo+0x1c>
jmp    1173 <qn_freeaddrinfo+0x63>
jmp    1131 <qn_freeaddrinfo+0x21>
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
cmpq   $0x0,(%rax)
je     1157 <qn_freeaddrinfo+0x47>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
call   1030 <free@plt>
mov    -0x8(%rbp),%rdi
call   1030 <free@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    1131 <qn_freeaddrinfo+0x21>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<qn_freeaddrinfo>:
push   %r14
push   %rbx
push   %rax
test   %rdi,%rdi
je     1143 <qn_freeaddrinfo+0x33>
mov    %rdi,%rbx
jmp    1130 <qn_freeaddrinfo+0x20>
xchg   %ax,%ax
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r14,%rbx
test   %r14,%r14
je     1143 <qn_freeaddrinfo+0x33>
mov    (%rbx),%rdi
mov    0x8(%rbx),%r14
test   %rdi,%rdi
je     1120 <qn_freeaddrinfo+0x10>
call   1030 <free@plt>
jmp    1120 <qn_freeaddrinfo+0x10>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
%struct.addrinfo = type { %struct.addrinfo*, %struct.addrinfo* }
define void @qn_freeaddrinfo(%struct.addrinfo* %0) {
%2 = icmp eq %struct.addrinfo* %0, null
br i1 %2, label %15, label %3
3: ; preds = %1, %12
%4 = phi %struct.addrinfo* [ %6, %12 ], [ %0, %1 ]
%5 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %4, i64 0, i32 1
%6 = load %struct.addrinfo*, %struct.addrinfo** %5
%7 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %4, i64 0, i32 0
%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)
br label %12
12: ; preds = %10, %3
%13 = tail call i32 @free(%struct.addrinfo* %4)
%14 = icmp eq %struct.addrinfo* %6, null
br i1 %14, label %15, label %3
15: ; preds = %12, %1
ret void
}