#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 *);
char *malloc(scalar_t__);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
scalar_t__ strlen(char *);
char *os_defaultinitname(void) {
  char *p, *q;
  p = getenv("EDT_INITFILE");
  if (p != NULL)
    return (p);
  p = getenv("HOME");
  if (p != NULL) {
    q = malloc(strlen(p) + 16);
    strcpy(q, p);
    strcat(q, "/.edt_init");
    return (q);
  }
  return (NULL);
}


x86 assembly (clang, -O0):
<os_defaultinitname>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xea1(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1180 <os_defaultinitname+0x30>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11e6 <os_defaultinitname+0x96>
lea    0xe86(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11de <os_defaultinitname+0x8e>
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,%rdi
add    $0x10,%rdi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x18(%rbp),%rdi
lea    0xe46(%rip),%rsi
call   1070 <strcat@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11e6 <os_defaultinitname+0x96>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<os_defaultinitname>:
push   %r14
push   %rbx
push   %rax
lea    0xea5(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    11ae <os_defaultinitname+0x5e>
lea    0xe9e(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     11ac <os_defaultinitname+0x5c>
mov    %rax,%r14
mov    %rax,%rdi
call   1050 <strlen@plt>
lea    0x10(%rax),%rdi
call   1060 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r14,%rsi
call   1040 <strcpy@plt>
lea    0xe70(%rip),%rsi
mov    %rbx,%rdi
call   1070 <strcat@plt>
jmp    11ae <os_defaultinitname+0x5e>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [13 x i8] c"EDT_INITFILE\00"
@.str.1 = [5 x i8] c"HOME\00"
@.str.2 = [11 x i8] c"/.edt_init\00"
define i8* @os_defaultinitname() {
%1 = alloca i8*
%2 = alloca i8*
%3 = alloca i8*
%4 = call i8* @getenv(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
store i8* %4, i8** %2
%5 = load i8*, i8** %2
%6 = icmp ne i8* %5, null
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = load i8*, i8** %2
store i8* %8, i8** %1
br label %25
9: ; preds = %0
%10 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
store i8* %10, i8** %2
%11 = load i8*, i8** %2
%12 = icmp ne i8* %11, null
br i1 %12, label %13, label %24
13: ; preds = %9
%14 = load i8*, i8** %2
%15 = call i64 @strlen(i8* %14)
%16 = add nsw i64 %15, 16
%17 = call i8* @malloc(i64 %16)
store i8* %17, i8** %3
%18 = load i8*, i8** %3
%19 = load i8*, i8** %2
%20 = call i32 @strcpy(i8* %18, i8* %19)
%21 = load i8*, i8** %3
%22 = call i32 @strcat(i8* %21, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
%23 = load i8*, i8** %3
store i8* %23, i8** %1
br label %25
24: ; preds = %9
store i8* null, i8** %1
br label %25
25: ; preds = %24, %13, %7
%26 = load i8*, i8** %1
ret i8* %26
}

LLVM IR (-O2):
@.str = [13 x i8] c"EDT_INITFILE\00"
@.str.1 = [5 x i8] c"HOME\00"
@.str.2 = [11 x i8] c"/.edt_init\00"
define i8* @os_defaultinitname() {
%1 = tail call i8* @getenv(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%2 = icmp eq i8* %1, null
br i1 %2, label %3, label %12
3: ; preds = %0
%4 = tail call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%5 = icmp eq i8* %4, null
br i1 %5, label %12, label %6
6: ; preds = %3
%7 = tail call i64 @strlen(i8* %4)
%8 = add nsw i64 %7, 16
%9 = tail call i8* @malloc(i64 %8)
%10 = tail call i32 @strcpy(i8* %9, i8* %4)
%11 = tail call i32 @strcat(i8* %9, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
br label %12
12: ; preds = %3, %0, %6
%13 = phi i8* [ %9, %6 ], [ %1, %0 ], [ null, %3 ]
ret i8* %13
}