#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 */

/* Variables and functions */
int getdomainname(char *, int);
int gethostname(char *, int);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int GetFQDN(char fqdn[]) {
  int error;
  char hostName[64];
  char domainName[128];
  error = gethostname(hostName, 64);
  if (error == -1)
    return (-1);
  strcpy(fqdn, hostName);
  error = getdomainname(domainName, 128);
  if (error != -1) {
    strcat(fqdn, ".");
    strcat(fqdn, domainName);
    return (0);
  } else
    return (-2);
}


x86 assembly (clang, -O0):
<GetFQDN>:
push   %rbp
mov    %rsp,%rbp
sub    $0xe0,%rsp
mov    %rdi,-0x10(%rbp)
lea    -0x60(%rbp),%rdi
mov    $0x40,%esi
call   1060 <gethostname@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    1176 <GetFQDN+0x36>
movl   $0xffffffff,-0x4(%rbp)
jmp    11d4 <GetFQDN+0x94>
mov    -0x10(%rbp),%rdi
lea    -0x60(%rbp),%rsi
call   1030 <strcpy@plt>
lea    -0xe0(%rbp),%rdi
mov    $0x80,%esi
call   1040 <getdomainname@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
je     11cd <GetFQDN+0x8d>
mov    -0x10(%rbp),%rdi
lea    0xe54(%rip),%rsi
call   1050 <strcat@plt>
mov    -0x10(%rbp),%rdi
lea    -0xe0(%rbp),%rsi
call   1050 <strcat@plt>
movl   $0x0,-0x4(%rbp)
jmp    11d4 <GetFQDN+0x94>
movl   $0xfffffffe,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xe0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<GetFQDN>:
push   %rbx
sub    $0xc0,%rsp
mov    %rdi,%rbx
mov    %rsp,%rdi
mov    $0x40,%esi
call   1060 <gethostname@plt>
cmp    $0xffffffff,%eax
je     119c <GetFQDN+0x5c>
mov    %rsp,%rsi
mov    %rbx,%rdi
call   1030 <strcpy@plt>
lea    0x40(%rsp),%rdi
mov    $0x80,%esi
call   1040 <getdomainname@plt>
cmp    $0xffffffff,%eax
je     11a3 <GetFQDN+0x63>
lea    0xe7d(%rip),%rsi
mov    %rbx,%rdi
call   1050 <strcat@plt>
lea    0x40(%rsp),%rsi
mov    %rbx,%rdi
call   1050 <strcat@plt>
xor    %eax,%eax
jmp    11a8 <GetFQDN+0x68>
mov    $0xffffffff,%eax
jmp    11a8 <GetFQDN+0x68>
mov    $0xfffffffe,%eax
add    $0xc0,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [2 x i8] c".\00"
define i32 @GetFQDN(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca [64 x i8]
%6 = alloca [128 x i8]
store i8* %0, i8** %3
%7 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i64 0, i64 0
%8 = call i32 @gethostname(i8* %7, i32 64)
store i32 %8, i32* %4
%9 = load i32, i32* %4
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %12
11: ; preds = %1
store i32 -1, i32* %2
br label %27
12: ; preds = %1
%13 = load i8*, i8** %3
%14 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i64 0, i64 0
%15 = call i32 @strcpy(i8* %13, i8* %14)
%16 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 0
%17 = call i32 @getdomainname(i8* %16, i32 128)
store i32 %17, i32* %4
%18 = load i32, i32* %4
%19 = icmp ne i32 %18, -1
br i1 %19, label %20, label %26
20: ; preds = %12
%21 = load i8*, i8** %3
%22 = call i32 @strcat(i8* %21, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%23 = load i8*, i8** %3
%24 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 0
%25 = call i32 @strcat(i8* %23, i8* %24)
store i32 0, i32* %2
br label %27
26: ; preds = %12
store i32 -2, i32* %2
br label %27
27: ; preds = %26, %20, %11
%28 = load i32, i32* %2
ret i32 %28
}

LLVM IR (-O2):
@.str = [2 x i8] c".\00"
define i32 @GetFQDN(i8* %0) {
%2 = alloca [64 x i8]
%3 = alloca [128 x i8]
%4 = getelementptr inbounds [64 x i8], [64 x i8]* %2, i64 0, i64 0
%5 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%6 = call i32 @gethostname(i8* %4, i32 64)
%7 = icmp eq i32 %6, -1
br i1 %7, label %15, label %8
8: ; preds = %1
%9 = call i32 @strcpy(i8* %0, i8* %4)
%10 = call i32 @getdomainname(i8* %5, i32 128)
%11 = icmp eq i32 %10, -1
br i1 %11, label %15, label %12
12: ; preds = %8
%13 = call i32 @strcat(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%14 = call i32 @strcat(i8* %0, i8* %5)
br label %15
15: ; preds = %8, %1, %12
%16 = phi i32 [ 0, %12 ], [ -1, %1 ], [ -2, %8 ]
ret i32 %16
}