#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 */
struct utsname {
  char *nodename;
};

/* Variables and functions */
int /*<<< orphan*/ cctools_debug(long long, char *, char *, ...);
int /*<<< orphan*/ domain_name_cache_lookup(char *, char *);
int /*<<< orphan*/ domain_name_cache_lookup_reverse(char *, char *);
scalar_t__ guess_dns_domain(char *);
int /*<<< orphan*/ sprintf(char *, char *, char *, ...);
int /*<<< orphan*/ strcmp(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int /*<<< orphan*/ strncmp(char *, char *, int);
scalar_t__ uname(struct utsname *);
int domain_name_cache_guess(char *name) {
  struct utsname n;
  char addr[256];
  char domain[256];
  if (uname(&n) < 0)
    return 0;
  if (!domain_name_cache_lookup(n.nodename, addr))
    return 0;
  if (!domain_name_cache_lookup_reverse(addr, name))
    return 0;
  cctools_debug((1LL << 10),
                "finding my hostname: uname = %s, address = %s, hostname = %s",
                n.nodename, addr, name);
  if (!strncmp(name, "localhost", 9) || !strcmp(addr, "127.0.0.1")) {
    cctools_debug((1LL << 10), "local address of '%s' (%s) is not very useful.",
                  name, addr);
    if (guess_dns_domain(domain)) {
      sprintf(name, "%s.%s", n.nodename, domain);
      cctools_debug((1LL << 10),
                    "but /etc/resolv.conf says domain = %s so hostname = %s",
                    domain, name);
      if (!domain_name_cache_lookup(name, addr)) {
        cctools_debug((1LL << 10),
                      "unfortunately %s is meaningless, so going back to %s",
                      name, n.nodename);
        sprintf(name, "%s", n.nodename);
      }
    } else {
      strcpy(name, n.nodename);
      cctools_debug((1LL << 10),
                    "cannot find any more info, so use hostname = %s",
                    n.nodename);
    }
  }
  return 1;
}


x86 assembly (clang, -O0):
<domain_name_cache_guess>:
push   %rbp
mov    %rsp,%rbp
sub    $0x220,%rsp
mov    %rdi,-0x10(%rbp)
lea    -0x18(%rbp),%rdi
call   1060 <uname@plt>
cmp    $0x0,%rax
jge    11be <domain_name_cache_guess+0x2e>
movl   $0x0,-0x4(%rbp)
jmp    1352 <domain_name_cache_guess+0x1c2>
mov    -0x18(%rbp),%rdi
lea    -0x120(%rbp),%rsi
call   1070 <domain_name_cache_lookup@plt>
cmp    $0x0,%eax
jne    11e3 <domain_name_cache_guess+0x53>
movl   $0x0,-0x4(%rbp)
jmp    1352 <domain_name_cache_guess+0x1c2>
lea    -0x120(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   10a0 <domain_name_cache_lookup_reverse@plt>
cmp    $0x0,%eax
jne    1208 <domain_name_cache_guess+0x78>
movl   $0x0,-0x4(%rbp)
jmp    1352 <domain_name_cache_guess+0x1c2>
mov    -0x18(%rbp),%rdx
lea    -0x120(%rbp),%rcx
mov    -0x10(%rbp),%r8
mov    $0x400,%edi
lea    0xddd(%rip),%rsi
mov    $0x0,%al
call   1090 <cctools_debug@plt>
mov    -0x10(%rbp),%rdi
lea    0xe08(%rip),%rsi
mov    $0x9,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%eax
je     1264 <domain_name_cache_guess+0xd4>
lea    -0x120(%rbp),%rdi
lea    0xdf1(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%eax
jne    134b <domain_name_cache_guess+0x1bb>
mov    -0x10(%rbp),%rdx
lea    -0x120(%rbp),%rcx
mov    $0x400,%edi
lea    0xdd6(%rip),%rsi
mov    $0x0,%al
call   1090 <cctools_debug@plt>
lea    -0x220(%rbp),%rdi
call   1030 <guess_dns_domain@plt>
cmp    $0x0,%rax
je     1322 <domain_name_cache_guess+0x192>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    -0x220(%rbp),%rcx
lea    0xdd2(%rip),%rsi
mov    $0x0,%al
call   10b0 <sprintf@plt>
lea    -0x220(%rbp),%rdx
mov    -0x10(%rbp),%rcx
mov    $0x400,%edi
lea    0xdba(%rip),%rsi
mov    $0x0,%al
call   1090 <cctools_debug@plt>
mov    -0x10(%rbp),%rdi
lea    -0x120(%rbp),%rsi
call   1070 <domain_name_cache_lookup@plt>
cmp    $0x0,%eax
jne    131d <domain_name_cache_guess+0x18d>
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
mov    $0x400,%edi
lea    0xdbd(%rip),%rsi
mov    $0x0,%al
call   1090 <cctools_debug@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xd24(%rip),%rsi
mov    $0x0,%al
call   10b0 <sprintf@plt>
jmp    1346 <domain_name_cache_guess+0x1b6>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <strcpy@plt>
mov    -0x18(%rbp),%rdx
mov    $0x400,%edi
lea    0xdb3(%rip),%rsi
mov    $0x0,%al
call   1090 <cctools_debug@plt>
jmp    134b <domain_name_cache_guess+0x1bb>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x220,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<domain_name_cache_guess>:
push   %rbp
push   %r14
push   %rbx
sub    $0x210,%rsp
mov    %rdi,%rbx
lea    0x8(%rsp),%rdi
call   1060 <uname@plt>
xor    %ebp,%ebp
test   %rax,%rax
js     12f5 <domain_name_cache_guess+0x175>
mov    0x8(%rsp),%r14
lea    0x10(%rsp),%rsi
mov    %r14,%rdi
call   1070 <domain_name_cache_lookup@plt>
test   %eax,%eax
je     12f5 <domain_name_cache_guess+0x175>
lea    0x10(%rsp),%rdi
mov    %rbx,%rsi
call   1090 <domain_name_cache_lookup_reverse@plt>
test   %eax,%eax
je     12f5 <domain_name_cache_guess+0x175>
lea    0xe27(%rip),%rsi
lea    0x10(%rsp),%rcx
mov    $0x400,%edi
mov    %r14,%rdx
mov    %rbx,%r8
xor    %eax,%eax
call   1080 <cctools_debug@plt>
lea    0xe46(%rip),%rsi
mov    %rbx,%rdi
mov    $0x9,%edx
call   1040 <strncmp@plt>
test   %eax,%eax
je     122e <domain_name_cache_guess+0xae>
movabs $0x2e302e302e373231,%rax
2e 30 2e
xor    0x10(%rsp),%rax
movzwl 0x18(%rsp),%ecx
xor    $0x31,%rcx
or     %rax,%rcx
mov    $0x1,%ebp
jne    12f5 <domain_name_cache_guess+0x175>
lea    0xe1c(%rip),%rsi
lea    0x10(%rsp),%rcx
mov    $0x400,%edi
mov    %rbx,%rdx
xor    %eax,%eax
call   1080 <cctools_debug@plt>
lea    0x110(%rsp),%rdi
call   1030 <guess_dns_domain@plt>
test   %rax,%rax
je     12cf <domain_name_cache_guess+0x14f>
lea    0xe1e(%rip),%rsi
lea    0x110(%rsp),%rbp
mov    %rbx,%rdi
mov    %r14,%rdx
mov    %rbp,%rcx
xor    %eax,%eax
call   10a0 <sprintf@plt>
lea    0xe05(%rip),%rsi
mov    $0x400,%edi
mov    %rbp,%rdx
mov    %rbx,%rcx
xor    %eax,%eax
call   1080 <cctools_debug@plt>
lea    0x10(%rsp),%rsi
mov    %rbx,%rdi
call   1070 <domain_name_cache_lookup@plt>
mov    $0x1,%ebp
test   %eax,%eax
jne    12f5 <domain_name_cache_guess+0x175>
lea    0xe0d(%rip),%rsi
mov    $0x400,%edi
mov    %rbx,%rdx
mov    %r14,%rcx
xor    %eax,%eax
call   1080 <cctools_debug@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1050 <strcpy@plt>
jmp    12f5 <domain_name_cache_guess+0x175>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1050 <strcpy@plt>
lea    0xe11(%rip),%rsi
mov    $0x400,%edi
mov    %r14,%rdx
xor    %eax,%eax
call   1080 <cctools_debug@plt>
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x210,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.utsname = type { i8* }
@.str = [61 x i8] c"finding my hostname: uname = %s, address = %s, hostname = %s\00"
@.str.1 = [10 x i8] c"localhost\00"
@.str.2 = [10 x i8] c"127.0.0.1\00"
@.str.3 = [47 x i8] c"local address of '%s' (%s) is not very useful.\00"
@.str.4 = [6 x i8] c"%s.%s\00"
@.str.5 = [55 x i8] c"but /etc/resolv.conf says domain = %s so hostname = %s\00"
@.str.6 = [53 x i8] c"unfortunately %s is meaningless, so going back to %s\00"
@.str.7 = [3 x i8] c"%s\00"
@.str.8 = [48 x i8] c"cannot find any more info, so use hostname = %s\00"
define i32 @domain_name_cache_guess(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca %struct.utsname
%5 = alloca [256 x i8]
%6 = alloca [256 x i8]
store i8* %0, i8** %3
%7 = call i64 @uname(%struct.utsname* %4)
%8 = icmp slt i64 %7, 0
br i1 %8, label %9, label %10
9: ; preds = %1
store i32 0, i32* %2
br label %76
10: ; preds = %1
%11 = getelementptr inbounds %struct.utsname, %struct.utsname* %4, i32 0, i32 0
%12 = load i8*, i8** %11
%13 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%14 = call i32 @domain_name_cache_lookup(i8* %12, i8* %13)
%15 = icmp ne i32 %14, 0
br i1 %15, label %17, label %16
16: ; preds = %10
store i32 0, i32* %2
br label %76
17: ; preds = %10
%18 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%19 = load i8*, i8** %3
%20 = call i32 @domain_name_cache_lookup_reverse(i8* %18, i8* %19)
%21 = icmp ne i32 %20, 0
br i1 %21, label %23, label %22
22: ; preds = %17
store i32 0, i32* %2
br label %76
23: ; preds = %17
%24 = getelementptr inbounds %struct.utsname, %struct.utsname* %4, i32 0, i32 0
%25 = load i8*, i8** %24
%26 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%27 = load i8*, i8** %3
%28 = call i32 (i64, i8*, i8*, ...) @cctools_debug(i64 1024, i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str, i64 0, i64 0), i8* %25, i8* %26, i8* %27)
%29 = load i8*, i8** %3
%30 = call i32 @strncmp(i8* %29, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 9)
%31 = icmp ne i32 %30, 0
br i1 %31, label %32, label %36
32: ; preds = %23
%33 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%34 = call i32 @strcmp(i8* %33, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
%35 = icmp ne i32 %34, 0
br i1 %35, label %75, label %36
36: ; preds = %32, %23
%37 = load i8*, i8** %3
%38 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%39 = call i32 (i64, i8*, i8*, ...) @cctools_debug(i64 1024, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.3, i64 0, i64 0), i8* %37, i8* %38)
%40 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%41 = call i64 @guess_dns_domain(i8* %40)
%42 = icmp ne i64 %41, 0
br i1 %42, label %43, label %66
43: ; preds = %36
%44 = load i8*, i8** %3
%45 = getelementptr inbounds %struct.utsname, %struct.utsname* %4, i32 0, i32 0
%46 = load i8*, i8** %45
%47 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%48 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %44, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8* %46, i8* %47)
%49 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%50 = load i8*, i8** %3
%51 = call i32 (i64, i8*, i8*, ...) @cctools_debug(i64 1024, i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.5, i64 0, i64 0), i8* %49, i8* %50)
%52 = load i8*, i8** %3
%53 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%54 = call i32 @domain_name_cache_lookup(i8* %52, i8* %53)
%55 = icmp ne i32 %54, 0
br i1 %55, label %65, label %56
56: ; preds = %43
%57 = load i8*, i8** %3
%58 = getelementptr inbounds %struct.utsname, %struct.utsname* %4, i32 0, i32 0
%59 = load i8*, i8** %58
%60 = call i32 (i64, i8*, i8*, ...) @cctools_debug(i64 1024, i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.6, i64 0, i64 0), i8* %57, i8* %59)
%61 = load i8*, i8** %3
%62 = getelementptr inbounds %struct.utsname, %struct.utsname* %4, i32 0, i32 0
%63 = load i8*, i8** %62
%64 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %61, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i8* %63)
br label %65
65: ; preds = %56, %43
br label %74
66: ; preds = %36
%67 = load i8*, i8** %3
%68 = getelementptr inbounds %struct.utsname, %struct.utsname* %4, i32 0, i32 0
%69 = load i8*, i8** %68
%70 = call i32 @strcpy(i8* %67, i8* %69)
%71 = getelementptr inbounds %struct.utsname, %struct.utsname* %4, i32 0, i32 0
%72 = load i8*, i8** %71
%73 = call i32 (i64, i8*, i8*, ...) @cctools_debug(i64 1024, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.8, i64 0, i64 0), i8* %72)
br label %74
74: ; preds = %66, %65
br label %75
75: ; preds = %74, %32
store i32 1, i32* %2
br label %76
76: ; preds = %75, %22, %16, %9
%77 = load i32, i32* %2
ret i32 %77
}

