#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 /*<<< orphan*/);
struct hostent *gethostbyname(char *);
scalar_t__ gethostname(char *, int);
int /*<<< orphan*/ inet_ntoa(struct in_addr);
int /*<<< orphan*/ strcpy(char *, int /*<<< orphan*/);
void getmyaddr(char *addr) {
  char hostname[64];
  struct hostent *hp;
  if (gethostname(hostname, 64) < 0) {
    exit(0);
  }
  hp = gethostbyname(hostname);
  strcpy(addr, inet_ntoa(*(struct in_addr *)hp->h_addr_list[0]));
}


x86 assembly (clang, -O0):
<getmyaddr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0x50(%rbp),%rdi
mov    $0x40,%esi
call   1060 <gethostname@plt>
cmp    $0x0,%rax
jge    117b <getmyaddr+0x2b>
xor    %edi,%edi
call   1070 <exit@plt>
lea    -0x50(%rbp),%rdi
call   1050 <gethostbyname@plt>
mov    %rax,-0x58(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    -0x58(%rbp),%rax
mov    (%rax),%rax
mov    (%rax),%rax
mov    (%rax),%edi
call   1040 <inet_ntoa@plt>
mov    -0x60(%rbp),%rdi
mov    %eax,%esi
call   1030 <strcpy@plt>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getmyaddr>:
push   %rbx
sub    $0x40,%rsp
mov    %rdi,%rbx
mov    %rsp,%rdi
mov    $0x40,%esi
call   1060 <gethostname@plt>
test   %rax,%rax
js     118f <getmyaddr+0x3f>
mov    %rsp,%rdi
call   1050 <gethostbyname@plt>
mov    (%rax),%rax
mov    (%rax),%rax
mov    (%rax),%edi
call   1040 <inet_ntoa@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1030 <strcpy@plt>
add    $0x40,%rsp
pop    %rbx
ret
xor    %edi,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
%struct.hostent = type { i64* }
%struct.in_addr = type { i32 }
define void @getmyaddr(i8* %0) {
%2 = alloca i8*
%3 = alloca [64 x i8]
%4 = alloca %struct.hostent*
store i8* %0, i8** %2
%5 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 0
%6 = call i64 @gethostname(i8* %5, i32 64)
%7 = icmp slt i64 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %1
%9 = call i32 @exit(i32 0)
unreachable
10: ; preds = %1
%11 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 0
%12 = call %struct.hostent* @gethostbyname(i8* %11)
store %struct.hostent* %12, %struct.hostent** %4
%13 = load i8*, i8** %2
%14 = load %struct.hostent*, %struct.hostent** %4
%15 = getelementptr inbounds %struct.hostent, %struct.hostent* %14, i32 0, i32 0
%16 = load i64*, i64** %15
%17 = getelementptr inbounds i64, i64* %16, i64 0
%18 = load i64, i64* %17
%19 = inttoptr i64 %18 to %struct.in_addr*
%20 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %19, i32 0, i32 0
%21 = load i32, i32* %20
%22 = call i32 @inet_ntoa(i32 %21)
%23 = call i32 @strcpy(i8* %13, i32 %22)
ret void
}

LLVM IR (-O2):
%struct.hostent = type { i64* }
%struct.in_addr = type { i32 }
define void @getmyaddr(i8* %0) {
%2 = alloca [64 x i8]
%3 = getelementptr inbounds [64 x i8], [64 x i8]* %2, i64 0, i64 0
%4 = call i64 @gethostname(i8* %3, i32 64)
%5 = icmp slt i64 %4, 0
br i1 %5, label %6, label %8
6: ; preds = %1
%7 = call i32 @exit(i32 0)
unreachable
8: ; preds = %1
%9 = call %struct.hostent* @gethostbyname(i8* %3)
%10 = getelementptr inbounds %struct.hostent, %struct.hostent* %9, i64 0, i32 0
%11 = load i64*, i64** %10
%12 = load i64, i64* %11
%13 = inttoptr i64 %12 to %struct.in_addr*
%14 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %13, i64 0, i32 0
%15 = load i32, i32* %14
%16 = call i32 @inet_ntoa(i32 %15)
%17 = call i32 @strcpy(i8* %0, i32 %16)
ret void
}