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

/* Variables and functions */
int errno;
int gethostname(char *, int);
int /*<<< orphan*/ printf(char *, ...);
char *strerror(int);
int main(void) {
  char hostname[512];
  int ret;
  ret = gethostname(hostname, sizeof(hostname));
  if (ret < 0) {
    printf("gethostname() returned error %d: %s\n", errno, strerror(errno));
    return 1;
  }
  printf("gethostname() returned '%s'\n", hostname);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x220,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x210(%rbp),%rdi
mov    $0x200,%esi
call   1040 <gethostname@plt>
mov    %eax,-0x214(%rbp)
cmpl   $0x0,-0x214(%rbp)
jge    11a6 <main+0x76>
mov    0x2e73(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x218(%rbp)
mov    0x2e64(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
mov    -0x218(%rbp),%esi
mov    %rax,%rdx
lea    0xe6d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    11c2 <main+0x92>
lea    -0x210(%rbp),%rsi
lea    0xe71(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x220,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x200,%rsp
mov    %rsp,%rdi
mov    $0x200,%esi
call   1040 <gethostname@plt>
test   %eax,%eax
js     115e <main+0x2e>
lea    0xed5(%rip),%rdi
xor    %ebx,%ebx
mov    %rsp,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
jmp    1186 <main+0x56>
mov    0x2e7b(%rip),%rax
mov    (%rax),%ebx
mov    %ebx,%edi
call   1050 <strerror@plt>
lea    0xe8b(%rip),%rdi
mov    %ebx,%esi
mov    %rax,%rdx
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0x1,%ebx
mov    %ebx,%eax
add    $0x200,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [37 x i8] c"gethostname() returned error %d: %s\0A\00"
@errno = global i32 0
@.str.1 = [29 x i8] c"gethostname() returned '%s'\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [512 x i8]
%3 = alloca i32
store i32 0, i32* %1
%4 = getelementptr inbounds [512 x i8], [512 x i8]* %2, i64 0, i64 0
%5 = call i32 @gethostname(i8* %4, i32 512)
store i32 %5, i32* %3
%6 = load i32, i32* %3
%7 = icmp slt i32 %6, 0
br i1 %7, label %8, label %13
8: ; preds = %0
%9 = load i32, i32* @errno
%10 = load i32, i32* @errno
%11 = call i8* @strerror(i32 %10)
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i32 %9, i8* %11)
store i32 1, i32* %1
br label %16
13: ; preds = %0
%14 = getelementptr inbounds [512 x i8], [512 x i8]* %2, i64 0, i64 0
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i8* %14)
store i32 0, i32* %1
br label %16
16: ; preds = %13, %8
%17 = load i32, i32* %1
ret i32 %17
}

LLVM IR (-O2):
@.str = [37 x i8] c"gethostname() returned error %d: %s\0A\00"
@errno = global i32 0
@.str.1 = [29 x i8] c"gethostname() returned '%s'\0A\00"
define i32 @main() {
%1 = alloca [512 x i8]
%2 = getelementptr inbounds [512 x i8], [512 x i8]* %1, i64 0, i64 0
%3 = call i32 @gethostname(i8* %2, i32 512)
%4 = icmp slt i32 %3, 0
br i1 %4, label %5, label %9
5: ; preds = %0
%6 = load i32, i32* @errno
%7 = call i8* @strerror(i32 %6)
%8 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i32 %6, i8* %7)
br label %11
9: ; preds = %0
%10 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i8* %2)
br label %11
11: ; preds = %9, %5
%12 = phi i32 [ 1, %5 ], [ 0, %9 ]
ret i32 %12
}