#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 sockaddr_in6 {
  int /*<<< orphan*/ sin6_addr;
};
struct sockaddr_in {
  int /*<<< orphan*/ sin_addr;
};
struct addrinfo {
  scalar_t__ ai_family;
  char *ai_canonname;
  scalar_t__ ai_addr;
  struct addrinfo *ai_next;
  int /*<<< orphan*/ ai_socktype;
  int /*<<< orphan*/ ai_flags;
};
typedef int /*<<< orphan*/ hostbuf;
typedef int /*<<< orphan*/ hints;

/* Variables and functions */
scalar_t__ AF_INET;
int /*<<< orphan*/ AI_CANONNAME;
int NI_MAXHOST;
scalar_t__ PF_UNSPEC;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, ...);
int /*<<< orphan*/ freeaddrinfo(struct addrinfo *);
char *gai_strerror(int);
int getaddrinfo(char *, char *, struct addrinfo *, struct addrinfo **);
scalar_t__ inet_ntop(scalar_t__, char const *, char *, int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  char hostbuf[NI_MAXHOST];
  struct addrinfo hints;
  struct addrinfo *res0;
  struct addrinfo *res;
  const char *addr;
  int err;
  if (argc != 2) {
    fprintf(stderr, "usage: %s hostname\n", argv[0]);
    exit(1);
  }
  memset((char *)&hints, 0, sizeof(hints));
  hints.ai_family = PF_UNSPEC;
  hints.ai_flags = AI_CANONNAME;
  hints.ai_socktype = SOCK_STREAM;
  if ((err = getaddrinfo(argv[1], ((char *)0), &hints, &res0)) != 0) {
    fprintf(stderr, "host %s not found: %s\n", argv[1], gai_strerror(err));
    exit(1);
  }
  printf("Hostname:\t%s\n", res0->ai_canonname);
  printf("Addresses:\t");
  for (res = res0; res != 0; res = res->ai_next) {
    addr = (res->ai_family == AF_INET
                ? (char *)&((struct sockaddr_in *)res->ai_addr)->sin_addr
                : (char *)&((struct sockaddr_in6 *)res->ai_addr)->sin6_addr);
    if (inet_ntop(res->ai_family, addr, hostbuf, sizeof(hostbuf)) == 0) {
      perror("inet_ntop:");
      exit(1);
    }
    printf("%s ", hostbuf);
  }
  printf("\n");
  freeaddrinfo(res0);
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e08(%rip),%rax
mov    (%rax),%eax
mov    %rax,-0x78(%rbp)
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x70(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x20(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     120b <main+0x7b>
mov    0x2dde(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe06(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
lea    -0x48(%rbp),%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1060 <memset@plt>
mov    0x2dc6(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x48(%rbp)
mov    0x2da8(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    0x2d84(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
lea    -0x48(%rbp),%rdx
lea    -0x50(%rbp),%rcx
call   10a0 <getaddrinfo@plt>
mov    %eax,-0x64(%rbp)
cmp    $0x0,%eax
je     12ae <main+0x11e>
mov    0x2d5b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x84(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x80(%rbp)
mov    -0x64(%rbp),%edi
call   1050 <gai_strerror@plt>
mov    -0x84(%rbp),%edi
mov    -0x80(%rbp),%rdx
mov    %rax,%rcx
lea    0xd77(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x50(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xd6e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xd6e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x50(%rbp),%rax
mov    %rax,-0x58(%rbp)
cmpq   $0x0,-0x58(%rbp)
je     1387 <main+0x1f7>
mov    -0x58(%rbp),%rax
mov    (%rax),%rax
mov    0x2ced(%rip),%rcx
cmp    (%rcx),%rax
jne    1310 <main+0x180>
mov    -0x58(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x90(%rbp)
jmp    131f <main+0x18f>
mov    -0x58(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x90(%rbp)
mov    -0x70(%rbp),%rdx
mov    -0x78(%rbp),%rax
mov    -0x90(%rbp),%rcx
mov    %rcx,-0x60(%rbp)
mov    -0x58(%rbp),%rcx
mov    (%rcx),%rdi
mov    -0x60(%rbp),%rsi
mov    %eax,%ecx
call   1030 <inet_ntop@plt>
cmp    $0x0,%rax
jne    1364 <main+0x1d4>
lea    0xcf0(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x70(%rbp),%rsi
lea    0xce1(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x58(%rbp),%rax
mov    0x18(%rax),%rax
mov    %rax,-0x58(%rbp)
jmp    12da <main+0x14a>
lea    0xc84(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x50(%rbp),%rdi
call   10b0 <freeaddrinfo@plt>
xor    %edi,%edi
call   1090 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %rsi,%r15
mov    0x2e05(%rip),%rax
mov    (%rax),%r14d
mov    %rsp,%r13
lea    0xf(%r14),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r13
mov    %r13,%rsp
cmp    $0x2,%edi
jne    12ab <main+0x10b>
lea    -0x58(%rbp),%r12
mov    %r12,%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1070 <memset@plt>
mov    0x2df6(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x58(%rbp)
mov    0x2de0(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    0x2dbc(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x38(%rbp)
mov    0x8(%r15),%rdi
lea    -0x30(%rbp),%rcx
xor    %esi,%esi
mov    %r12,%rdx
call   10b0 <getaddrinfo@plt>
test   %eax,%eax
jne    12cf <main+0x12f>
mov    -0x30(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xdf1(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xdf1(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    -0x30(%rbp),%rbx
test   %rbx,%rbx
je     1291 <main+0xf1>
lea    0xdf1(%rip),%r15
nop
mov    (%rbx),%rdi
mov    0x10(%rbx),%rsi
mov    %r13,%rdx
mov    %r14d,%ecx
call   1030 <inet_ntop@plt>
test   %rax,%rax
je     1303 <main+0x163>
mov    %r15,%rdi
mov    %r13,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x18(%rbx),%rbx
test   %rbx,%rbx
jne    1260 <main+0xc0>
mov    $0xa,%edi
call   1040 <putchar@plt>
mov    -0x30(%rbp),%rdi
call   10c0 <freeaddrinfo@plt>
xor    %edi,%edi
call   10a0 <exit@plt>
mov    0x2d1e(%rip),%rax
mov    (%rax),%edi
mov    (%r15),%rdx
lea    0xd42(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    0x2cfa(%rip),%rcx
mov    (%rcx),%ebx
mov    0x8(%r15),%r14
mov    %eax,%edi
call   1060 <gai_strerror@plt>
lea    0xd2a(%rip),%rsi
mov    %ebx,%edi
mov    %r14,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
lea    0xd3b(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
%struct.addrinfo = type { i64, i8*, i64, %struct.addrinfo*, i32, i32 }
%struct.sockaddr_in = type { i32 }
%struct.sockaddr_in6 = type { i32 }
@NI_MAXHOST = global i32 0
@stderr = global i32 0
@.str = [20 x i8] c"usage: %s hostname\0A\00"
@PF_UNSPEC = global i64 0
@AI_CANONNAME = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [23 x i8] c"host %s not found: %s\0A\00"
@.str.2 = [14 x i8] c"Hostname:\09%s\0A\00"
@.str.3 = [12 x i8] c"Addresses:\09\00"
@AF_INET = global i64 0
@.str.4 = [11 x i8] c"inet_ntop:\00"
@.str.5 = [4 x i8] c"%s \00"
@.str.6 = [2 x i8] c"\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i64
%8 = alloca %struct.addrinfo
%9 = alloca %struct.addrinfo*
%10 = alloca %struct.addrinfo*
%11 = alloca i8*
%12 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = load i32, i32* @NI_MAXHOST
%14 = zext i32 %13 to i64
%15 = call i8* @llvm.stacksave()
store i8* %15, i8** %6
%16 = alloca i8, i64 %14
store i64 %14, i64* %7
%17 = load i32, i32* %4
%18 = icmp ne i32 %17, 2
br i1 %18, label %19, label %26
19: ; preds = %2
%20 = load i32, i32* @stderr
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 0
%23 = load i8*, i8** %22
%24 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %20, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %23)
%25 = call i32 @exit(i32 1)
unreachable
26: ; preds = %2
%27 = bitcast %struct.addrinfo* %8 to i8*
%28 = call i32 @memset(i8* %27, i32 0, i32 40)
%29 = load i64, i64* @PF_UNSPEC
%30 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %8, i32 0, i32 0
store i64 %29, i64* %30
%31 = load i32, i32* @AI_CANONNAME
%32 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %8, i32 0, i32 5
store i32 %31, i32* %32
%33 = load i32, i32* @SOCK_STREAM
%34 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %8, i32 0, i32 4
store i32 %33, i32* %34
%35 = load i8**, i8*** %5
%36 = getelementptr inbounds i8*, i8** %35, i64 1
%37 = load i8*, i8** %36
%38 = call i32 @getaddrinfo(i8* %37, i8* null, %struct.addrinfo* %8, %struct.addrinfo** %9)
store i32 %38, i32* %12
%39 = icmp ne i32 %38, 0
br i1 %39, label %40, label %49
40: ; preds = %26
%41 = load i32, i32* @stderr
%42 = load i8**, i8*** %5
%43 = getelementptr inbounds i8*, i8** %42, i64 1
%44 = load i8*, i8** %43
%45 = load i32, i32* %12
%46 = call i8* @gai_strerror(i32 %45)
%47 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %41, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %44, i8* %46)
%48 = call i32 @exit(i32 1)
unreachable
49: ; preds = %26
%50 = load %struct.addrinfo*, %struct.addrinfo** %9
%51 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %50, i32 0, i32 1
%52 = load i8*, i8** %51
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i8* %52)
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
%55 = load %struct.addrinfo*, %struct.addrinfo** %9
store %struct.addrinfo* %55, %struct.addrinfo** %10
br label %56
56: ; preds = %93, %49
%57 = load %struct.addrinfo*, %struct.addrinfo** %10
%58 = icmp ne %struct.addrinfo* %57, null
br i1 %58, label %59, label %97
59: ; preds = %56
%60 = load %struct.addrinfo*, %struct.addrinfo** %10
%61 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %60, i32 0, i32 0
%62 = load i64, i64* %61
%63 = load i64, i64* @AF_INET
%64 = icmp eq i64 %62, %63
br i1 %64, label %65, label %72
65: ; preds = %59
%66 = load %struct.addrinfo*, %struct.addrinfo** %10
%67 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %66, i32 0, i32 2
%68 = load i64, i64* %67
%69 = inttoptr i64 %68 to %struct.sockaddr_in*
%70 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %69, i32 0, i32 0
%71 = bitcast i32* %70 to i8*
br label %79
72: ; preds = %59
%73 = load %struct.addrinfo*, %struct.addrinfo** %10
%74 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %73, i32 0, i32 2
%75 = load i64, i64* %74
%76 = inttoptr i64 %75 to %struct.sockaddr_in6*
%77 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %76, i32 0, i32 0
%78 = bitcast i32* %77 to i8*
br label %79
79: ; preds = %72, %65
%80 = phi i8* [ %71, %65 ], [ %78, %72 ]
store i8* %80, i8** %11
%81 = load %struct.addrinfo*, %struct.addrinfo** %10
%82 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %81, i32 0, i32 0
%83 = load i64, i64* %82
%84 = load i8*, i8** %11
%85 = trunc i64 %14 to i32
%86 = call i64 @inet_ntop(i64 %83, i8* %84, i8* %16, i32 %85)
%87 = icmp eq i64 %86, 0
br i1 %87, label %88, label %91
88: ; preds = %79
%89 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0))
%90 = call i32 @exit(i32 1)
unreachable
91: ; preds = %79
%92 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i8* %16)
br label %93
93: ; preds = %91
%94 = load %struct.addrinfo*, %struct.addrinfo** %10
%95 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %94, i32 0, i32 3
%96 = load %struct.addrinfo*, %struct.addrinfo** %95
store %struct.addrinfo* %96, %struct.addrinfo** %10
br label %56
97: ; preds = %56
%98 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%99 = load %struct.addrinfo*, %struct.addrinfo** %9
%100 = call i32 @freeaddrinfo(%struct.addrinfo* %99)
%101 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
%struct.addrinfo = type { i64, i8*, i64, %struct.addrinfo*, i32, i32 }
@NI_MAXHOST = global i32 0
@stderr = global i32 0
@.str = [20 x i8] c"usage: %s hostname\0A\00"
@PF_UNSPEC = global i64 0
@AI_CANONNAME = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [23 x i8] c"host %s not found: %s\0A\00"
@.str.2 = [14 x i8] c"Hostname:\09%s\0A\00"
@.str.3 = [12 x i8] c"Addresses:\09\00"
@AF_INET = global i64 0
@.str.4 = [11 x i8] c"inet_ntop:\00"
@.str.5 = [4 x i8] c"%s \00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.addrinfo
%4 = alloca %struct.addrinfo*
%5 = load i32, i32* @NI_MAXHOST
%6 = zext i32 %5 to i64
%7 = alloca i8, i64 %6
%8 = bitcast %struct.addrinfo* %3 to i8*
%9 = bitcast %struct.addrinfo** %4 to i8*
%10 = icmp eq i32 %0, 2
br i1 %10, label %16, label %11
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = load i8*, i8** %1
%14 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %13)
%15 = tail call i32 @exit(i32 1)
unreachable
16: ; preds = %2
%17 = call i32 @memset(i8* %8, i32 0, i32 40)
%18 = load i64, i64* @PF_UNSPEC
%19 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i64 0, i32 0
store i64 %18, i64* %19
%20 = load i32, i32* @AI_CANONNAME
%21 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i64 0, i32 5
store i32 %20, i32* %21
%22 = load i32, i32* @SOCK_STREAM
%23 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i64 0, i32 4
store i32 %22, i32* %23
%24 = getelementptr inbounds i8*, i8** %1, i64 1
%25 = load i8*, i8** %24
%26 = call i32 @getaddrinfo(i8* %25, i8* null, %struct.addrinfo* %3, %struct.addrinfo** %4)
%27 = icmp eq i32 %26, 0
br i1 %27, label %34, label %28
28: ; preds = %16
%29 = load i32, i32* @stderr
%30 = load i8*, i8** %24
%31 = call i8* @gai_strerror(i32 %26)
%32 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %29, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %30, i8* %31)
%33 = call i32 @exit(i32 1)
unreachable
34: ; preds = %16
%35 = load %struct.addrinfo*, %struct.addrinfo** %4
%36 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %35, i64 0, i32 1
%37 = load i8*, i8** %36
%38 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i8* %37)
%39 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
%40 = load %struct.addrinfo*, %struct.addrinfo** %4
%41 = icmp eq %struct.addrinfo* %40, null
br i1 %41, label %59, label %42
42: ; preds = %34, %54
%43 = phi %struct.addrinfo* [ %57, %54 ], [ %40, %34 ]
%44 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %43, i64 0, i32 0
%45 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %43, i64 0, i32 2
%46 = load i64, i64* %45
%47 = inttoptr i64 %46 to i8*
%48 = load i64, i64* %44
%49 = call i64 @inet_ntop(i64 %48, i8* %47, i8* %7, i32 %5)
%50 = icmp eq i64 %49, 0
br i1 %50, label %51, label %54
51: ; preds = %42
%52 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0))
%53 = call i32 @exit(i32 1)
unreachable
54: ; preds = %42
%55 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i8* %7)
%56 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %43, i64 0, i32 3
%57 = load %struct.addrinfo*, %struct.addrinfo** %56
%58 = icmp eq %struct.addrinfo* %57, null
br i1 %58, label %59, label %42
59: ; preds = %54, %34
%60 = call i32 @putchar(i32 10)
%61 = load %struct.addrinfo*, %struct.addrinfo** %4
%62 = call i32 @freeaddrinfo(%struct.addrinfo* %61)
%63 = call i32 @exit(i32 0)
unreachable
}