#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*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
scalar_t__ strlen(char *);
int Sfile_home_adr_s(char *filename, char *fileadr, int fa_size, int flag) {
  char *home;
  strcpy(fileadr, filename);
  home = getenv("HOME");
  if (home == NULL)
    return (0);
  if ((int)(strlen(home) + strlen(filename) + 1) >= fa_size)
    return (-1);
  strcpy(fileadr, home);
  if (filename[0] != 0) {
    strcat(fileadr, "/");
    strcat(fileadr, filename);
  }
  return (1);
}


x86 assembly (clang, -O0):
<Sfile_home_adr_s>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %ecx,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <strcpy@plt>
lea    0xe96(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    118a <Sfile_home_adr_s+0x4a>
movl   $0x0,-0x4(%rbp)
jmp    1204 <Sfile_home_adr_s+0xc4>
mov    -0x28(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,%rcx
mov    -0x30(%rbp),%rax
add    %rcx,%rax
add    $0x1,%rax
cmp    -0x1c(%rbp),%eax
jl     11c3 <Sfile_home_adr_s+0x83>
movl   $0xffffffff,-0x4(%rbp)
jmp    1204 <Sfile_home_adr_s+0xc4>
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11fd <Sfile_home_adr_s+0xbd>
mov    -0x18(%rbp),%rdi
lea    0xe1a(%rip),%rsi
call   1060 <strcat@plt>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1060 <strcat@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Sfile_home_adr_s>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edx,%r15d
mov    %rsi,%r14
mov    %rdi,%r12
mov    %rsi,%rdi
mov    %r12,%rsi
call   1040 <strcpy@plt>
lea    0xe9d(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     11c5 <Sfile_home_adr_s+0x85>
mov    %rax,%rbx
mov    %rax,%rdi
call   1050 <strlen@plt>
mov    %rax,%rbp
mov    %r12,%rdi
call   1050 <strlen@plt>
add    %ebp,%eax
add    $0x1,%eax
mov    $0xffffffff,%ebp
cmp    %r15d,%eax
jge    11c7 <Sfile_home_adr_s+0x87>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1040 <strcpy@plt>
mov    $0x1,%ebp
cmpb   $0x0,(%r12)
je     11c7 <Sfile_home_adr_s+0x87>
lea    0xe55(%rip),%rsi
mov    %r14,%rdi
call   1060 <strcat@plt>
mov    %r14,%rdi
mov    %r12,%rsi
call   1060 <strcat@plt>
jmp    11c7 <Sfile_home_adr_s+0x87>
xor    %ebp,%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"HOME\00"
@.str.1 = [2 x i8] c"/\00"
define i32 @Sfile_home_adr_s(i8* %0, i8* %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
store i8* %0, i8** %6
store i8* %1, i8** %7
store i32 %2, i32* %8
store i32 %3, i32* %9
%11 = load i8*, i8** %7
%12 = load i8*, i8** %6
%13 = call i32 @strcpy(i8* %11, i8* %12)
%14 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
store i8* %14, i8** %10
%15 = load i8*, i8** %10
%16 = icmp eq i8* %15, null
br i1 %16, label %17, label %18
17: ; preds = %4
store i32 0, i32* %5
br label %45
18: ; preds = %4
%19 = load i8*, i8** %10
%20 = call i64 @strlen(i8* %19)
%21 = load i8*, i8** %6
%22 = call i64 @strlen(i8* %21)
%23 = add nsw i64 %20, %22
%24 = add nsw i64 %23, 1
%25 = trunc i64 %24 to i32
%26 = load i32, i32* %8
%27 = icmp sge i32 %25, %26
br i1 %27, label %28, label %29
28: ; preds = %18
store i32 -1, i32* %5
br label %45
29: ; preds = %18
%30 = load i8*, i8** %7
%31 = load i8*, i8** %10
%32 = call i32 @strcpy(i8* %30, i8* %31)
%33 = load i8*, i8** %6
%34 = getelementptr inbounds i8, i8* %33, i64 0
%35 = load i8, i8* %34
%36 = sext i8 %35 to i32
%37 = icmp ne i32 %36, 0
br i1 %37, label %38, label %44
38: ; preds = %29
%39 = load i8*, i8** %7
%40 = call i32 @strcat(i8* %39, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%41 = load i8*, i8** %7
%42 = load i8*, i8** %6
%43 = call i32 @strcat(i8* %41, i8* %42)
br label %44
44: ; preds = %38, %29
store i32 1, i32* %5
br label %45
45: ; preds = %44, %28, %17
%46 = load i32, i32* %5
ret i32 %46
}

LLVM IR (-O2):
@.str = [5 x i8] c"HOME\00"
@.str.1 = [2 x i8] c"/\00"
define i32 @Sfile_home_adr_s(i8* %0, i8* %1, i32 %2, i32 %3) {
%5 = tail call i32 @strcpy(i8* %1, i8* %0)
%6 = tail call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i8* %6, null
br i1 %7, label %22, label %8
8: ; preds = %4
%9 = tail call i64 @strlen(i8* %6)
%10 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%11 = add nsw i64 %10, %9
%12 = trunc i64 %11 to i32
%13 = add i32 %12, 1
%14 = icmp slt i32 %13, %2
br i1 %14, label %15, label %22
15: ; preds = %8
%16 = tail call i32 @strcpy(i8* %1, i8* %6)
%17 = load i8, i8* %0
%18 = icmp eq i8 %17, 0
br i1 %18, label %22, label %19
19: ; preds = %15
%20 = tail call i32 @strcat(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%21 = tail call i32 @strcat(i8* %1, i8* %0)
br label %22
22: ; preds = %15, %19, %8, %4
%23 = phi i32 [ 0, %4 ], [ -1, %8 ], [ 1, %19 ], [ 1, %15 ]
ret i32 %23
}