#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 stat {
  int /*<<< orphan*/ st_mode;
};

/* Variables and functions */
scalar_t__ S_ISDIR(int /*<<< orphan*/);
char *gethome();
scalar_t__ sstrncat(char *, size_t *, int, char const *, int);
scalar_t__ stat(char *, struct stat *);
int strlen(char const *);
int has_localdb(void) {
  struct stat s;
  size_t len;
  char const *homedir;
  char outhome[512];
  homedir = gethome();
  if (homedir == NULL)
    return 0;
  len = 0;
  if (sstrncat(outhome, &len, 512, homedir, strlen(homedir)))
    return 0;
  if (sstrncat(outhome, &len, 512, "/.tldrc", (sizeof("/.tldrc") - 1)))
    return 0;
  if ((stat(outhome, &s) == 0) && (S_ISDIR(s.st_mode)))
    return 1;
  return 0;
}


x86 assembly (clang, -O0):
<has_localdb>:
push   %rbp
mov    %rsp,%rbp
sub    $0x230,%rsp
mov    $0x0,%al
call   1070 <gethome@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    117d <has_localdb+0x2d>
movl   $0x0,-0x4(%rbp)
jmp    1253 <has_localdb+0x103>
movq   $0x0,-0x10(%rbp)
lea    -0x220(%rbp),%rax
mov    %rax,-0x230(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x228(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x230(%rbp),%rdi
mov    -0x228(%rbp),%rcx
mov    %eax,%r8d
lea    -0x10(%rbp),%rsi
mov    $0x200,%edx
call   1050 <sstrncat@plt>
cmp    $0x0,%rax
je     11dc <has_localdb+0x8c>
movl   $0x0,-0x4(%rbp)
jmp    1253 <has_localdb+0x103>
lea    -0x220(%rbp),%rdi
lea    -0x10(%rbp),%rsi
mov    $0x200,%edx
lea    0xe0d(%rip),%rcx
mov    $0x7,%r8d
call   1050 <sstrncat@plt>
cmp    $0x0,%rax
je     1214 <has_localdb+0xc4>
movl   $0x0,-0x4(%rbp)
jmp    1253 <has_localdb+0x103>
lea    -0x220(%rbp),%rdi
lea    -0x8(%rbp),%rsi
call   1060 <stat@plt>
cmp    $0x0,%rax
jne    124c <has_localdb+0xfc>
mov    -0x8(%rbp),%edi
call   1040 <S_ISDIR@plt>
cmp    $0x0,%rax
je     124c <has_localdb+0xfc>
movl   $0x1,-0x4(%rbp)
jmp    1253 <has_localdb+0x103>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x230,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<has_localdb>:
push   %rbp
push   %rbx
sub    $0x218,%rsp
xor    %ebp,%ebp
xor    %eax,%eax
call   1070 <gethome@plt>
test   %rax,%rax
je     11e6 <has_localdb+0x96>
mov    %rax,%rbx
movq   $0x0,0x8(%rsp)
mov    %rax,%rdi
call   1030 <strlen@plt>
lea    0x10(%rsp),%rdi
lea    0x8(%rsp),%rsi
mov    $0x200,%edx
mov    %rbx,%rcx
mov    %eax,%r8d
call   1050 <sstrncat@plt>
test   %rax,%rax
jne    11e6 <has_localdb+0x96>
lea    0xe5f(%rip),%rcx
lea    0x10(%rsp),%rdi
lea    0x8(%rsp),%rsi
mov    $0x200,%edx
mov    $0x7,%r8d
call   1050 <sstrncat@plt>
test   %rax,%rax
jne    11e6 <has_localdb+0x96>
lea    0x10(%rsp),%rdi
mov    %rsp,%rsi
call   1060 <stat@plt>
test   %rax,%rax
jne    11e4 <has_localdb+0x94>
mov    (%rsp),%edi
call   1040 <S_ISDIR@plt>
mov    $0x1,%ebp
test   %rax,%rax
jne    11e6 <has_localdb+0x96>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x218,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [8 x i8] c"/.tldrc\00"
define i32 @has_localdb() {
%1 = alloca i32
%2 = alloca %struct.stat
%3 = alloca i64
%4 = alloca i8*
%5 = alloca [512 x i8]
%6 = call i8* (...) @gethome()
store i8* %6, i8** %4
%7 = load i8*, i8** %4
%8 = icmp eq i8* %7, null
br i1 %8, label %9, label %10
9: ; preds = %0
store i32 0, i32* %1
br label %34
10: ; preds = %0
store i64 0, i64* %3
%11 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%12 = load i8*, i8** %4
%13 = load i8*, i8** %4
%14 = call i32 @strlen(i8* %13)
%15 = call i64 @sstrncat(i8* %11, i64* %3, i32 512, i8* %12, i32 %14)
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %10
store i32 0, i32* %1
br label %34
18: ; preds = %10
%19 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%20 = call i64 @sstrncat(i8* %19, i64* %3, i32 512, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 7)
%21 = icmp ne i64 %20, 0
br i1 %21, label %22, label %23
22: ; preds = %18
store i32 0, i32* %1
br label %34
23: ; preds = %18
%24 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%25 = call i64 @stat(i8* %24, %struct.stat* %2)
%26 = icmp eq i64 %25, 0
br i1 %26, label %27, label %33
27: ; preds = %23
%28 = getelementptr inbounds %struct.stat, %struct.stat* %2, i32 0, i32 0
%29 = load i32, i32* %28
%30 = call i64 @S_ISDIR(i32 %29)
%31 = icmp ne i64 %30, 0
br i1 %31, label %32, label %33
32: ; preds = %27
store i32 1, i32* %1
br label %34
33: ; preds = %27, %23
store i32 0, i32* %1
br label %34
34: ; preds = %33, %32, %22, %17, %9
%35 = load i32, i32* %1
ret i32 %35
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [8 x i8] c"/.tldrc\00"
define i32 @has_localdb() {
%1 = alloca %struct.stat
%2 = alloca i64
%3 = alloca [512 x i8]
%4 = bitcast %struct.stat* %1 to i8*
%5 = bitcast i64* %2 to i8*
%6 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%7 = tail call i8* (...) @gethome()
%8 = icmp eq i8* %7, null
br i1 %8, label %25, label %9
9: ; preds = %0
store i64 0, i64* %2
%10 = tail call i32 @strlen(i8* %7)
%11 = call i64 @sstrncat(i8* %6, i64* %2, i32 512, i8* %7, i32 %10)
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %25
13: ; preds = %9
%14 = call i64 @sstrncat(i8* %6, i64* %2, i32 512, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 7)
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %25
16: ; preds = %13
%17 = call i64 @stat(i8* %6, %struct.stat* %1)
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %24
19: ; preds = %16
%20 = getelementptr inbounds %struct.stat, %struct.stat* %1, i64 0, i32 0
%21 = load i32, i32* %20
%22 = call i64 @S_ISDIR(i32 %21)
%23 = icmp eq i64 %22, 0
br i1 %23, label %24, label %25
24: ; preds = %19, %16
br label %25
25: ; preds = %19, %13, %9, %0, %24
%26 = phi i32 [ 0, %24 ], [ 0, %0 ], [ 0, %9 ], [ 0, %13 ], [ 1, %19 ]
ret i32 %26
}