#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_in {
  int /*<<< orphan*/ sin_addr;
};
struct addrinfo {
  scalar_t__ ai_addr;
  struct addrinfo *ai_next;
  int /*<<< orphan*/ ai_socktype;
  int /*<<< orphan*/ ai_family;
};
typedef int /*<<< orphan*/ hint;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ bzero(struct addrinfo *, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ freeaddrinfo(struct addrinfo *);
char *gai_strerror(int);
int getaddrinfo(char *, int /*<<< orphan*/ *, struct addrinfo *,
                struct addrinfo **);
int /*<<< orphan*/ inet_ntop(int /*<<< orphan*/, int /*<<< orphan*/ *, char *,
                             int);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  if (argc != 2) {
    fprintf(stderr, "Usage: %s hostname\n", argv[1]);
    exit(1);
  }
  struct addrinfo *answer, hint, *curr;
  char ipstr[16];
  bzero(&hint, sizeof(hint));
  hint.ai_family = AF_INET;
  hint.ai_socktype = SOCK_STREAM;
  int ret = getaddrinfo(argv[1], NULL, &hint, &answer);
  if (ret != 0) {
    fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(ret));
    exit(1);
  }
  for (curr = answer; curr != NULL; curr = curr->ai_next) {
    inet_ntop(AF_INET, &(((struct sockaddr_in *)(curr->ai_addr))->sin_addr),
              ipstr, 16);
    printf("IP: %s\n", ipstr);
  }
  freeaddrinfo(answer);
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11c7 <main+0x47>
mov    0x2e31(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xe48(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
lea    -0x30(%rbp),%rdi
mov    $0x18,%esi
call   1070 <bzero@plt>
mov    0x2e0c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    0x2de8(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
lea    -0x30(%rbp),%rdx
lea    -0x18(%rbp),%rcx
call   1090 <getaddrinfo@plt>
mov    %eax,-0x54(%rbp)
cmpl   $0x0,-0x54(%rbp)
je     1243 <main+0xc3>
mov    0x2dbe(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x58(%rbp)
mov    -0x54(%rbp),%edi
call   1050 <gai_strerror@plt>
mov    -0x58(%rbp),%edi
mov    %rax,%rdx
lea    0xde0(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
je     1295 <main+0x115>
mov    0x2d8b(%rip),%rax
mov    (%rax),%edi
mov    -0x38(%rbp),%rax
mov    (%rax),%rsi
lea    -0x50(%rbp),%rdx
mov    $0x10,%ecx
call   1030 <inet_ntop@plt>
lea    -0x50(%rbp),%rsi
lea    0xda6(%rip),%rdi
call   1040 <printf@plt>
mov    -0x38(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x38(%rbp)
jmp    124b <main+0xcb>
mov    -0x18(%rbp),%rdi
call   10a0 <freeaddrinfo@plt>
xor    %edi,%edi
call   1080 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %rsi,%rbx
cmp    $0x2,%edi
jne    11e2 <main+0x62>
lea    0x8(%rsp),%r14
mov    %r14,%rdi
mov    $0x18,%esi
call   1070 <bzero@plt>
mov    0x2e3c(%rip),%r15
mov    (%r15),%eax
mov    %eax,0x1c(%rsp)
mov    0x2e16(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x18(%rsp)
mov    0x8(%rbx),%rdi
mov    %rsp,%rcx
xor    %esi,%esi
mov    %r14,%rdx
call   1090 <getaddrinfo@plt>
test   %eax,%eax
jne    11f8 <main+0x78>
mov    (%rsp),%rbx
test   %rbx,%rbx
jne    1223 <main+0xa3>
xor    %edi,%edi
jmp    125b <main+0xdb>
mov    0x2def(%rip),%rax
mov    (%rax),%edi
mov    0x8(%rbx),%rdx
lea    0xe0a(%rip),%rsi
jmp    1214 <main+0x94>
mov    0x2dd9(%rip),%rcx
mov    (%rcx),%ebx
mov    %eax,%edi
call   1050 <gai_strerror@plt>
lea    0xe05(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
lea    0x20(%rsp),%r12
lea    0xdf6(%rip),%r14
nop
mov    (%r15),%edi
mov    (%rbx),%rsi
mov    %r12,%rdx
mov    $0x10,%ecx
call   1030 <inet_ntop@plt>
mov    %r14,%rdi
mov    %r12,%rsi
call   1040 <printf@plt>
mov    0x8(%rbx),%rbx
test   %rbx,%rbx
jne    1230 <main+0xb0>
mov    (%rsp),%rdi
call   10a0 <freeaddrinfo@plt>
xor    %edi,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
%struct.addrinfo = type { i64, %struct.addrinfo*, i32, i32 }
%struct.sockaddr_in = type { i32 }
@stderr = global i32 0
@.str = [20 x i8] c"Usage: %s hostname\0A\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [17 x i8] c"getaddrinfo: %s\0A\00"
@.str.2 = [8 x i8] c"IP: %s\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 %struct.addrinfo*
%9 = alloca [16 x i8]
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* %4
%12 = icmp ne i32 %11, 2
br i1 %12, label %13, label %20
13: ; preds = %2
%14 = load i32, i32* @stderr
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
%18 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %17)
%19 = call i32 @exit(i32 1)
unreachable
20: ; preds = %2
%21 = call i32 @bzero(%struct.addrinfo* %7, i32 24)
%22 = load i32, i32* @AF_INET
%23 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %7, i32 0, i32 3
store i32 %22, i32* %23
%24 = load i32, i32* @SOCK_STREAM
%25 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %7, i32 0, i32 2
store i32 %24, i32* %25
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 1
%28 = load i8*, i8** %27
%29 = call i32 @getaddrinfo(i8* %28, i32* null, %struct.addrinfo* %7, %struct.addrinfo** %6)
store i32 %29, i32* %10
%30 = load i32, i32* %10
%31 = icmp ne i32 %30, 0
br i1 %31, label %32, label %38
32: ; preds = %20
%33 = load i32, i32* @stderr
%34 = load i32, i32* %10
%35 = call i8* @gai_strerror(i32 %34)
%36 = call i32 @fprintf(i32 %33, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* %35)
%37 = call i32 @exit(i32 1)
unreachable
38: ; preds = %20
%39 = load %struct.addrinfo*, %struct.addrinfo** %6
store %struct.addrinfo* %39, %struct.addrinfo** %8
br label %40
40: ; preds = %54, %38
%41 = load %struct.addrinfo*, %struct.addrinfo** %8
%42 = icmp ne %struct.addrinfo* %41, null
br i1 %42, label %43, label %58
43: ; preds = %40
%44 = load i32, i32* @AF_INET
%45 = load %struct.addrinfo*, %struct.addrinfo** %8
%46 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %45, i32 0, i32 0
%47 = load i64, i64* %46
%48 = inttoptr i64 %47 to %struct.sockaddr_in*
%49 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %48, i32 0, i32 0
%50 = getelementptr inbounds [16 x i8], [16 x i8]* %9, i64 0, i64 0
%51 = call i32 @inet_ntop(i32 %44, i32* %49, i8* %50, i32 16)
%52 = getelementptr inbounds [16 x i8], [16 x i8]* %9, i64 0, i64 0
%53 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* %52)
br label %54
54: ; preds = %43
%55 = load %struct.addrinfo*, %struct.addrinfo** %8
%56 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %55, i32 0, i32 1
%57 = load %struct.addrinfo*, %struct.addrinfo** %56
store %struct.addrinfo* %57, %struct.addrinfo** %8
br label %40
58: ; preds = %40
%59 = load %struct.addrinfo*, %struct.addrinfo** %6
%60 = call i32 @freeaddrinfo(%struct.addrinfo* %59)
%61 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
%struct.addrinfo = type { i64, %struct.addrinfo*, i32, i32 }
%struct.sockaddr_in = type { i32 }
@stderr = global i32 0
@.str = [20 x i8] c"Usage: %s hostname\0A\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [17 x i8] c"getaddrinfo: %s\0A\00"
@.str.2 = [8 x i8] c"IP: %s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.addrinfo*
%4 = alloca %struct.addrinfo
%5 = alloca [16 x i8]
%6 = icmp eq i32 %0, 2
br i1 %6, label %13, label %7
7: ; preds = %2
%8 = load i32, i32* @stderr
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = tail call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %10)
%12 = tail call i32 @exit(i32 1)
unreachable
13: ; preds = %2
%14 = bitcast %struct.addrinfo** %3 to i8*
%15 = bitcast %struct.addrinfo* %4 to i8*
%16 = getelementptr inbounds [16 x i8], [16 x i8]* %5, i64 0, i64 0
%17 = call i32 @bzero(%struct.addrinfo* %4, i32 24)
%18 = load i32, i32* @AF_INET
%19 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %4, i64 0, i32 3
store i32 %18, i32* %19
%20 = load i32, i32* @SOCK_STREAM
%21 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %4, i64 0, i32 2
store i32 %20, i32* %21
%22 = getelementptr inbounds i8*, i8** %1, i64 1
%23 = load i8*, i8** %22
%24 = call i32 @getaddrinfo(i8* %23, i32* null, %struct.addrinfo* %4, %struct.addrinfo** %3)
%25 = icmp eq i32 %24, 0
br i1 %25, label %26, label %29
26: ; preds = %13
%27 = load %struct.addrinfo*, %struct.addrinfo** %3
%28 = icmp eq %struct.addrinfo* %27, null
br i1 %28, label %48, label %34
29: ; preds = %13
%30 = load i32, i32* @stderr
%31 = call i8* @gai_strerror(i32 %24)
%32 = call i32 @fprintf(i32 %30, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* %31)
%33 = call i32 @exit(i32 1)
unreachable
34: ; preds = %26, %34
%35 = phi %struct.addrinfo* [ %44, %34 ], [ %27, %26 ]
%36 = load i32, i32* @AF_INET
%37 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %35, i64 0, i32 0
%38 = load i64, i64* %37
%39 = inttoptr i64 %38 to %struct.sockaddr_in*
%40 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %39, i64 0, i32 0
%41 = call i32 @inet_ntop(i32 %36, i32* %40, i8* %16, i32 16)
%42 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* %16)
%43 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %35, i64 0, i32 1
%44 = load %struct.addrinfo*, %struct.addrinfo** %43
%45 = icmp eq %struct.addrinfo* %44, null
br i1 %45, label %46, label %34
46: ; preds = %34
%47 = load %struct.addrinfo*, %struct.addrinfo** %3
br label %48
48: ; preds = %46, %26
%49 = phi %struct.addrinfo* [ %47, %46 ], [ null, %26 ]
%50 = call i32 @freeaddrinfo(%struct.addrinfo* %49)
%51 = call i32 @exit(i32 0)
unreachable
}