#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 in_addr {
  int dummy;
};
struct sockaddr_in {
  struct in_addr sin_addr;
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
struct addrinfo {
  int ai_addrlen;
  struct sockaddr *ai_addr;
};
typedef int /*<<< orphan*/ sin;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ NI_NAMEREQD;
int /*<<< orphan*/ NI_NUMERICHOST;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
scalar_t__ getaddrinfo(char *, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                       struct addrinfo **);
scalar_t__ getnameinfo(struct sockaddr *, int, char *, int,
                       int /*<<< orphan*/ *, int /*<<< orphan*/,
                       int /*<<< orphan*/);
scalar_t__ inet_aton(char *, struct in_addr *);
int /*<<< orphan*/ printf(char *, char *, ...);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  if (argc != 2) {
    fprintf(stderr, "Usage: %s <host>\n", argv[0]);
    return -1;
  }
  struct in_addr in;
  struct addrinfo *addr = NULL;
  char host[512];
  if (inet_aton(argv[1], &in) != 0) {
    const struct sockaddr_in sin = {
        .sin_family = AF_INET,
        .sin_port = 0,
        .sin_addr = in,
    };
    if (getnameinfo((struct sockaddr *)&sin, sizeof(sin), host, 512, NULL, 0,
                    NI_NAMEREQD) == 0) {
      printf("%s has address %s\n", argv[1], host);
      return 0;
    }
  } else {
    if (getaddrinfo(argv[1], NULL, NULL, &addr) == 0) {
      getnameinfo(addr->ai_addr, addr->ai_addrlen, host, 512, NULL, 0,
                  NI_NUMERICHOST);
      printf("%s has address %s\n", argv[1], host);
      return 0;
    }
  }
  printf("Host %s not found.\n", argv[1]);
  return -1;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x240,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     119b <main+0x4b>
mov    0x2e56(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe76(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12e5 <main+0x195>
movq   $0x0,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x18(%rbp),%rsi
call   1060 <inet_aton@plt>
cmp    $0x0,%rax
je     1247 <main+0xf7>
mov    -0x18(%rbp),%eax
mov    %eax,-0x230(%rbp)
movl   $0x0,-0x22c(%rbp)
mov    0x2e08(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x228(%rbp)
lea    -0x230(%rbp),%rdi
lea    -0x220(%rbp),%rdx
mov    0x2dfb(%rip),%rax
mov    (%rax),%eax
mov    $0xc,%esi
mov    $0x200,%ecx
xor    %r8d,%r8d
xor    %r9d,%r9d
mov    %eax,(%rsp)
call   1040 <getnameinfo@plt>
cmp    $0x0,%rax
jne    1242 <main+0xf2>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    -0x220(%rbp),%rdx
lea    0xde3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    12e5 <main+0x195>
jmp    12c8 <main+0x178>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
xor    %eax,%eax
mov    %eax,%edx
lea    -0x20(%rbp),%rcx
mov    %rdx,%rsi
call   1070 <getaddrinfo@plt>
cmp    $0x0,%rax
jne    12c3 <main+0x173>
mov    -0x20(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x20(%rbp),%rax
mov    (%rax),%esi
lea    -0x220(%rbp),%rdx
mov    0x2d43(%rip),%rax
mov    (%rax),%eax
mov    $0x200,%ecx
xor    %r8d,%r8d
xor    %r9d,%r9d
mov    %eax,(%rsp)
call   1040 <getnameinfo@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    -0x220(%rbp),%rdx
lea    0xd62(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    12e5 <main+0x195>
jmp    12c8 <main+0x178>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xd4e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x240,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x230,%rsp
mov    %rsi,%rbx
cmp    $0x2,%edi
jne    11e9 <main+0x99>
movq   $0x0,0x18(%rsp)
mov    0x8(%rbx),%rdi
lea    0x10(%rsp),%rsi
call   1060 <inet_aton@plt>
test   %rax,%rax
je     1203 <main+0xb3>
mov    0x10(%rsp),%eax
mov    %eax,0x20(%rsp)
movl   $0x0,0x24(%rsp)
mov    0x2e45(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x28(%rsp)
mov    0x2e48(%rip),%rax
mov    (%rax),%eax
mov    %eax,(%rsp)
xor    %r14d,%r14d
lea    0x20(%rsp),%rdi
lea    0x30(%rsp),%rdx
mov    $0xc,%esi
mov    $0x200,%ecx
xor    %r8d,%r8d
xor    %r9d,%r9d
call   1040 <getnameinfo@plt>
test   %rax,%rax
jne    121d <main+0xcd>
mov    0x8(%rbx),%rsi
lea    0xe33(%rip),%rdi
lea    0x30(%rsp),%rdx
jmp    1282 <main+0x132>
mov    0x2de0(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xe04(%rip),%rsi
call   1050 <fprintf@plt>
jmp    122f <main+0xdf>
mov    0x8(%rbx),%rdi
xor    %r14d,%r14d
lea    0x18(%rsp),%rcx
xor    %esi,%esi
xor    %edx,%edx
call   1070 <getaddrinfo@plt>
test   %rax,%rax
je     1245 <main+0xf5>
mov    0x8(%rbx),%rsi
lea    0xdfd(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0xffffffff,%r14d
mov    %r14d,%eax
add    $0x230,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
mov    0x18(%rsp),%rax
mov    0x8(%rax),%rdi
mov    (%rax),%esi
mov    0x2d71(%rip),%rax
mov    (%rax),%eax
mov    %eax,(%rsp)
lea    0x30(%rsp),%r15
mov    %r15,%rdx
mov    $0x200,%ecx
xor    %r8d,%r8d
xor    %r9d,%r9d
call   1040 <getnameinfo@plt>
mov    0x8(%rbx),%rsi
lea    0xd93(%rip),%rdi
mov    %r15,%rdx
xor    %eax,%eax
call   1030 <printf@plt>
jmp    1235 <main+0xe5>

LLVM IR (-O0):
%struct.in_addr = type { i32 }
%struct.addrinfo = type { i32, %struct.sockaddr* }
%struct.sockaddr = type { i32 }
%struct.sockaddr_in = type { %struct.in_addr, i32, i32 }
@stderr = global i32 0
@.str = [18 x i8] c"Usage: %s <host>\0A\00"
@AF_INET = global i32 0
@NI_NAMEREQD = global i32 0
@.str.1 = [19 x i8] c"%s has address %s\0A\00"
@NI_NUMERICHOST = global i32 0
@.str.2 = [20 x i8] c"Host %s not found.\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.in_addr
%7 = alloca %struct.addrinfo*
%8 = alloca [512 x i8]
%9 = alloca %struct.sockaddr_in
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, 2
br i1 %11, label %12, label %18
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 ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %16)
store i32 -1, i32* %3
br label %70
18: ; preds = %2
store %struct.addrinfo* null, %struct.addrinfo** %7
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 1
%21 = load i8*, i8** %20
%22 = call i64 @inet_aton(i8* %21, %struct.in_addr* %6)
%23 = icmp ne i64 %22, 0
br i1 %23, label %24, label %43
24: ; preds = %18
%25 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 0
%26 = bitcast %struct.in_addr* %25 to i8*
%27 = bitcast %struct.in_addr* %6 to i8*
%28 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 1
store i32 0, i32* %28
%29 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 2
%30 = load i32, i32* @AF_INET
store i32 %30, i32* %29
%31 = bitcast %struct.sockaddr_in* %9 to %struct.sockaddr*
%32 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
%33 = load i32, i32* @NI_NAMEREQD
%34 = call i64 @getnameinfo(%struct.sockaddr* %31, i32 12, i8* %32, i32 512, i32* null, i32 0, i32 %33)
%35 = icmp eq i64 %34, 0
br i1 %35, label %36, label %42
36: ; preds = %24
%37 = load i8**, i8*** %5
%38 = getelementptr inbounds i8*, i8** %37, i64 1
%39 = load i8*, i8** %38
%40 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
%41 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* %39, i8* %40)
store i32 0, i32* %3
br label %70
42: ; preds = %24
br label %65
43: ; preds = %18
%44 = load i8**, i8*** %5
%45 = getelementptr inbounds i8*, i8** %44, i64 1
%46 = load i8*, i8** %45
%47 = call i64 @getaddrinfo(i8* %46, i32* null, i32* null, %struct.addrinfo** %7)
%48 = icmp eq i64 %47, 0
br i1 %48, label %49, label %64
49: ; preds = %43
%50 = load %struct.addrinfo*, %struct.addrinfo** %7
%51 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %50, i32 0, i32 1
%52 = load %struct.sockaddr*, %struct.sockaddr** %51
%53 = load %struct.addrinfo*, %struct.addrinfo** %7
%54 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %53, i32 0, i32 0
%55 = load i32, i32* %54
%56 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
%57 = load i32, i32* @NI_NUMERICHOST
%58 = call i64 @getnameinfo(%struct.sockaddr* %52, i32 %55, i8* %56, i32 512, i32* null, i32 0, i32 %57)
%59 = load i8**, i8*** %5
%60 = getelementptr inbounds i8*, i8** %59, i64 1
%61 = load i8*, i8** %60
%62 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
%63 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* %61, i8* %62)
store i32 0, i32* %3
br label %70
64: ; preds = %43
br label %65
65: ; preds = %64, %42
%66 = load i8**, i8*** %5
%67 = getelementptr inbounds i8*, i8** %66, i64 1
%68 = load i8*, i8** %67
%69 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* %68)
store i32 -1, i32* %3
br label %70
70: ; preds = %65, %49, %36, %12
%71 = load i32, i32* %3
ret i32 %71
}

LLVM IR (-O2):
%struct.in_addr = type { i32 }
%struct.addrinfo = type { i32, %struct.sockaddr* }
%struct.sockaddr = type { i32 }
%struct.sockaddr_in = type { %struct.in_addr, i32, i32 }
@stderr = global i32 0
@.str = [18 x i8] c"Usage: %s <host>\0A\00"
@AF_INET = global i32 0
@NI_NAMEREQD = global i32 0
@.str.1 = [19 x i8] c"%s has address %s\0A\00"
@NI_NUMERICHOST = global i32 0
@.str.2 = [20 x i8] c"Host %s not found.\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.in_addr
%4 = alloca %struct.addrinfo*
%5 = alloca [512 x i8]
%6 = alloca %struct.sockaddr_in
%7 = icmp eq i32 %0, 2
br i1 %7, label %12, 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 ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %10)
br label %55
12: ; preds = %2
%13 = bitcast %struct.in_addr* %3 to i8*
%14 = bitcast %struct.addrinfo** %4 to i8*
store %struct.addrinfo* null, %struct.addrinfo** %4
%15 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%16 = getelementptr inbounds i8*, i8** %1, i64 1
%17 = load i8*, i8** %16
%18 = call i64 @inet_aton(i8* %17, %struct.in_addr* %3)
%19 = icmp eq i64 %18, 0
br i1 %19, label %35, label %20
20: ; preds = %12
%21 = bitcast %struct.sockaddr_in* %6 to i8*
%22 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %3, i64 0, i32 0
%23 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i64 0, i32 0, i32 0
%24 = load i32, i32* %22
store i32 %24, i32* %23
%25 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i64 0, i32 1
store i32 0, i32* %25
%26 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i64 0, i32 2
%27 = load i32, i32* @AF_INET
store i32 %27, i32* %26
%28 = bitcast %struct.sockaddr_in* %6 to %struct.sockaddr*
%29 = load i32, i32* @NI_NAMEREQD
%30 = call i64 @getnameinfo(%struct.sockaddr* %28, i32 12, i8* %15, i32 512, i32* null, i32 0, i32 %29)
%31 = icmp eq i64 %30, 0
br i1 %31, label %32, label %49
32: ; preds = %20
%33 = load i8*, i8** %16
%34 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* %33, i8* %15)
br label %53
35: ; preds = %12
%36 = load i8*, i8** %16
%37 = call i64 @getaddrinfo(i8* %36, i32* null, i32* null, %struct.addrinfo** %4)
%38 = icmp eq i64 %37, 0
br i1 %38, label %39, label %50
39: ; preds = %35
%40 = load %struct.addrinfo*, %struct.addrinfo** %4
%41 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %40, i64 0, i32 1
%42 = load %struct.sockaddr*, %struct.sockaddr** %41
%43 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %40, i64 0, i32 0
%44 = load i32, i32* %43
%45 = load i32, i32* @NI_NUMERICHOST
%46 = call i64 @getnameinfo(%struct.sockaddr* %42, i32 %44, i8* %15, i32 512, i32* null, i32 0, i32 %45)
%47 = load i8*, i8** %16
%48 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* %47, i8* %15)
br label %53
49: ; preds = %20
br label %50
50: ; preds = %49, %35
%51 = load i8*, i8** %16
%52 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* %51)
br label %53
53: ; preds = %32, %50, %39
%54 = phi i32 [ -1, %50 ], [ 0, %32 ], [ 0, %39 ]
br label %55
55: ; preds = %53, %8
%56 = phi i32 [ -1, %8 ], [ %54, %53 ]
ret i32 %56
}