#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 BUFSIZ;
int gethostname(char *, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
int main(int argc, char **argv) {
  char name[BUFSIZ];
  int ret = 0;
  ret = gethostname(name, BUFSIZ - 1);
  if (ret == -1) {
    perror("gethostname");
    return -1;
  }
  name[BUFSIZ - 1] = '0';
  printf("%s\n", name);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e93(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x30(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    0x2e60(%rip),%rax
mov    (%rax),%esi
sub    $0x1,%esi
call   1050 <gethostname@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0xffffffff,-0x24(%rbp)
jne    11b6 <main+0x86>
lea    0xe62(%rip),%rdi
call   1040 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x28(%rbp)
jmp    11e6 <main+0xb6>
mov    -0x30(%rbp),%rsi
mov    0x2e1f(%rip),%rax
mov    (%rax),%eax
sub    $0x1,%eax
cltq
movb   $0x30,(%rsi,%rax,1)
lea    0xe39(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x28(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r14
push   %rbx
mov    0x2ea2(%rip),%r14
mov    (%r14),%eax
mov    %rsp,%rbx
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
sub    %rcx,%rbx
mov    %rbx,%rsp
lea    -0x1(%rax),%esi
mov    %rbx,%rdi
call   1050 <gethostname@plt>
cmp    $0xffffffff,%eax
je     1187 <main+0x57>
movslq (%r14),%rax
movb   $0x30,-0x1(%rax,%rbx,1)
lea    0xe98(%rip),%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
xor    %eax,%eax
lea    -0x10(%rbp),%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xe72(%rip),%rdi
call   1040 <perror@plt>
mov    $0xffffffff,%eax
jmp    117e <main+0x4e>

LLVM IR (-O0):
@BUFSIZ = global i32 0
@.str = [12 x i8] c"gethostname\00"
@.str.1 = [4 x i8] c"%s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* @BUFSIZ
%11 = zext i32 %10 to i64
%12 = call i8* @llvm.stacksave()
store i8* %12, i8** %6
%13 = alloca i8, i64 %11
store i64 %11, i64* %7
store i32 0, i32* %8
%14 = load i32, i32* @BUFSIZ
%15 = sub nsw i32 %14, 1
%16 = call i32 @gethostname(i8* %13, i32 %15)
store i32 %16, i32* %8
%17 = load i32, i32* %8
%18 = icmp eq i32 %17, -1
br i1 %18, label %19, label %21
19: ; preds = %2
%20 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
store i32 1, i32* %9
br label %27
21: ; preds = %2
%22 = load i32, i32* @BUFSIZ
%23 = sub nsw i32 %22, 1
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %13, i64 %24
store i8 48, i8* %25
%26 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %13)
store i32 0, i32* %3
store i32 1, i32* %9
br label %27
27: ; preds = %21, %19
%28 = load i8*, i8** %6
%29 = load i32, i32* %3
ret i32 %29
}

LLVM IR (-O2):
@BUFSIZ = global i32 0
@.str = [12 x i8] c"gethostname\00"
@.str.1 = [4 x i8] c"%s\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = load i32, i32* @BUFSIZ
%4 = zext i32 %3 to i64
%5 = alloca i8, i64 %4
%6 = add nsw i32 %3, -1
%7 = call i32 @gethostname(i8* %5, i32 %6)
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %11
9: ; preds = %2
%10 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
br label %17
11: ; preds = %2
%12 = load i32, i32* @BUFSIZ
%13 = add nsw i32 %12, -1
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds i8, i8* %5, i64 %14
store i8 48, i8* %15
%16 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %5)
br label %17
17: ; preds = %11, %9
%18 = phi i32 [ -1, %9 ], [ 0, %11 ]
ret i32 %18
}