#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 hostent {
  int dummy;
};

/* Variables and functions */
int EXIT_SUCCESS;
struct hostent *gethostbyaddr_wrapper(char *);
struct hostent *gethostbyname(char *);
int /*<<< orphan*/ hostent_fprint(struct hostent *, int /*<<< orphan*/);
scalar_t__ is_ip_address(char *);
int /*<<< orphan*/ res_init();
int /*<<< orphan*/ server_print();
int /*<<< orphan*/ show_usage();
int nslookup_main(int argc, char **argv) {
  struct hostent *host;
  if (argc < 2 || *argv[1] == '-') {
    show_usage();
  }
  res_init();
  server_print();
  if (is_ip_address(argv[1])) {
    host = gethostbyaddr_wrapper(argv[1]);
  } else {
    host = gethostbyname(argv[1]);
  }
  hostent_fprint(host, 0);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<nslookup_main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x4(%rbp)
jl     119d <nslookup_main+0x2d>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
movsbl (%rax),%eax
cmp    $0x2d,%eax
jne    11a4 <nslookup_main+0x34>
mov    $0x0,%al
call   1080 <show_usage@plt>
mov    $0x0,%al
call   1040 <res_init@plt>
mov    $0x0,%al
call   1050 <server_print@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1030 <is_ip_address@plt>
cmp    $0x0,%rax
je     11df <nslookup_main+0x6f>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1090 <gethostbyaddr_wrapper@plt>
mov    %rax,-0x18(%rbp)
jmp    11f0 <nslookup_main+0x80>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1060 <gethostbyname@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
xor    %esi,%esi
call   1070 <hostent_fprint@plt>
mov    0x2dde(%rip),%rax
mov    (%rax),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<nslookup_main>:
push   %rbx
mov    %rsi,%rbx
cmp    $0x2,%edi
jl     1182 <nslookup_main+0x12>
mov    0x8(%rbx),%rax
cmpb   $0x2d,(%rax)
jne    1189 <nslookup_main+0x19>
xor    %eax,%eax
call   1080 <show_usage@plt>
xor    %eax,%eax
call   1040 <res_init@plt>
xor    %eax,%eax
call   1050 <server_print@plt>
mov    0x8(%rbx),%rdi
call   1030 <is_ip_address@plt>
mov    0x8(%rbx),%rdi
test   %rax,%rax
je     11b0 <nslookup_main+0x40>
call   1090 <gethostbyaddr_wrapper@plt>
jmp    11b5 <nslookup_main+0x45>
call   1060 <gethostbyname@plt>
mov    %rax,%rdi
xor    %esi,%esi
call   1070 <hostent_fprint@plt>
mov    0x2e1a(%rip),%rax
mov    (%rax),%eax
pop    %rbx
ret

LLVM IR (-O0):
%struct.hostent = type { i32 }
@EXIT_SUCCESS = global i32 0
define i32 @nslookup_main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca %struct.hostent*
store i32 %0, i32* %3
store i8** %1, i8*** %4
%6 = load i32, i32* %3
%7 = icmp slt i32 %6, 2
br i1 %7, label %15, label %8
8: ; preds = %2
%9 = load i8**, i8*** %4
%10 = getelementptr inbounds i8*, i8** %9, i64 1
%11 = load i8*, i8** %10
%12 = load i8, i8* %11
%13 = sext i8 %12 to i32
%14 = icmp eq i32 %13, 45
br i1 %14, label %15, label %17
15: ; preds = %8, %2
%16 = call i32 (...) @show_usage()
br label %17
17: ; preds = %15, %8
%18 = call i32 (...) @res_init()
%19 = call i32 (...) @server_print()
%20 = load i8**, i8*** %4
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
%23 = call i64 @is_ip_address(i8* %22)
%24 = icmp ne i64 %23, 0
br i1 %24, label %25, label %30
25: ; preds = %17
%26 = load i8**, i8*** %4
%27 = getelementptr inbounds i8*, i8** %26, i64 1
%28 = load i8*, i8** %27
%29 = call %struct.hostent* @gethostbyaddr_wrapper(i8* %28)
store %struct.hostent* %29, %struct.hostent** %5
br label %35
30: ; preds = %17
%31 = load i8**, i8*** %4
%32 = getelementptr inbounds i8*, i8** %31, i64 1
%33 = load i8*, i8** %32
%34 = call %struct.hostent* @gethostbyname(i8* %33)
store %struct.hostent* %34, %struct.hostent** %5
br label %35
35: ; preds = %30, %25
%36 = load %struct.hostent*, %struct.hostent** %5
%37 = call i32 @hostent_fprint(%struct.hostent* %36, i32 0)
%38 = load i32, i32* @EXIT_SUCCESS
ret i32 %38
}

LLVM IR (-O2):
%struct.hostent = type { i32 }
@EXIT_SUCCESS = global i32 0
define i32 @nslookup_main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %9, label %4
4: ; preds = %2
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = load i8, i8* %6
%8 = icmp eq i8 %7, 45
br i1 %8, label %9, label %11
9: ; preds = %4, %2
%10 = tail call i32 (...) @show_usage()
br label %11
11: ; preds = %9, %4
%12 = tail call i32 (...) @res_init()
%13 = tail call i32 (...) @server_print()
%14 = getelementptr inbounds i8*, i8** %1, i64 1
%15 = load i8*, i8** %14
%16 = tail call i64 @is_ip_address(i8* %15)
%17 = icmp eq i64 %16, 0
%18 = load i8*, i8** %14
br i1 %17, label %21, label %19
19: ; preds = %11
%20 = tail call %struct.hostent* @gethostbyaddr_wrapper(i8* %18)
br label %23
21: ; preds = %11
%22 = tail call %struct.hostent* @gethostbyname(i8* %18)
br label %23
23: ; preds = %21, %19
%24 = phi %struct.hostent* [ %20, %19 ], [ %22, %21 ]
%25 = tail call i32 @hostent_fprint(%struct.hostent* %24, i32 0)
%26 = load i32, i32* @EXIT_SUCCESS
ret i32 %26
}