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

/* Variables and functions */
int gethostname(char *, int);
char *strchr(char *, char);
int strlen(char *);
char *xstrdup(char *);
char *xshort_hostname(void) {
  int error_code;
  char *dot_ptr, path_name[1024];
  error_code = gethostname(path_name, sizeof(path_name));
  if (error_code)
    return NULL;
  dot_ptr = strchr(path_name, '.');
  if (dot_ptr == NULL)
    dot_ptr = path_name + strlen(path_name);
  else
    dot_ptr[0] = '\0';
  return xstrdup(path_name);
}


x86 assembly (clang, -O0):
<xshort_hostname>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
lea    -0x420(%rbp),%rdi
mov    $0x400,%esi
call   1060 <gethostname@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     1176 <xshort_hostname+0x36>
movq   $0x0,-0x8(%rbp)
jmp    11df <xshort_hostname+0x9f>
lea    -0x420(%rbp),%rdi
mov    $0x2e,%esi
call   1040 <strchr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11c8 <xshort_hostname+0x88>
lea    -0x420(%rbp),%rax
mov    %rax,-0x428(%rbp)
lea    -0x420(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x428(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
jmp    11cf <xshort_hostname+0x8f>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
lea    -0x420(%rbp),%rdi
call   1050 <xstrdup@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<xshort_hostname>:
sub    $0x408,%rsp
mov    %rsp,%rdi
mov    $0x400,%esi
call   1060 <gethostname@plt>
test   %eax,%eax
je     1162 <xshort_hostname+0x22>
xor    %eax,%eax
add    $0x408,%rsp
ret
mov    %rsp,%rdi
mov    $0x2e,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     1179 <xshort_hostname+0x39>
movb   $0x0,(%rax)
jmp    1181 <xshort_hostname+0x41>
mov    %rsp,%rdi
call   1030 <strlen@plt>
mov    %rsp,%rdi
call   1050 <xstrdup@plt>
add    $0x408,%rsp
ret

LLVM IR (-O0):
define i8* @xshort_hostname() {
%1 = alloca i8*
%2 = alloca i32
%3 = alloca i8*
%4 = alloca [1024 x i8]
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%6 = call i32 @gethostname(i8* %5, i32 1024)
store i32 %6, i32* %2
%7 = load i32, i32* %2
%8 = icmp ne i32 %7, 0
br i1 %8, label %9, label %10
9: ; preds = %0
store i8* null, i8** %1
br label %27
10: ; preds = %0
%11 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%12 = call i8* @strchr(i8* %11, i8 signext 46)
store i8* %12, i8** %3
%13 = load i8*, i8** %3
%14 = icmp eq i8* %13, null
br i1 %14, label %15, label %21
15: ; preds = %10
%16 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%17 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%18 = call i32 @strlen(i8* %17)
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i8, i8* %16, i64 %19
store i8* %20, i8** %3
br label %24
21: ; preds = %10
%22 = load i8*, i8** %3
%23 = getelementptr inbounds i8, i8* %22, i64 0
store i8 0, i8* %23
br label %24
24: ; preds = %21, %15
%25 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%26 = call i8* @xstrdup(i8* %25)
store i8* %26, i8** %1
br label %27
27: ; preds = %24, %9
%28 = load i8*, i8** %1
ret i8* %28
}

LLVM IR (-O2):
define i8* @xshort_hostname() {
%1 = alloca [1024 x i8]
%2 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 0
%3 = call i32 @gethostname(i8* %2, i32 1024)
%4 = icmp eq i32 %3, 0
br i1 %4, label %5, label %13
5: ; preds = %0
%6 = call i8* @strchr(i8* %2, i8 signext 46)
%7 = icmp eq i8* %6, null
br i1 %7, label %8, label %10
8: ; preds = %5
%9 = call i32 @strlen(i8* %2)
br label %11
10: ; preds = %5
store i8 0, i8* %6
br label %11
11: ; preds = %10, %8
%12 = call i8* @xstrdup(i8* %2)
br label %13
13: ; preds = %0, %11
%14 = phi i8* [ %12, %11 ], [ null, %0 ]
ret i8* %14
}