#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;
  int /*<<< orphan*/ ai_flags;
};
typedef int /*<<< orphan*/ hints;

/* Variables and functions */
int /*<<< orphan*/ AF_UNSPEC;
int /*<<< orphan*/ AI_PASSIVE;
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ EXIT_SUCCESS;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
char *gai_strerror(int);
int getaddrinfo(int /*<<< orphan*/ *, char *, struct addrinfo *,
                struct addrinfo **);
int /*<<< orphan*/ memset(struct addrinfo *, int /*<<< orphan*/, int);
int /*<<< orphan*/ show_addrinfo(struct addrinfo *);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  struct addrinfo hints, *res, *aip;
  int s;
  memset(&hints, 0, sizeof(hints));
  hints.ai_flags = AI_PASSIVE;
  hints.ai_family = AF_UNSPEC;
  hints.ai_socktype = SOCK_STREAM;
  if ((s = getaddrinfo(NULL, argv[1], &hints, &res)) != 0) {
    fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(s));
    exit(EXIT_FAILURE);
  }
  for (aip = res; aip != NULL; aip = aip->ai_next)
    show_addrinfo(aip);
  exit(EXIT_SUCCESS);
}


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)
lea    -0x28(%rbp),%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1050 <memset@plt>
mov    0x2e5b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    0x2e47(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    0x2e23(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
xor    %eax,%eax
mov    %eax,%edi
lea    -0x28(%rbp),%rdx
lea    -0x30(%rbp),%rcx
call   1080 <getaddrinfo@plt>
mov    %eax,-0x3c(%rbp)
cmp    $0x0,%eax
je     1203 <main+0xa3>
mov    0x2dfa(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x40(%rbp)
mov    -0x3c(%rbp),%edi
call   1040 <gai_strerror@plt>
mov    -0x40(%rbp),%edi
mov    %rax,%rdx
lea    0xe10(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2dc4(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    -0x30(%rbp),%rax
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
je     122f <main+0xcf>
mov    -0x38(%rbp),%rdi
call   1030 <show_addrinfo@plt>
mov    -0x38(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x38(%rbp)
jmp    120b <main+0xab>
mov    0x2d82(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    %rsi,%rbx
lea    0x10(%rsp),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1050 <memset@plt>
mov    0x2e63(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x20(%rsp)
mov    0x2e4e(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x1c(%rsp)
mov    0x2e29(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x18(%rsp)
mov    0x8(%rbx),%rsi
lea    0x8(%rsp),%rcx
xor    %edi,%edi
mov    %r14,%rdx
call   1080 <getaddrinfo@plt>
test   %eax,%eax
jne    11ee <main+0x8e>
mov    0x8(%rsp),%rbx
test   %rbx,%rbx
je     11e0 <main+0x80>
cs nopw 0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1030 <show_addrinfo@plt>
mov    (%rbx),%rbx
test   %rbx,%rbx
jne    11d0 <main+0x70>
mov    0x2dd1(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    0x2ddb(%rip),%rcx
mov    (%rcx),%ebx
mov    %eax,%edi
call   1040 <gai_strerror@plt>
lea    0xdfb(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1060 <fprintf@plt>
mov    0x2daa(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

LLVM IR (-O0):
%struct.addrinfo = type { %struct.addrinfo*, i32, i32, i32 }
@AI_PASSIVE = global i32 0
@AF_UNSPEC = global i32 0
@SOCK_STREAM = global i32 0
@stderr = global i32 0
@.str = [17 x i8] c"getaddrinfo: %s\0A\00"
@EXIT_FAILURE = global i32 0
@EXIT_SUCCESS = global i32 0
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 = call i32 @memset(%struct.addrinfo* %6, i32 0, i32 24)
%11 = load i32, i32* @AI_PASSIVE
%12 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %6, i32 0, i32 3
store i32 %11, i32* %12
%13 = load i32, i32* @AF_UNSPEC
%14 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %6, i32 0, i32 2
store i32 %13, i32* %14
%15 = load i32, i32* @SOCK_STREAM
%16 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %6, i32 0, i32 1
store i32 %15, i32* %16
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
%20 = call i32 @getaddrinfo(i32* null, i8* %19, %struct.addrinfo* %6, %struct.addrinfo** %7)
store i32 %20, i32* %9
%21 = icmp ne i32 %20, 0
br i1 %21, label %22, label %29
22: ; preds = %2
%23 = load i32, i32* @stderr
%24 = load i32, i32* %9
%25 = call i8* @gai_strerror(i32 %24)
%26 = call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %25)
%27 = load i32, i32* @EXIT_FAILURE
%28 = call i32 @exit(i32 %27)
unreachable
29: ; preds = %2
%30 = load %struct.addrinfo*, %struct.addrinfo** %7
store %struct.addrinfo* %30, %struct.addrinfo** %8
br label %31
31: ; preds = %37, %29
%32 = load %struct.addrinfo*, %struct.addrinfo** %8
%33 = icmp ne %struct.addrinfo* %32, null
br i1 %33, label %34, label %41
34: ; preds = %31
%35 = load %struct.addrinfo*, %struct.addrinfo** %8
%36 = call i32 @show_addrinfo(%struct.addrinfo* %35)
br label %37
37: ; preds = %34
%38 = load %struct.addrinfo*, %struct.addrinfo** %8
%39 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %38, i32 0, i32 0
%40 = load %struct.addrinfo*, %struct.addrinfo** %39
store %struct.addrinfo* %40, %struct.addrinfo** %8
br label %31
41: ; preds = %31
%42 = load i32, i32* @EXIT_SUCCESS
%43 = call i32 @exit(i32 %42)
unreachable
}

LLVM IR (-O2):
%struct.addrinfo = type { %struct.addrinfo*, i32, i32, i32 }
@AI_PASSIVE = global i32 0
@AF_UNSPEC = global i32 0
@SOCK_STREAM = global i32 0
@stderr = global i32 0
@.str = [17 x i8] c"getaddrinfo: %s\0A\00"
@EXIT_FAILURE = global i32 0
@EXIT_SUCCESS = global i32 0
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 = call i32 @memset(%struct.addrinfo* %3, i32 0, i32 24)
%8 = load i32, i32* @AI_PASSIVE
%9 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i64 0, i32 3
store i32 %8, i32* %9
%10 = load i32, i32* @AF_UNSPEC
%11 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i64 0, i32 2
store i32 %10, i32* %11
%12 = load i32, i32* @SOCK_STREAM
%13 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i64 0, i32 1
store i32 %12, i32* %13
%14 = getelementptr inbounds i8*, i8** %1, i64 1
%15 = load i8*, i8** %14
%16 = call i32 @getaddrinfo(i32* null, i8* %15, %struct.addrinfo* %3, %struct.addrinfo** %4)
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %2
%19 = load %struct.addrinfo*, %struct.addrinfo** %4
%20 = icmp eq %struct.addrinfo* %19, null
br i1 %20, label %33, label %27
21: ; preds = %2
%22 = load i32, i32* @stderr
%23 = call i8* @gai_strerror(i32 %16)
%24 = call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %23)
%25 = load i32, i32* @EXIT_FAILURE
%26 = call i32 @exit(i32 %25)
unreachable
27: ; preds = %18, %27
%28 = phi %struct.addrinfo* [ %31, %27 ], [ %19, %18 ]
%29 = call i32 @show_addrinfo(%struct.addrinfo* %28)
%30 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %28, i64 0, i32 0
%31 = load %struct.addrinfo*, %struct.addrinfo** %30
%32 = icmp eq %struct.addrinfo* %31, null
br i1 %32, label %33, label %27
33: ; preds = %27, %18
%34 = load i32, i32* @EXIT_SUCCESS
%35 = call i32 @exit(i32 %34)
unreachable
}