#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 hostent {
  char *h_name;
  scalar_t__ h_addr;
};

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
struct hostent *gethostbyname(char *);
int /*<<< orphan*/ herror(char *);
char *inet_ntoa(struct in_addr);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  struct hostent *h;
  if (argc != 2) {
    fprintf(stderr, "usage: getip address\n");
    exit(1);
  }
  if ((h = gethostbyname(argv[1])) == NULL) {
    herror("gethostbyname");
    exit(1);
  }
  printf("Host name  : %s\n", h->h_name);
  printf("IP Address : %s\n", inet_ntoa(*((struct in_addr *)h->h_addr)));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     119f <main+0x3f>
mov    0x2e59(%rip),%rax
mov    (%rax),%edi
lea    0xe70(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1050 <gethostbyname@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11d0 <main+0x70>
lea    0xe55(%rip),%rdi
call   1070 <herror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%rsi
lea    0xe46(%rip),%rdi
call   1040 <printf@plt>
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rax
mov    (%rax),%edi
call   1030 <inet_ntoa@plt>
mov    %rax,%rsi
lea    0xe39(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
cmp    $0x2,%edi
jne    11a4 <main+0x44>
mov    0x8(%rsi),%rdi
call   1050 <gethostbyname@plt>
test   %rax,%rax
je     11c3 <main+0x63>
mov    %rax,%rbx
mov    (%rax),%rsi
lea    0xea3(%rip),%rdi
call   1040 <printf@plt>
mov    0x8(%rbx),%rax
mov    (%rax),%edi
call   1030 <inet_ntoa@plt>
lea    0xe9d(%rip),%rdi
mov    %rax,%rsi
call   1040 <printf@plt>
xor    %eax,%eax
pop    %rbx
ret
mov    0x2e35(%rip),%rax
mov    (%rax),%edi
lea    0xe4c(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
lea    0xe4c(%rip),%rdi
call   1070 <herror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
%struct.hostent = type { i8*, i64 }
%struct.in_addr = type { i32 }
@stderr = global i32 0
@.str = [22 x i8] c"usage: getip address\0A\00"
@.str.1 = [14 x i8] c"gethostbyname\00"
@.str.2 = [17 x i8] c"Host name : %s\0A\00"
@.str.3 = [17 x i8] c"IP Address : %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.hostent*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = load i32, i32* %4
%8 = icmp ne i32 %7, 2
br i1 %8, label %9, label %13
9: ; preds = %2
%10 = load i32, i32* @stderr
%11 = call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%12 = call i32 @exit(i32 1)
unreachable
13: ; preds = %2
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 1
%16 = load i8*, i8** %15
%17 = call %struct.hostent* @gethostbyname(i8* %16)
store %struct.hostent* %17, %struct.hostent** %6
%18 = icmp eq %struct.hostent* %17, null
br i1 %18, label %19, label %22
19: ; preds = %13
%20 = call i32 @herror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%21 = call i32 @exit(i32 1)
unreachable
22: ; preds = %13
%23 = load %struct.hostent*, %struct.hostent** %6
%24 = getelementptr inbounds %struct.hostent, %struct.hostent* %23, i32 0, i32 0
%25 = load i8*, i8** %24
%26 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8* %25)
%27 = load %struct.hostent*, %struct.hostent** %6
%28 = getelementptr inbounds %struct.hostent, %struct.hostent* %27, i32 0, i32 1
%29 = load i64, i64* %28
%30 = inttoptr i64 %29 to %struct.in_addr*
%31 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %30, i32 0, i32 0
%32 = load i32, i32* %31
%33 = call i8* @inet_ntoa(i32 %32)
%34 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i8* %33)
ret i32 0
}

LLVM IR (-O2):
%struct.hostent = type { i8*, i64 }
%struct.in_addr = type { i32 }
@stderr = global i32 0
@.str = [22 x i8] c"usage: getip address\0A\00"
@.str.1 = [14 x i8] c"gethostbyname\00"
@.str.2 = [17 x i8] c"Host name : %s\0A\00"
@.str.3 = [17 x i8] c"IP Address : %s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %8, label %4
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%7 = tail call i32 @exit(i32 1)
unreachable
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = tail call %struct.hostent* @gethostbyname(i8* %10)
%12 = icmp eq %struct.hostent* %11, null
br i1 %12, label %13, label %16
13: ; preds = %8
%14 = tail call i32 @herror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%15 = tail call i32 @exit(i32 1)
unreachable
16: ; preds = %8
%17 = getelementptr inbounds %struct.hostent, %struct.hostent* %11, i64 0, i32 0
%18 = load i8*, i8** %17
%19 = tail call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8* %18)
%20 = getelementptr inbounds %struct.hostent, %struct.hostent* %11, i64 0, i32 1
%21 = load i64, i64* %20
%22 = inttoptr i64 %21 to %struct.in_addr*
%23 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %22, i64 0, i32 0
%24 = load i32, i32* %23
%25 = tail call i8* @inet_ntoa(i32 %24)
%26 = tail call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i8* %25)
ret i32 0
}