#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*/ ENOSPC;
int /*<<< orphan*/ errno;
char *getenv(char *);
int snprintf(char *, size_t, char *, char *);
int os_get_tsimrc_path(char buf[], size_t sz) {
  char *home = getenv("HOME");
  int need = snprintf(buf, sz, "%s/.tsimrc", home);
  if ((size_t)need >= sz) {
    errno = ENOSPC;
    return 1;
  }
  return need < 0;
}


x86 assembly (clang, -O0):
<os_get_tsimrc_path>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
lea    0xec9(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rcx
lea    0xeb2(%rip),%rdx
call   1040 <snprintf@plt>
mov    %eax,-0x24(%rbp)
movslq -0x24(%rbp),%rax
cmp    -0x18(%rbp),%rax
jb     1187 <os_get_tsimrc_path+0x67>
mov    0x2e68(%rip),%rax
mov    (%rax),%ecx
mov    0x2e67(%rip),%rax
mov    %ecx,(%rax)
movl   $0x1,-0x4(%rbp)
jmp    1196 <os_get_tsimrc_path+0x76>
cmpl   $0x0,-0x24(%rbp)
setl   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<os_get_tsimrc_path>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
lea    0xecf(%rip),%rdi
call   1030 <getenv@plt>
lea    0xec8(%rip),%rdx
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %rax,%rcx
call   1040 <snprintf@plt>
movslq %eax,%rcx
cmp    %rbx,%rcx
jae    1158 <os_get_tsimrc_path+0x38>
shr    $0x1f,%eax
jmp    116f <os_get_tsimrc_path+0x4f>
mov    0x2e79(%rip),%rax
mov    (%rax),%eax
mov    0x2e78(%rip),%rcx
mov    %eax,(%rcx)
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [5 x i8] c"HOME\00"
@.str.1 = [11 x i8] c"%s/.tsimrc\00"
@ENOSPC = global i32 0
@errno = global i32 0
define i32 @os_get_tsimrc_path(i8* %0, i64 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i8*
%7 = alloca i32
store i8* %0, i8** %4
store i64 %1, i64* %5
%8 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
store i8* %8, i8** %6
%9 = load i8*, i8** %4
%10 = load i64, i64* %5
%11 = load i8*, i8** %6
%12 = call i32 @snprintf(i8* %9, i64 %10, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* %11)
store i32 %12, i32* %7
%13 = load i32, i32* %7
%14 = sext i32 %13 to i64
%15 = load i64, i64* %5
%16 = icmp uge i64 %14, %15
br i1 %16, label %17, label %19
17: ; preds = %2
%18 = load i32, i32* @ENOSPC
store i32 %18, i32* @errno
store i32 1, i32* %3
br label %23
19: ; preds = %2
%20 = load i32, i32* %7
%21 = icmp slt i32 %20, 0
%22 = zext i1 %21 to i32
store i32 %22, i32* %3
br label %23
23: ; preds = %19, %17
%24 = load i32, i32* %3
ret i32 %24
}

LLVM IR (-O2):
@.str = [5 x i8] c"HOME\00"
@.str.1 = [11 x i8] c"%s/.tsimrc\00"
@ENOSPC = global i32 0
@errno = global i32 0
define i32 @os_get_tsimrc_path(i8* %0, i64 %1) {
%3 = tail call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%4 = tail call i32 @snprintf(i8* %0, i64 %1, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* %3)
%5 = sext i32 %4 to i64
%6 = icmp ult i64 %5, %1
br i1 %6, label %9, label %7
7: ; preds = %2
%8 = load i32, i32* @ENOSPC
store i32 %8, i32* @errno
br label %11
9: ; preds = %2
%10 = lshr i32 %4, 31
br label %11
11: ; preds = %9, %7
%12 = phi i32 [ 1, %7 ], [ %10, %9 ]
ret i32 %12
}