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

/* Variables and functions */
void append_addrinfo(struct addrinfo **head, struct addrinfo *addr) {
  if (*head == NULL) {
    *head = addr;
    return;
  }
  struct addrinfo *ai = *head;
  while (ai->ai_next != NULL) {
    ai = ai->ai_next;
  }
  ai->ai_next = addr;
}


x86 assembly (clang, -O0):
<append_addrinfo>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
cmpq   $0x0,(%rax)
jne    112a <append_addrinfo+0x2a>
mov    -0x10(%rbp),%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
jmp    115e <append_addrinfo+0x5e>
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmpq   $0x0,(%rax)
je     1153 <append_addrinfo+0x53>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
jmp    1135 <append_addrinfo+0x35>
mov    -0x10(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
pop    %rbp
ret

x86 assembly (clang, -O2):
<append_addrinfo>:
mov    (%rdi),%rax
test   %rax,%rax
je     111b <append_addrinfo+0x1b>
nopl   0x0(%rax,%rax,1)
mov    %rax,%rdi
mov    (%rax),%rax
test   %rax,%rax
jne    1110 <append_addrinfo+0x10>
mov    %rsi,(%rdi)
ret

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

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