#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 */
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
scalar_t__ EEXIST;
scalar_t__ errno;
char *getenv(char *);
int /*<<< orphan*/ index(char *, char);
scalar_t__ isprint(char);
int mkdir(char *, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
char *os_idtodir(char *id) {
  static char buf[4096];
  char *p;
  if (getenv("TMPDIR")) {
    strcpy(buf, getenv("TMPDIR"));
  } else {
    strcpy(buf, "/var/tmp");
  }
  strcat(buf, "/m-prts-");
  p = getenv("USER");
  if (!p)
    p = getenv("LOGNAME");
  if (!p)
    p = "x";
  strcat(buf, p);
  (void)mkdir(buf, 0700);
  p = buf + strlen(buf);
  *p++ = '/';
  while (*id && p < buf + sizeof(buf) - 10) {
    if (isprint(*id) && !index("!$&*()|\'\";<>[]{}?/`\\ \t", *id))
      *p++ = *id;
    id++;
  }
  *p = '\0';
  if (mkdir(buf, 0700) == -1 && errno != EEXIST) {
    perror(buf);
    return 0;
  }
  *p++ = '/';
  *p = '\0';
  return buf;
}


x86 assembly (clang, -O0):
<os_idtodir>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
lea    0xe6d(%rip),%rdi
call   1030 <getenv@plt>
cmp    $0x0,%rax
je     11c2 <os_idtodir+0x42>
lea    0xe57(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rsi
lea    0x2eb8(%rip),%rdi
call   1040 <strcpy@plt>
jmp    11d5 <os_idtodir+0x55>
lea    0x2ea7(%rip),%rdi
lea    0xe37(%rip),%rsi
call   1040 <strcpy@plt>
lea    0x2e94(%rip),%rdi
lea    0xe2d(%rip),%rsi
call   10a0 <strcat@plt>
lea    0xe2a(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1213 <os_idtodir+0x93>
lea    0xe14(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1229 <os_idtodir+0xa9>
lea    0xe01(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rsi
lea    0x2e3c(%rip),%rdi
call   10a0 <strcat@plt>
lea    0x2e30(%rip),%rdi
mov    $0x1c0,%esi
call   1050 <mkdir@plt>
lea    0x2e1f(%rip),%rdi
call   1060 <strlen@plt>
movslq %eax,%rcx
lea    0x2e10(%rip),%rax
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
movb   $0x2f,(%rax)
mov    -0x10(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x19(%rbp)
je     12a9 <os_idtodir+0x129>
lea    0x2ddb(%rip),%rax
add    $0x1000,%rax
add    $0xfffffffffffffff6,%rax
cmp    %rax,-0x18(%rbp)
setb   %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    12b9 <os_idtodir+0x139>
jmp    1313 <os_idtodir+0x193>
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1080 <isprint@plt>
cmp    $0x0,%rax
je     1302 <os_idtodir+0x182>
mov    -0x10(%rbp),%rax
lea    0xd4e(%rip),%rdi
movsbl (%rax),%esi
call   1070 <index@plt>
cmp    $0x0,%eax
jne    1302 <os_idtodir+0x182>
mov    -0x10(%rbp),%rax
mov    (%rax),%cl
mov    -0x18(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x18(%rbp)
mov    %cl,(%rax)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1279 <os_idtodir+0xf9>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
lea    0x2d4f(%rip),%rdi
mov    $0x1c0,%esi
call   1050 <mkdir@plt>
cmp    $0xffffffff,%eax
jne    1367 <os_idtodir+0x1e7>
mov    0x2c9d(%rip),%rax
mov    (%rax),%rax
mov    0x2c9b(%rip),%rcx
cmp    (%rcx),%rax
je     1367 <os_idtodir+0x1e7>
lea    0x2d1b(%rip),%rdi
call   1090 <perror@plt>
movq   $0x0,-0x8(%rbp)
jmp    138b <os_idtodir+0x20b>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
movb   $0x2f,(%rax)
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
lea    0x2ce9(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<os_idtodir>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%rbx
lea    0xe6e(%rip),%rdi
call   1030 <getenv@plt>
lea    0x2ed2(%rip),%rdi
test   %rax,%rax
je     11a8 <os_idtodir+0x28>
mov    %rax,%rsi
jmp    11af <os_idtodir+0x2f>
lea    0xe58(%rip),%rsi
call   1040 <strcpy@plt>
lea    0x2eb5(%rip),%r14
lea    0xe4e(%rip),%rsi
mov    %r14,%rdi
call   10a0 <strcat@plt>
lea    0xe48(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
jne    11e7 <os_idtodir+0x67>
lea    0xe3c(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
lea    0xe35(%rip),%rsi
cmovne %rax,%rsi
mov    %r14,%rdi
call   10a0 <strcat@plt>
mov    %r14,%rdi
mov    $0x1c0,%esi
call   1050 <mkdir@plt>
mov    %r14,%rdi
call   1060 <strlen@plt>
cltq
lea    (%rax,%r14,1),%r15
add    $0x1,%r15
movb   $0x2f,(%rax,%r14,1)
mov    (%rbx),%al
test   %al,%al
je     1277 <os_idtodir+0xf7>
lea    0x3e38(%rip),%r12
cmp    %r12,%r15
jae    1277 <os_idtodir+0xf7>
lea    0xdee(%rip),%r14
nopw   0x0(%rax,%rax,1)
movsbl %al,%edi
call   1080 <isprint@plt>
test   %rax,%rax
je     1266 <os_idtodir+0xe6>
movsbl (%rbx),%esi
mov    %r14,%rdi
call   1070 <index@plt>
test   %eax,%eax
jne    1266 <os_idtodir+0xe6>
movzbl (%rbx),%eax
mov    %al,(%r15)
add    $0x1,%r15
movzbl 0x1(%rbx),%eax
test   %al,%al
je     1277 <os_idtodir+0xf7>
add    $0x1,%rbx
cmp    %r12,%r15
jb     1240 <os_idtodir+0xc0>
movb   $0x0,(%r15)
lea    0x2dee(%rip),%rbx
mov    %rbx,%rdi
mov    $0x1c0,%esi
call   1050 <mkdir@plt>
cmp    $0xffffffff,%eax
jne    12aa <os_idtodir+0x12a>
mov    0x2d3d(%rip),%rax
mov    (%rax),%rax
mov    0x2d3b(%rip),%rcx
cmp    (%rcx),%rax
jne    12bf <os_idtodir+0x13f>
movw   $0x2f,(%r15)
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
lea    0x2daa(%rip),%rdi
call   1090 <perror@plt>
xor    %ebx,%ebx
jmp    12b0 <os_idtodir+0x130>

LLVM IR (-O0):
@os_idtodir.buf = internal global [4096 x i8] zeroinitializer
@.str = [7 x i8] c"TMPDIR\00"
@.str.1 = [9 x i8] c"/var/tmp\00"
@.str.2 = [9 x i8] c"/m-prts-\00"
@.str.3 = [5 x i8] c"USER\00"
@.str.4 = [8 x i8] c"LOGNAME\00"
@.str.5 = [2 x i8] c"x\00"
@.str.6 = [23 x i8] c"!$&*()|'\22;<>[]{}?/`\\ \09\00"
@errno = global i64 0
@EEXIST = global i64 0
define i8* @os_idtodir(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
store i8* %0, i8** %3
%5 = call i8* @getenv(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%6 = icmp ne i8* %5, null
br i1 %6, label %7, label %10
7: ; preds = %1
%8 = call i8* @getenv(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%9 = call i32 @strcpy(i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @os_idtodir.buf, i64 0, i64 0), i8* %8)
br label %12
10: ; preds = %1
%11 = call i32 @strcpy(i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @os_idtodir.buf, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
br label %12
12: ; preds = %10, %7
%13 = call i32 @strcat(i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @os_idtodir.buf, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
%14 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
store i8* %14, i8** %4
%15 = load i8*, i8** %4
%16 = icmp ne i8* %15, null
br i1 %16, label %19, label %17
17: ; preds = %12
%18 = call i8* @getenv(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
store i8* %18, i8** %4
br label %19
19: ; preds = %17, %12
%20 = load i8*, i8** %4
%21 = icmp ne i8* %20, null
br i1 %21, label %23, label %22
22: ; preds = %19
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0), i8** %4
br label %23
23: ; preds = %22, %19
%24 = load i8*, i8** %4
%25 = call i32 @strcat(i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @os_idtodir.buf, i64 0, i64 0), i8* %24)
%26 = call i32 @mkdir(i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @os_idtodir.buf, i64 0, i64 0), i32 448)
%27 = call i32 @strlen(i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @os_idtodir.buf, i64 0, i64 0))
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8, i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @os_idtodir.buf, i64 0, i64 0), i64 %28
store i8* %29, i8** %4
%30 = load i8*, i8** %4
%31 = getelementptr inbounds i8, i8* %30, i32 1
store i8* %31, i8** %4
store i8 47, i8* %30
br label %32
32: ; preds = %57, %23
%33 = load i8*, i8** %3
%34 = load i8, i8* %33
%35 = sext i8 %34 to i32
%36 = icmp ne i32 %35, 0
br i1 %36, label %37, label %40
37: ; preds = %32
%38 = load i8*, i8** %4
%39 = icmp ult i8* %38, getelementptr inbounds ([4096 x i8], [4096 x i8]* @os_idtodir.buf, i64 1, i64 -10)
br label %40
40: ; preds = %37, %32
%41 = phi i1 [ false, %32 ], [ %39, %37 ]
br i1 %41, label %42, label %60
42: ; preds = %40
%43 = load i8*, i8** %3
%44 = load i8, i8* %43
%45 = call i64 @isprint(i8 signext %44)
%46 = icmp ne i64 %45, 0
br i1 %46, label %47, label %57
47: ; preds = %42
%48 = load i8*, i8** %3
%49 = load i8, i8* %48
%50 = call i32 @index(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.6, i64 0, i64 0), i8 signext %49)
%51 = icmp ne i32 %50, 0
br i1 %51, label %57, label %52
52: ; preds = %47
%53 = load i8*, i8** %3
%54 = load i8, i8* %53
%55 = load i8*, i8** %4
%56 = getelementptr inbounds i8, i8* %55, i32 1
store i8* %56, i8** %4
store i8 %54, i8* %55
br label %57
57: ; preds = %52, %47, %42
%58 = load i8*, i8** %3
%59 = getelementptr inbounds i8, i8* %58, i32 1
store i8* %59, i8** %3
br label %32
60: ; preds = %40
%61 = load i8*, i8** %4
store i8 0, i8* %61
%62 = call i32 @mkdir(i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @os_idtodir.buf, i64 0, i64 0), i32 448)
%63 = icmp eq i32 %62, -1
br i1 %63, label %64, label %70
64: ; preds = %60
%65 = load i64, i64* @errno
%66 = load i64, i64* @EEXIST
%67 = icmp ne i64 %65, %66
br i1 %67, label %68, label %70
68: ; preds = %64
%69 = call i32 @perror(i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @os_idtodir.buf, i64 0, i64 0))
store i8* null, i8** %2
br label %74
70: ; preds = %64, %60
%71 = load i8*, i8** %4
%72 = getelementptr inbounds i8, i8* %71, i32 1
store i8* %72, i8** %4
store i8 47, i8* %71
%73 = load i8*, i8** %4
store i8 0, i8* %73
store i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @os_idtodir.buf, i64 0, i64 0), i8** %2
br label %74
74: ; preds = %70, %68
%75 = load i8*, i8** %2
ret i8* %75
}

LLVM IR (-O2):
@os_idtodir.buf = internal global [4096 x i8] zeroinitializer
@.str = [7 x i8] c"TMPDIR\00"
@.str.1 = [9 x i8] c"/var/tmp\00"
@.str.2 = [9 x i8] c"/m-prts-\00"
@.str.3 = [5 x i8] c"USER\00"
@.str.4 = [8 x i8] c"LOGNAME\00"
@.str.5 = [2 x i8] c"x\00"
@.str.6 = [23 x i8] c"!$&*()|'\22;<>[]{}?/`\\ \09\00"
@errno = global i64 0
@EEXIST = global i64 0
define i8* @os_idtodir(i8* nocapture %0) {
%2 = tail call i8* @getenv(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i8* %2, null
br i1 %3, label %6, label %4
4: ; preds = %1
%5 = tail call i32 @strcpy(i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @os_idtodir.buf, i64 0, i64 0), i8* %2)
br label %8
6: ; preds = %1
%7 = tail call i32 @strcpy(i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @os_idtodir.buf, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
br label %8
8: ; preds = %6, %4
%9 = tail call i32 @strcat(i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @os_idtodir.buf, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
%10 = tail call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%11 = icmp eq i8* %10, null
br i1 %11, label %12, label %14
12: ; preds = %8
%13 = tail call i8* @getenv(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
br label %14
14: ; preds = %12, %8
%15 = phi i8* [ %10, %8 ], [ %13, %12 ]
%16 = icmp eq i8* %15, null
%17 = select i1 %16, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0), i8* %15
%18 = tail call i32 @strcat(i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @os_idtodir.buf, i64 0, i64 0), i8* %17)
%19 = tail call i32 @mkdir(i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @os_idtodir.buf, i64 0, i64 0), i32 448)
%20 = tail call i32 @strlen(i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @os_idtodir.buf, i64 0, i64 0))
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds [4096 x i8], [4096 x i8]* @os_idtodir.buf, i64 0, i64 %21
%23 = getelementptr inbounds i8, i8* %22, i64 1
store i8 47, i8* %22
%24 = load i8, i8* %0
%25 = icmp ne i8 %24, 0
%26 = icmp ult i8* %23, getelementptr inbounds ([4096 x i8], [4096 x i8]* @os_idtodir.buf, i64 0, i64 4086)
%27 = select i1 %25, i1 %26, i1 false
br i1 %27, label %28, label %48
28: ; preds = %14, %41
%29 = phi i8 [ %44, %41 ], [ %24, %14 ]
%30 = phi i8* [ %42, %41 ], [ %23, %14 ]
%31 = phi i8* [ %43, %41 ], [ %0, %14 ]
%32 = tail call i64 @isprint(i8 signext %29)
%33 = icmp eq i64 %32, 0
br i1 %33, label %41, label %34
34: ; preds = %28
%35 = load i8, i8* %31
%36 = tail call i32 @index(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.6, i64 0, i64 0), i8 signext %35)
%37 = icmp eq i32 %36, 0
br i1 %37, label %38, label %41
38: ; preds = %34
%39 = load i8, i8* %31
%40 = getelementptr inbounds i8, i8* %30, i64 1
store i8 %39, i8* %30
br label %41
41: ; preds = %38, %34, %28
%42 = phi i8* [ %30, %34 ], [ %40, %38 ], [ %30, %28 ]
%43 = getelementptr inbounds i8, i8* %31, i64 1
%44 = load i8, i8* %43
%45 = icmp ne i8 %44, 0
%46 = icmp ult i8* %42, getelementptr inbounds ([4096 x i8], [4096 x i8]* @os_idtodir.buf, i64 0, i64 4086)
%47 = select i1 %45, i1 %46, i1 false
br i1 %47, label %28, label %48
48: ; preds = %41, %14
%49 = phi i8* [ %23, %14 ], [ %42, %41 ]
store i8 0, i8* %49
%50 = tail call i32 @mkdir(i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @os_idtodir.buf, i64 0, i64 0), i32 448)
%51 = icmp eq i32 %50, -1
br i1 %51, label %52, label %58
52: ; preds = %48
%53 = load i64, i64* @errno
%54 = load i64, i64* @EEXIST
%55 = icmp eq i64 %53, %54
br i1 %55, label %58, label %56
56: ; preds = %52
%57 = tail call i32 @perror(i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @os_idtodir.buf, i64 0, i64 0))
br label %60
58: ; preds = %52, %48
%59 = getelementptr inbounds i8, i8* %49, i64 1
store i8 47, i8* %49
store i8 0, i8* %59
br label %60
60: ; preds = %58, %56
%61 = phi i8* [ null, %56 ], [ getelementptr inbounds ([4096 x i8], [4096 x i8]* @os_idtodir.buf, i64 0, i64 0), %58 ]
ret i8* %61
}