#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 */
size_t gen_fn(char *, char const *, size_t, char *);
size_t strlen(char const *);
int /*<<< orphan*/ ulz_mkdtemp(char *);
size_t mktempdir(const char *prefix, char *buffer, size_t bufsize) {
  size_t ret, pl = strlen(prefix);
  if (bufsize < sizeof("/dev/shm/") - 1 + pl + sizeof("XXXXXX"))
    return 0;
  ret = gen_fn(buffer, prefix, pl, "/dev/shm/");
  if (!ulz_mkdtemp(buffer)) {
    ret = gen_fn(buffer, prefix, pl, "/tmp/");
    if (!ulz_mkdtemp(buffer))
      return 0;
  }
  return ret;
}


x86 assembly (clang, -O0):
<mktempdir>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rax
mov    -0x30(%rbp),%rcx
add    $0x9,%rcx
add    $0x7,%rcx
cmp    %rcx,%rax
jae    1177 <mktempdir+0x47>
movq   $0x0,-0x8(%rbp)
jmp    11ed <mktempdir+0xbd>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x30(%rbp),%rdx
lea    0xe76(%rip),%rcx
call   1050 <gen_fn@plt>
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <ulz_mkdtemp@plt>
cmp    $0x0,%eax
jne    11e5 <mktempdir+0xb5>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x30(%rbp),%rdx
lea    0xe52(%rip),%rcx
call   1050 <gen_fn@plt>
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <ulz_mkdtemp@plt>
cmp    $0x0,%eax
jne    11e0 <mktempdir+0xb0>
movq   $0x0,-0x8(%rbp)
jmp    11ed <mktempdir+0xbd>
jmp    11e5 <mktempdir+0xb5>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mktempdir>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdx,%rbx
mov    %rsi,%r15
mov    %rdi,%r12
call   1040 <strlen@plt>
mov    %rax,%r13
add    $0x10,%rax
cmp    %rbx,%rax
jbe    1158 <mktempdir+0x28>
xor    %r14d,%r14d
jmp    11a0 <mktempdir+0x70>
lea    0xea1(%rip),%rcx
mov    %r15,%rdi
mov    %r12,%rsi
mov    %r13,%rdx
call   1050 <gen_fn@plt>
mov    %rax,%r14
mov    %r15,%rdi
call   1030 <ulz_mkdtemp@plt>
test   %eax,%eax
jne    11a0 <mktempdir+0x70>
lea    0xe87(%rip),%rcx
mov    %r15,%rdi
mov    %r12,%rsi
mov    %r13,%rdx
call   1050 <gen_fn@plt>
mov    %rax,%r14
mov    %r15,%rdi
call   1030 <ulz_mkdtemp@plt>
test   %eax,%eax
je     1153 <mktempdir+0x23>
mov    %r14,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [10 x i8] c"/dev/shm/\00"
@.str.1 = [6 x i8] c"/tmp/\00"
define i64 @mktempdir(i8* %0, i8* %1, i64 %2) {
%4 = alloca i64
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i64
%9 = alloca i64
store i8* %0, i8** %5
store i8* %1, i8** %6
store i64 %2, i64* %7
%10 = load i8*, i8** %5
%11 = call i64 @strlen(i8* %10)
store i64 %11, i64* %9
%12 = load i64, i64* %7
%13 = load i64, i64* %9
%14 = add i64 9, %13
%15 = add i64 %14, 7
%16 = icmp ult i64 %12, %15
br i1 %16, label %17, label %18
17: ; preds = %3
store i64 0, i64* %4
br label %38
18: ; preds = %3
%19 = load i8*, i8** %6
%20 = load i8*, i8** %5
%21 = load i64, i64* %9
%22 = call i64 @gen_fn(i8* %19, i8* %20, i64 %21, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
store i64 %22, i64* %8
%23 = load i8*, i8** %6
%24 = call i32 @ulz_mkdtemp(i8* %23)
%25 = icmp ne i32 %24, 0
br i1 %25, label %36, label %26
26: ; preds = %18
%27 = load i8*, i8** %6
%28 = load i8*, i8** %5
%29 = load i64, i64* %9
%30 = call i64 @gen_fn(i8* %27, i8* %28, i64 %29, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
store i64 %30, i64* %8
%31 = load i8*, i8** %6
%32 = call i32 @ulz_mkdtemp(i8* %31)
%33 = icmp ne i32 %32, 0
br i1 %33, label %35, label %34
34: ; preds = %26
store i64 0, i64* %4
br label %38
35: ; preds = %26
br label %36
36: ; preds = %35, %18
%37 = load i64, i64* %8
store i64 %37, i64* %4
br label %38
38: ; preds = %36, %34, %17
%39 = load i64, i64* %4
ret i64 %39
}

LLVM IR (-O2):
@.str = [10 x i8] c"/dev/shm/\00"
@.str.1 = [6 x i8] c"/tmp/\00"
define i64 @mktempdir(i8* %0, i8* %1, i64 %2) {
%4 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%5 = add i64 %4, 16
%6 = icmp ugt i64 %5, %2
br i1 %6, label %17, label %7
7: ; preds = %3
%8 = tail call i64 @gen_fn(i8* %1, i8* %0, i64 %4, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%9 = tail call i32 @ulz_mkdtemp(i8* %1)
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %15
11: ; preds = %7
%12 = tail call i64 @gen_fn(i8* %1, i8* %0, i64 %4, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%13 = tail call i32 @ulz_mkdtemp(i8* %1)
%14 = icmp eq i32 %13, 0
br i1 %14, label %17, label %15
15: ; preds = %11, %7
%16 = phi i64 [ %8, %7 ], [ %12, %11 ]
br label %17
17: ; preds = %11, %3, %15
%18 = phi i64 [ %16, %15 ], [ 0, %3 ], [ 0, %11 ]
ret i64 %18
}