#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 */
typedef struct TYPE_2__ TYPE_1__;

/* Type definitions */
struct TYPE_2__ {
  int s_addr;
};
struct sockaddr_in {
  TYPE_1__ sin_addr;
};
struct hostent {
  scalar_t__ *h_addr_list;
};
struct addrinfo {
  char *ai_canonname;
  scalar_t__ ai_addr;
  int /*<<< orphan*/ ai_family;
  int /*<<< orphan*/ ai_flags;
};

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ AI_CANONNAME;
scalar_t__ calloc(int, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ free(struct addrinfo *);
int /*<<< orphan*/ freeaddrinfo(struct addrinfo *);
char *gai_strerror(int);
int getaddrinfo(char *, int /*<<< orphan*/ *, struct addrinfo *,
                struct addrinfo **);
struct hostent *gethostbyname(char *);
int gethostname(char *, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcpy(char *, char *);
int main(int argc, char **argv) {
  int i, got;
  char host[1024];
  struct hostent *hostent;
  struct addrinfo *hints = NULL, *addrinfo = NULL;
  struct sockaddr_in *p;
  if (argc > 1)
    strcpy(host, argv[1]);
  else {
    fprintf(stderr, "calling gethostname() ...\n");
    if (gethostname(host, 1024) == -1) {
      perror("gethostname");
      exit(1);
    } else {
      fprintf(stderr, "host name is %s\n", host);
    }
  }
  fprintf(stderr, "\n");
  fprintf(stderr, "calling getaddrinfo (preferred) ...\n");
  hints = (struct addrinfo *)calloc(1, sizeof(struct addrinfo));
  hints->ai_flags |= AI_CANONNAME;
  hints->ai_family = AF_INET;
  got = getaddrinfo(host, NULL, hints, &addrinfo);
  if (got != 0) {
    fprintf(stderr, "getaddrinfo rtn: %d %s\n", got, gai_strerror(got));
    perror("getaddrinfo");
    exit(1);
  } else {
    fprintf(stderr, "getaddrinfo() succeeded\n");
  }
  fprintf(stderr, "printing ip address via getaddrinfo ...\n");
  if (addrinfo) {
    p = (struct sockaddr_in *)(addrinfo->ai_addr);
    fprintf(stderr, "%x (canonical: %s)\n", p->sin_addr.s_addr,
            addrinfo->ai_canonname);
    freeaddrinfo(addrinfo);
    if (hints)
      free(hints);
  } else {
    fprintf(stderr, "ERROR: can't look up: %s\n", host);
  }
  fprintf(stderr, "\n");
  fprintf(stderr, "calling gethostbyname (obsolete) ...\n");
  if (!(hostent = gethostbyname(host))) {
    perror("gethostbyname");
    exit(1);
  } else {
    fprintf(stderr, "gethostbyname() succeeded\n");
  }
  fprintf(stderr, "printing ip address(es) via gethostbyname ...\n");
  if (hostent) {
    for (i = 0; hostent->h_addr_list[i]; i++) {
      fprintf(stderr, "%x\n", *(int *)hostent->h_addr_list[i]);
    }
  } else {
    fprintf(stderr, "ERROR: can't look up: %s\n", host);
  }
  fprintf(stderr, "\n");
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x450,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x430(%rbp)
movq   $0x0,-0x438(%rbp)
cmpl   $0x1,-0x8(%rbp)
jle    1202 <main+0x52>
lea    -0x420(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
call   1040 <strcpy@plt>
jmp    126c <main+0xbc>
mov    0x2dc7(%rip),%rax
mov    (%rax),%edi
lea    0xdee(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
lea    -0x420(%rbp),%rdi
mov    $0x400,%esi
call   10a0 <gethostname@plt>
cmp    $0xffffffff,%eax
jne    1249 <main+0x99>
lea    0xde1(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    0x2d80(%rip),%rax
mov    (%rax),%edi
lea    -0x420(%rbp),%rdx
lea    0xdc7(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
jmp    126c <main+0xbc>
mov    0x2d5d(%rip),%rax
mov    (%rax),%edi
lea    0xe59(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    0x2d46(%rip),%rax
mov    (%rax),%edi
lea    0xda5(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    $0x1,%edi
mov    $0x18,%esi
call   1060 <calloc@plt>
mov    %rax,-0x430(%rbp)
mov    0x2d29(%rip),%rax
mov    (%rax),%ecx
mov    -0x430(%rbp),%rax
or     0x14(%rax),%ecx
mov    %ecx,0x14(%rax)
mov    0x2d1b(%rip),%rax
mov    (%rax),%ecx
mov    -0x430(%rbp),%rax
mov    %ecx,0x10(%rax)
lea    -0x420(%rbp),%rdi
mov    -0x430(%rbp),%rdx
xor    %eax,%eax
mov    %eax,%esi
lea    -0x438(%rbp),%rcx
call   10c0 <getaddrinfo@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
je     1357 <main+0x1a7>
mov    0x2cc5(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x448(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x444(%rbp)
mov    -0x18(%rbp),%edi
call   1050 <gai_strerror@plt>
mov    -0x448(%rbp),%edi
mov    -0x444(%rbp),%edx
mov    %rax,%rcx
lea    0xd23(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
lea    0xd2d(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    0x2c72(%rip),%rax
mov    (%rax),%edi
lea    0xd1a(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    0x2c5b(%rip),%rax
mov    (%rax),%edi
lea    0xd1c(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
cmpq   $0x0,-0x438(%rbp)
je     13fa <main+0x24a>
mov    -0x438(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x440(%rbp)
mov    0x2c24(%rip),%rax
mov    (%rax),%edi
mov    -0x440(%rbp),%rax
mov    (%rax),%edx
mov    -0x438(%rbp),%rax
mov    (%rax),%rcx
lea    0xcfb(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    -0x438(%rbp),%rdi
call   10d0 <freeaddrinfo@plt>
cmpq   $0x0,-0x430(%rbp)
je     13f5 <main+0x245>
mov    -0x430(%rbp),%rdi
call   1030 <free@plt>
jmp    1418 <main+0x268>
mov    0x2bcf(%rip),%rax
mov    (%rax),%edi
lea    -0x420(%rbp),%rdx
lea    0xcc6(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    0x2bb1(%rip),%rax
mov    (%rax),%edi
lea    0xcad(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    0x2b9a(%rip),%rax
mov    (%rax),%edi
lea    0xcb2(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
lea    -0x420(%rbp),%rdi
call   1070 <gethostbyname@plt>
mov    %rax,-0x428(%rbp)
cmp    $0x0,%rax
jne    1479 <main+0x2c9>
lea    0xcad(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    0x2b50(%rip),%rax
mov    (%rax),%edi
lea    0xc9c(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    0x2b39(%rip),%rax
mov    (%rax),%edi
lea    0xca0(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
cmpq   $0x0,-0x428(%rbp)
je     1513 <main+0x363>
movl   $0x0,-0x14(%rbp)
mov    -0x428(%rbp),%rax
mov    (%rax),%rax
movslq -0x14(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
je     150e <main+0x35e>
mov    0x2af4(%rip),%rax
mov    (%rax),%edi
mov    -0x428(%rbp),%rax
mov    (%rax),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    (%rax),%edx
lea    0xc76(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    14bc <main+0x30c>
jmp    1531 <main+0x381>
mov    0x2ab6(%rip),%rax
mov    (%rax),%edi
lea    -0x420(%rbp),%rdx
lea    0xbad(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    0x2a98(%rip),%rax
mov    (%rax),%edi
lea    0xb94(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
xor    %eax,%eax
add    $0x450,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x410,%rsp
movq   $0x0,0x8(%rsp)
cmp    $0x2,%edi
jl     11dd <main+0x2d>
mov    0x8(%rsi),%rsi
lea    0x10(%rsp),%rdi
call   1040 <strcpy@plt>
jmp    1221 <main+0x71>
mov    0x2dec(%rip),%rbx
mov    (%rbx),%edi
lea    0xe13(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
lea    0x10(%rsp),%rdi
mov    $0x400,%esi
call   10a0 <gethostname@plt>
cmp    $0xffffffff,%eax
je     1407 <main+0x257>
mov    (%rbx),%edi
lea    0xe12(%rip),%rsi
lea    0x10(%rsp),%rdx
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    0x2da8(%rip),%r12
mov    (%r12),%edi
lea    0xea2(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    (%r12),%edi
lea    0xdf3(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    $0x1,%edi
mov    $0x18,%esi
call   1060 <calloc@plt>
mov    %rax,%rbx
mov    0x2d7b(%rip),%rax
mov    (%rax),%eax
or     %eax,0x14(%rbx)
mov    0x2d77(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x10(%rbx)
lea    0x10(%rsp),%rdi
lea    0x8(%rsp),%rcx
xor    %esi,%esi
mov    %rbx,%rdx
call   10c0 <getaddrinfo@plt>
mov    (%r12),%r14d
test   %eax,%eax
jne    13d4 <main+0x224>
lea    0xde4(%rip),%rsi
mov    %r14d,%edi
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    (%r12),%edi
lea    0xde8(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    0x8(%rsp),%rax
test   %rax,%rax
je     12f7 <main+0x147>
mov    (%rax),%rcx
mov    0x8(%rax),%rax
mov    (%r12),%edi
mov    (%rax),%edx
lea    0xdec(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    0x8(%rsp),%rdi
call   10d0 <freeaddrinfo@plt>
test   %rbx,%rbx
je     130e <main+0x15e>
mov    %rbx,%rdi
call   1030 <free@plt>
jmp    130e <main+0x15e>
mov    (%r12),%edi
lea    0xdd5(%rip),%rsi
lea    0x10(%rsp),%rdx
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    (%r12),%edi
lea    0xdbc(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    (%r12),%edi
lea    0xdc6(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
lea    0x10(%rsp),%rdi
call   1070 <gethostbyname@plt>
test   %rax,%rax
je     13fe <main+0x24e>
mov    %rax,%rbx
mov    (%r12),%edi
lea    0xdd2(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    (%r12),%edi
lea    0xddb(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    (%rbx),%rax
mov    (%rax),%rax
test   %rax,%rax
je     13b0 <main+0x200>
mov    $0x8,%ebp
lea    0xdec(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    (%r12),%edi
mov    (%rax),%edx
mov    %r14,%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    (%rbx),%rax
mov    (%rax,%rbp,1),%rax
add    $0x8,%rbp
test   %rax,%rax
jne    1390 <main+0x1e0>
mov    (%r12),%edi
lea    0xd1a(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
xor    %eax,%eax
add    $0x410,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %eax,%r15d
mov    %eax,%edi
call   1050 <gai_strerror@plt>
lea    0xc78(%rip),%rsi
mov    %r14d,%edi
mov    %r15d,%edx
mov    %rax,%rcx
xor    %eax,%eax
call   1080 <fprintf@plt>
lea    0xc79(%rip),%rdi
jmp    140e <main+0x25e>
lea    0xd12(%rip),%rdi
jmp    140e <main+0x25e>
lea    0xc0d(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
%struct.hostent = type { i64* }
%struct.addrinfo = type { i8*, i64, i32, i32 }
%struct.sockaddr_in = type { %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i32 }
@stderr = global i32 0
@.str = [27 x i8] c"calling gethostname() ...\0A\00"
@.str.1 = [12 x i8] c"gethostname\00"
@.str.2 = [17 x i8] c"host name is %s\0A\00"
@.str.3 = [2 x i8] c"\0A\00"
@.str.4 = [37 x i8] c"calling getaddrinfo (preferred) ...\0A\00"
@AI_CANONNAME = global i32 0
@AF_INET = global i32 0
@.str.5 = [24 x i8] c"getaddrinfo rtn: %d %s\0A\00"
@.str.6 = [12 x i8] c"getaddrinfo\00"
@.str.7 = [25 x i8] c"getaddrinfo() succeeded\0A\00"
@.str.8 = [41 x i8] c"printing ip address via getaddrinfo ...\0A\00"
@.str.9 = [20 x i8] c"%x (canonical: %s)\0A\00"
@.str.10 = [26 x i8] c"ERROR: can't look up: %s\0A\00"
@.str.11 = [38 x i8] c"calling gethostbyname (obsolete) ...\0A\00"
@.str.12 = [14 x i8] c"gethostbyname\00"
@.str.13 = [27 x i8] c"gethostbyname() succeeded\0A\00"
@.str.14 = [47 x i8] c"printing ip address(es) via gethostbyname ...\0A\00"
@.str.15 = [4 x i8] c"%x\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca [1024 x i8]
%9 = alloca %struct.hostent*
%10 = alloca %struct.addrinfo*
%11 = alloca %struct.addrinfo*
%12 = alloca %struct.sockaddr_in*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store %struct.addrinfo* null, %struct.addrinfo** %10
store %struct.addrinfo* null, %struct.addrinfo** %11
%13 = load i32, i32* %4
%14 = icmp sgt i32 %13, 1
br i1 %14, label %15, label %21
15: ; preds = %2
%16 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
%20 = call i32 @strcpy(i8* %16, i8* %19)
br label %35
21: ; preds = %2
%22 = load i32, i32* @stderr
%23 = call i32 (i32, i8*, ...) @fprintf(i32 %22, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%24 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%25 = call i32 @gethostname(i8* %24, i32 1024)
%26 = icmp eq i32 %25, -1
br i1 %26, label %27, label %30
27: ; preds = %21
%28 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
%29 = call i32 @exit(i32 1)
unreachable
30: ; preds = %21
%31 = load i32, i32* @stderr
%32 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%33 = call i32 (i32, i8*, ...) @fprintf(i32 %31, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8* %32)
br label %34
34: ; preds = %30
br label %35
35: ; preds = %34, %15
%36 = load i32, i32* @stderr
%37 = call i32 (i32, i8*, ...) @fprintf(i32 %36, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%38 = load i32, i32* @stderr
%39 = call i32 (i32, i8*, ...) @fprintf(i32 %38, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.4, i64 0, i64 0))
%40 = call i64 @calloc(i32 1, i32 24)
%41 = inttoptr i64 %40 to %struct.addrinfo*
store %struct.addrinfo* %41, %struct.addrinfo** %10
%42 = load i32, i32* @AI_CANONNAME
%43 = load %struct.addrinfo*, %struct.addrinfo** %10
%44 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %43, i32 0, i32 3
%45 = load i32, i32* %44
%46 = or i32 %45, %42
store i32 %46, i32* %44
%47 = load i32, i32* @AF_INET
%48 = load %struct.addrinfo*, %struct.addrinfo** %10
%49 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %48, i32 0, i32 2
store i32 %47, i32* %49
%50 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%51 = load %struct.addrinfo*, %struct.addrinfo** %10
%52 = call i32 @getaddrinfo(i8* %50, i32* null, %struct.addrinfo* %51, %struct.addrinfo** %11)
store i32 %52, i32* %7
%53 = load i32, i32* %7
%54 = icmp ne i32 %53, 0
br i1 %54, label %55, label %63
55: ; preds = %35
%56 = load i32, i32* @stderr
%57 = load i32, i32* %7
%58 = load i32, i32* %7
%59 = call i8* @gai_strerror(i32 %58)
%60 = call i32 (i32, i8*, ...) @fprintf(i32 %56, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0), i32 %57, i8* %59)
%61 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0))
%62 = call i32 @exit(i32 1)
unreachable
63: ; preds = %35
%64 = load i32, i32* @stderr
%65 = call i32 (i32, i8*, ...) @fprintf(i32 %64, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.7, i64 0, i64 0))
br label %66
66: ; preds = %63
%67 = load i32, i32* @stderr
%68 = call i32 (i32, i8*, ...) @fprintf(i32 %67, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.8, i64 0, i64 0))
%69 = load %struct.addrinfo*, %struct.addrinfo** %11
%70 = icmp ne %struct.addrinfo* %69, null
br i1 %70, label %71, label %93
71: ; preds = %66
%72 = load %struct.addrinfo*, %struct.addrinfo** %11
%73 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %72, i32 0, i32 1
%74 = load i64, i64* %73
%75 = inttoptr i64 %74 to %struct.sockaddr_in*
store %struct.sockaddr_in* %75, %struct.sockaddr_in** %12
%76 = load i32, i32* @stderr
%77 = load %struct.sockaddr_in*, %struct.sockaddr_in** %12
%78 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %77, i32 0, i32 0
%79 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %78, i32 0, i32 0
%80 = load i32, i32* %79
%81 = load %struct.addrinfo*, %struct.addrinfo** %11
%82 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %81, i32 0, i32 0
%83 = load i8*, i8** %82
%84 = call i32 (i32, i8*, ...) @fprintf(i32 %76, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.9, i64 0, i64 0), i32 %80, i8* %83)
%85 = load %struct.addrinfo*, %struct.addrinfo** %11
%86 = call i32 @freeaddrinfo(%struct.addrinfo* %85)
%87 = load %struct.addrinfo*, %struct.addrinfo** %10
%88 = icmp ne %struct.addrinfo* %87, null
br i1 %88, label %89, label %92
89: ; preds = %71
%90 = load %struct.addrinfo*, %struct.addrinfo** %10
%91 = call i32 @free(%struct.addrinfo* %90)
br label %92
92: ; preds = %89, %71
br label %97
93: ; preds = %66
%94 = load i32, i32* @stderr
%95 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%96 = call i32 (i32, i8*, ...) @fprintf(i32 %94, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.10, i64 0, i64 0), i8* %95)
br label %97
97: ; preds = %93, %92
%98 = load i32, i32* @stderr
%99 = call i32 (i32, i8*, ...) @fprintf(i32 %98, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%100 = load i32, i32* @stderr
%101 = call i32 (i32, i8*, ...) @fprintf(i32 %100, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.11, i64 0, i64 0))
%102 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%103 = call %struct.hostent* @gethostbyname(i8* %102)
store %struct.hostent* %103, %struct.hostent** %9
%104 = icmp ne %struct.hostent* %103, null
br i1 %104, label %108, label %105
105: ; preds = %97
%106 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.12, i64 0, i64 0))
%107 = call i32 @exit(i32 1)
unreachable
108: ; preds = %97
%109 = load i32, i32* @stderr
%110 = call i32 (i32, i8*, ...) @fprintf(i32 %109, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.13, i64 0, i64 0))
br label %111
111: ; preds = %108
%112 = load i32, i32* @stderr
%113 = call i32 (i32, i8*, ...) @fprintf(i32 %112, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.14, i64 0, i64 0))
%114 = load %struct.hostent*, %struct.hostent** %9
%115 = icmp ne %struct.hostent* %114, null
br i1 %115, label %116, label %142
116: ; preds = %111
store i32 0, i32* %6
br label %117
117: ; preds = %138, %116
%118 = load %struct.hostent*, %struct.hostent** %9
%119 = getelementptr inbounds %struct.hostent, %struct.hostent* %118, i32 0, i32 0
%120 = load i64*, i64** %119
%121 = load i32, i32* %6
%122 = sext i32 %121 to i64
%123 = getelementptr inbounds i64, i64* %120, i64 %122
%124 = load i64, i64* %123
%125 = icmp ne i64 %124, 0
br i1 %125, label %126, label %141
126: ; preds = %117
%127 = load i32, i32* @stderr
%128 = load %struct.hostent*, %struct.hostent** %9
%129 = getelementptr inbounds %struct.hostent, %struct.hostent* %128, i32 0, i32 0
%130 = load i64*, i64** %129
%131 = load i32, i32* %6
%132 = sext i32 %131 to i64
%133 = getelementptr inbounds i64, i64* %130, i64 %132
%134 = load i64, i64* %133
%135 = inttoptr i64 %134 to i32*
%136 = load i32, i32* %135
%137 = call i32 (i32, i8*, ...) @fprintf(i32 %127, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.15, i64 0, i64 0), i32 %136)
br label %138
138: ; preds = %126
%139 = load i32, i32* %6
%140 = add nsw i32 %139, 1
store i32 %140, i32* %6
br label %117
141: ; preds = %117
br label %146
142: ; preds = %111
%143 = load i32, i32* @stderr
%144 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%145 = call i32 (i32, i8*, ...) @fprintf(i32 %143, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.10, i64 0, i64 0), i8* %144)
br label %146
146: ; preds = %142, %141
%147 = load i32, i32* @stderr
%148 = call i32 (i32, i8*, ...) @fprintf(i32 %147, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
%struct.addrinfo = type { i8*, i64, i32, i32 }
%struct.sockaddr_in = type { %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i32 }
%struct.hostent = type { i64* }
@stderr = global i32 0
@.str = [27 x i8] c"calling gethostname() ...\0A\00"
@.str.1 = [12 x i8] c"gethostname\00"
@.str.2 = [17 x i8] c"host name is %s\0A\00"
@.str.3 = [2 x i8] c"\0A\00"
@.str.4 = [37 x i8] c"calling getaddrinfo (preferred) ...\0A\00"
@AI_CANONNAME = global i32 0
@AF_INET = global i32 0
@.str.5 = [24 x i8] c"getaddrinfo rtn: %d %s\0A\00"
@.str.6 = [12 x i8] c"getaddrinfo\00"
@.str.7 = [25 x i8] c"getaddrinfo() succeeded\0A\00"
@.str.8 = [41 x i8] c"printing ip address via getaddrinfo ...\0A\00"
@.str.9 = [20 x i8] c"%x (canonical: %s)\0A\00"
@.str.10 = [26 x i8] c"ERROR: can't look up: %s\0A\00"
@.str.11 = [38 x i8] c"calling gethostbyname (obsolete) ...\0A\00"
@.str.12 = [14 x i8] c"gethostbyname\00"
@.str.13 = [27 x i8] c"gethostbyname() succeeded\0A\00"
@.str.14 = [47 x i8] c"printing ip address(es) via gethostbyname ...\0A\00"
@.str.15 = [4 x i8] c"%x\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [1024 x i8]
%4 = alloca %struct.addrinfo*
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%6 = bitcast %struct.addrinfo** %4 to i8*
store %struct.addrinfo* null, %struct.addrinfo** %4
%7 = icmp sgt i32 %0, 1
br i1 %7, label %8, label %12
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = call i32 @strcpy(i8* %5, i8* %10)
br label %23
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = tail call i32 (i32, i8*, ...) @fprintf(i32 %13, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%15 = call i32 @gethostname(i8* %5, i32 1024)
%16 = icmp eq i32 %15, -1
br i1 %16, label %17, label %20
17: ; preds = %12
%18 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
%19 = call i32 @exit(i32 1)
unreachable
20: ; preds = %12
%21 = load i32, i32* @stderr
%22 = call i32 (i32, i8*, ...) @fprintf(i32 %21, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8* %5)
br label %23
23: ; preds = %20, %8
%24 = load i32, i32* @stderr
%25 = call i32 (i32, i8*, ...) @fprintf(i32 %24, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%26 = load i32, i32* @stderr
%27 = call i32 (i32, i8*, ...) @fprintf(i32 %26, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.4, i64 0, i64 0))
%28 = call i64 @calloc(i32 1, i32 24)
%29 = inttoptr i64 %28 to %struct.addrinfo*
%30 = load i32, i32* @AI_CANONNAME
%31 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %29, i64 0, i32 3
%32 = load i32, i32* %31
%33 = or i32 %32, %30
store i32 %33, i32* %31
%34 = load i32, i32* @AF_INET
%35 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %29, i64 0, i32 2
store i32 %34, i32* %35
%36 = call i32 @getaddrinfo(i8* %5, i32* null, %struct.addrinfo* %29, %struct.addrinfo** %4)
%37 = icmp eq i32 %36, 0
%38 = load i32, i32* @stderr
br i1 %37, label %44, label %39
39: ; preds = %23
%40 = call i8* @gai_strerror(i32 %36)
%41 = call i32 (i32, i8*, ...) @fprintf(i32 %38, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0), i32 %36, i8* %40)
%42 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0))
%43 = call i32 @exit(i32 1)
unreachable
44: ; preds = %23
%45 = call i32 (i32, i8*, ...) @fprintf(i32 %38, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.7, i64 0, i64 0))
%46 = load i32, i32* @stderr
%47 = call i32 (i32, i8*, ...) @fprintf(i32 %46, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.8, i64 0, i64 0))
%48 = load %struct.addrinfo*, %struct.addrinfo** %4
%49 = icmp eq %struct.addrinfo* %48, null
br i1 %49, label %65, label %50
50: ; preds = %44
%51 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %48, i64 0, i32 1
%52 = load i64, i64* %51
%53 = inttoptr i64 %52 to %struct.sockaddr_in*
%54 = load i32, i32* @stderr
%55 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %53, i64 0, i32 0, i32 0
%56 = load i32, i32* %55
%57 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %48, i64 0, i32 0
%58 = load i8*, i8** %57
%59 = call i32 (i32, i8*, ...) @fprintf(i32 %54, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.9, i64 0, i64 0), i32 %56, i8* %58)
%60 = load %struct.addrinfo*, %struct.addrinfo** %4
%61 = call i32 @freeaddrinfo(%struct.addrinfo* %60)
%62 = icmp eq i64 %28, 0
br i1 %62, label %68, label %63
63: ; preds = %50
%64 = call i32 @free(%struct.addrinfo* %29)
br label %68
65: ; preds = %44
%66 = load i32, i32* @stderr
%67 = call i32 (i32, i8*, ...) @fprintf(i32 %66, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.10, i64 0, i64 0), i8* %5)
br label %68
68: ; preds = %50, %63, %65
%69 = load i32, i32* @stderr
%70 = call i32 (i32, i8*, ...) @fprintf(i32 %69, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%71 = load i32, i32* @stderr
%72 = call i32 (i32, i8*, ...) @fprintf(i32 %71, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.11, i64 0, i64 0))
%73 = call %struct.hostent* @gethostbyname(i8* %5)
%74 = icmp eq %struct.hostent* %73, null
br i1 %74, label %75, label %78
75: ; preds = %68
%76 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.12, i64 0, i64 0))
%77 = call i32 @exit(i32 1)
unreachable
78: ; preds = %68
%79 = load i32, i32* @stderr
%80 = call i32 (i32, i8*, ...) @fprintf(i32 %79, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.13, i64 0, i64 0))
%81 = load i32, i32* @stderr
%82 = call i32 (i32, i8*, ...) @fprintf(i32 %81, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.14, i64 0, i64 0))
%83 = getelementptr inbounds %struct.hostent, %struct.hostent* %73, i64 0, i32 0
%84 = load i64*, i64** %83
%85 = load i64, i64* %84
%86 = icmp eq i64 %85, 0
br i1 %86, label %99, label %87
87: ; preds = %78, %87
%88 = phi i64 [ %94, %87 ], [ 0, %78 ]
%89 = phi i64 [ %97, %87 ], [ %85, %78 ]
%90 = load i32, i32* @stderr
%91 = inttoptr i64 %89 to i32*
%92 = load i32, i32* %91
%93 = call i32 (i32, i8*, ...) @fprintf(i32 %90, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.15, i64 0, i64 0), i32 %92)
%94 = add nuw i64 %88, 1
%95 = load i64*, i64** %83
%96 = getelementptr inbounds i64, i64* %95, i64 %94
%97 = load i64, i64* %96
%98 = icmp eq i64 %97, 0
br i1 %98, label %99, label %87
99: ; preds = %87, %78
%100 = load i32, i32* @stderr
%101 = call i32 (i32, i8*, ...) @fprintf(i32 %100, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
ret i32 0
}