#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*/ die(int /*<<< orphan*/, char *);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ mkdtemp(char *);
char *strdup(char *);
char *tmpdir(void) {
  char *dir;
  if (!(dir = strdup("/tmp/XXXXXX")))
    die(errno, "strdup");
  else if (!mkdtemp(dir))
    die(0, "Failed to create temporary directory");
  return dir;
}


x86 assembly (clang, -O0):
<tmpdir>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xec1(%rip),%rdi
call   1050 <strdup@plt>
mov    %rax,-0x8(%rbp)
cmp    $0x0,%rax
jne    116c <tmpdir+0x3c>
mov    0x2e87(%rip),%rax
mov    (%rax),%edi
lea    0xeaa(%rip),%rsi
call   1040 <die@plt>
jmp    1191 <tmpdir+0x61>
mov    -0x8(%rbp),%rdi
call   1030 <mkdtemp@plt>
cmp    $0x0,%eax
jne    118c <tmpdir+0x5c>
xor    %edi,%edi
lea    0xe8c(%rip),%rsi
call   1040 <die@plt>
jmp    1191 <tmpdir+0x61>
mov    -0x8(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tmpdir>:
push   %rbx
lea    0xec8(%rip),%rdi
call   1050 <strdup@plt>
mov    %rax,%rbx
test   %rax,%rax
je     115c <tmpdir+0x2c>
mov    %rbx,%rdi
call   1030 <mkdtemp@plt>
test   %eax,%eax
jne    1171 <tmpdir+0x41>
lea    0xebb(%rip),%rsi
xor    %edi,%edi
jmp    116c <tmpdir+0x3c>
mov    0x2e7d(%rip),%rax
mov    (%rax),%edi
lea    0xea0(%rip),%rsi
call   1040 <die@plt>
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [12 x i8] c"/tmp/XXXXXX\00"
@errno = global i32 0
@.str.1 = [7 x i8] c"strdup\00"
@.str.2 = [37 x i8] c"Failed to create temporary directory\00"
define i8* @tmpdir() {
%1 = alloca i8*
%2 = call i8* @strdup(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
store i8* %2, i8** %1
%3 = icmp ne i8* %2, null
br i1 %3, label %7, label %4
4: ; preds = %0
%5 = load i32, i32* @errno
%6 = call i32 @die(i32 %5, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
br label %14
7: ; preds = %0
%8 = load i8*, i8** %1
%9 = call i32 @mkdtemp(i8* %8)
%10 = icmp ne i32 %9, 0
br i1 %10, label %13, label %11
11: ; preds = %7
%12 = call i32 @die(i32 0, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0))
br label %13
13: ; preds = %11, %7
br label %14
14: ; preds = %13, %4
%15 = load i8*, i8** %1
ret i8* %15
}

LLVM IR (-O2):
@.str = [12 x i8] c"/tmp/XXXXXX\00"
@errno = global i32 0
@.str.1 = [7 x i8] c"strdup\00"
@.str.2 = [37 x i8] c"Failed to create temporary directory\00"
define i8* @tmpdir() {
%1 = tail call dereferenceable_or_null(12) i8* @strdup(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%2 = icmp eq i8* %1, null
br i1 %2, label %3, label %6
3: ; preds = %0
%4 = load i32, i32* @errno
%5 = tail call i32 @die(i32 %4, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
br label %11
6: ; preds = %0
%7 = tail call i32 @mkdtemp(i8* %1)
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %6
%10 = tail call i32 @die(i32 0, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0))
br label %11
11: ; preds = %6, %9, %3
ret i8* %1
}