#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 *);
char *mkdtemp(char *);
int /*<<< orphan*/ strcat(char *, char const *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char const *);
int mktestdir(const char *name, char *pathbuf, size_t bufsz) {
  int st;
  size_t l;
  char *tp;
  st = 0;
  if (strlen(name) > 16)
    return -1;
  tp = getenv("TMPDIR");
  if (!tp)
    return -1;
  if (strlen(tp) + 32 < bufsz) {
    strcpy(pathbuf, tp);
    l = strlen(pathbuf);
    if (pathbuf[l - 1] != '/')
      strcat(pathbuf, "/");
    strcat(pathbuf, name);
    strcat(pathbuf, "XXXXX");
    tp = mkdtemp(pathbuf);
    if (tp)
      return 0;
    else
      return -1;
  } else
    return -1;
}


x86 assembly (clang, -O0):
<mktestdir>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
cmp    $0x10,%eax
jle    1189 <mktestdir+0x39>
movl   $0xffffffff,-0x4(%rbp)
jmp    1261 <mktestdir+0x111>
lea    0xe70(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    11b0 <mktestdir+0x60>
movl   $0xffffffff,-0x4(%rbp)
jmp    1261 <mktestdir+0x111>
mov    -0x38(%rbp),%rdi
call   1050 <strlen@plt>
add    $0x20,%eax
cltq
cmp    -0x20(%rbp),%rax
jae    125a <mktestdir+0x10a>
mov    -0x18(%rbp),%rdi
mov    -0x38(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
cltq
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x30(%rbp),%rcx
sub    $0x1,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2f,%eax
je     120d <mktestdir+0xbd>
mov    -0x18(%rbp),%rdi
lea    0xdff(%rip),%rsi
call   1070 <strcat@plt>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1070 <strcat@plt>
mov    -0x18(%rbp),%rdi
lea    0xde4(%rip),%rsi
call   1070 <strcat@plt>
mov    -0x18(%rbp),%rdi
call   1060 <mkdtemp@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
je     124e <mktestdir+0xfe>
movl   $0x0,-0x4(%rbp)
jmp    1261 <mktestdir+0x111>
movl   $0xffffffff,-0x4(%rbp)
jmp    1261 <mktestdir+0x111>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mktestdir>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdx,%r15
mov    %rsi,%r14
mov    %rdi,%r12
call   1050 <strlen@plt>
mov    $0xffffffff,%ebp
cmp    $0x10,%eax
jg     11ea <mktestdir+0x9a>
lea    0xe89(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     11ea <mktestdir+0x9a>
mov    %rax,%rbx
mov    %rax,%rdi
call   1050 <strlen@plt>
add    $0x20,%eax
cltq
cmp    %r15,%rax
jae    11ea <mktestdir+0x9a>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1040 <strcpy@plt>
mov    %r14,%rdi
call   1050 <strlen@plt>
cltq
cmpb   $0x2f,-0x1(%rax,%r14,1)
je     11c2 <mktestdir+0x72>
lea    0xe4d(%rip),%rsi
mov    %r14,%rdi
call   1070 <strcat@plt>
mov    %r14,%rdi
mov    %r12,%rsi
call   1070 <strcat@plt>
lea    0xe35(%rip),%rsi
mov    %r14,%rdi
call   1070 <strcat@plt>
mov    %r14,%rdi
call   1060 <mkdtemp@plt>
cmp    $0x1,%rax
sbb    %ebp,%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [7 x i8] c"TMPDIR\00"
@.str.1 = [2 x i8] c"/\00"
@.str.2 = [6 x i8] c"XXXXX\00"
define i32 @mktestdir(i8* %0, i8* %1, i64 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i32
%9 = alloca i64
%10 = alloca i8*
store i8* %0, i8** %5
store i8* %1, i8** %6
store i64 %2, i64* %7
store i32 0, i32* %8
%11 = load i8*, i8** %5
%12 = call i32 @strlen(i8* %11)
%13 = icmp sgt i32 %12, 16
br i1 %13, label %14, label %15
14: ; preds = %3
store i32 -1, i32* %4
br label %57
15: ; preds = %3
%16 = call i8* @getenv(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
store i8* %16, i8** %10
%17 = load i8*, i8** %10
%18 = icmp ne i8* %17, null
br i1 %18, label %20, label %19
19: ; preds = %15
store i32 -1, i32* %4
br label %57
20: ; preds = %15
%21 = load i8*, i8** %10
%22 = call i32 @strlen(i8* %21)
%23 = add nsw i32 %22, 32
%24 = sext i32 %23 to i64
%25 = load i64, i64* %7
%26 = icmp ult i64 %24, %25
br i1 %26, label %27, label %56
27: ; preds = %20
%28 = load i8*, i8** %6
%29 = load i8*, i8** %10
%30 = call i32 @strcpy(i8* %28, i8* %29)
%31 = load i8*, i8** %6
%32 = call i32 @strlen(i8* %31)
%33 = sext i32 %32 to i64
store i64 %33, i64* %9
%34 = load i8*, i8** %6
%35 = load i64, i64* %9
%36 = sub i64 %35, 1
%37 = getelementptr inbounds i8, i8* %34, i64 %36
%38 = load i8, i8* %37
%39 = sext i8 %38 to i32
%40 = icmp ne i32 %39, 47
br i1 %40, label %41, label %44
41: ; preds = %27
%42 = load i8*, i8** %6
%43 = call i32 @strcat(i8* %42, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %44
44: ; preds = %41, %27
%45 = load i8*, i8** %6
%46 = load i8*, i8** %5
%47 = call i32 @strcat(i8* %45, i8* %46)
%48 = load i8*, i8** %6
%49 = call i32 @strcat(i8* %48, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%50 = load i8*, i8** %6
%51 = call i8* @mkdtemp(i8* %50)
store i8* %51, i8** %10
%52 = load i8*, i8** %10
%53 = icmp ne i8* %52, null
br i1 %53, label %54, label %55
54: ; preds = %44
store i32 0, i32* %4
br label %57
55: ; preds = %44
store i32 -1, i32* %4
br label %57
56: ; preds = %20
store i32 -1, i32* %4
br label %57
57: ; preds = %56, %55, %54, %19, %14
%58 = load i32, i32* %4
ret i32 %58
}

LLVM IR (-O2):
@.str = [7 x i8] c"TMPDIR\00"
@.str.1 = [2 x i8] c"/\00"
@.str.2 = [6 x i8] c"XXXXX\00"
define i32 @mktestdir(i8* %0, i8* %1, i64 %2) {
%4 = tail call i32 @strlen(i8* %0)
%5 = icmp sgt i32 %4, 16
br i1 %5, label %30, label %6
6: ; preds = %3
%7 = tail call i8* @getenv(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i8* %7, null
br i1 %8, label %30, label %9
9: ; preds = %6
%10 = tail call i32 @strlen(i8* %7)
%11 = add nsw i32 %10, 32
%12 = sext i32 %11 to i64
%13 = icmp ult i64 %12, %2
br i1 %13, label %14, label %30
14: ; preds = %9
%15 = tail call i32 @strcpy(i8* %1, i8* %7)
%16 = tail call i32 @strlen(i8* %1)
%17 = sext i32 %16 to i64
%18 = add nsw i64 %17, -1
%19 = getelementptr inbounds i8, i8* %1, i64 %18
%20 = load i8, i8* %19
%21 = icmp eq i8 %20, 47
br i1 %21, label %24, label %22
22: ; preds = %14
%23 = tail call i32 @strcat(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %24
24: ; preds = %22, %14
%25 = tail call i32 @strcat(i8* %1, i8* %0)
%26 = tail call i32 @strcat(i8* %1, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%27 = tail call i8* @mkdtemp(i8* %1)
%28 = icmp eq i8* %27, null
%29 = sext i1 %28 to i32
br label %30
30: ; preds = %9, %24, %6, %3
%31 = phi i32 [ -1, %3 ], [ -1, %6 ], [ %29, %24 ], [ -1, %9 ]
ret i32 %31
}