#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 */
typedef int /*<<< orphan*/ suffix;

/* Variables and functions */
int /*<<< orphan*/ assert(int);
char *calloc(int, size_t);
int snprintf(char *, size_t, char *, char const *, char const *);
size_t strlen(char const *);
char *filename_to_mkstemp_template(const char *file) {
  size_t len = strlen(file);
  static const char suffix[] = ".XXXXXX";
  size_t new_len = len + sizeof(suffix);
  char *ret_str = calloc(1, new_len);
  int ret = snprintf(ret_str, new_len, "%s%s", file, suffix);
  assert(ret == new_len - 1);
  assert(ret_str[new_len] == '\0');
  return ret_str;
}


x86 assembly (clang, -O0):
<filename_to_mkstemp_template>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rsi
mov    $0x1,%edi
call   1050 <calloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x8(%rbp),%rcx
lea    0xe7e(%rip),%rdx
lea    0xe6f(%rip),%r8
call   1040 <snprintf@plt>
mov    %eax,-0x24(%rbp)
movslq -0x24(%rbp),%rax
mov    -0x18(%rbp),%rcx
sub    $0x1,%rcx
cmp    %rcx,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
mov    -0x20(%rbp),%rax
mov    -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
mov    -0x20(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<filename_to_mkstemp_template>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r15
call   1030 <strlen@plt>
mov    %rax,%r12
lea    0x8(%rax),%rbx
mov    $0x1,%edi
mov    %rbx,%rsi
call   1050 <calloc@plt>
mov    %rax,%r14
lea    0xe9a(%rip),%rdx
lea    0xe8b(%rip),%r8
mov    %rax,%rdi
mov    %rbx,%rsi
mov    %r15,%rcx
call   1040 <snprintf@plt>
cltq
lea    0x7(%r12),%rcx
xor    %edi,%edi
cmp    %rax,%rcx
sete   %dil
call   1060 <assert@plt>
xor    %edi,%edi
cmpb   $0x0,0x8(%r14,%r12,1)
sete   %dil
call   1060 <assert@plt>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@filename_to_mkstemp_template.suffix = internal constant [8 x i8] c".XXXXXX\00"
@.str = [5 x i8] c"%s%s\00"
define i8* @filename_to_mkstemp_template(i8* %0) {
%2 = alloca i8*
%3 = alloca i64
%4 = alloca i64
%5 = alloca i8*
%6 = alloca i32
store i8* %0, i8** %2
%7 = load i8*, i8** %2
%8 = call i64 @strlen(i8* %7)
store i64 %8, i64* %3
%9 = load i64, i64* %3
%10 = add i64 %9, 8
store i64 %10, i64* %4
%11 = load i64, i64* %4
%12 = call i8* @calloc(i32 1, i64 %11)
store i8* %12, i8** %5
%13 = load i8*, i8** %5
%14 = load i64, i64* %4
%15 = load i8*, i8** %2
%16 = call i32 @snprintf(i8* %13, i64 %14, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %15, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @filename_to_mkstemp_template.suffix, i64 0, i64 0))
store i32 %16, i32* %6
%17 = load i32, i32* %6
%18 = sext i32 %17 to i64
%19 = load i64, i64* %4
%20 = sub i64 %19, 1
%21 = icmp eq i64 %18, %20
%22 = zext i1 %21 to i32
%23 = call i32 @assert(i32 %22)
%24 = load i8*, i8** %5
%25 = load i64, i64* %4
%26 = getelementptr inbounds i8, i8* %24, i64 %25
%27 = load i8, i8* %26
%28 = sext i8 %27 to i32
%29 = icmp eq i32 %28, 0
%30 = zext i1 %29 to i32
%31 = call i32 @assert(i32 %30)
%32 = load i8*, i8** %5
ret i8* %32
}

LLVM IR (-O2):
@filename_to_mkstemp_template.suffix = internal constant [8 x i8] c".XXXXXX\00"
@.str = [5 x i8] c"%s%s\00"
define i8* @filename_to_mkstemp_template(i8* %0) {
%2 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%3 = add i64 %2, 8
%4 = tail call i8* @calloc(i32 1, i64 %3)
%5 = tail call i32 @snprintf(i8* %4, i64 %3, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %0, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @filename_to_mkstemp_template.suffix, i64 0, i64 0))
%6 = sext i32 %5 to i64
%7 = add i64 %2, 7
%8 = icmp eq i64 %7, %6
%9 = zext i1 %8 to i32
%10 = tail call i32 @assert(i32 %9)
%11 = getelementptr inbounds i8, i8* %4, i64 %3
%12 = load i8, i8* %11
%13 = icmp eq i8 %12, 0
%14 = zext i1 %13 to i32
%15 = tail call i32 @assert(i32 %14)
ret i8* %4
}