#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__ calloc(scalar_t__, int);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ remove(char *);
int /*<<< orphan*/ sprintf(char *, char *, char const *, int);
scalar_t__ strlen(char const *);
void mm_split_rm_tmp(const char *prefix, int n_splits) {
  int i;
  char *fn;
  fn = ((char *)calloc((strlen(prefix) + 10), sizeof(char)));
  for (i = 0; i < n_splits; ++i) {
    sprintf(fn, "%s.%.4d.tmp", prefix, i);
    remove(fn);
  }
  free(fn);
}


x86 assembly (clang, -O0):
<mm_split_rm_tmp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,%rdi
add    $0xa,%rdi
mov    $0x1,%esi
call   1060 <calloc@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11be <mm_split_rm_tmp+0x6e>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    -0x10(%rbp),%ecx
lea    0xe5e(%rip),%rsi
call   1070 <sprintf@plt>
mov    -0x18(%rbp),%rdi
call   1040 <remove@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1184 <mm_split_rm_tmp+0x34>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mm_split_rm_tmp>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %esi,%r14d
mov    %rdi,%r15
call   1050 <strlen@plt>
lea    0xa(%rax),%rdi
mov    $0x1,%esi
call   1060 <calloc@plt>
mov    %rax,%rbp
test   %r14d,%r14d
jle    11b0 <mm_split_rm_tmp+0x60>
xor    %ebx,%ebx
lea    0xe7e(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rbp,%rdi
mov    %r12,%rsi
mov    %r15,%rdx
mov    %ebx,%ecx
call   1070 <sprintf@plt>
mov    %rbp,%rdi
call   1040 <remove@plt>
add    $0x1,%ebx
cmp    %ebx,%r14d
jne    1190 <mm_split_rm_tmp+0x40>
mov    %rbp,%rdi
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free@plt>

LLVM IR (-O0):
@.str = [12 x i8] c"%s.%.4d.tmp\00"
define void @mm_split_rm_tmp(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
store i8* %0, i8** %3
store i32 %1, i32* %4
%7 = load i8*, i8** %3
%8 = call i64 @strlen(i8* %7)
%9 = add nsw i64 %8, 10
%10 = call i64 @calloc(i64 %9, i32 1)
%11 = inttoptr i64 %10 to i8*
store i8* %11, i8** %6
store i32 0, i32* %5
br label %12
12: ; preds = %23, %2
%13 = load i32, i32* %5
%14 = load i32, i32* %4
%15 = icmp slt i32 %13, %14
br i1 %15, label %16, label %26
16: ; preds = %12
%17 = load i8*, i8** %6
%18 = load i8*, i8** %3
%19 = load i32, i32* %5
%20 = call i32 @sprintf(i8* %17, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* %18, i32 %19)
%21 = load i8*, i8** %6
%22 = call i32 @remove(i8* %21)
br label %23
23: ; preds = %16
%24 = load i32, i32* %5
%25 = add nsw i32 %24, 1
store i32 %25, i32* %5
br label %12
26: ; preds = %12
%27 = load i8*, i8** %6
%28 = call i32 @free(i8* %27)
ret void
}

LLVM IR (-O2):
@.str = [12 x i8] c"%s.%.4d.tmp\00"
define void @mm_split_rm_tmp(i8* %0, i32 %1) {
%3 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%4 = add nsw i64 %3, 10
%5 = tail call i64 @calloc(i64 %4, i32 1)
%6 = inttoptr i64 %5 to i8*
%7 = icmp sgt i32 %1, 0
br i1 %7, label %8, label %14
8: ; preds = %2, %8
%9 = phi i32 [ %12, %8 ], [ 0, %2 ]
%10 = tail call i32 @sprintf(i8* dereferenceable(1) %6, i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* %0, i32 %9)
%11 = tail call i32 @remove(i8* %6)
%12 = add nuw nsw i32 %9, 1
%13 = icmp eq i32 %12, %1
br i1 %13, label %14, label %8
14: ; preds = %8, %2
%15 = tail call i32 @free(i8* %6)
ret void
}