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

/* Variables and functions */
int MAXHOSTNAMELEN;
int /*<<< orphan*/ gethostname(char *, int);
int /*<<< orphan*/ strcasecmp(char const *, char const *);
char *topdomain(char const *);
int local_domain(const char *h) {
  char localhost[MAXHOSTNAMELEN];
  const char *p1, *p2;
  localhost[0] = 0;
  (void)gethostname(localhost, sizeof(localhost));
  p1 = topdomain(localhost);
  p2 = topdomain(h);
  if (p1 == NULL || p2 == NULL || !strcasecmp(p1, p2))
    return (1);
  return (0);
}


x86 assembly (clang, -O0):
<local_domain>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    0x2ea5(%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,-0x40(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x20(%rbp)
movb   $0x0,(%rdi)
mov    %eax,%esi
call   1050 <gethostname@plt>
mov    -0x40(%rbp),%rdi
call   1040 <topdomain@plt>
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <topdomain@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     11b8 <local_domain+0x88>
cmpq   $0x0,-0x30(%rbp)
je     11b8 <local_domain+0x88>
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1030 <strcasecmp@plt>
cmp    $0x0,%eax
jne    11cb <local_domain+0x9b>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x34(%rbp)
jmp    11d9 <local_domain+0xa9>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x34(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<local_domain>:
push   %rbp
mov    %rsp,%rbp
push   %r14
push   %rbx
mov    %rdi,%r14
mov    0x2ea7(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rax
mov    %rsi,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rax,%rbx
sub    %rcx,%rbx
mov    %rbx,%rsp
neg    %rcx
movb   $0x0,(%rax,%rcx,1)
mov    %rbx,%rdi
call   1050 <gethostname@plt>
mov    %rbx,%rdi
call   1040 <topdomain@plt>
mov    %rax,%rbx
mov    %r14,%rdi
call   1040 <topdomain@plt>
mov    %rax,%rsi
mov    $0x1,%eax
test   %rbx,%rbx
je     119f <local_domain+0x6f>
test   %rsi,%rsi
je     119f <local_domain+0x6f>
mov    %rbx,%rdi
call   1030 <strcasecmp@plt>
mov    %eax,%ecx
xor    %eax,%eax
test   %ecx,%ecx
sete   %al
lea    -0x10(%rbp),%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@MAXHOSTNAMELEN = global i32 0
define i32 @local_domain(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
store i8* %0, i8** %3
%9 = load i32, i32* @MAXHOSTNAMELEN
%10 = zext i32 %9 to i64
%11 = call i8* @llvm.stacksave()
store i8* %11, i8** %4
%12 = alloca i8, i64 %10
store i64 %10, i64* %5
%13 = getelementptr inbounds i8, i8* %12, i64 0
store i8 0, i8* %13
%14 = trunc i64 %10 to i32
%15 = call i32 @gethostname(i8* %12, i32 %14)
%16 = call i8* @topdomain(i8* %12)
store i8* %16, i8** %6
%17 = load i8*, i8** %3
%18 = call i8* @topdomain(i8* %17)
store i8* %18, i8** %7
%19 = load i8*, i8** %6
%20 = icmp eq i8* %19, null
br i1 %20, label %29, label %21
21: ; preds = %1
%22 = load i8*, i8** %7
%23 = icmp eq i8* %22, null
br i1 %23, label %29, label %24
24: ; preds = %21
%25 = load i8*, i8** %6
%26 = load i8*, i8** %7
%27 = call i32 @strcasecmp(i8* %25, i8* %26)
%28 = icmp ne i32 %27, 0
br i1 %28, label %30, label %29
29: ; preds = %24, %21, %1
store i32 1, i32* %2
store i32 1, i32* %8
br label %31
30: ; preds = %24
store i32 0, i32* %2
store i32 1, i32* %8
br label %31
31: ; preds = %30, %29
%32 = load i8*, i8** %4
%33 = load i32, i32* %2
ret i32 %33
}

LLVM IR (-O2):
@MAXHOSTNAMELEN = global i32 0
define i32 @local_domain(i8* %0) {
%2 = load i32, i32* @MAXHOSTNAMELEN
%3 = zext i32 %2 to i64
%4 = alloca i8, i64 %3
store i8 0, i8* %4
%5 = call i32 @gethostname(i8* %4, i32 %2)
%6 = call i8* @topdomain(i8* %4)
%7 = call i8* @topdomain(i8* %0)
%8 = icmp eq i8* %6, null
%9 = icmp eq i8* %7, null
%10 = select i1 %8, i1 true, i1 %9
br i1 %10, label %15, label %11
11: ; preds = %1
%12 = call i32 @strcasecmp(i8* %6, i8* %7)
%13 = icmp eq i32 %12, 0
%14 = zext i1 %13 to i32
br label %15
15: ; preds = %11, %1
%16 = phi i32 [ 1, %1 ], [ %14, %11 ]
ret i32 %16
}