LLVM IR (-O2):
%struct.utsname = type { i8* }
@.str = [61 x i8] c"finding my hostname: uname = %s, address = %s, hostname = %s\00"
@.str.1 = [10 x i8] c"localhost\00"
@.str.2 = [10 x i8] c"127.0.0.1\00"
@.str.3 = [47 x i8] c"local address of '%s' (%s) is not very useful.\00"
@.str.4 = [6 x i8] c"%s.%s\00"
@.str.5 = [55 x i8] c"but /etc/resolv.conf says domain = %s so hostname = %s\00"
@.str.6 = [53 x i8] c"unfortunately %s is meaningless, so going back to %s\00"
@.str.8 = [48 x i8] c"cannot find any more info, so use hostname = %s\00"
define i32 @domain_name_cache_guess(i8* %0) {
%2 = alloca %struct.utsname
%3 = alloca [256 x i8]
%4 = alloca [256 x i8]
%5 = bitcast %struct.utsname* %2 to i8*
%6 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%7 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%8 = call i64 @uname(%struct.utsname* %2)
%9 = icmp slt i64 %8, 0
br i1 %9, label %40, label %10
10: ; preds = %1
%11 = getelementptr inbounds %struct.utsname, %struct.utsname* %2, i64 0, i32 0
%12 = load i8*, i8** %11
%13 = call i32 @domain_name_cache_lookup(i8* %12, i8* %6)
%14 = icmp eq i32 %13, 0
br i1 %14, label %40, label %15
15: ; preds = %10
%16 = call i32 @domain_name_cache_lookup_reverse(i8* %6, i8* %0)
%17 = icmp eq i32 %16, 0
br i1 %17, label %40, label %18
18: ; preds = %15
%19 = call i32 (i64, i8*, i8*, ...) @cctools_debug(i64 1024, i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str, i64 0, i64 0), i8* %12, i8* %6, i8* %0)
%20 = call i32 @strncmp(i8* %0, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 9)
%21 = icmp eq i32 %20, 0
br i1 %21, label %25, label %22
22: ; preds = %18
%23 = call i32 @bcmp(i8* dereferenceable(10) %6, i8* dereferenceable(10) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i64 10)
%24 = icmp eq i32 %23, 0
br i1 %24, label %25, label %40
25: ; preds = %22, %18
%26 = call i32 (i64, i8*, i8*, ...) @cctools_debug(i64 1024, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.3, i64 0, i64 0), i8* %0, i8* %6)
%27 = call i64 @guess_dns_domain(i8* %7)
%28 = icmp eq i64 %27, 0
br i1 %28, label %37, label %29
29: ; preds = %25
%30 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8* %12, i8* %7)
%31 = call i32 (i64, i8*, i8*, ...) @cctools_debug(i64 1024, i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.5, i64 0, i64 0), i8* %7, i8* %0)
%32 = call i32 @domain_name_cache_lookup(i8* %0, i8* %6)
%33 = icmp eq i32 %32, 0
br i1 %33, label %34, label %40
34: ; preds = %29
%35 = call i32 (i64, i8*, i8*, ...) @cctools_debug(i64 1024, i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.6, i64 0, i64 0), i8* %0, i8* %12)
%36 = call i8* bitcast (i32 (i8*, i8*)* @strcpy to i8* (i8*, i8*)*)(i8* %0, i8* %12)
br label %40
37: ; preds = %25
%38 = call i32 @strcpy(i8* %0, i8* %12)
%39 = call i32 (i64, i8*, i8*, ...) @cctools_debug(i64 1024, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.8, i64 0, i64 0), i8* %12)
br label %40
40: ; preds = %22, %29, %34, %37, %15, %10, %1
%41 = phi i32 [ 0, %1 ], [ 0, %10 ], [ 0, %15 ], [ 1, %37 ], [ 1, %34 ], [ 1, %29 ], [ 1, %22 ]
ret i32 %41
}