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

/* Variables and functions */
char *getenv(char *);
int /*<<< orphan*/ memset(char *, char, size_t);
int /*<<< orphan*/ strncat(char *, char *, size_t);
int /*<<< orphan*/ strncpy(char *, char *, size_t);
void eof_get_configdir(char buf[], size_t len) {
  char *p;
  memset(buf, '\0', len);
  p = getenv("EOF_HOME");
  if (p) {
    strncpy(buf, p, len);
    return;
  }
  p = getenv("HOME");
  if (p) {
    strncpy(buf, p, len);
  }
  strncat(buf, "/", len - 1);
  strncat(buf, ".ceof", len - 1);
}


x86 assembly (clang, -O0):
<eof_get_configdir>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rdx
xor    %esi,%esi
call   1050 <memset@plt>
lea    0xe9a(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1190 <eof_get_configdir+0x50>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x10(%rbp),%rdx
call   1040 <strncpy@plt>
jmp    11ec <eof_get_configdir+0xac>
lea    0xe6d(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11bc <eof_get_configdir+0x7c>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x10(%rbp),%rdx
call   1040 <strncpy@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rdx
sub    $0x1,%rdx
lea    0xe3a(%rip),%rsi
call   1060 <strncat@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rdx
sub    $0x1,%rdx
lea    0xe24(%rip),%rsi
call   1060 <strncat@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<eof_get_configdir>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
xor    %esi,%esi
mov    %rbx,%rdx
call   1050 <memset@plt>
lea    0xea5(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     117a <eof_get_configdir+0x3a>
mov    %r14,%rdi
mov    %rax,%rsi
mov    %rbx,%rdx
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1040 <strncpy@plt>
lea    0xe83(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     1199 <eof_get_configdir+0x59>
mov    %r14,%rdi
mov    %rax,%rsi
mov    %rbx,%rdx
call   1040 <strncpy@plt>
add    $0xffffffffffffffff,%rbx
lea    0xe65(%rip),%rsi
mov    %r14,%rdi
mov    %rbx,%rdx
call   1060 <strncat@plt>
lea    0xe55(%rip),%rsi
mov    %r14,%rdi
mov    %rbx,%rdx
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1060 <strncat@plt>

LLVM IR (-O0):
@.str = [9 x i8] c"EOF_HOME\00"
@.str.1 = [5 x i8] c"HOME\00"
@.str.2 = [2 x i8] c"/\00"
@.str.3 = [6 x i8] c".ceof\00"
define void @eof_get_configdir(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i8*
store i8* %0, i8** %3
store i64 %1, i64* %4
%6 = load i8*, i8** %3
%7 = load i64, i64* %4
%8 = call i32 @memset(i8* %6, i8 signext 0, i64 %7)
%9 = call i8* @getenv(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
store i8* %9, i8** %5
%10 = load i8*, i8** %5
%11 = icmp ne i8* %10, null
br i1 %11, label %12, label %17
12: ; preds = %2
%13 = load i8*, i8** %3
%14 = load i8*, i8** %5
%15 = load i64, i64* %4
%16 = call i32 @strncpy(i8* %13, i8* %14, i64 %15)
br label %35
17: ; preds = %2
%18 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
store i8* %18, i8** %5
%19 = load i8*, i8** %5
%20 = icmp ne i8* %19, null
br i1 %20, label %21, label %26
21: ; preds = %17
%22 = load i8*, i8** %3
%23 = load i8*, i8** %5
%24 = load i64, i64* %4
%25 = call i32 @strncpy(i8* %22, i8* %23, i64 %24)
br label %26
26: ; preds = %21, %17
%27 = load i8*, i8** %3
%28 = load i64, i64* %4
%29 = sub i64 %28, 1
%30 = call i32 @strncat(i8* %27, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i64 %29)
%31 = load i8*, i8** %3
%32 = load i64, i64* %4
%33 = sub i64 %32, 1
%34 = call i32 @strncat(i8* %31, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i64 %33)
br label %35
35: ; preds = %26, %12
ret void
}

LLVM IR (-O2):
@.str = [9 x i8] c"EOF_HOME\00"
@.str.1 = [5 x i8] c"HOME\00"
@.str.2 = [2 x i8] c"/\00"
@.str.3 = [6 x i8] c".ceof\00"
define void @eof_get_configdir(i8* %0, i64 %1) {
%3 = tail call i32 @memset(i8* %0, i8 signext 0, i64 %1)
%4 = tail call i8* @getenv(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i8* %4, null
br i1 %5, label %8, label %6
6: ; preds = %2
%7 = tail call i32 @strncpy(i8* %0, i8* %4, i64 %1)
br label %17
8: ; preds = %2
%9 = tail call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%10 = icmp eq i8* %9, null
br i1 %10, label %13, label %11
11: ; preds = %8
%12 = tail call i32 @strncpy(i8* %0, i8* %9, i64 %1)
br label %13
13: ; preds = %11, %8
%14 = add i64 %1, -1
%15 = tail call i32 @strncat(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i64 %14)
%16 = tail call i32 @strncat(i8* %0, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i64 %14)
br label %17
17: ; preds = %13, %6
ret void
}