#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*/ create_file(char *, char *);
int get_next_sequence(char *);
int /*<<< orphan*/ sprintf(char *, char *, char *, int);
char *create_new_file(char *path_filename, char *mode) {
  static char new[1024];
  int next_sequence;
  next_sequence = get_next_sequence(path_filename);
  sprintf(new, "%s_#%d", path_filename, next_sequence);
  if (!create_file(new, mode))
    return (char *)0;
  else
    return new;
}


x86 assembly (clang, -O0):
<create_new_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <get_next_sequence@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rdx
mov    -0x1c(%rbp),%ecx
lea    0x2ef6(%rip),%rdi
lea    0xe9f(%rip),%rsi
call   1050 <sprintf@plt>
mov    -0x18(%rbp),%rsi
lea    0x2edf(%rip),%rdi
call   1040 <create_file@plt>
cmp    $0x0,%eax
jne    118c <create_new_file+0x5c>
movq   $0x0,-0x8(%rbp)
jmp    1197 <create_new_file+0x67>
lea    0x2ebd(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<create_new_file>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbx
call   1030 <get_next_sequence@plt>
lea    0x2f09(%rip),%r15
lea    0xeb2(%rip),%rsi
mov    %r15,%rdi
mov    %rbx,%rdx
mov    %eax,%ecx
call   1050 <sprintf@plt>
mov    %r15,%rdi
mov    %r14,%rsi
call   1040 <create_file@plt>
xor    %ecx,%ecx
test   %eax,%eax
cmovne %r15,%rcx
mov    %rcx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@create_new_file.new = internal global [1024 x i8] zeroinitializer
@.str = [7 x i8] c"%s_#%d\00"
define i8* @create_new_file(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%7 = load i8*, i8** %4
%8 = call i32 @get_next_sequence(i8* %7)
store i32 %8, i32* %6
%9 = load i8*, i8** %4
%10 = load i32, i32* %6
%11 = call i32 @sprintf(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @create_new_file.new, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %9, i32 %10)
%12 = load i8*, i8** %5
%13 = call i32 @create_file(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @create_new_file.new, i64 0, i64 0), i8* %12)
%14 = icmp ne i32 %13, 0
br i1 %14, label %16, label %15
15: ; preds = %2
store i8* null, i8** %3
br label %17
16: ; preds = %2
store i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @create_new_file.new, i64 0, i64 0), i8** %3
br label %17
17: ; preds = %16, %15
%18 = load i8*, i8** %3
ret i8* %18
}

LLVM IR (-O2):
@create_new_file.new = internal global [1024 x i8] zeroinitializer
@.str = [7 x i8] c"%s_#%d\00"
define i8* @create_new_file(i8* %0, i8* %1) {
%3 = tail call i32 @get_next_sequence(i8* %0)
%4 = tail call i32 @sprintf(i8* dereferenceable(1) getelementptr inbounds ([1024 x i8], [1024 x i8]* @create_new_file.new, i64 0, i64 0), i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %0, i32 %3)
%5 = tail call i32 @create_file(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @create_new_file.new, i64 0, i64 0), i8* %1)
%6 = icmp eq i32 %5, 0
%7 = select i1 %6, i8* null, i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @create_new_file.new, i64 0, i64 0)
ret i8* %7
}