#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 */
scalar_t__ chkFileExist(char *);
int /*<<< orphan*/ free(char *);
int ll_createfile(char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ memset(char *, int, int);
int /*<<< orphan*/ sprintf(char *, char *, char const *, int);
int strlen(char const *);
int ll_createfile_postfix(const char *filename) {
  int i = 0;
  char *fn;
  int fl = (strlen(filename) + 4);
  fn = (char *)malloc(fl * sizeof(char));
  memset(fn, 0x0, fl);
  do {
    if (i == 999) {
      break;
    }
    sprintf(fn, "%s_%d", filename, i);
    if (chkFileExist(fn)) {
      continue;
    } else {
      return ll_createfile(fn);
    }
  } while (i <= 999);
  free(fn);
  return -13;
}


x86 assembly (clang, -O0):
<ll_createfile_postfix>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
add    $0x4,%eax
mov    %eax,-0x24(%rbp)
movslq -0x24(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x24(%rbp),%edx
xor    %esi,%esi
call   1050 <memset@plt>
cmpl   $0x3e7,-0x14(%rbp)
jne    11c5 <ll_createfile_postfix+0x55>
jmp    1212 <ll_createfile_postfix+0xa2>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    -0x14(%rbp),%ecx
lea    0xe29(%rip),%rsi
call   1090 <sprintf@plt>
mov    -0x20(%rbp),%rdi
call   1080 <chkFileExist@plt>
cmp    $0x0,%rax
je     11f4 <ll_createfile_postfix+0x84>
jmp    1205 <ll_createfile_postfix+0x95>
mov    -0x20(%rbp),%rdi
call   1070 <ll_createfile@plt>
mov    %eax,-0x4(%rbp)
jmp    1222 <ll_createfile_postfix+0xb2>
cmpl   $0x3e7,-0x14(%rbp)
jle    11b3 <ll_createfile_postfix+0x43>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
movl   $0xfffffff3,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ll_createfile_postfix>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
call   1030 <strlen@plt>
lea    0x4(%rax),%ebp
mov    %ebp,%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
xor    %esi,%esi
mov    %ebp,%edx
call   1040 <memset@plt>
lea    0xe71(%rip),%r15
nop
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
xor    %ecx,%ecx
call   1080 <sprintf@plt>
mov    %rbx,%rdi
call   1070 <chkFileExist@plt>
test   %rax,%rax
jne    1190 <ll_createfile_postfix+0x30>
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1060 <ll_createfile@plt>

LLVM IR (-O0):
@.str = [6 x i8] c"%s_%d\00"
define i32 @ll_createfile_postfix(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
store i8* %0, i8** %3
store i32 0, i32* %4
%7 = load i8*, i8** %3
%8 = call i32 @strlen(i8* %7)
%9 = add nsw i32 %8, 4
store i32 %9, i32* %6
%10 = load i32, i32* %6
%11 = sext i32 %10 to i64
%12 = mul i64 %11, 1
%13 = trunc i64 %12 to i32
%14 = call i64 @malloc(i32 %13)
%15 = inttoptr i64 %14 to i8*
store i8* %15, i8** %5
%16 = load i8*, i8** %5
%17 = load i32, i32* %6
%18 = call i32 @memset(i8* %16, i32 0, i32 %17)
br label %19
19: ; preds = %35, %1
%20 = load i32, i32* %4
%21 = icmp eq i32 %20, 999
br i1 %21, label %22, label %23
22: ; preds = %19
br label %38
23: ; preds = %19
%24 = load i8*, i8** %5
%25 = load i8*, i8** %3
%26 = load i32, i32* %4
%27 = call i32 @sprintf(i8* %24, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %25, i32 %26)
%28 = load i8*, i8** %5
%29 = call i64 @chkFileExist(i8* %28)
%30 = icmp ne i64 %29, 0
br i1 %30, label %31, label %32
31: ; preds = %23
br label %35
32: ; preds = %23
%33 = load i8*, i8** %5
%34 = call i32 @ll_createfile(i8* %33)
store i32 %34, i32* %2
br label %41
35: ; preds = %31
%36 = load i32, i32* %4
%37 = icmp sle i32 %36, 999
br i1 %37, label %19, label %38
38: ; preds = %35, %22
%39 = load i8*, i8** %5
%40 = call i32 @free(i8* %39)
store i32 -13, i32* %2
br label %41
41: ; preds = %38, %32
%42 = load i32, i32* %2
ret i32 %42
}

LLVM IR (-O2):
@.str = [6 x i8] c"%s_%d\00"
define i32 @ll_createfile_postfix(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = add nsw i32 %2, 4
%4 = tail call i64 @malloc(i32 %3)
%5 = inttoptr i64 %4 to i8*
%6 = tail call i32 @memset(i8* %5, i32 0, i32 %3)
br label %7
7: ; preds = %7, %1
%8 = tail call i32 @sprintf(i8* dereferenceable(1) %5, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %0, i32 0)
%9 = tail call i64 @chkFileExist(i8* %5)
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %7
11: ; preds = %7
%12 = tail call i32 @ll_createfile(i8* %5)
ret i32 %12
}