#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*/ time_t;
struct link {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ cctools_debug(long long, char *, ...);
int /*<<< orphan*/ domain_name_cache_lookup_reverse(char *, char *);
int /*<<< orphan*/ link_address_remote(struct link *, char *, int *);
int /*<<< orphan*/ link_putlstring(struct link *, char *, int,
                                   int /*<<< orphan*/);
char *strdup(char *);
int auth_hostname_accept(struct link *link, char **subject, time_t stoptime) {
  char addr[48];
  char name[256];
  int port;
  if (!link_address_remote(link, addr, &port)) {
    cctools_debug((1LL << 12), "hostname: couldn't get address of link");
    goto reject;
  }
  if (!domain_name_cache_lookup_reverse(addr, name)) {
    cctools_debug((1LL << 12), "hostname: couldn't look up name of %s", name);
    goto reject;
  }
  *subject = strdup(name);
  if (!*subject) {
    cctools_debug((1LL << 12), "hostname: out of memory");
    goto reject;
  }
  (link_putlstring(link,
                   "yes\n"
                   "",
                   ((sizeof("yes\n")) - 1), stoptime));
  return 1;
reject:
  (link_putlstring(link,
                   "no\n"
                   "",
                   ((sizeof("no\n")) - 1), stoptime));
  return 0;
}


x86 assembly (clang, -O0):
<auth_hostname_accept>:
push   %rbp
mov    %rsp,%rbp
sub    $0x160,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x50(%rbp),%rsi
lea    -0x154(%rbp),%rdx
call   1050 <link_address_remote@plt>
cmp    $0x0,%eax
jne    119b <auth_hostname_accept+0x4b>
mov    $0x1000,%edi
lea    0xe71(%rip),%rsi
mov    $0x0,%al
call   1030 <cctools_debug@plt>
jmp    1233 <auth_hostname_accept+0xe3>
lea    -0x50(%rbp),%rdi
lea    -0x150(%rbp),%rsi
call   1060 <domain_name_cache_lookup_reverse@plt>
cmp    $0x0,%eax
jne    11d3 <auth_hostname_accept+0x83>
lea    -0x150(%rbp),%rdx
mov    $0x1000,%edi
lea    0xe60(%rip),%rsi
mov    $0x0,%al
call   1030 <cctools_debug@plt>
jmp    1233 <auth_hostname_accept+0xe3>
lea    -0x150(%rbp),%rdi
call   1070 <strdup@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rax
cmpq   $0x0,(%rax)
jne    120f <auth_hostname_accept+0xbf>
mov    $0x1000,%edi
lea    0xe4a(%rip),%rsi
mov    $0x0,%al
call   1030 <cctools_debug@plt>
jmp    1233 <auth_hostname_accept+0xe3>
mov    -0x10(%rbp),%rdi
mov    -0x1c(%rbp),%ecx
lea    0xe48(%rip),%rsi
mov    $0x4,%edx
call   1040 <link_putlstring@plt>
movl   $0x1,-0x4(%rbp)
jmp    1252 <auth_hostname_accept+0x102>
mov    -0x10(%rbp),%rdi
mov    -0x1c(%rbp),%ecx
lea    0xe29(%rip),%rsi
mov    $0x3,%edx
call   1040 <link_putlstring@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x160,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<auth_hostname_accept>:
push   %rbp
push   %r14
push   %rbx
sub    $0x140,%rsp
mov    %edx,%r14d
mov    %rsi,%rbp
mov    %rdi,%rbx
lea    0x10(%rsp),%rsi
lea    0xc(%rsp),%rdx
call   1050 <link_address_remote@plt>
test   %eax,%eax
je     11bb <auth_hostname_accept+0x6b>
lea    0x10(%rsp),%rdi
lea    0x40(%rsp),%rsi
call   1060 <domain_name_cache_lookup_reverse@plt>
test   %eax,%eax
je     11c4 <auth_hostname_accept+0x74>
lea    0x40(%rsp),%rdi
call   1070 <strdup@plt>
mov    %rax,0x0(%rbp)
test   %rax,%rax
je     11de <auth_hostname_accept+0x8e>
lea    0xec1(%rip),%rsi
mov    %rbx,%rdi
mov    $0x4,%edx
mov    %r14d,%ecx
call   1040 <link_putlstring@plt>
mov    $0x1,%eax
jmp    120a <auth_hostname_accept+0xba>
lea    0xe3e(%rip),%rsi
jmp    11e5 <auth_hostname_accept+0x95>
lea    0xe5c(%rip),%rsi
lea    0x40(%rsp),%rdx
mov    $0x1000,%edi
xor    %eax,%eax
call   1030 <cctools_debug@plt>
jmp    11f1 <auth_hostname_accept+0xa1>
lea    0xe68(%rip),%rsi
mov    $0x1000,%edi
xor    %eax,%eax
call   1030 <cctools_debug@plt>
lea    0xe72(%rip),%rsi
mov    %rbx,%rdi
mov    $0x3,%edx
mov    %r14d,%ecx
call   1040 <link_putlstring@plt>
xor    %eax,%eax
add    $0x140,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.link = type { i32 }
@.str = [39 x i8] c"hostname: couldn't get address of link\00"
@.str.1 = [38 x i8] c"hostname: couldn't look up name of %s\00"
@.str.2 = [24 x i8] c"hostname: out of memory\00"
@.str.3 = [5 x i8] c"yes\0A\00"
@.str.4 = [4 x i8] c"no\0A\00"
define i32 @auth_hostname_accept(%struct.link* %0, i8** %1, i32 %2) {
%4 = alloca i32
%5 = alloca %struct.link*
%6 = alloca i8**
%7 = alloca i32
%8 = alloca [48 x i8]
%9 = alloca [256 x i8]
%10 = alloca i32
store %struct.link* %0, %struct.link** %5
store i8** %1, i8*** %6
store i32 %2, i32* %7
%11 = load %struct.link*, %struct.link** %5
%12 = getelementptr inbounds [48 x i8], [48 x i8]* %8, i64 0, i64 0
%13 = call i32 @link_address_remote(%struct.link* %11, i8* %12, i32* %10)
%14 = icmp ne i32 %13, 0
br i1 %14, label %17, label %15
15: ; preds = %3
%16 = call i32 (i64, i8*, ...) @cctools_debug(i64 4096, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
br label %38
17: ; preds = %3
%18 = getelementptr inbounds [48 x i8], [48 x i8]* %8, i64 0, i64 0
%19 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%20 = call i32 @domain_name_cache_lookup_reverse(i8* %18, i8* %19)
%21 = icmp ne i32 %20, 0
br i1 %21, label %25, label %22
22: ; preds = %17
%23 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%24 = call i32 (i64, i8*, ...) @cctools_debug(i64 4096, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i8* %23)
br label %38
25: ; preds = %17
%26 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%27 = call i8* @strdup(i8* %26)
%28 = load i8**, i8*** %6
store i8* %27, i8** %28
%29 = load i8**, i8*** %6
%30 = load i8*, i8** %29
%31 = icmp ne i8* %30, null
br i1 %31, label %34, label %32
32: ; preds = %25
%33 = call i32 (i64, i8*, ...) @cctools_debug(i64 4096, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
br label %38
34: ; preds = %25
%35 = load %struct.link*, %struct.link** %5
%36 = load i32, i32* %7
%37 = call i32 @link_putlstring(%struct.link* %35, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 4, i32 %36)
store i32 1, i32* %4
br label %42
38: ; preds = %32, %22, %15
%39 = load %struct.link*, %struct.link** %5
%40 = load i32, i32* %7
%41 = call i32 @link_putlstring(%struct.link* %39, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 3, i32 %40)
store i32 0, i32* %4
br label %42
42: ; preds = %38, %34
%43 = load i32, i32* %4
ret i32 %43
}

LLVM IR (-O2):
%struct.link = type { i32 }
@.str = [39 x i8] c"hostname: couldn't get address of link\00"
@.str.1 = [38 x i8] c"hostname: couldn't look up name of %s\00"
@.str.2 = [24 x i8] c"hostname: out of memory\00"
@.str.3 = [5 x i8] c"yes\0A\00"
@.str.4 = [4 x i8] c"no\0A\00"
define i32 @auth_hostname_accept(%struct.link* %0, i8** nocapture writeonly %1, i32 %2) {
%4 = alloca [48 x i8]
%5 = alloca [256 x i8]
%6 = alloca i32
%7 = getelementptr inbounds [48 x i8], [48 x i8]* %4, i64 0, i64 0
%8 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%9 = bitcast i32* %6 to i8*
%10 = call i32 @link_address_remote(%struct.link* %0, i8* %7, i32* %6)
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %3
%13 = call i32 (i64, i8*, ...) @cctools_debug(i64 4096, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
br label %26
14: ; preds = %3
%15 = call i32 @domain_name_cache_lookup_reverse(i8* %7, i8* %8)
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %14
%18 = call i32 (i64, i8*, ...) @cctools_debug(i64 4096, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i8* %8)
br label %26
19: ; preds = %14
%20 = call i8* @strdup(i8* %8)
store i8* %20, i8** %1
%21 = icmp eq i8* %20, null
br i1 %21, label %22, label %24
22: ; preds = %19
%23 = call i32 (i64, i8*, ...) @cctools_debug(i64 4096, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
br label %26
24: ; preds = %19
%25 = call i32 @link_putlstring(%struct.link* %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 4, i32 %2)
br label %28
26: ; preds = %22, %17, %12
%27 = call i32 @link_putlstring(%struct.link* %0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 3, i32 %2)
br label %28
28: ; preds = %26, %24
%29 = phi i32 [ 1, %24 ], [ 0, %26 ]
ret i32 %29
}