#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 getdomainname(char *, int);
int handle_zng(int);
int /*<<< orphan*/ printf(char *, ...);
int getdomainname_test(char *name, int namelen) {
  int ret, save_errno;
  int passed;
  printf("getdomainname(): name=0x%p, namelen=%d\n", name, namelen);
  fflush(NULL);
  passed = handle_zng(ret = getdomainname(name, namelen));
  save_errno = errno;
  switch (passed) {
  case -1:
  case 0:
    printf("\t\tname = %s\n", (((name) == NULL) ? "(null)" : (name)));
    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):
<getdomainname_test>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rsi
mov    -0xc(%rbp),%edx
lea    0xea3(%rip),%rdi
xor    %eax,%eax
mov    %eax,-0x20(%rbp)
call   1050 <printf@plt>
mov    -0x20(%rbp),%eax
mov    %eax,%edi
call   1060 <fflush@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1040 <getdomainname@plt>
mov    %eax,%edi
mov    %edi,-0x10(%rbp)
call   1030 <handle_zng@plt>
mov    %eax,-0x18(%rbp)
mov    0x2e4f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x1c(%rbp)
sub    $0xfffffffe,%eax
je     120f <getdomainname_test+0xcf>
jmp    11aa <getdomainname_test+0x6a>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
sub    $0x1,%eax
ja     122e <getdomainname_test+0xee>
jmp    11be <getdomainname_test+0x7e>
cmpq   $0x0,-0x8(%rbp)
jne    11d9 <getdomainname_test+0x99>
lea    0xe65(%rip),%rax
mov    %rax,-0x28(%rbp)
jmp    11e1 <getdomainname_test+0xa1>
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rsi
lea    0xe3c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe42(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1060 <fflush@plt>
jmp    1248 <getdomainname_test+0x108>
mov    -0x10(%rbp),%esi
lea    0xe37(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1060 <fflush@plt>
jmp    1248 <getdomainname_test+0x108>
mov    -0x18(%rbp),%esi
lea    0xe4d(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1060 <fflush@plt>
mov    -0x14(%rbp),%ecx
mov    0x2d8e(%rip),%rax
mov    %ecx,(%rax)
mov    -0x10(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getdomainname_test>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%rbx
lea    0xe9d(%rip),%rdi
mov    %rbx,%rsi
mov    %ebp,%edx
xor    %eax,%eax
call   1060 <printf@plt>
xor    %edi,%edi
call   1070 <fflush@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
call   1050 <getdomainname@plt>
mov    %eax,%ebp
mov    %eax,%edi
call   1040 <handle_zng@plt>
mov    0x2e50(%rip),%r14
mov    (%r14),%r15d
lea    0x1(%rax),%ecx
cmp    $0x2,%ecx
jae    11c5 <getdomainname_test+0x75>
test   %rbx,%rbx
lea    0xe90(%rip),%rsi
cmovne %rbx,%rsi
lea    0xe78(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xede(%rip),%rdi
call   1030 <puts@plt>
jmp    11e5 <getdomainname_test+0x95>
cmp    $0xfffffffe,%eax
jne    11d5 <getdomainname_test+0x85>
lea    0xe6b(%rip),%rdi
mov    %ebp,%esi
jmp    11de <getdomainname_test+0x8e>
lea    0xe95(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %edi,%edi
call   1070 <fflush@plt>
mov    %r15d,(%r14)
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [40 x i8] c"getdomainname(): name=0x%p, namelen=%d\0A\00"
@errno = global i32 0
@.str.1 = [13 x i8] c"\09\09name = %s\0A\00"
@.str.2 = [7 x i8] c"(null)\00"
@.str.3 = [20 x i8] c"\09Succeeded Phase 1\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 @getdomainname_test(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
%8 = load i8*, i8** %3
%9 = load i32, i32* %4
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), i8* %8, i32 %9)
%11 = call i32 @fflush(i32* null)
%12 = load i8*, i8** %3
%13 = load i32, i32* %4
%14 = call i32 @getdomainname(i8* %12, i32 %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 %33 [
i32 -1, label %18
i32 0, label %18
i32 -2, label %29
]
18: ; preds = %2, %2
%19 = load i8*, i8** %3
%20 = icmp eq i8* %19, null
br i1 %20, label %21, label %22
21: ; preds = %18
br label %24
22: ; preds = %18
%23 = load i8*, i8** %3
br label %24
24: ; preds = %22, %21
%25 = phi i8* [ getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), %21 ], [ %23, %22 ]
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* %25)
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
%28 = call i32 @fflush(i32* null)
br label %37
29: ; preds = %2
%30 = load i32, i32* %5
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.4, i64 0, i64 0), i32 %30)
%32 = call i32 @fflush(i32* null)
br label %37
33: ; preds = %2
%34 = load i32, i32* %7
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.5, i64 0, i64 0), i32 %34)
%36 = call i32 @fflush(i32* null)
br label %37
37: ; preds = %33, %29, %24
%38 = load i32, i32* %6
store i32 %38, i32* @errno
%39 = load i32, i32* %5
ret i32 %39
}

LLVM IR (-O2):
@.str = [40 x i8] c"getdomainname(): name=0x%p, namelen=%d\0A\00"
@errno = global i32 0
@.str.1 = [13 x i8] c"\09\09name = %s\0A\00"
@.str.2 = [7 x i8] c"(null)\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 = [19 x i8] c"\09Succeeded Phase 1\00"
define i32 @getdomainname_test(i8* %0, i32 %1) {
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), i8* %0, i32 %1)
%4 = tail call i32 @fflush(i32* null)
%5 = tail call i32 @getdomainname(i8* %0, i32 %1)
%6 = tail call i32 @handle_zng(i32 %5)
%7 = load i32, i32* @errno
switch i32 %6, label %15 [
i32 -1, label %8
i32 0, label %8
i32 -2, label %13
]
8: ; preds = %2, %2
%9 = icmp eq i8* %0, null
%10 = select i1 %9, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* %0
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* %10)
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str, i64 0, i64 0))
br label %17
13: ; preds = %2
%14 = 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 %17
15: ; preds = %2
%16 = 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 %17
17: ; preds = %15, %13, %8
%18 = tail call i32 @fflush(i32* null)
store i32 %7, i32* @errno
ret i32 %5
}