#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_addr;
  scalar_t__ ai_protocol;
  int /*<<< orphan*/ ai_flags;
  int /*<<< orphan*/ ai_socktype;
  int /*<<< orphan*/ ai_family;
};

/* Variables and functions */
int /*<<< orphan*/ AF_UNSPEC;
int /*<<< orphan*/ AI_CANONNAME;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ freeaddrinfo(struct addrinfo *);
char *gai_strerror(int);
int getaddrinfo(char *, int /*<<< orphan*/ *, struct addrinfo *,
                struct addrinfo **);
int /*<<< orphan*/ memset(struct addrinfo *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ printhost(int /*<<< orphan*/);
int /*<<< orphan*/ printip(struct addrinfo *);
int main(int argc, char **argv) {
  struct addrinfo hints;
  struct addrinfo *res;
  int ret;
  if (argc < 2) {
    printf("More arguments needed!\n");
    return 1;
  }
  memset(&hints, 0, sizeof(struct addrinfo));
  hints.ai_family = AF_UNSPEC;
  hints.ai_socktype = SOCK_STREAM;
  hints.ai_flags |= AI_CANONNAME;
  hints.ai_protocol = 0;
  ret = getaddrinfo(argv[1], NULL, &hints, &res);
  if (ret != 0) {
    printf("getaddrinfo: %s\n", gai_strerror(ret));
    return 1;
  }
  printf("Host:\n");
  printhost(res->ai_addr);
  printf("\nIPs:\n");
  printip(res);
  freeaddrinfo(res);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    11aa <main+0x3a>
lea    0xe69(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1274 <main+0x104>
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1050 <memset@plt>
mov    0x2e27(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    0x2e03(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    0x2e07(%rip),%rax
mov    (%rax),%eax
or     -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
lea    -0x30(%rbp),%rdx
lea    -0x38(%rbp),%rcx
call   1080 <getaddrinfo@plt>
mov    %eax,-0x3c(%rbp)
cmpl   $0x0,-0x3c(%rbp)
je     1234 <main+0xc4>
mov    -0x3c(%rbp),%edi
call   1040 <gai_strerror@plt>
mov    %rax,%rsi
lea    0xdf7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1274 <main+0x104>
lea    0xdee(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x38(%rbp),%rax
mov    (%rax),%edi
call   1070 <printhost@plt>
lea    0xddc(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x38(%rbp),%rdi
call   1060 <printip@plt>
mov    -0x38(%rbp),%rdi
call   1090 <freeaddrinfo@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x30,%rsp
cmp    $0x1,%edi
jg     11a5 <main+0x25>
lea    0xe88(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%r14d
jmp    125e <main+0xde>
mov    %rsi,%rbx
lea    0x10(%rsp),%r15
xor    %r14d,%r14d
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1060 <memset@plt>
mov    0x2e22(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x28(%rsp)
mov    0x2dfd(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x24(%rsp)
mov    0x2e00(%rip),%rax
mov    (%rax),%eax
or     %eax,0x20(%rsp)
movq   $0x0,0x18(%rsp)
mov    0x8(%rbx),%rdi
lea    0x8(%rsp),%rcx
xor    %esi,%esi
mov    %r15,%rdx
call   1090 <getaddrinfo@plt>
test   %eax,%eax
je     1226 <main+0xa6>
mov    %eax,%edi
call   1050 <gai_strerror@plt>
lea    0xdec(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%r14d
jmp    125e <main+0xde>
lea    0xde4(%rip),%rdi
call   1030 <puts@plt>
mov    0x8(%rsp),%rax
mov    (%rax),%edi
call   1080 <printhost@plt>
lea    0xdd2(%rip),%rdi
call   1030 <puts@plt>
mov    0x8(%rsp),%rdi
call   1070 <printip@plt>
mov    0x8(%rsp),%rdi
call   10a0 <freeaddrinfo@plt>
mov    %r14d,%eax
add    $0x30,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.addrinfo = type { i32, i64, i32, i32, i32 }
@.str = [24 x i8] c"More arguments needed!\0A\00"
@AF_UNSPEC = global i32 0
@SOCK_STREAM = global i32 0
@AI_CANONNAME = global i32 0
@.str.1 = [17 x i8] c"getaddrinfo: %s\0A\00"
@.str.2 = [7 x i8] c"Host:\0A\00"
@.str.3 = [7 x i8] c"\0AIPs:\0A\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*
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp slt i32 %9, 2
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %45
13: ; preds = %2
%14 = call i32 @memset(%struct.addrinfo* %6, i32 0, i32 32)
%15 = load i32, i32* @AF_UNSPEC
%16 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %6, i32 0, i32 4
store i32 %15, i32* %16
%17 = load i32, i32* @SOCK_STREAM
%18 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %6, i32 0, i32 3
store i32 %17, i32* %18
%19 = load i32, i32* @AI_CANONNAME
%20 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %6, i32 0, i32 2
%21 = load i32, i32* %20
%22 = or i32 %21, %19
store i32 %22, i32* %20
%23 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %6, i32 0, i32 1
store i64 0, i64* %23
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 1
%26 = load i8*, i8** %25
%27 = call i32 @getaddrinfo(i8* %26, i32* null, %struct.addrinfo* %6, %struct.addrinfo** %7)
store i32 %27, i32* %8
%28 = load i32, i32* %8
%29 = icmp ne i32 %28, 0
br i1 %29, label %30, label %34
30: ; preds = %13
%31 = load i32, i32* %8
%32 = call i8* @gai_strerror(i32 %31)
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* %32)
store i32 1, i32* %3
br label %45
34: ; preds = %13
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%36 = load %struct.addrinfo*, %struct.addrinfo** %7
%37 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %36, i32 0, i32 0
%38 = load i32, i32* %37
%39 = call i32 @printhost(i32 %38)
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%41 = load %struct.addrinfo*, %struct.addrinfo** %7
%42 = call i32 @printip(%struct.addrinfo* %41)
%43 = load %struct.addrinfo*, %struct.addrinfo** %7
%44 = call i32 @freeaddrinfo(%struct.addrinfo* %43)
store i32 0, i32* %3
br label %45
45: ; preds = %34, %30, %11
%46 = load i32, i32* %3
ret i32 %46
}

LLVM IR (-O2):
%struct.addrinfo = type { i32, i64, i32, i32, i32 }
@AF_UNSPEC = global i32 0
@SOCK_STREAM = global i32 0
@AI_CANONNAME = global i32 0
@.str.1 = [17 x i8] c"getaddrinfo: %s\0A\00"
@str = [6 x i8] c"Host:\00"
@str.4 = [6 x i8] c"\0AIPs:\00"
@str.5 = [23 x i8] c"More arguments needed!\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.addrinfo
%4 = alloca %struct.addrinfo*
%5 = bitcast %struct.addrinfo* %3 to i8*
%6 = bitcast %struct.addrinfo** %4 to i8*
%7 = icmp slt i32 %0, 2
br i1 %7, label %8, label %10
8: ; preds = %2
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str.5, i64 0, i64 0))
br label %39
10: ; preds = %2
%11 = call i32 @memset(%struct.addrinfo* %3, i32 0, i32 32)
%12 = load i32, i32* @AF_UNSPEC
%13 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i64 0, i32 4
store i32 %12, i32* %13
%14 = load i32, i32* @SOCK_STREAM
%15 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i64 0, i32 3
store i32 %14, i32* %15
%16 = load i32, i32* @AI_CANONNAME
%17 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i64 0, i32 2
%18 = load i32, i32* %17
%19 = or i32 %18, %16
store i32 %19, i32* %17
%20 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i64 0, i32 1
store i64 0, i64* %20
%21 = getelementptr inbounds i8*, i8** %1, i64 1
%22 = load i8*, i8** %21
%23 = call i32 @getaddrinfo(i8* %22, i32* null, %struct.addrinfo* %3, %struct.addrinfo** %4)
%24 = icmp eq i32 %23, 0
br i1 %24, label %28, label %25
25: ; preds = %10
%26 = call i8* @gai_strerror(i32 %23)
%27 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* %26)
br label %39
28: ; preds = %10
%29 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @str, i64 0, i64 0))
%30 = load %struct.addrinfo*, %struct.addrinfo** %4
%31 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %30, i64 0, i32 0
%32 = load i32, i32* %31
%33 = call i32 @printhost(i32 %32)
%34 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @str.4, i64 0, i64 0))
%35 = load %struct.addrinfo*, %struct.addrinfo** %4
%36 = call i32 @printip(%struct.addrinfo* %35)
%37 = load %struct.addrinfo*, %struct.addrinfo** %4
%38 = call i32 @freeaddrinfo(%struct.addrinfo* %37)
br label %39
39: ; preds = %28, %25, %8
%40 = phi i32 [ 1, %8 ], [ 1, %25 ], [ 0, %28 ]
ret i32 %40
}