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

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ errno;
char *getenv(char *);
int /*<<< orphan*/ memcpy(char *, char const *, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ puterr(char *, int /*<<< orphan*/);
int getAdminFile(void) {
  static const char cjdnsadmin[] = "/.cjdnsadmin";
  char buf[1024];
  char *p = getenv("HOME");
  char *q = buf;
  int fd;
  while (*p)
    *q++ = *p++;
  memcpy(q, cjdnsadmin, sizeof(cjdnsadmin));
  if ((fd = open(buf, O_RDONLY)) < 0)
    puterr(buf, errno);
  return fd;
}


x86 assembly (clang, -O0):
<getAdminFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
lea    0xebb(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x408(%rbp)
lea    -0x400(%rbp),%rax
mov    %rax,-0x410(%rbp)
mov    -0x408(%rbp),%rax
cmpb   $0x0,(%rax)
je     11af <getAdminFile+0x6f>
mov    -0x408(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x408(%rbp)
mov    (%rax),%cl
mov    -0x410(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x410(%rbp)
mov    %cl,(%rax)
jmp    116c <getAdminFile+0x2c>
mov    -0x410(%rbp),%rdi
lea    0xe43(%rip),%rsi
mov    $0xd,%edx
call   1050 <memcpy@plt>
lea    -0x400(%rbp),%rdi
mov    0x2e13(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
mov    %eax,-0x414(%rbp)
cmp    $0x0,%eax
jge    1200 <getAdminFile+0xc0>
lea    -0x400(%rbp),%rdi
mov    0x2ddf(%rip),%rax
mov    (%rax),%esi
call   1040 <puterr@plt>
mov    -0x414(%rbp),%eax
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getAdminFile>:
push   %rbx
sub    $0x400,%rsp
lea    0xebe(%rip),%rdi
call   1030 <getenv@plt>
mov    (%rax),%cl
mov    %rsp,%rdi
test   %cl,%cl
je     1181 <getAdminFile+0x41>
add    $0x1,%rax
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %cl,(%rdi)
add    $0x1,%rdi
movzbl (%rax),%ecx
add    $0x1,%rax
test   %cl,%cl
jne    1170 <getAdminFile+0x30>
lea    0xe78(%rip),%rsi
mov    $0xd,%edx
call   1050 <memcpy@plt>
mov    0x2e4f(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rdi
call   1060 <open@plt>
mov    %eax,%ebx
test   %eax,%eax
jns    11ba <getAdminFile+0x7a>
mov    0x2e28(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rdi
call   1040 <puterr@plt>
mov    %ebx,%eax
add    $0x400,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@getAdminFile.cjdnsadmin = internal constant [13 x i8] c"/.cjdnsadmin\00"
@.str = [5 x i8] c"HOME\00"
@O_RDONLY = global i32 0
@errno = global i32 0
define i32 @getAdminFile() {
%1 = alloca [1024 x i8]
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
%5 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
store i8* %5, i8** %2
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 0
store i8* %6, i8** %3
br label %7
7: ; preds = %11, %0
%8 = load i8*, i8** %2
%9 = load i8, i8* %8
%10 = icmp ne i8 %9, 0
br i1 %10, label %11, label %17
11: ; preds = %7
%12 = load i8*, i8** %2
%13 = getelementptr inbounds i8, i8* %12, i32 1
store i8* %13, i8** %2
%14 = load i8, i8* %12
%15 = load i8*, i8** %3
%16 = getelementptr inbounds i8, i8* %15, i32 1
store i8* %16, i8** %3
store i8 %14, i8* %15
br label %7
17: ; preds = %7
%18 = load i8*, i8** %3
%19 = call i32 @memcpy(i8* %18, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @getAdminFile.cjdnsadmin, i64 0, i64 0), i32 13)
%20 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 0
%21 = load i32, i32* @O_RDONLY
%22 = call i32 @open(i8* %20, i32 %21)
store i32 %22, i32* %4
%23 = icmp slt i32 %22, 0
br i1 %23, label %24, label %28
24: ; preds = %17
%25 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 0
%26 = load i32, i32* @errno
%27 = call i32 @puterr(i8* %25, i32 %26)
br label %28
28: ; preds = %24, %17
%29 = load i32, i32* %4
ret i32 %29
}

LLVM IR (-O2):
@getAdminFile.cjdnsadmin = internal constant [13 x i8] c"/.cjdnsadmin\00"
@.str = [5 x i8] c"HOME\00"
@O_RDONLY = global i32 0
@errno = global i32 0
define i32 @getAdminFile() {
%1 = alloca [1024 x i8]
%2 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 0
%3 = tail call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%4 = load i8, i8* %3
%5 = icmp eq i8 %4, 0
br i1 %5, label %14, label %6
6: ; preds = %0, %6
%7 = phi i8 [ %12, %6 ], [ %4, %0 ]
%8 = phi i8* [ %10, %6 ], [ %3, %0 ]
%9 = phi i8* [ %11, %6 ], [ %2, %0 ]
%10 = getelementptr inbounds i8, i8* %8, i64 1
%11 = getelementptr inbounds i8, i8* %9, i64 1
store i8 %7, i8* %9
%12 = load i8, i8* %10
%13 = icmp eq i8 %12, 0
br i1 %13, label %14, label %6
14: ; preds = %6, %0
%15 = phi i8* [ %2, %0 ], [ %11, %6 ]
%16 = call i32 @memcpy(i8* %15, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @getAdminFile.cjdnsadmin, i64 0, i64 0), i32 13)
%17 = load i32, i32* @O_RDONLY
%18 = call i32 @open(i8* %2, i32 %17)
%19 = icmp slt i32 %18, 0
br i1 %19, label %20, label %23
20: ; preds = %14
%21 = load i32, i32* @errno
%22 = call i32 @puterr(i8* %2, i32 %21)
br label %23
23: ; preds = %20, %14
ret i32 %18
}