#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*/ errno;
int /*<<< orphan*/ error(int, int /*<<< orphan*/, char *);
int /*<<< orphan*/ mkdtemp(char *);
char *strdup(char *);
char *tmpdir(void) {
  char *dir;
  if (!(dir = strdup("/tmp/XXXXXX")))
    error(1, errno, "strdup");
  else if (!mkdtemp(dir))
    error(1, 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    1171 <tmpdir+0x41>
mov    0x2e87(%rip),%rax
mov    (%rax),%esi
mov    $0x1,%edi
lea    0xea5(%rip),%rdx
call   1040 <error@plt>
jmp    119b <tmpdir+0x6b>
mov    -0x8(%rbp),%rdi
call   1030 <mkdtemp@plt>
cmp    $0x0,%eax
jne    1196 <tmpdir+0x66>
mov    $0x1,%edi
xor    %esi,%esi
lea    0xe82(%rip),%rdx
call   1040 <error@plt>
jmp    119b <tmpdir+0x6b>
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     1161 <tmpdir+0x31>
mov    %rbx,%rdi
call   1030 <mkdtemp@plt>
test   %eax,%eax
jne    117b <tmpdir+0x4b>
lea    0xebb(%rip),%rdx
mov    $0x1,%edi
xor    %esi,%esi
jmp    1176 <tmpdir+0x46>
mov    0x2e78(%rip),%rax
mov    (%rax),%esi
lea    0xe9b(%rip),%rdx
mov    $0x1,%edi
call   1040 <error@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 @error(i32 1, 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 @error(i32 1, 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 @error(i32 1, 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 @error(i32 1, 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
}