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

/* Variables and functions */
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*/ pr_addrinfo(struct addrinfo *);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  if (argc != 3) {
    fprintf(stderr, "Usage: %s host service\n", argv[0]);
    exit(1);
  }
  struct addrinfo hint, *ailist, *aip;
  int err;
  memset(&hint, 0, sizeof(hint));
  if ((err = getaddrinfo(argv[1], argv[2], &hint, &ailist)) != 0) {
    fprintf(stderr, "getaddrinfo error: %s\n", gai_strerror(err));
    exit(1);
  }
  for (aip = ailist; aip != NULL; aip = aip->ai_next) {
    pr_addrinfo(aip);
  }
  freeaddrinfo(ailist);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     11b6 <main+0x46>
mov    0x2e49(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe59(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
lea    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1040 <memset@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
lea    -0x18(%rbp),%rdx
lea    -0x20(%rbp),%rcx
call   1080 <getaddrinfo@plt>
mov    %eax,-0x2c(%rbp)
cmp    $0x0,%eax
je     121f <main+0xaf>
mov    0x2dea(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
mov    -0x2c(%rbp),%edi
call   1030 <gai_strerror@plt>
mov    -0x30(%rbp),%edi
mov    %rax,%rdx
lea    0xe08(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     124b <main+0xdb>
mov    -0x28(%rbp),%rdi
call   1060 <pr_addrinfo@plt>
mov    -0x28(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
jmp    1227 <main+0xb7>
mov    -0x20(%rbp),%rdi
call   1090 <freeaddrinfo@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbx
cmp    $0x3,%edi
jne    11e8 <main+0x78>
lea    0x10(%rsp),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1040 <memset@plt>
mov    0x8(%rbx),%rdi
mov    0x10(%rbx),%rsi
lea    0x8(%rsp),%rcx
mov    %r14,%rdx
call   1080 <getaddrinfo@plt>
test   %eax,%eax
jne    11fd <main+0x8d>
mov    0x8(%rsp),%rbx
test   %rbx,%rbx
je     11d7 <main+0x67>
cs nopw 0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1060 <pr_addrinfo@plt>
mov    (%rbx),%rbx
test   %rbx,%rbx
jne    11c0 <main+0x50>
mov    0x8(%rsp),%rdi
jmp    11d9 <main+0x69>
xor    %edi,%edi
call   1090 <freeaddrinfo@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret
mov    0x2df1(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xe05(%rip),%rsi
jmp    1219 <main+0xa9>
mov    0x2ddc(%rip),%rcx
mov    (%rcx),%ebx
mov    %eax,%edi
call   1030 <gai_strerror@plt>
lea    0xe04(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
%struct.addrinfo = type { %struct.addrinfo* }
@stderr = global i32 0
@.str = [24 x i8] c"Usage: %s host service\0A\00"
@.str.1 = [23 x i8] c"getaddrinfo error: %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 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 ([24 x i8], [24 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 8)
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 1
%23 = load i8*, i8** %22
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 2
%26 = load i8*, i8** %25
%27 = call i32 @getaddrinfo(i8* %23, i8* %26, %struct.addrinfo* %6, %struct.addrinfo** %7)
store i32 %27, i32* %9
%28 = icmp ne i32 %27, 0
br i1 %28, label %29, label %35
29: ; preds = %19
%30 = load i32, i32* @stderr
%31 = load i32, i32* %9
%32 = call i8* @gai_strerror(i32 %31)
%33 = call i32 @fprintf(i32 %30, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %32)
%34 = call i32 @exit(i32 1)
unreachable
35: ; preds = %19
%36 = load %struct.addrinfo*, %struct.addrinfo** %7
store %struct.addrinfo* %36, %struct.addrinfo** %8
br label %37
37: ; preds = %43, %35
%38 = load %struct.addrinfo*, %struct.addrinfo** %8
%39 = icmp ne %struct.addrinfo* %38, null
br i1 %39, label %40, label %47
40: ; preds = %37
%41 = load %struct.addrinfo*, %struct.addrinfo** %8
%42 = call i32 @pr_addrinfo(%struct.addrinfo* %41)
br label %43
43: ; preds = %40
%44 = load %struct.addrinfo*, %struct.addrinfo** %8
%45 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %44, i32 0, i32 0
%46 = load %struct.addrinfo*, %struct.addrinfo** %45
store %struct.addrinfo* %46, %struct.addrinfo** %8
br label %37
47: ; preds = %37
%48 = load %struct.addrinfo*, %struct.addrinfo** %7
%49 = call i32 @freeaddrinfo(%struct.addrinfo* %48)
ret i32 0
}

LLVM IR (-O2):
%struct.addrinfo = type { %struct.addrinfo* }
@stderr = global i32 0
@.str = [24 x i8] c"Usage: %s host service\0A\00"
@.str.1 = [23 x i8] c"getaddrinfo error: %s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.addrinfo
%4 = alloca %struct.addrinfo*
%5 = icmp eq i32 %0, 3
br i1 %5, label %11, label %6
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = load i8*, i8** %1
%9 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %8)
%10 = tail call i32 @exit(i32 1)
unreachable
11: ; preds = %2
%12 = bitcast %struct.addrinfo* %3 to i8*
%13 = bitcast %struct.addrinfo** %4 to i8*
%14 = call i32 @memset(%struct.addrinfo* %3, i32 0, i32 8)
%15 = getelementptr inbounds i8*, i8** %1, i64 1
%16 = load i8*, i8** %15
%17 = getelementptr inbounds i8*, i8** %1, i64 2
%18 = load i8*, i8** %17
%19 = call i32 @getaddrinfo(i8* %16, i8* %18, %struct.addrinfo* %3, %struct.addrinfo** %4)
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %11
%22 = load %struct.addrinfo*, %struct.addrinfo** %4
%23 = icmp eq %struct.addrinfo* %22, null
br i1 %23, label %37, label %29
24: ; preds = %11
%25 = load i32, i32* @stderr
%26 = call i8* @gai_strerror(i32 %19)
%27 = call i32 @fprintf(i32 %25, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %26)
%28 = call i32 @exit(i32 1)
unreachable
29: ; preds = %21, %29
%30 = phi %struct.addrinfo* [ %33, %29 ], [ %22, %21 ]
%31 = call i32 @pr_addrinfo(%struct.addrinfo* %30)
%32 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %30, i64 0, i32 0
%33 = load %struct.addrinfo*, %struct.addrinfo** %32
%34 = icmp eq %struct.addrinfo* %33, null
br i1 %34, label %35, label %29
35: ; preds = %29
%36 = load %struct.addrinfo*, %struct.addrinfo** %4
br label %37
37: ; preds = %35, %21
%38 = phi %struct.addrinfo* [ %36, %35 ], [ null, %21 ]
%39 = call i32 @freeaddrinfo(%struct.addrinfo* %38)
ret i32 0
}