#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 {
  scalar_t__ *h_addr_list;
};

/* Variables and functions */
int /*<<< orphan*/ exit(int);
struct hostent *gethostbyname(char *);
char *inet_ntoa(struct in_addr);
int /*<<< orphan*/ printf(char *, char *, ...);
int main(int argc, char *argv[]) {
  struct hostent *host_info;
  struct in_addr *address;
  if (argc < 2) {
    printf("Usage: %s <hostname>\n", argv[0]);
    exit(1);
  }
  host_info = gethostbyname(argv[1]);
  if (host_info == NULL) {
    printf("Couldn't lookup %s\n", argv[1]);
  } else {
    address = (struct in_addr *)(host_info->h_addr_list[0]);
    printf("%s has address %s\n", argv[1], inet_ntoa(*address));
  }
  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   $0x2,-0x8(%rbp)
jge    117f <main+0x3f>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe92(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1050 <gethostbyname@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11b6 <main+0x76>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe6c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11f0 <main+0xb0>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
mov    (%rax),%edi
call   1030 <inet_ntoa@plt>
mov    -0x28(%rbp),%rsi
mov    %rax,%rdx
lea    0xe41(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    %rsi,%rbx
cmp    $0x1,%edi
jle    1194 <main+0x54>
mov    0x8(%rbx),%rdi
call   1050 <gethostbyname@plt>
test   %rax,%rax
je     117e <main+0x3e>
mov    (%rax),%rax
mov    (%rax),%rax
mov    0x8(%rbx),%rbx
mov    (%rax),%edi
call   1030 <inet_ntoa@plt>
lea    0xebb(%rip),%rdi
mov    %rbx,%rsi
mov    %rax,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
jmp    1190 <main+0x50>
mov    0x8(%rbx),%rsi
lea    0xe8d(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
pop    %rbx
ret
mov    (%rbx),%rsi
lea    0xe62(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
%struct.hostent = type { i64* }
%struct.in_addr = type { i32 }
@.str = [22 x i8] c"Usage: %s <hostname>\0A\00"
@.str.1 = [20 x i8] c"Couldn't lookup %s\0A\00"
@.str.2 = [19 x i8] c"%s has address %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.hostent*
%7 = alloca %struct.in_addr*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp slt i32 %8, 2
br i1 %9, label %10, label %16
10: ; preds = %2
%11 = load i8**, i8*** %5
%12 = getelementptr inbounds i8*, i8** %11, i64 0
%13 = load i8*, i8** %12
%14 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %13)
%15 = call i32 @exit(i32 1)
unreachable
16: ; preds = %2
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
%20 = call %struct.hostent* @gethostbyname(i8* %19)
store %struct.hostent* %20, %struct.hostent** %6
%21 = load %struct.hostent*, %struct.hostent** %6
%22 = icmp eq %struct.hostent* %21, null
br i1 %22, label %23, label %28
23: ; preds = %16
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 1
%26 = load i8*, i8** %25
%27 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %26)
br label %43
28: ; preds = %16
%29 = load %struct.hostent*, %struct.hostent** %6
%30 = getelementptr inbounds %struct.hostent, %struct.hostent* %29, i32 0, i32 0
%31 = load i64*, i64** %30
%32 = getelementptr inbounds i64, i64* %31, i64 0
%33 = load i64, i64* %32
%34 = inttoptr i64 %33 to %struct.in_addr*
store %struct.in_addr* %34, %struct.in_addr** %7
%35 = load i8**, i8*** %5
%36 = getelementptr inbounds i8*, i8** %35, i64 1
%37 = load i8*, i8** %36
%38 = load %struct.in_addr*, %struct.in_addr** %7
%39 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %38, i32 0, i32 0
%40 = load i32, i32* %39
%41 = call i8* @inet_ntoa(i32 %40)
%42 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i8* %37, i8* %41)
br label %43
43: ; preds = %28, %23
ret i32 0
}

LLVM IR (-O2):
%struct.hostent = type { i64* }
%struct.in_addr = type { i32 }
@.str = [22 x i8] c"Usage: %s <hostname>\0A\00"
@.str.1 = [20 x i8] c"Couldn't lookup %s\0A\00"
@.str.2 = [19 x i8] c"%s has address %s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %4, label %8
4: ; preds = %2
%5 = load i8*, i8** %1
%6 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %5)
%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 = load i8*, i8** %9
%15 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %14)
br label %26
16: ; preds = %8
%17 = getelementptr inbounds %struct.hostent, %struct.hostent* %11, i64 0, i32 0
%18 = load i64*, i64** %17
%19 = load i64, i64* %18
%20 = inttoptr i64 %19 to %struct.in_addr*
%21 = load i8*, i8** %9
%22 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %20, i64 0, i32 0
%23 = load i32, i32* %22
%24 = tail call i8* @inet_ntoa(i32 %23)
%25 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i8* %21, i8* %24)
br label %26
26: ; preds = %16, %13
ret i32 0
}