#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[0]);
    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("%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     11c6 <main+0x46>
mov    0x2e31(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe49(%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    0x2e0d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    0x2de9(%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     1242 <main+0xc2>
mov    0x2dbf(%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    0xde1(%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     1294 <main+0x114>
mov    0x2d8c(%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    0xda3(%rip),%rdi
call   1040 <printf@plt>
mov    -0x38(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x38(%rbp)
jmp    124a <main+0xca>
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    11f7 <main+0x77>
mov    (%rsp),%rbx
test   %rbx,%rbx
jne    1222 <main+0xa2>
xor    %edi,%edi
jmp    125b <main+0xdb>
mov    0x2def(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xe0b(%rip),%rsi
jmp    1213 <main+0x93>
mov    0x2dda(%rip),%rcx
mov    (%rcx),%ebx
mov    %eax,%edi
call   1050 <gai_strerror@plt>
lea    0xe06(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
lea    0x20(%rsp),%r12
lea    0xdf3(%rip),%r14
xchg   %ax,%ax
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 = [4 x i8] c"%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 0
%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 ([4 x i8], [4 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 = [4 x i8] c"%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 %12, label %7
7: ; preds = %2
%8 = load i32, i32* @stderr
%9 = load i8*, i8** %1
%10 = tail call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %9)
%11 = tail call i32 @exit(i32 1)
unreachable
12: ; preds = %2
%13 = bitcast %struct.addrinfo** %3 to i8*
%14 = bitcast %struct.addrinfo* %4 to i8*
%15 = getelementptr inbounds [16 x i8], [16 x i8]* %5, i64 0, i64 0
%16 = call i32 @bzero(%struct.addrinfo* %4, i32 24)
%17 = load i32, i32* @AF_INET
%18 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %4, i64 0, i32 3
store i32 %17, i32* %18
%19 = load i32, i32* @SOCK_STREAM
%20 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %4, i64 0, i32 2
store i32 %19, i32* %20
%21 = getelementptr inbounds i8*, i8** %1, i64 1
%22 = load i8*, i8** %21
%23 = call i32 @getaddrinfo(i8* %22, i32* null, %struct.addrinfo* %4, %struct.addrinfo** %3)
%24 = icmp eq i32 %23, 0
br i1 %24, label %25, label %28
25: ; preds = %12
%26 = load %struct.addrinfo*, %struct.addrinfo** %3
%27 = icmp eq %struct.addrinfo* %26, null
br i1 %27, label %47, label %33
28: ; preds = %12
%29 = load i32, i32* @stderr
%30 = call i8* @gai_strerror(i32 %23)
%31 = call i32 @fprintf(i32 %29, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* %30)
%32 = call i32 @exit(i32 1)
unreachable
33: ; preds = %25, %33
%34 = phi %struct.addrinfo* [ %43, %33 ], [ %26, %25 ]
%35 = load i32, i32* @AF_INET
%36 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %34, i64 0, i32 0
%37 = load i64, i64* %36
%38 = inttoptr i64 %37 to %struct.sockaddr_in*
%39 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %38, i64 0, i32 0
%40 = call i32 @inet_ntop(i32 %35, i32* %39, i8* %15, i32 16)
%41 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %15)
%42 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %34, i64 0, i32 1
%43 = load %struct.addrinfo*, %struct.addrinfo** %42
%44 = icmp eq %struct.addrinfo* %43, null
br i1 %44, label %45, label %33
45: ; preds = %33
%46 = load %struct.addrinfo*, %struct.addrinfo** %3
br label %47
47: ; preds = %45, %25
%48 = phi %struct.addrinfo* [ %46, %45 ], [ null, %25 ]
%49 = call i32 @freeaddrinfo(%struct.addrinfo* %48)
%50 = call i32 @exit(i32 0)
unreachable
}