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

/* Variables and functions */
struct hostent *gethostbyname(char *);
int /*<<< orphan*/ printf(char *, ...);
int main() {
  struct hostent *hptr;
  char *exampleHostName = "www.google.com";
  if (hptr = gethostbyname(exampleHostName)) {
    printf("host ip  = %s", hptr->h_addr_list[0]);
  } else {
    printf("error");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeca(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <gethostbyname@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
je     116e <main+0x4e>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    (%rax),%rsi
lea    0xead(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    117c <main+0x5c>
lea    0xea8(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
lea    0xed8(%rip),%rdi
call   1040 <gethostbyname@plt>
test   %rax,%rax
je     1148 <main+0x28>
mov    (%rax),%rax
mov    (%rax),%rsi
lea    0xed0(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
jmp    1156 <main+0x36>
lea    0xece(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
%struct.hostent = type { i8** }
@.str = [15 x i8] c"www.google.com\00"
@.str.1 = [14 x i8] c"host ip = %s\00"
@.str.2 = [6 x i8] c"error\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.hostent*
%3 = alloca i8*
store i32 0, i32* %1
store i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8** %3
%4 = load i8*, i8** %3
%5 = call %struct.hostent* @gethostbyname(i8* %4)
store %struct.hostent* %5, %struct.hostent** %2
%6 = icmp ne %struct.hostent* %5, null
br i1 %6, label %7, label %14
7: ; preds = %0
%8 = load %struct.hostent*, %struct.hostent** %2
%9 = getelementptr inbounds %struct.hostent, %struct.hostent* %8, i32 0, i32 0
%10 = load i8**, i8*** %9
%11 = getelementptr inbounds i8*, i8** %10, i64 0
%12 = load i8*, i8** %11
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8* %12)
br label %16
14: ; preds = %0
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
br label %16
16: ; preds = %14, %7
ret i32 0
}

LLVM IR (-O2):
%struct.hostent = type { i8** }
@.str = [15 x i8] c"www.google.com\00"
@.str.1 = [14 x i8] c"host ip = %s\00"
@.str.2 = [6 x i8] c"error\00"
define i32 @main() {
%1 = tail call %struct.hostent* @gethostbyname(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%2 = icmp eq %struct.hostent* %1, null
br i1 %2, label %8, label %3
3: ; preds = %0
%4 = getelementptr inbounds %struct.hostent, %struct.hostent* %1, i64 0, i32 0
%5 = load i8**, i8*** %4
%6 = load i8*, i8** %5
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8* %6)
br label %10
8: ; preds = %0
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
br label %10
10: ; preds = %8, %3
ret i32 0
}