#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 */
int NI_MAXHOST;
int NI_MAXSERV;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, ...);
char *gai_strerror(int);
int lookup_addrinfo(struct addrinfo const *, char *, int, char *, int);
int /*<<< orphan*/ stderr;
void print_addresses(const struct addrinfo *ai) {
  char host[NI_MAXHOST];
  char service[NI_MAXSERV];
  for (; ai; ai = ai->ai_next) {
    int error = lookup_addrinfo(ai, host, sizeof host, service, sizeof service);
    if (error) {
      fprintf(stderr, "numeric conv: %s\n", gai_strerror(error));
      continue;
    }
    fprintf(stderr, "Address: %s port %s\n", host, service);
  }
}


x86 assembly (clang, -O0):
<print_addresses>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    0x2e8d(%rip),%rax
mov    (%rax),%eax
mov    %rax,-0x48(%rbp)
mov    %rsp,%rcx
mov    %rcx,-0x10(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x40(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x18(%rbp)
mov    0x2e75(%rip),%rax
mov    (%rax),%eax
mov    %rax,-0x38(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x30(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     1225 <print_addresses+0xf5>
mov    -0x30(%rbp),%rcx
mov    -0x40(%rbp),%rsi
mov    -0x38(%rbp),%rax
mov    -0x48(%rbp),%rdx
mov    -0x8(%rbp),%rdi
mov    %eax,%r8d
call   1050 <lookup_addrinfo@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
je     11f6 <print_addresses+0xc6>
mov    0x2e08(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4c(%rbp)
mov    -0x24(%rbp),%edi
call   1030 <gai_strerror@plt>
mov    -0x4c(%rbp),%edi
mov    %rax,%rdx
lea    0xe16(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
jmp    1215 <print_addresses+0xe5>
mov    -0x30(%rbp),%rcx
mov    -0x40(%rbp),%rdx
mov    0x2dd3(%rip),%rax
mov    (%rax),%edi
lea    0xe04(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x8(%rbp)
jmp    1195 <print_addresses+0x65>
mov    -0x10(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_addresses>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    0x2e8b(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%r15
mov    %rax,-0x30(%rbp)
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r15
mov    %r15,%rsp
mov    0x2e85(%rip),%rax
mov    (%rax),%r12d
mov    %rsp,%r13
lea    0xf(%r12),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r13
mov    %r13,%rsp
test   %rdi,%rdi
je     11ef <print_addresses+0xbf>
mov    %rdi,%rbx
jmp    11af <print_addresses+0x7f>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r14d,%edi
lea    0xe78(%rip),%rsi
mov    %r15,%rdx
mov    %r13,%rcx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    (%rbx),%rbx
test   %rbx,%rbx
je     11ef <print_addresses+0xbf>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    -0x30(%rbp),%rdx
mov    %r13,%rcx
mov    %r12d,%r8d
call   1050 <lookup_addrinfo@plt>
mov    0x2e0d(%rip),%rcx
mov    (%rcx),%r14d
test   %eax,%eax
je     1190 <print_addresses+0x60>
mov    %eax,%edi
call   1030 <gai_strerror@plt>
mov    %r14d,%edi
lea    0xe1d(%rip),%rsi
mov    %rax,%rdx
xor    %eax,%eax
call   1040 <fprintf@plt>
jmp    11a7 <print_addresses+0x77>
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.addrinfo = type { %struct.addrinfo* }
@NI_MAXHOST = global i32 0
@NI_MAXSERV = global i32 0
@stderr = global i32 0
@.str = [18 x i8] c"numeric conv: %s\0A\00"
@.str.1 = [21 x i8] c"Address: %s port %s\0A\00"
define void @print_addresses(%struct.addrinfo* %0) {
%2 = alloca %struct.addrinfo*
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i64
%6 = alloca i32
store %struct.addrinfo* %0, %struct.addrinfo** %2
%7 = load i32, i32* @NI_MAXHOST
%8 = zext i32 %7 to i64
%9 = call i8* @llvm.stacksave()
store i8* %9, i8** %3
%10 = alloca i8, i64 %8
store i64 %8, i64* %4
%11 = load i32, i32* @NI_MAXSERV
%12 = zext i32 %11 to i64
%13 = alloca i8, i64 %12
store i64 %12, i64* %5
br label %14
14: ; preds = %32, %1
%15 = load %struct.addrinfo*, %struct.addrinfo** %2
%16 = icmp ne %struct.addrinfo* %15, null
br i1 %16, label %17, label %36
17: ; preds = %14
%18 = load %struct.addrinfo*, %struct.addrinfo** %2
%19 = trunc i64 %8 to i32
%20 = trunc i64 %12 to i32
%21 = call i32 @lookup_addrinfo(%struct.addrinfo* %18, i8* %10, i32 %19, i8* %13, i32 %20)
store i32 %21, i32* %6
%22 = load i32, i32* %6
%23 = icmp ne i32 %22, 0
br i1 %23, label %24, label %29
24: ; preds = %17
%25 = load i32, i32* @stderr
%26 = load i32, i32* %6
%27 = call i8* @gai_strerror(i32 %26)
%28 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %25, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %27)
br label %32
29: ; preds = %17
%30 = load i32, i32* @stderr
%31 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %30, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* %10, i8* %13)
br label %32
32: ; preds = %29, %24
%33 = load %struct.addrinfo*, %struct.addrinfo** %2
%34 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %33, i32 0, i32 0
%35 = load %struct.addrinfo*, %struct.addrinfo** %34
store %struct.addrinfo* %35, %struct.addrinfo** %2
br label %14
36: ; preds = %14
%37 = load i8*, i8** %3
ret void
}

LLVM IR (-O2):
%struct.addrinfo = type { %struct.addrinfo* }
@NI_MAXHOST = global i32 0
@NI_MAXSERV = global i32 0
@stderr = global i32 0
@.str = [18 x i8] c"numeric conv: %s\0A\00"
@.str.1 = [21 x i8] c"Address: %s port %s\0A\00"
define void @print_addresses(%struct.addrinfo* %0) {
%2 = load i32, i32* @NI_MAXHOST
%3 = zext i32 %2 to i64
%4 = alloca i8, i64 %3
%5 = load i32, i32* @NI_MAXSERV
%6 = zext i32 %5 to i64
%7 = alloca i8, i64 %6
%8 = icmp eq %struct.addrinfo* %0, null
br i1 %8, label %23, label %9
9: ; preds = %1, %19
%10 = phi %struct.addrinfo* [ %21, %19 ], [ %0, %1 ]
%11 = call i32 @lookup_addrinfo(%struct.addrinfo* %10, i8* %4, i32 %2, i8* %7, i32 %5)
%12 = icmp eq i32 %11, 0
%13 = load i32, i32* @stderr
br i1 %12, label %17, label %14
14: ; preds = %9
%15 = call i8* @gai_strerror(i32 %11)
%16 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %13, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %15)
br label %19
17: ; preds = %9
%18 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %13, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* %4, i8* %7)
br label %19
19: ; preds = %17, %14
%20 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %10, i64 0, i32 0
%21 = load %struct.addrinfo*, %struct.addrinfo** %20
%22 = icmp eq %struct.addrinfo* %21, null
br i1 %22, label %23, label %9
23: ; preds = %19, %1
ret void
}