#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 _error(char const *, char *, int);
scalar_t__ gethostname(char *, int);
int /*<<< orphan*/ printf(char *, char const *);
int _gethostname(char const *progname) {
  char hostname[64];
  printf("%s: Testing gethostname()\n", progname);
  if (gethostname(hostname, sizeof(hostname)) != 0)
    return _error(progname, "gethostname", 32);
  else
    printf("hostname: %s\n", hostname);
  return 0;
}


x86 assembly (clang, -O0):
<_gethostname>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xeb9(%rip),%rdi
call   1030 <printf@plt>
lea    -0x50(%rbp),%rdi
mov    $0x40,%esi
call   1050 <gethostname@plt>
cmp    $0x0,%rax
je     1181 <_gethostname+0x51>
mov    -0x10(%rbp),%rdi
lea    0xeac(%rip),%rsi
mov    $0x20,%edx
call   1040 <_error@plt>
mov    %eax,-0x4(%rbp)
jmp    1198 <_gethostname+0x68>
lea    -0x50(%rbp),%rsi
lea    0xe9b(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_gethostname>:
push   %rbx
sub    $0x40,%rsp
mov    %rdi,%rbx
lea    0xec1(%rip),%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
mov    %rsp,%rdi
mov    $0x40,%esi
call   1050 <gethostname@plt>
test   %rax,%rax
je     116f <_gethostname+0x3f>
lea    0xebb(%rip),%rsi
mov    %rbx,%rdi
mov    $0x20,%edx
call   1040 <_error@plt>
jmp    1180 <_gethostname+0x50>
lea    0xeb1(%rip),%rdi
mov    %rsp,%rsi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [27 x i8] c"%s: Testing gethostname()\0A\00"
@.str.1 = [12 x i8] c"gethostname\00"
@.str.2 = [14 x i8] c"hostname: %s\0A\00"
define i32 @_gethostname(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca [64 x i8]
store i8* %0, i8** %3
%5 = load i8*, i8** %3
%6 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* %5)
%7 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 0
%8 = call i64 @gethostname(i8* %7, i32 64)
%9 = icmp ne i64 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %1
%11 = load i8*, i8** %3
%12 = call i32 @_error(i8* %11, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 32)
store i32 %12, i32* %2
br label %17
13: ; preds = %1
%14 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 0
%15 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i8* %14)
br label %16
16: ; preds = %13
store i32 0, i32* %2
br label %17
17: ; preds = %16, %10
%18 = load i32, i32* %2
ret i32 %18
}

LLVM IR (-O2):
@.str = [27 x i8] c"%s: Testing gethostname()\0A\00"
@.str.1 = [12 x i8] c"gethostname\00"
@.str.2 = [14 x i8] c"hostname: %s\0A\00"
define i32 @_gethostname(i8* %0) {
%2 = alloca [64 x i8]
%3 = getelementptr inbounds [64 x i8], [64 x i8]* %2, i64 0, i64 0
%4 = tail call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* %0)
%5 = call i64 @gethostname(i8* %3, i32 64)
%6 = icmp eq i64 %5, 0
br i1 %6, label %9, label %7
7: ; preds = %1
%8 = call i32 @_error(i8* %0, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 32)
br label %11
9: ; preds = %1
%10 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i8* %3)
br label %11
11: ; preds = %9, %7
%12 = phi i32 [ %8, %7 ], [ 0, %9 ]
ret i32 %12
}