#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 {
  int ai_family;
  int ai_socktype;
  int ai_protocol;
  struct addrinfo *ai_next;
  scalar_t__ ai_flags;
};

/* Variables and functions */
int AF_UNSPEC;
int 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 **);
int /*<<< orphan*/ memset(struct addrinfo *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, int, int, int);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  struct addrinfo hints;
  struct addrinfo *result;
  struct addrinfo *rp;
  int s;
  if (argc != 3) {
    fprintf(stderr, "Usage: %s host port\n", argv[0]);
    exit(1);
  }
  memset(&hints, 0, sizeof(struct addrinfo));
  hints.ai_family = AF_UNSPEC;
  hints.ai_socktype = SOCK_STREAM;
  hints.ai_flags = 0;
  hints.ai_protocol = 0;
  s = getaddrinfo(argv[1], argv[2], &hints, &result);
  if (s != 0) {
    fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(s));
    exit(1);
  }
  for (rp = result; rp != NULL; rp = rp->ai_next) {
    printf("(family = %2d, socktype = %2d, protocol = %2d)\n", rp->ai_family,
           rp->ai_socktype, rp->ai_protocol);
  }
  freeaddrinfo(result);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     11b6 <main+0x46>
mov    0x2e41(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe59(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1050 <memset@plt>
mov    0x2e1b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
mov    0x2df7(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
movq   $0x0,-0x18(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
lea    -0x30(%rbp),%rdx
lea    -0x38(%rbp),%rcx
call   1080 <getaddrinfo@plt>
mov    %eax,-0x44(%rbp)
cmpl   $0x0,-0x44(%rbp)
je     1247 <main+0xd7>
mov    0x2dba(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x48(%rbp)
mov    -0x44(%rbp),%edi
call   1040 <gai_strerror@plt>
mov    -0x48(%rbp),%edi
mov    %rax,%rdx
lea    0xddd(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x38(%rbp),%rax
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
je     128b <main+0x11b>
mov    -0x40(%rbp),%rax
mov    (%rax),%esi
mov    -0x40(%rbp),%rax
mov    0x4(%rax),%edx
mov    -0x40(%rbp),%rax
mov    0x8(%rax),%ecx
lea    0xdb1(%rip),%rdi
call   1030 <printf@plt>
mov    -0x40(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x40(%rbp)
jmp    124f <main+0xdf>
mov    -0x38(%rbp),%rdi
call   1090 <freeaddrinfo@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    %rsi,%rbx
cmp    $0x3,%edi
jne    1220 <main+0xb0>
lea    0x8(%rsp),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1050 <memset@plt>
mov    0x2e4a(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x8(%rsp)
mov    0x2e25(%rip),%rax
mov    (%rax),%eax
mov    %eax,0xc(%rsp)
movq   $0x0,0x20(%rsp)
movl   $0x0,0x10(%rsp)
mov    0x8(%rbx),%rdi
mov    0x10(%rbx),%rsi
mov    %rsp,%rcx
mov    %r14,%rdx
call   1080 <getaddrinfo@plt>
test   %eax,%eax
jne    1235 <main+0xc5>
mov    (%rsp),%rbx
test   %rbx,%rbx
je     120f <main+0x9f>
lea    0xe3d(%rip),%r14
nopl   0x0(%rax)
mov    (%rbx),%esi
mov    0x4(%rbx),%edx
mov    0x8(%rbx),%ecx
mov    %r14,%rdi
call   1030 <printf@plt>
mov    0x10(%rbx),%rbx
test   %rbx,%rbx
jne    11f0 <main+0x80>
mov    (%rsp),%rdi
jmp    1211 <main+0xa1>
xor    %edi,%edi
call   1090 <freeaddrinfo@plt>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r14
ret
mov    0x2db1(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xdcd(%rip),%rsi
jmp    1251 <main+0xe1>
mov    0x2d9c(%rip),%rcx
mov    (%rcx),%ebx
mov    %eax,%edi
call   1040 <gai_strerror@plt>
lea    0xdc9(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

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

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