#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_name;
};

/* Variables and functions */
struct hostent *gethostbyname(char *);
scalar_t__ gethostname(char *, int);
scalar_t__ malloc(int);
char *getfullhostname() {
  struct hostent *hp = NULL;
  char *buf = (char *)malloc(254 + 1);
  if (gethostname(buf, 254) < 0) {
    return (NULL);
  }
  if ((hp = gethostbyname(buf)) == NULL) {
    return NULL;
  }
  return (hp->h_name);
}


x86 assembly (clang, -O0):
<getfullhostname>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movq   $0x0,-0x10(%rbp)
mov    $0xff,%edi
call   1040 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    $0xfe,%esi
call   1050 <gethostname@plt>
cmp    $0x0,%rax
jge    1173 <getfullhostname+0x43>
movq   $0x0,-0x8(%rbp)
jmp    11a2 <getfullhostname+0x72>
mov    -0x18(%rbp),%rdi
call   1030 <gethostbyname@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    1197 <getfullhostname+0x67>
movq   $0x0,-0x8(%rbp)
jmp    11a2 <getfullhostname+0x72>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getfullhostname>:
push   %rbx
mov    $0xff,%edi
call   1040 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    $0xfe,%esi
call   1050 <gethostname@plt>
test   %rax,%rax
js     1162 <getfullhostname+0x32>
mov    %rbx,%rdi
call   1030 <gethostbyname@plt>
test   %rax,%rax
je     1162 <getfullhostname+0x32>
mov    (%rax),%rax
pop    %rbx
ret
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
%struct.hostent = type { i8* }
define i8* @getfullhostname() {
%1 = alloca i8*
%2 = alloca %struct.hostent*
%3 = alloca i8*
store %struct.hostent* null, %struct.hostent** %2
%4 = call i64 @malloc(i32 255)
%5 = inttoptr i64 %4 to i8*
store i8* %5, i8** %3
%6 = load i8*, i8** %3
%7 = call i64 @gethostname(i8* %6, i32 254)
%8 = icmp slt i64 %7, 0
br i1 %8, label %9, label %10
9: ; preds = %0
store i8* null, i8** %1
br label %19
10: ; preds = %0
%11 = load i8*, i8** %3
%12 = call %struct.hostent* @gethostbyname(i8* %11)
store %struct.hostent* %12, %struct.hostent** %2
%13 = icmp eq %struct.hostent* %12, null
br i1 %13, label %14, label %15
14: ; preds = %10
store i8* null, i8** %1
br label %19
15: ; preds = %10
%16 = load %struct.hostent*, %struct.hostent** %2
%17 = getelementptr inbounds %struct.hostent, %struct.hostent* %16, i32 0, i32 0
%18 = load i8*, i8** %17
store i8* %18, i8** %1
br label %19
19: ; preds = %15, %14, %9
%20 = load i8*, i8** %1
ret i8* %20
}

LLVM IR (-O2):
%struct.hostent = type { i8* }
define i8* @getfullhostname() {
%1 = tail call i64 @malloc(i32 255)
%2 = inttoptr i64 %1 to i8*
%3 = tail call i64 @gethostname(i8* %2, i32 254)
%4 = icmp slt i64 %3, 0
br i1 %4, label %11, label %5
5: ; preds = %0
%6 = tail call %struct.hostent* @gethostbyname(i8* %2)
%7 = icmp eq %struct.hostent* %6, null
br i1 %7, label %11, label %8
8: ; preds = %5
%9 = getelementptr inbounds %struct.hostent, %struct.hostent* %6, i64 0, i32 0
%10 = load i8*, i8** %9
br label %11
11: ; preds = %5, %0, %8
%12 = phi i8* [ %10, %8 ], [ null, %0 ], [ null, %5 ]
ret i8* %12
}