#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;
};
typedef int /*<<< orphan*/ hostname;

/* Variables and functions */
struct hostent *gethostbyname(char *);
int /*<<< orphan*/ gethostname(char *, int);
char *inet_ntoa(struct in_addr);
int /*<<< orphan*/ printf(char *, char *);
int main() {
  struct hostent *he;
  char hostname[20] = {0};
  gethostname(hostname, sizeof(hostname));
  he = gethostbyname(hostname);
  printf("hostname=%s\n", hostname);
  printf("%s\n", inet_ntoa(*(struct in_addr *)(he->h_addr)));
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x14,%edx
call   1050 <memset@plt>
lea    -0x20(%rbp),%rdi
mov    $0x14,%esi
call   1070 <gethostname@plt>
lea    -0x20(%rbp),%rdi
call   1060 <gethostbyname@plt>
mov    %rax,-0x8(%rbp)
lea    -0x20(%rbp),%rsi
lea    0xe72(%rip),%rdi
call   1040 <printf@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    (%rax),%edi
call   1030 <inet_ntoa@plt>
mov    %rax,%rsi
lea    0xe5e(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x18,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,(%rsp)
movl   $0x0,0x10(%rsp)
mov    %rsp,%r14
mov    %r14,%rdi
mov    $0x14,%esi
call   1060 <gethostname@plt>
mov    %r14,%rdi
call   1050 <gethostbyname@plt>
mov    %rax,%rbx
lea    0xe88(%rip),%rdi
mov    %r14,%rsi
call   1040 <printf@plt>
mov    (%rbx),%rax
mov    (%rax),%edi
call   1030 <inet_ntoa@plt>
lea    0xe78(%rip),%rdi
mov    %rax,%rsi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.hostent = type { i64 }
%struct.in_addr = type { i32 }
@.str = [13 x i8] c"hostname=%s\0A\00"
@.str.1 = [4 x i8] c"%s\0A\00"
define i32 @main() {
%1 = alloca %struct.hostent*
%2 = alloca [20 x i8]
%3 = bitcast [20 x i8]* %2 to i8*
%4 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 0
%5 = call i32 @gethostname(i8* %4, i32 20)
%6 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 0
%7 = call %struct.hostent* @gethostbyname(i8* %6)
store %struct.hostent* %7, %struct.hostent** %1
%8 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 0
%9 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* %8)
%10 = load %struct.hostent*, %struct.hostent** %1
%11 = getelementptr inbounds %struct.hostent, %struct.hostent* %10, i32 0, i32 0
%12 = load i64, i64* %11
%13 = inttoptr i64 %12 to %struct.in_addr*
%14 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %13, i32 0, i32 0
%15 = load i32, i32* %14
%16 = call i8* @inet_ntoa(i32 %15)
%17 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %16)
ret i32 0
}

LLVM IR (-O2):
%struct.hostent = type { i64 }
%struct.in_addr = type { i32 }
@.str = [13 x i8] c"hostname=%s\0A\00"
@.str.1 = [4 x i8] c"%s\0A\00"
define i32 @main() {
%1 = alloca [20 x i8]
%2 = getelementptr inbounds [20 x i8], [20 x i8]* %1, i64 0, i64 0
%3 = call i32 @gethostname(i8* %2, i32 20)
%4 = call %struct.hostent* @gethostbyname(i8* %2)
%5 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* %2)
%6 = getelementptr inbounds %struct.hostent, %struct.hostent* %4, i64 0, i32 0
%7 = load i64, i64* %6
%8 = inttoptr i64 %7 to %struct.in_addr*
%9 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %8, i64 0, i32 0
%10 = load i32, i32* %9
%11 = call i8* @inet_ntoa(i32 %10)
%12 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %11)
ret i32 0
}