#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 addrinfo {
  int /*<<< orphan*/ ai_addrlen;
  int /*<<< orphan*/ ai_addr;
};

/* Variables and functions */
int /*<<< orphan*/ freeaddrinfo(struct addrinfo *);
scalar_t__ getaddrinfo(char *, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                       struct addrinfo **);
int gethostname(char *, size_t);
int getnameinfo(int /*<<< orphan*/, int /*<<< orphan*/, char *, size_t,
                int /*<<< orphan*/ *, int /*<<< orphan*/, int /*<<< orphan*/);
int c_fullyQualifiedDomainName(char *buffer, size_t bufferLength) {
  if (gethostname(buffer, bufferLength) == -1)
    return -1;
  struct addrinfo *ai = NULL;
  if (getaddrinfo(buffer, NULL, NULL, &ai) != 0)
    return -1;
  int ret = getnameinfo(ai->ai_addr, ai->ai_addrlen, buffer, bufferLength, NULL,
                        0, 0);
  freeaddrinfo(ai);
  return !!ret;
}


x86 assembly (clang, -O0):
<c_fullyQualifiedDomainName>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <gethostname@plt>
cmp    $0xffffffff,%eax
jne    1172 <c_fullyQualifiedDomainName+0x32>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ec <c_fullyQualifiedDomainName+0xac>
movq   $0x0,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%edx
lea    -0x20(%rbp),%rcx
mov    %rdx,%rsi
call   1050 <getaddrinfo@plt>
cmp    $0x0,%rax
je     11a4 <c_fullyQualifiedDomainName+0x64>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ec <c_fullyQualifiedDomainName+0xac>
mov    -0x20(%rbp),%rax
mov    0x4(%rax),%edi
mov    -0x20(%rbp),%rax
mov    (%rax),%esi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
xor    %eax,%eax
mov    %eax,%r8d
xor    %r9d,%r9d
movl   $0x0,(%rsp)
call   1030 <getnameinfo@plt>
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%rdi
call   1060 <freeaddrinfo@plt>
cmpl   $0x0,-0x24(%rbp)
setne  %al
xor    $0xff,%al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<c_fullyQualifiedDomainName>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
call   1040 <gethostname@plt>
cmp    $0xffffffff,%eax
je     11b5 <c_fullyQualifiedDomainName+0x75>
movq   $0x0,0x10(%rsp)
lea    0x10(%rsp),%rcx
mov    %rbx,%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1050 <getaddrinfo@plt>
mov    %rax,%rcx
mov    $0xffffffff,%eax
test   %rcx,%rcx
jne    11ba <c_fullyQualifiedDomainName+0x7a>
mov    0x10(%rsp),%rax
mov    (%rax),%esi
mov    0x4(%rax),%edi
movl   $0x0,(%rsp)
mov    %rbx,%rdx
mov    %r14,%rcx
xor    %r8d,%r8d
xor    %r9d,%r9d
call   1030 <getnameinfo@plt>
mov    %eax,%ebx
mov    0x10(%rsp),%rdi
call   1060 <freeaddrinfo@plt>
xor    %eax,%eax
test   %ebx,%ebx
setne  %al
jmp    11ba <c_fullyQualifiedDomainName+0x7a>
mov    $0xffffffff,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.addrinfo = type { i32, i32 }
define i32 @c_fullyQualifiedDomainName(i8* %0, i64 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i64
%6 = alloca %struct.addrinfo*
%7 = alloca i32
store i8* %0, i8** %4
store i64 %1, i64* %5
%8 = load i8*, i8** %4
%9 = load i64, i64* %5
%10 = call i32 @gethostname(i8* %8, i64 %9)
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %13
12: ; preds = %2
store i32 -1, i32* %3
br label %35
13: ; preds = %2
store %struct.addrinfo* null, %struct.addrinfo** %6
%14 = load i8*, i8** %4
%15 = call i64 @getaddrinfo(i8* %14, i32* null, i32* null, %struct.addrinfo** %6)
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %13
store i32 -1, i32* %3
br label %35
18: ; preds = %13
%19 = load %struct.addrinfo*, %struct.addrinfo** %6
%20 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %19, i32 0, i32 1
%21 = load i32, i32* %20
%22 = load %struct.addrinfo*, %struct.addrinfo** %6
%23 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %22, i32 0, i32 0
%24 = load i32, i32* %23
%25 = load i8*, i8** %4
%26 = load i64, i64* %5
%27 = call i32 @getnameinfo(i32 %21, i32 %24, i8* %25, i64 %26, i32* null, i32 0, i32 0)
store i32 %27, i32* %7
%28 = load %struct.addrinfo*, %struct.addrinfo** %6
%29 = call i32 @freeaddrinfo(%struct.addrinfo* %28)
%30 = load i32, i32* %7
%31 = icmp ne i32 %30, 0
%32 = xor i1 %31, true
%33 = xor i1 %32, true
%34 = zext i1 %33 to i32
store i32 %34, i32* %3
br label %35
35: ; preds = %18, %17, %12
%36 = load i32, i32* %3
ret i32 %36
}

LLVM IR (-O2):
%struct.addrinfo = type { i32, i32 }
define i32 @c_fullyQualifiedDomainName(i8* %0, i64 %1) {
%3 = alloca %struct.addrinfo*
%4 = tail call i32 @gethostname(i8* %0, i64 %1)
%5 = icmp eq i32 %4, -1
br i1 %5, label %23, label %6
6: ; preds = %2
%7 = bitcast %struct.addrinfo** %3 to i8*
store %struct.addrinfo* null, %struct.addrinfo** %3
%8 = call i64 @getaddrinfo(i8* %0, i32* null, i32* null, %struct.addrinfo** %3)
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %21
10: ; preds = %6
%11 = load %struct.addrinfo*, %struct.addrinfo** %3
%12 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %11, i64 0, i32 1
%13 = load i32, i32* %12
%14 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %11, i64 0, i32 0
%15 = load i32, i32* %14
%16 = call i32 @getnameinfo(i32 %13, i32 %15, i8* %0, i64 %1, i32* null, i32 0, i32 0)
%17 = load %struct.addrinfo*, %struct.addrinfo** %3
%18 = call i32 @freeaddrinfo(%struct.addrinfo* %17)
%19 = icmp ne i32 %16, 0
%20 = zext i1 %19 to i32
br label %21
21: ; preds = %6, %10
%22 = phi i32 [ %20, %10 ], [ -1, %6 ]
br label %23
23: ; preds = %2, %21
%24 = phi i32 [ %22, %21 ], [ -1, %2 ]
ret i32 %24
}