#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 */
int /*<<< orphan*/ free(char *);
char *getenv(char *);
char *malloc(scalar_t__);
int /*<<< orphan*/ rc_setvar(char *, ...);
int /*<<< orphan*/ sprintf(char *, char *, char *);
scalar_t__ strlen(char *);
void sys_initpath() {
  char *buf, *home = getenv("HOME");
  if (!home) {
    rc_setvar("rcpath", ".");
    rc_setvar("savedir", ".");
    return;
  }
  buf = malloc(strlen(home) + strlen(".gnuboy") + 8);
  sprintf(buf,
          "%s/"
          ".gnuboy"
          ":.",
          home);
  rc_setvar("rcpath", 1, &buf);
  sprintf(buf,
          "%s/"
          ".gnuboy"
          "/saves",
          home);
  rc_setvar("savedir", 1, &buf);
  free(buf);
}


x86 assembly (clang, -O0):
<sys_initpath>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xe91(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11b2 <sys_initpath+0x52>
lea    0xe7b(%rip),%rdi
lea    0xe96(%rip),%rsi
mov    $0x0,%al
call   1060 <rc_setvar@plt>
lea    0xe6d(%rip),%rdi
lea    0xe81(%rip),%rsi
mov    $0x0,%al
call   1060 <rc_setvar@plt>
jmp    123e <sys_initpath+0xde>
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,-0x18(%rbp)
lea    0xe4e(%rip),%rdi
call   1050 <strlen@plt>
mov    -0x18(%rbp),%rdi
add    %rax,%rdi
add    $0x8,%rdi
call   1070 <malloc@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xe2e(%rip),%rsi
call   1080 <sprintf@plt>
lea    0xe0b(%rip),%rdi
mov    $0x1,%esi
lea    -0x8(%rbp),%rdx
mov    $0x0,%al
call   1060 <rc_setvar@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xe10(%rip),%rsi
call   1080 <sprintf@plt>
lea    0xde7(%rip),%rdi
mov    $0x1,%esi
lea    -0x8(%rbp),%rdx
mov    $0x0,%al
call   1060 <rc_setvar@plt>
mov    -0x8(%rbp),%rdi
call   1040 <free@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sys_initpath>:
push   %r14
push   %rbx
push   %rax
lea    0xe95(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     11f2 <sys_initpath+0x92>
mov    %rax,%rbx
mov    %rax,%rdi
call   1050 <strlen@plt>
lea    0xf(%rax),%rdi
call   1070 <malloc@plt>
mov    %rax,(%rsp)
lea    0xe80(%rip),%rsi
mov    %rax,%rdi
mov    %rbx,%rdx
call   1080 <sprintf@plt>
lea    0xe5f(%rip),%rdi
mov    %rsp,%r14
mov    $0x1,%esi
mov    %r14,%rdx
xor    %eax,%eax
call   1060 <rc_setvar@plt>
mov    (%rsp),%rdi
lea    0xe5e(%rip),%rsi
mov    %rbx,%rdx
call   1080 <sprintf@plt>
lea    0xe3a(%rip),%rdi
mov    $0x1,%esi
mov    %r14,%rdx
xor    %eax,%eax
call   1060 <rc_setvar@plt>
mov    (%rsp),%rdi
call   1040 <free@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe0c(%rip),%rdi
lea    0xe1f(%rip),%rbx
mov    %rbx,%rsi
xor    %eax,%eax
call   1060 <rc_setvar@plt>
lea    0xdfb(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1060 <rc_setvar@plt>

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

LLVM IR (-O2):
@.str = [5 x i8] c"HOME\00"
@.str.1 = [7 x i8] c"rcpath\00"
@.str.2 = [2 x i8] c".\00"
@.str.3 = [8 x i8] c"savedir\00"
@.str.5 = [13 x i8] c"%s/.gnuboy:.\00"
@.str.6 = [17 x i8] c"%s/.gnuboy/saves\00"
define void @sys_initpath() {
%1 = alloca i8*
%2 = bitcast i8** %1 to i8*
%3 = tail call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i8* %3, null
br i1 %4, label %5, label %8
5: ; preds = %0
%6 = tail call i32 (i8*, ...) @rc_setvar(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%7 = tail call i32 (i8*, ...) @rc_setvar(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %19
8: ; preds = %0
%9 = tail call i64 @strlen(i8* %3)
%10 = add nsw i64 %9, 15
%11 = tail call i8* @malloc(i64 %10)
store i8* %11, i8** %1
%12 = tail call i32 @sprintf(i8* dereferenceable(1) %11, i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0), i8* %3)
%13 = call i32 (i8*, ...) @rc_setvar(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 1, i8** %1)
%14 = load i8*, i8** %1
%15 = call i32 @sprintf(i8* dereferenceable(1) %14, i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0), i8* %3)
%16 = call i32 (i8*, ...) @rc_setvar(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i32 1, i8** %1)
%17 = load i8*, i8** %1
%18 = call i32 @free(i8* %17)
br label %19
19: ; preds = %8, %5
ret void
}