#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 {
  struct addrinfo *ai_next;
  int /*<<< orphan*/ ai_socktype;
  int /*<<< orphan*/ ai_family;
};

/* Variables and functions */
int /*<<< orphan*/ AF_UNSPEC;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ freeaddrinfo(struct addrinfo *);
char *gai_strerror(int);
int getaddrinfo(char const *, int /*<<< orphan*/ *, struct addrinfo *,
                struct addrinfo **);
int /*<<< orphan*/ memset(struct addrinfo *, int /*<<< orphan*/, int);
int /*<<< orphan*/ print_address(struct addrinfo *);
int /*<<< orphan*/ printf(char *, char const *);
int /*<<< orphan*/ stderr;
int main(int argc, const char *argv[]) {
  struct addrinfo hints, *result, *iterator;
  int status;
  if (argc < 2) {
    fprintf(stderr, "usage: ip hostname\n");
    return 1;
  }
  memset(&hints, 0, sizeof hints);
  hints.ai_family = AF_UNSPEC;
  hints.ai_socktype = SOCK_STREAM;
  status = getaddrinfo(argv[1], NULL, &hints, &result);
  if (status != 0) {
    fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(status));
    return 2;
  }
  printf("IP addresses for %s:\n\n", argv[1]);
  for (iterator = result; iterator != NULL; iterator = iterator->ai_next) {
    print_address(iterator);
  }
  freeaddrinfo(result);
  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    11b3 <main+0x43>
mov    0x2e41(%rip),%rax
mov    (%rax),%edi
lea    0xe60(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1285 <main+0x115>
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1060 <memset@plt>
mov    0x2e1e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    0x2dfa(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
lea    -0x20(%rbp),%rdx
lea    -0x28(%rbp),%rcx
call   1080 <getaddrinfo@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
je     1235 <main+0xc5>
mov    0x2dd0(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x38(%rbp)
mov    -0x34(%rbp),%edi
call   1050 <gai_strerror@plt>
mov    -0x38(%rbp),%edi
mov    %rax,%rdx
lea    0xdf2(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
movl   $0x2,-0x4(%rbp)
jmp    1285 <main+0x115>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xde1(%rip),%rdi
call   1040 <printf@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     1275 <main+0x105>
mov    -0x30(%rbp),%rdi
call   1030 <print_address@plt>
mov    -0x30(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x30(%rbp)
jmp    1251 <main+0xe1>
mov    -0x28(%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   %r14
push   %rbx
sub    $0x18,%rsp
cmp    $0x1,%edi
jg     119e <main+0x2e>
mov    0x2e55(%rip),%rax
mov    (%rax),%edi
lea    0xe74(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    $0x1,%r14d
jmp    124d <main+0xdd>
mov    %rsi,%rbx
lea    0x8(%rsp),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1060 <memset@plt>
mov    0x2e2c(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x14(%rsp)
mov    0x2e07(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x10(%rsp)
mov    0x8(%rbx),%rdi
mov    %rsp,%rcx
xor    %esi,%esi
mov    %r14,%rdx
call   1080 <getaddrinfo@plt>
test   %eax,%eax
je     120f <main+0x9f>
mov    0x2ded(%rip),%rcx
mov    (%rcx),%ebx
mov    %eax,%edi
call   1050 <gai_strerror@plt>
lea    0xe19(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    $0x2,%r14d
jmp    124d <main+0xdd>
mov    0x8(%rbx),%rsi
lea    0xe0b(%rip),%rdi
call   1040 <printf@plt>
mov    (%rsp),%rbx
xor    %r14d,%r14d
test   %rbx,%rbx
je     1246 <main+0xd6>
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1030 <print_address@plt>
mov    (%rbx),%rbx
test   %rbx,%rbx
jne    1230 <main+0xc0>
mov    (%rsp),%rdi
jmp    1248 <main+0xd8>
xor    %edi,%edi
call   1090 <freeaddrinfo@plt>
mov    %r14d,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
%struct.addrinfo = type { %struct.addrinfo*, i32, i32 }
@stderr = global i32 0
@.str = [20 x i8] c"usage: ip hostname\0A\00"
@AF_UNSPEC = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [17 x i8] c"getaddrinfo: %s\0A\00"
@.str.2 = [23 x i8] c"IP addresses for %s:\0A\0A\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 %11
8: ; preds = %2
%9 = load i32, i32* @stderr
%10 = tail call i32 (i32, i8*, ...) @fprintf(i32 %9, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
br label %41
11: ; preds = %2
%12 = call i32 @memset(%struct.addrinfo* %3, i32 0, i32 16)
%13 = load i32, i32* @AF_UNSPEC
%14 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i64 0, i32 2
store i32 %13, i32* %14
%15 = load i32, i32* @SOCK_STREAM
%16 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i64 0, i32 1
store i32 %15, i32* %16
%17 = getelementptr inbounds i8*, i8** %1, i64 1
%18 = load i8*, i8** %17
%19 = call i32 @getaddrinfo(i8* %18, i32* null, %struct.addrinfo* %3, %struct.addrinfo** %4)
%20 = icmp eq i32 %19, 0
br i1 %20, label %25, label %21
21: ; preds = %11
%22 = load i32, i32* @stderr
%23 = call i8* @gai_strerror(i32 %19)
%24 = call i32 (i32, i8*, ...) @fprintf(i32 %22, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* %23)
br label %41
25: ; preds = %11
%26 = load i8*, i8** %17
%27 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i8* %26)
%28 = load %struct.addrinfo*, %struct.addrinfo** %4
%29 = icmp eq %struct.addrinfo* %28, null
br i1 %29, label %38, label %30
30: ; preds = %25, %30
%31 = phi %struct.addrinfo* [ %34, %30 ], [ %28, %25 ]
%32 = call i32 @print_address(%struct.addrinfo* %31)
%33 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %31, i64 0, i32 0
%34 = load %struct.addrinfo*, %struct.addrinfo** %33
%35 = icmp eq %struct.addrinfo* %34, null
br i1 %35, label %36, label %30
36: ; preds = %30
%37 = load %struct.addrinfo*, %struct.addrinfo** %4
br label %38
38: ; preds = %36, %25
%39 = phi %struct.addrinfo* [ %37, %36 ], [ null, %25 ]
%40 = call i32 @freeaddrinfo(%struct.addrinfo* %39)
br label %41
41: ; preds = %38, %21, %8
%42 = phi i32 [ 1, %8 ], [ 2, %21 ], [ 0, %38 ]
ret i32 %42
}