#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, char **);
int /*<<< orphan*/ sprintf(char *, char *, char *);
scalar_t__ strlen(char *);
void sys_initpath() {
  char *buf, *home = getenv("HOME");
  if (!home) {
    buf = ".";
    rc_setvar("rcpath", 1, &buf);
    rc_setvar("savedir", 1, &buf);
    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    11bd <sys_initpath+0x5d>
lea    0xe9d(%rip),%rax
mov    %rax,-0x8(%rbp)
lea    0xe70(%rip),%rdi
mov    $0x1,%esi
lea    -0x8(%rbp),%rdx
call   1060 <rc_setvar@plt>
lea    0xe62(%rip),%rdi
mov    $0x1,%esi
lea    -0x8(%rbp),%rdx
call   1060 <rc_setvar@plt>
jmp    1245 <sys_initpath+0xe5>
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,-0x18(%rbp)
lea    0xe43(%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    0xe23(%rip),%rsi
call   1080 <sprintf@plt>
lea    0xe00(%rip),%rdi
mov    $0x1,%esi
lea    -0x8(%rbp),%rdx
call   1060 <rc_setvar@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xe07(%rip),%rsi
call   1080 <sprintf@plt>
lea    0xdde(%rip),%rdi
mov    $0x1,%esi
lea    -0x8(%rbp),%rdx
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     11e8 <sys_initpath+0x88>
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
call   1060 <rc_setvar@plt>
mov    (%rsp),%rdi
lea    0xe60(%rip),%rsi
mov    %rbx,%rdx
call   1080 <sprintf@plt>
lea    0xe3c(%rip),%rdi
mov    $0x1,%esi
mov    %r14,%rdx
call   1060 <rc_setvar@plt>
mov    (%rsp),%rdi
call   1040 <free@plt>
jmp    121e <sys_initpath+0xbe>
lea    0xe30(%rip),%rax
mov    %rax,(%rsp)
lea    0xe0b(%rip),%rdi
mov    %rsp,%rbx
mov    $0x1,%esi
mov    %rbx,%rdx
call   1060 <rc_setvar@plt>
lea    0xdfb(%rip),%rdi
mov    $0x1,%esi
mov    %rbx,%rdx
call   1060 <rc_setvar@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [5 x i8] c"HOME\00"
@.str.1 = [2 x i8] c".\00"
@.str.2 = [7 x i8] c"rcpath\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
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8** %1
%7 = call i32 @rc_setvar(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 1, i8** %1)
%8 = call i32 @rc_setvar(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i32 1, i8** %1)
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 @rc_setvar(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, 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 @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 = [2 x i8] c".\00"
@.str.2 = [7 x i8] c"rcpath\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
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8** %1
%6 = call i32 @rc_setvar(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 1, i8** %1)
%7 = call i32 @rc_setvar(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i32 1, i8** %1)
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 @rc_setvar(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, 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 @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
}