#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*/ filename_template;

/* Variables and functions */
char *ec_malloc(size_t);
int /*<<< orphan*/ snprintf(char *, size_t, char *, char *, int /*<<< orphan*/);
char *create_debug_filename() {
  static unsigned int count = 0;
  char filename_template[] = "picture";
  size_t size = sizeof(filename_template) + 2;
  char *filename = ec_malloc(size);
  snprintf(filename, size, "%s.%d", filename_template, count++);
  if (count > 9)
    count = 0;
  return filename;
}


x86 assembly (clang, -O0):
<create_debug_filename>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    0xed1(%rip),%rax
mov    %rax,-0x8(%rbp)
movq   $0xa,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <ec_malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
lea    -0x8(%rbp),%rcx
mov    0x2ed9(%rip),%r8d
mov    %r8d,%eax
add    $0x1,%eax
mov    %eax,0x2ecd(%rip)
lea    0xe9a(%rip),%rdx
call   1040 <snprintf@plt>
cmpl   $0x9,0x2eba(%rip)
jbe    118a <create_debug_filename+0x6a>
movl   $0x0,0x2eaa(%rip)
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<create_debug_filename>:
push   %rbx
sub    $0x10,%rsp
movabs $0x65727574636970,%rax
mov    %rax,0x8(%rsp)
mov    $0xa,%edi
call   1030 <ec_malloc@plt>
mov    %rax,%rbx
mov    0x2eec(%rip),%r8d
lea    0x1(%r8),%eax
mov    %eax,0x2ee2(%rip)
lea    0xea7(%rip),%rdx
lea    0x8(%rsp),%rcx
mov    $0xa,%esi
mov    %rbx,%rdi
call   1040 <snprintf@plt>
cmpl   $0xa,0x2ec2(%rip)
jb     117e <create_debug_filename+0x5e>
movl   $0x0,0x2eb6(%rip)
mov    %rbx,%rax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@create_debug_filename.count = internal global i32 0
@__const.create_debug_filename.filename_template = [8 x i8] c"picture\00"
@.str = [6 x i8] c"%s.%d\00"
define i8* @create_debug_filename() {
%1 = alloca [8 x i8]
%2 = alloca i64
%3 = alloca i8*
%4 = bitcast [8 x i8]* %1 to i8*
store i64 10, i64* %2
%5 = load i64, i64* %2
%6 = call i8* @ec_malloc(i64 %5)
store i8* %6, i8** %3
%7 = load i8*, i8** %3
%8 = load i64, i64* %2
%9 = getelementptr inbounds [8 x i8], [8 x i8]* %1, i64 0, i64 0
%10 = load i32, i32* @create_debug_filename.count
%11 = add i32 %10, 1
store i32 %11, i32* @create_debug_filename.count
%12 = call i32 @snprintf(i8* %7, i64 %8, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %9, i32 %10)
%13 = load i32, i32* @create_debug_filename.count
%14 = icmp ugt i32 %13, 9
br i1 %14, label %15, label %16
15: ; preds = %0
store i32 0, i32* @create_debug_filename.count
br label %16
16: ; preds = %15, %0
%17 = load i8*, i8** %3
ret i8* %17
}

LLVM IR (-O2):
@create_debug_filename.count = internal unnamed_addr global i32 0
@.str = [6 x i8] c"%s.%d\00"
define i8* @create_debug_filename() {
%1 = alloca i64
%2 = bitcast i64* %1 to i8*
store i64 28554821437188464, i64* %1
%3 = tail call i8* @ec_malloc(i64 10)
%4 = load i32, i32* @create_debug_filename.count
%5 = add i32 %4, 1
store i32 %5, i32* @create_debug_filename.count
%6 = call i32 @snprintf(i8* %3, i64 10, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %2, i32 %4)
%7 = load i32, i32* @create_debug_filename.count
%8 = icmp ugt i32 %7, 9
br i1 %8, label %9, label %10
9: ; preds = %0
store i32 0, i32* @create_debug_filename.count
br label %10
10: ; preds = %9, %0
ret i8* %3
}