#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 {
  int /*<<< orphan*/ ai_family;
  int /*<<< orphan*/ ai_flags;
};
typedef int /*<<< orphan*/ hints;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ AI_CANONNAME;
int /*<<< orphan*/ bzero(struct addrinfo *, int);
int /*<<< orphan*/ freeaddrinfo(struct addrinfo *);
int /*<<< orphan*/ getaddrinfo(char *, char *, struct addrinfo *,
                               struct addrinfo **);
int /*<<< orphan*/ print_addrinfo(struct addrinfo *);
int main(int argc, char *argv[]) {
  struct addrinfo hints, *res;
  bzero(&hints, sizeof(hints));
  hints.ai_flags = AI_CANONNAME;
  hints.ai_family = AF_INET;
  getaddrinfo("localhost", "domain", &hints, &res);
  print_addrinfo(res);
  freeaddrinfo(res);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x18(%rbp),%rdi
mov    $0x8,%esi
call   1040 <bzero@plt>
mov    0x2e75(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    0x2e71(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
lea    0xe7d(%rip),%rdi
lea    0xe80(%rip),%rsi
lea    -0x18(%rbp),%rdx
lea    -0x20(%rbp),%rcx
call   1050 <getaddrinfo@plt>
mov    -0x20(%rbp),%rdi
call   1030 <print_addrinfo@plt>
mov    -0x20(%rbp),%rdi
call   1060 <freeaddrinfo@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
lea    0x8(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x8,%esi
call   1040 <bzero@plt>
mov    0x2e82(%rip),%rax
mov    (%rax),%eax
mov    %eax,0xc(%rsp)
mov    0x2e7d(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x8(%rsp)
lea    0xe88(%rip),%rdi
lea    0xe8b(%rip),%rsi
mov    %rsp,%rcx
mov    %rbx,%rdx
call   1050 <getaddrinfo@plt>
mov    (%rsp),%rdi
call   1030 <print_addrinfo@plt>
mov    (%rsp),%rdi
call   1060 <freeaddrinfo@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.addrinfo = type { i32, i32 }
@AI_CANONNAME = global i32 0
@AF_INET = global i32 0
@.str = [10 x i8] c"localhost\00"
@.str.1 = [7 x i8] c"domain\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.addrinfo
%7 = alloca %struct.addrinfo*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = call i32 @bzero(%struct.addrinfo* %6, i32 8)
%9 = load i32, i32* @AI_CANONNAME
%10 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %6, i32 0, i32 1
store i32 %9, i32* %10
%11 = load i32, i32* @AF_INET
%12 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %6, i32 0, i32 0
store i32 %11, i32* %12
%13 = call i32 @getaddrinfo(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), %struct.addrinfo* %6, %struct.addrinfo** %7)
%14 = load %struct.addrinfo*, %struct.addrinfo** %7
%15 = call i32 @print_addrinfo(%struct.addrinfo* %14)
%16 = load %struct.addrinfo*, %struct.addrinfo** %7
%17 = call i32 @freeaddrinfo(%struct.addrinfo* %16)
ret i32 0
}

LLVM IR (-O2):
%struct.addrinfo = type { i32, i32 }
@AI_CANONNAME = global i32 0
@AF_INET = global i32 0
@.str = [10 x i8] c"localhost\00"
@.str.1 = [7 x i8] c"domain\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca %struct.addrinfo
%4 = alloca %struct.addrinfo*
%5 = bitcast %struct.addrinfo* %3 to i8*
%6 = bitcast %struct.addrinfo** %4 to i8*
%7 = call i32 @bzero(%struct.addrinfo* %3, i32 8)
%8 = load i32, i32* @AI_CANONNAME
%9 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i64 0, i32 1
store i32 %8, i32* %9
%10 = load i32, i32* @AF_INET
%11 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i64 0, i32 0
store i32 %10, i32* %11
%12 = call i32 @getaddrinfo(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), %struct.addrinfo* %3, %struct.addrinfo** %4)
%13 = load %struct.addrinfo*, %struct.addrinfo** %4
%14 = call i32 @print_addrinfo(%struct.addrinfo* %13)
%15 = load %struct.addrinfo*, %struct.addrinfo** %4
%16 = call i32 @freeaddrinfo(%struct.addrinfo* %15)
ret i32 0
}