#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*/ memcpy(char *, char const *, int);
int strlen(char const *);
const char *tpipe_name(int c) {
  static char path[256];
  static int ix = -1;
  if (ix < 0) {
    const char *s = getenv("LF_TMPDIR");
    if (!s || !*s || (ix = strlen(s)) > 248)
      s = "/tmp", ix = 4;
    memcpy(path, s, ix);
    memcpy(path + ix, "/_\0", 4);
    ix++;
  }
  path[ix] = c;
  return path;
}


x86 assembly (clang, -O0):
<tpipe_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
cmpl   $0x0,0x2ef6(%rip)
jge    11e6 <tpipe_name+0xb6>
lea    0xeb1(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     118a <tpipe_name+0x5a>
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
je     118a <tpipe_name+0x5a>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,0x2eb9(%rip)
cmp    $0xf8,%eax
jle    119f <tpipe_name+0x6f>
lea    0xe79(%rip),%rax
mov    %rax,-0x10(%rbp)
movl   $0x4,0x2e99(%rip)
mov    -0x10(%rbp),%rsi
mov    0x2e8f(%rip),%edx
lea    0x2ea0(%rip),%rdi
call   1050 <memcpy@plt>
movslq 0x2e7c(%rip),%rax
lea    0x2e8d(%rip),%rdi
add    %rax,%rdi
lea    0xe42(%rip),%rsi
mov    $0x4,%edx
call   1050 <memcpy@plt>
mov    0x2e5b(%rip),%eax
add    $0x1,%eax
mov    %eax,0x2e52(%rip)
mov    -0x4(%rbp),%eax
mov    %al,%dl
movslq 0x2e46(%rip),%rcx
lea    0x2e57(%rip),%rax
mov    %dl,(%rax,%rcx,1)
lea    0x2e4d(%rip),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tpipe_name>:
push   %rbp
push   %r14
push   %rbx
mov    %edi,%ebp
mov    0x2efc(%rip),%eax
test   %eax,%eax
jns    11b8 <tpipe_name+0x88>
lea    0xeb9(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     116a <tpipe_name+0x3a>
mov    %rax,%rbx
cmpb   $0x0,(%rax)
je     116a <tpipe_name+0x3a>
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %eax,%edx
cmp    $0xf9,%eax
jl     1176 <tpipe_name+0x46>
lea    0xe99(%rip),%rbx
mov    $0x4,%edx
mov    %edx,0x2ebc(%rip)
lea    0x2ecd(%rip),%r14
mov    %r14,%rdi
mov    %rbx,%rsi
call   1050 <memcpy@plt>
movslq 0x2ea3(%rip),%rdi
add    %r14,%rdi
lea    0xe70(%rip),%rsi
mov    $0x4,%edx
call   1050 <memcpy@plt>
mov    0x2e89(%rip),%eax
add    $0x1,%eax
mov    %eax,0x2e80(%rip)
movslq %eax,%rcx
lea    0x2e8e(%rip),%rax
mov    %bpl,(%rcx,%rax,1)
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@tpipe_name.path = internal global [256 x i8] zeroinitializer
@tpipe_name.ix = internal global i32 -1
@.str = [10 x i8] c"LF_TMPDIR\00"
@.str.1 = [5 x i8] c"/tmp\00"
@.str.2 = [4 x i8] c"/_\00\00"
define i8* @tpipe_name(i32 %0) {
%2 = alloca i32
%3 = alloca i8*
store i32 %0, i32* %2
%4 = load i32, i32* @tpipe_name.ix
%5 = icmp slt i32 %4, 0
br i1 %5, label %6, label %29
6: ; preds = %1
%7 = call i8* @getenv(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
store i8* %7, i8** %3
%8 = load i8*, i8** %3
%9 = icmp ne i8* %8, null
br i1 %9, label %10, label %18
10: ; preds = %6
%11 = load i8*, i8** %3
%12 = load i8, i8* %11
%13 = icmp ne i8 %12, 0
br i1 %13, label %14, label %18
14: ; preds = %10
%15 = load i8*, i8** %3
%16 = call i32 @strlen(i8* %15)
store i32 %16, i32* @tpipe_name.ix
%17 = icmp sgt i32 %16, 248
br i1 %17, label %18, label %19
18: ; preds = %14, %10, %6
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8** %3
store i32 4, i32* @tpipe_name.ix
br label %19
19: ; preds = %18, %14
%20 = load i8*, i8** %3
%21 = load i32, i32* @tpipe_name.ix
%22 = call i32 @memcpy(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @tpipe_name.path, i64 0, i64 0), i8* %20, i32 %21)
%23 = load i32, i32* @tpipe_name.ix
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* getelementptr inbounds ([256 x i8], [256 x i8]* @tpipe_name.path, i64 0, i64 0), i64 %24
%26 = call i32 @memcpy(i8* %25, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 4)
%27 = load i32, i32* @tpipe_name.ix
%28 = add nsw i32 %27, 1
store i32 %28, i32* @tpipe_name.ix
br label %29
29: ; preds = %19, %1
%30 = load i32, i32* %2
%31 = trunc i32 %30 to i8
%32 = load i32, i32* @tpipe_name.ix
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds [256 x i8], [256 x i8]* @tpipe_name.path, i64 0, i64 %33
store i8 %31, i8* %34
ret i8* getelementptr inbounds ([256 x i8], [256 x i8]* @tpipe_name.path, i64 0, i64 0)
}

LLVM IR (-O2):
@tpipe_name.path = internal global [256 x i8] zeroinitializer
@tpipe_name.ix = internal unnamed_addr global i32 -1
@.str = [10 x i8] c"LF_TMPDIR\00"
@.str.1 = [5 x i8] c"/tmp\00"
@.str.2 = [4 x i8] c"/_\00\00"
define i8* @tpipe_name(i32 %0) {
%2 = load i32, i32* @tpipe_name.ix
%3 = icmp slt i32 %2, 0
br i1 %3, label %4, label %24
4: ; preds = %1
%5 = tail call i8* @getenv(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i8* %5, null
br i1 %6, label %13, label %7
7: ; preds = %4
%8 = load i8, i8* %5
%9 = icmp eq i8 %8, 0
br i1 %9, label %13, label %10
10: ; preds = %7
%11 = tail call i32 @strlen(i8* %5)
%12 = icmp sgt i32 %11, 248
br i1 %12, label %13, label %14
13: ; preds = %10, %7, %4
br label %14
14: ; preds = %13, %10
%15 = phi i32 [ 4, %13 ], [ %11, %10 ]
%16 = phi i8* [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), %13 ], [ %5, %10 ]
store i32 %15, i32* @tpipe_name.ix
%17 = tail call i32 @memcpy(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @tpipe_name.path, i64 0, i64 0), i8* %16, i32 %15)
%18 = load i32, i32* @tpipe_name.ix
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds [256 x i8], [256 x i8]* @tpipe_name.path, i64 0, i64 %19
%21 = tail call i32 @memcpy(i8* %20, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 4)
%22 = load i32, i32* @tpipe_name.ix
%23 = add nsw i32 %22, 1
store i32 %23, i32* @tpipe_name.ix
br label %24
24: ; preds = %14, %1
%25 = phi i32 [ %23, %14 ], [ %2, %1 ]
%26 = trunc i32 %0 to i8
%27 = sext i32 %25 to i64
%28 = getelementptr inbounds [256 x i8], [256 x i8]* @tpipe_name.path, i64 0, i64 %27
store i8 %26, i8* %28
ret i8* getelementptr inbounds ([256 x i8], [256 x i8]* @tpipe_name.path, i64 0, i64 0)
}