#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 *mkdtemp(char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ snprintf(char *, int, char *, char *);
char *strdup(char *);
char *ace_tu_fs_create_temp_dir(char *name) {
  char template[256];
  snprintf(template, 256, "/tmp/ace_test_%s_XXXXXX", name);
  char *path = mkdtemp(template);
  if (path == NULL) {
    perror("Failed to create temporary directory");
    return NULL;
  }
  return strdup(path);
}


x86 assembly (clang, -O0):
<ace_tu_fs_create_temp_dir>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
mov    %rdi,-0x10(%rbp)
lea    -0x110(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x100,%esi
lea    0xe9a(%rip),%rdx
call   1030 <snprintf@plt>
lea    -0x110(%rbp),%rdi
call   1040 <mkdtemp@plt>
mov    %rax,-0x118(%rbp)
cmpq   $0x0,-0x118(%rbp)
jne    11a5 <ace_tu_fs_create_temp_dir+0x65>
lea    0xe85(%rip),%rdi
call   1050 <perror@plt>
movq   $0x0,-0x8(%rbp)
jmp    11b5 <ace_tu_fs_create_temp_dir+0x75>
mov    -0x118(%rbp),%rdi
call   1060 <strdup@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ace_tu_fs_create_temp_dir>:
push   %rbx
sub    $0x100,%rsp
mov    %rdi,%rcx
lea    0xeae(%rip),%rdx
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x100,%esi
call   1030 <snprintf@plt>
mov    %rbx,%rdi
call   1040 <mkdtemp@plt>
test   %rax,%rax
je     1180 <ace_tu_fs_create_temp_dir+0x40>
mov    %rax,%rdi
call   1060 <strdup@plt>
add    $0x100,%rsp
pop    %rbx
ret
lea    0xe91(%rip),%rdi
call   1050 <perror@plt>
xor    %eax,%eax
jmp    1177 <ace_tu_fs_create_temp_dir+0x37>

LLVM IR (-O0):
@.str = [24 x i8] c"/tmp/ace_test_%s_XXXXXX\00"
@.str.1 = [37 x i8] c"Failed to create temporary directory\00"
define i8* @ace_tu_fs_create_temp_dir(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca [256 x i8]
%5 = alloca i8*
store i8* %0, i8** %3
%6 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%7 = load i8*, i8** %3
%8 = call i32 @snprintf(i8* %6, i32 256, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %7)
%9 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%10 = call i8* @mkdtemp(i8* %9)
store i8* %10, i8** %5
%11 = load i8*, i8** %5
%12 = icmp eq i8* %11, null
br i1 %12, label %13, label %15
13: ; preds = %1
%14 = call i32 @perror(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0))
store i8* null, i8** %2
br label %18
15: ; preds = %1
%16 = load i8*, i8** %5
%17 = call i8* @strdup(i8* %16)
store i8* %17, i8** %2
br label %18
18: ; preds = %15, %13
%19 = load i8*, i8** %2
ret i8* %19
}

LLVM IR (-O2):
@.str = [24 x i8] c"/tmp/ace_test_%s_XXXXXX\00"
@.str.1 = [37 x i8] c"Failed to create temporary directory\00"
define noalias i8* @ace_tu_fs_create_temp_dir(i8* %0) {
%2 = alloca [256 x i8]
%3 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%4 = call i32 @snprintf(i8* %3, i32 256, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %0)
%5 = call i8* @mkdtemp(i8* %3)
%6 = icmp eq i8* %5, null
br i1 %6, label %7, label %9
7: ; preds = %1
%8 = call i32 @perror(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0))
br label %11
9: ; preds = %1
%10 = call i8* @strdup(i8* %5)
br label %11
11: ; preds = %9, %7
%12 = phi i8* [ null, %7 ], [ %10, %9 ]
ret i8* %12
}