#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 errno;
int /*<<< orphan*/ fflush(int /*<<< orphan*/ *);
int gethostname(char *, size_t);
int handle_zng(int);
int /*<<< orphan*/ printf(char *, ...);
int gethostname_test(char *name, size_t len) {
  int ret, save_errno;
  int passed;
  printf("gethostname(): name=0x%p, len=%zu\n", name, len);
  fflush(NULL);
  passed = handle_zng(ret = gethostname(name, len));
  save_errno = errno;
  switch (passed) {
  case -1:
    printf("\t\tret = %d\n", ret);
    printf("\tSucceeded Phase 1\n");
    fflush(NULL);
    break;
  case 0:
    printf("\t\tname = %.80s\n", name);
    printf("\t\tret = %d\n", ret);
    printf("\tSucceeded Phase 1\n");
    fflush(NULL);
    break;
  case -2:
    printf("\tFailed Phase 1: returned undefined value! "
           "ret = %d\n",
           ret);
    fflush(NULL);
    break;
  default:
    printf("Internal syscalltester error: passed = %d\n", passed);
    fflush(NULL);
    break;
  }
  errno = save_errno;
  return ret;
}


x86 assembly (clang, -O0):
<gethostname_test>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rdx
lea    0xea1(%rip),%rdi
xor    %eax,%eax
mov    %eax,-0x24(%rbp)
call   1040 <printf@plt>
mov    -0x24(%rbp),%eax
mov    %eax,%edi
call   1050 <fflush@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1060 <gethostname@plt>
mov    %eax,%edi
mov    %edi,-0x14(%rbp)
call   1030 <handle_zng@plt>
mov    %eax,-0x1c(%rbp)
mov    0x2e4c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x20(%rbp)
sub    $0xfffffffe,%eax
je     123a <gethostname_test+0xfa>
jmp    11ad <gethostname_test+0x6d>
mov    -0x20(%rbp),%eax
sub    $0xffffffff,%eax
je     11ce <gethostname_test+0x8e>
jmp    11be <gethostname_test+0x7e>
mov    -0x20(%rbp),%eax
test   %eax,%eax
je     11fb <gethostname_test+0xbb>
jmp    1259 <gethostname_test+0x119>
mov    -0x14(%rbp),%esi
lea    0xe4b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe49(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1050 <fflush@plt>
jmp    1273 <gethostname_test+0x133>
mov    -0x8(%rbp),%rsi
lea    0xe3d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%esi
lea    0xe0c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe0a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1050 <fflush@plt>
jmp    1273 <gethostname_test+0x133>
mov    -0x14(%rbp),%esi
lea    0xe0f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1050 <fflush@plt>
jmp    1273 <gethostname_test+0x133>
mov    -0x1c(%rbp),%esi
lea    0xe25(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1050 <fflush@plt>
mov    -0x18(%rbp),%ecx
mov    0x2d63(%rip),%rax
mov    %ecx,(%rax)
mov    -0x14(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gethostname_test>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbp
mov    %rdi,%rbx
lea    0xe9c(%rip),%rdi
mov    %rbx,%rsi
mov    %rbp,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
xor    %edi,%edi
call   1060 <fflush@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1070 <gethostname@plt>
mov    %eax,%ebp
mov    %eax,%edi
call   1040 <handle_zng@plt>
mov    0x2e4d(%rip),%r14
mov    (%r14),%r15d
cmp    $0xfffffffe,%eax
je     11af <gethostname_test+0x5f>
test   %eax,%eax
je     11c1 <gethostname_test+0x71>
cmp    $0xffffffff,%eax
je     11d2 <gethostname_test+0x82>
lea    0xec9(%rip),%rdi
mov    %eax,%esi
jmp    11b8 <gethostname_test+0x68>
lea    0xe89(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    11ee <gethostname_test+0x9e>
lea    0xe67(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe4a(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xeb6(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   1060 <fflush@plt>
mov    %r15d,(%r14)
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [35 x i8] c"gethostname(): name=0x%p, len=%zu\0A\00"
@errno = global i32 0
@.str.1 = [12 x i8] c"\09\09ret = %d\0A\00"
@.str.2 = [20 x i8] c"\09Succeeded Phase 1\0A\00"
@.str.3 = [16 x i8] c"\09\09name = %.80s\0A\00"
@.str.4 = [53 x i8] c"\09Failed Phase 1: returned undefined value! ret = %d\0A\00"
@.str.5 = [43 x i8] c"Internal syscalltester error: passed = %d\0A\00"
define i32 @gethostname_test(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %3
store i64 %1, i64* %4
%8 = load i8*, i8** %3
%9 = load i64, i64* %4
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i8* %8, i64 %9)
%11 = call i32 @fflush(i32* null)
%12 = load i8*, i8** %3
%13 = load i64, i64* %4
%14 = call i32 @gethostname(i8* %12, i64 %13)
store i32 %14, i32* %5
%15 = call i32 @handle_zng(i32 %14)
store i32 %15, i32* %7
%16 = load i32, i32* @errno
store i32 %16, i32* %6
%17 = load i32, i32* %7
switch i32 %17, label %34 [
i32 -1, label %18
i32 0, label %23
i32 -2, label %30
]
18: ; preds = %2
%19 = load i32, i32* %5
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %19)
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
%22 = call i32 @fflush(i32* null)
br label %38
23: ; preds = %2
%24 = load i8*, i8** %3
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i8* %24)
%26 = load i32, i32* %5
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %26)
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
%29 = call i32 @fflush(i32* null)
br label %38
30: ; preds = %2
%31 = load i32, i32* %5
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.4, i64 0, i64 0), i32 %31)
%33 = call i32 @fflush(i32* null)
br label %38
34: ; preds = %2
%35 = load i32, i32* %7
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.5, i64 0, i64 0), i32 %35)
%37 = call i32 @fflush(i32* null)
br label %38
38: ; preds = %34, %30, %23, %18
%39 = load i32, i32* %6
store i32 %39, i32* @errno
%40 = load i32, i32* %5
ret i32 %40
}

LLVM IR (-O2):
@.str = [35 x i8] c"gethostname(): name=0x%p, len=%zu\0A\00"
@errno = global i32 0
@.str.1 = [12 x i8] c"\09\09ret = %d\0A\00"
@.str.3 = [16 x i8] c"\09\09name = %.80s\0A\00"
@.str.4 = [53 x i8] c"\09Failed Phase 1: returned undefined value! ret = %d\0A\00"
@.str.5 = [43 x i8] c"Internal syscalltester error: passed = %d\0A\00"
@str.6 = [19 x i8] c"\09Succeeded Phase 1\00"
define i32 @gethostname_test(i8* %0, i64 %1) {
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i8* %0, i64 %1)
%4 = tail call i32 @fflush(i32* null)
%5 = tail call i32 @gethostname(i8* %0, i64 %1)
%6 = tail call i32 @handle_zng(i32 %5)
%7 = load i32, i32* @errno
switch i32 %6, label %17 [
i32 -1, label %8
i32 0, label %11
i32 -2, label %15
]
8: ; preds = %2
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %5)
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str.6, i64 0, i64 0))
br label %19
11: ; preds = %2
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i8* %0)
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %5)
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str.6, i64 0, i64 0))
br label %19
15: ; preds = %2
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([53 x i8], [53 x i8]* @.str.4, i64 0, i64 0), i32 %5)
br label %19
17: ; preds = %2
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @.str.5, i64 0, i64 0), i32 %6)
br label %19
19: ; preds = %17, %15, %11, %8
%20 = tail call i32 @fflush(i32* null)
store i32 %7, i32* @errno
ret i32 %5
}