#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 /*<<< orphan*/ _SC_HOST_NAME_MAX;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/);
scalar_t__ gethostname(char *, int);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ stderr;
char *sysconf(int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  char buf[1024];
  printf("HOST_NAME_MAX=%ld\n", sysconf(_SC_HOST_NAME_MAX));
  if (gethostname(buf, 1023) < 0) {
    fputs("gethostname failed???\n", stderr);
    exit(1);
  }
  printf("hostname=%s\n", buf);
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x410,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e68(%rip),%rax
mov    (%rax),%edi
call   1050 <sysconf@plt>
mov    %rax,%rsi
lea    0xe7f(%rip),%rdi
call   1030 <printf@plt>
lea    -0x410(%rbp),%rdi
mov    $0x3ff,%esi
call   1060 <gethostname@plt>
cmp    $0x0,%rax
jge    11c0 <main+0x70>
mov    0x2e38(%rip),%rax
mov    (%rax),%esi
lea    0xe62(%rip),%rdi
call   1040 <fputs@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
lea    -0x410(%rbp),%rsi
lea    0xe5c(%rip),%rdi
call   1030 <printf@plt>
xor    %edi,%edi
call   1070 <exit@plt>

x86 assembly (clang, -O2):
<main>:
sub    $0x408,%rsp
mov    0x2e7a(%rip),%rax
mov    (%rax),%edi
call   1050 <sysconf@plt>
lea    0xe94(%rip),%rdi
mov    %rax,%rsi
call   1030 <printf@plt>
mov    %rsp,%rdi
mov    $0x3ff,%esi
call   1060 <gethostname@plt>
test   %rax,%rax
jns    11a5 <main+0x55>
mov    0x2e53(%rip),%rax
mov    (%rax),%esi
lea    0xe7d(%rip),%rdi
call   1040 <fputs@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
lea    0xe7e(%rip),%rdi
mov    %rsp,%rsi
call   1030 <printf@plt>
xor    %edi,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [19 x i8] c"HOST_NAME_MAX=%ld\0A\00"
@_SC_HOST_NAME_MAX = global i32 0
@.str.1 = [23 x i8] c"gethostname failed???\0A\00"
@stderr = global i32 0
@.str.2 = [13 x i8] c"hostname=%s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [1024 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = load i32, i32* @_SC_HOST_NAME_MAX
%8 = call i8* @sysconf(i32 %7)
%9 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %8)
%10 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%11 = call i64 @gethostname(i8* %10, i32 1023)
%12 = icmp slt i64 %11, 0
br i1 %12, label %13, label %17
13: ; preds = %2
%14 = load i32, i32* @stderr
%15 = call i32 @fputs(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 %14)
%16 = call i32 @exit(i32 1)
unreachable
17: ; preds = %2
%18 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%19 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i8* %18)
%20 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str = [19 x i8] c"HOST_NAME_MAX=%ld\0A\00"
@_SC_HOST_NAME_MAX = global i32 0
@.str.1 = [23 x i8] c"gethostname failed???\0A\00"
@stderr = global i32 0
@.str.2 = [13 x i8] c"hostname=%s\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [1024 x i8]
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%5 = load i32, i32* @_SC_HOST_NAME_MAX
%6 = tail call i8* @sysconf(i32 %5)
%7 = tail call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %6)
%8 = call i64 @gethostname(i8* %4, i32 1023)
%9 = icmp slt i64 %8, 0
br i1 %9, label %10, label %14
10: ; preds = %2
%11 = load i32, i32* @stderr
%12 = call i32 @fputs(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 %11)
%13 = call i32 @exit(i32 1)
unreachable
14: ; preds = %2
%15 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i8* %4)
%16 = call i32 @exit(i32 0)
unreachable
}