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

/* Variables and functions */
char *buildLorenzFileName(int /*<<< orphan*/ const);
int /*<<< orphan*/ cfree(char *);
char *malloc(int);
int rename(char *, char *);
int /*<<< orphan*/ sprintf(char *, char *, ...);
int /*<<< orphan*/ strcat(char *, char *);
int strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, size_t);
int /*<<< orphan*/ system(char *);
changeLorenzFileName(const mpfr_prec_t precision, const long int it) {
  int err = 0;
  char ext[] = ".dat";
  char toAdd[7];
  sprintf(toAdd, "(%ld)", it);
  char *oldName = buildLorenzFileName(precision);
  size_t namelen = strlen(oldName);
  char *newName =
      malloc(sizeof(char) * (strlen(toAdd) + namelen + strlen(".dat") + 1));
  strncpy(newName, oldName, namelen - strlen(ext));
  newName[namelen - strlen(ext)] = 0;
  strcat(newName, toAdd);
  strcat(newName, ".dat");
  err = rename(oldName, newName);
  char *command =
      malloc((strlen("mv \"%s\" \"stochFiles/%s\"") + strlen(newName) * 2) *
             sizeof(char));
  sprintf(command, "mv \"%s\" \"stochFiles/%s\"", newName, newName);
  system(command);
  cfree(command);
  cfree(oldName);
  cfree(newName);
  return err;
}


x86 assembly (clang, -O0):
<changeLorenzFileName>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    0xe51(%rip),%eax
mov    %eax,-0x19(%rbp)
mov    0xe4c(%rip),%al
mov    %al,-0x15(%rbp)
lea    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xe3b(%rip),%rsi
mov    $0x0,%al
call   10a0 <sprintf@plt>
mov    -0x4(%rbp),%edi
call   10b0 <buildLorenzFileName@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
call   1040 <strlen@plt>
cltq
mov    %rax,-0x30(%rbp)
lea    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
cltq
add    -0x30(%rbp),%rax
mov    %rax,-0x78(%rbp)
lea    0xdfa(%rip),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x78(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
add    $0x1,%rax
shl    $0x0,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,-0x68(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x70(%rbp)
lea    -0x19(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x70(%rbp),%rdx
mov    -0x68(%rbp),%rdi
mov    -0x60(%rbp),%rsi
cltq
sub    %rax,%rdx
call   1030 <strncpy@plt>
mov    -0x38(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x58(%rbp)
lea    -0x19(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x58(%rbp),%rcx
mov    %eax,%edx
mov    -0x50(%rbp),%rax
movslq %edx,%rdx
sub    %rdx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x38(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1090 <strcat@plt>
mov    -0x38(%rbp),%rdi
lea    0xd5a(%rip),%rsi
call   1090 <strcat@plt>
mov    -0x28(%rbp),%rdi
mov    -0x38(%rbp),%rsi
call   1070 <rename@plt>
mov    %eax,-0x14(%rbp)
lea    0xd49(%rip),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x44(%rbp)
mov    -0x38(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x44(%rbp),%eax
shl    $0x1,%ecx
add    %ecx,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rdi
mov    -0x38(%rbp),%rdx
mov    -0x38(%rbp),%rcx
lea    0xd0a(%rip),%rsi
mov    $0x0,%al
call   10a0 <sprintf@plt>
mov    -0x40(%rbp),%rdi
call   1050 <system@plt>
mov    -0x40(%rbp),%rdi
call   1080 <cfree@plt>
mov    -0x28(%rbp),%rdi
call   1080 <cfree@plt>
mov    -0x38(%rbp),%rdi
call   1080 <cfree@plt>
mov    -0x14(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<changeLorenzFileName>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rdx
mov    %edi,%ebx
movb   $0x0,0x10(%rsp)
movl   $0x7461642e,0xc(%rsp)
74
lea    0xe4f(%rip),%r15
lea    0xe42(%rip),%rsi
lea    0x11(%rsp),%r12
mov    %r12,%rdi
xor    %eax,%eax
call   10a0 <sprintf@plt>
mov    %ebx,%edi
call   10b0 <buildLorenzFileName@plt>
mov    %rax,%r14
mov    %rax,%rdi
call   1040 <strlen@plt>
movslq %eax,%rbp
mov    %r12,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebx
mov    %r15,%rdi
call   1040 <strlen@plt>
add    %ebp,%ebx
lea    (%rax,%rbx,1),%edi
add    $0x1,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
lea    0xc(%rsp),%r13
mov    %r13,%rdi
call   1040 <strlen@plt>
cltq
mov    %rbp,%rdx
sub    %rax,%rdx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1030 <strncpy@plt>
mov    %r13,%rdi
call   1040 <strlen@plt>
cltq
sub    %rax,%rbp
movb   $0x0,(%rbx,%rbp,1)
mov    %rbx,%rdi
mov    %r12,%rsi
call   1090 <strcat@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1090 <strcat@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1070 <rename@plt>
mov    %eax,%r15d
lea    0xdab(%rip),%r12
mov    %r12,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1040 <strlen@plt>
lea    0x0(%rbp,%rax,2),%edi
call   1060 <malloc@plt>
mov    %rax,%rbp
mov    %rax,%rdi
mov    %r12,%rsi
mov    %rbx,%rdx
mov    %rbx,%rcx
xor    %eax,%eax
call   10a0 <sprintf@plt>
mov    %rbp,%rdi
call   1050 <system@plt>
mov    %rbp,%rdi
call   1080 <cfree@plt>
mov    %r14,%rdi
call   1080 <cfree@plt>
mov    %rbx,%rdi
call   1080 <cfree@plt>
mov    %r15d,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@__const.changeLorenzFileName.ext = [5 x i8] c".dat\00"
@.str = [6 x i8] c"(%ld)\00"
@.str.1 = [5 x i8] c".dat\00"
@.str.2 = [24 x i8] c"mv \22%s\22 \22stochFiles/%s\22\00"
define i32 @changeLorenzFileName(i32 %0, i64 %1) {
%3 = alloca i32
%4 = alloca i64
%5 = alloca i32
%6 = alloca [5 x i8]
%7 = alloca [7 x i8]
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i8*
%11 = alloca i8*
store i32 %0, i32* %3
store i64 %1, i64* %4
store i32 0, i32* %5
%12 = bitcast [5 x i8]* %6 to i8*
%13 = getelementptr inbounds [7 x i8], [7 x i8]* %7, i64 0, i64 0
%14 = load i64, i64* %4
%15 = call i32 (i8*, i8*, ...) @sprintf(i8* %13, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i64 %14)
%16 = load i32, i32* %3
%17 = call i8* @buildLorenzFileName(i32 %16)
store i8* %17, i8** %8
%18 = load i8*, i8** %8
%19 = call i32 @strlen(i8* %18)
%20 = sext i32 %19 to i64
store i64 %20, i64* %9
%21 = getelementptr inbounds [7 x i8], [7 x i8]* %7, i64 0, i64 0
%22 = call i32 @strlen(i8* %21)
%23 = sext i32 %22 to i64
%24 = load i64, i64* %9
%25 = add i64 %23, %24
%26 = call i32 @strlen(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%27 = sext i32 %26 to i64
%28 = add i64 %25, %27
%29 = add i64 %28, 1
%30 = mul i64 1, %29
%31 = trunc i64 %30 to i32
%32 = call i8* @malloc(i32 %31)
store i8* %32, i8** %10
%33 = load i8*, i8** %10
%34 = load i8*, i8** %8
%35 = load i64, i64* %9
%36 = getelementptr inbounds [5 x i8], [5 x i8]* %6, i64 0, i64 0
%37 = call i32 @strlen(i8* %36)
%38 = sext i32 %37 to i64
%39 = sub i64 %35, %38
%40 = call i32 @strncpy(i8* %33, i8* %34, i64 %39)
%41 = load i8*, i8** %10
%42 = load i64, i64* %9
%43 = getelementptr inbounds [5 x i8], [5 x i8]* %6, i64 0, i64 0
%44 = call i32 @strlen(i8* %43)
%45 = sext i32 %44 to i64
%46 = sub i64 %42, %45
%47 = getelementptr inbounds i8, i8* %41, i64 %46
store i8 0, i8* %47
%48 = load i8*, i8** %10
%49 = getelementptr inbounds [7 x i8], [7 x i8]* %7, i64 0, i64 0
%50 = call i32 @strcat(i8* %48, i8* %49)
%51 = load i8*, i8** %10
%52 = call i32 @strcat(i8* %51, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%53 = load i8*, i8** %8
%54 = load i8*, i8** %10
%55 = call i32 @rename(i8* %53, i8* %54)
store i32 %55, i32* %5
%56 = call i32 @strlen(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
%57 = load i8*, i8** %10
%58 = call i32 @strlen(i8* %57)
%59 = mul nsw i32 %58, 2
%60 = add nsw i32 %56, %59
%61 = sext i32 %60 to i64
%62 = mul i64 %61, 1
%63 = trunc i64 %62 to i32
%64 = call i8* @malloc(i32 %63)
store i8* %64, i8** %11
%65 = load i8*, i8** %11
%66 = load i8*, i8** %10
%67 = load i8*, i8** %10
%68 = call i32 (i8*, i8*, ...) @sprintf(i8* %65, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i8* %66, i8* %67)
%69 = load i8*, i8** %11
%70 = call i32 @system(i8* %69)
%71 = load i8*, i8** %11
%72 = call i32 @cfree(i8* %71)
%73 = load i8*, i8** %8
%74 = call i32 @cfree(i8* %73)
%75 = load i8*, i8** %10
%76 = call i32 @cfree(i8* %75)
%77 = load i32, i32* %5
ret i32 %77
}

LLVM IR (-O2):
@.str = [6 x i8] c"(%ld)\00"
@.str.1 = [5 x i8] c".dat\00"
@.str.2 = [24 x i8] c"mv \22%s\22 \22stochFiles/%s\22\00"
define i32 @changeLorenzFileName(i32 %0, i64 %1) {
%3 = alloca [5 x i8]
%4 = alloca [7 x i8]
%5 = getelementptr inbounds [5 x i8], [5 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [7 x i8], [7 x i8]* %4, i64 0, i64 0
%7 = call i32 (i8*, i8*, ...) @sprintf(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i64 %1)
%8 = tail call i8* @buildLorenzFileName(i32 %0)
%9 = tail call i32 @strlen(i8* %8)
%10 = sext i32 %9 to i64
%11 = call i32 @strlen(i8* %6)
%12 = call i32 @strlen(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%13 = add i32 %9, 1
%14 = add i32 %13, %11
%15 = add i32 %14, %12
%16 = call i8* @malloc(i32 %15)
%17 = call i32 @strlen(i8* %5)
%18 = sext i32 %17 to i64
%19 = sub nsw i64 %10, %18
%20 = call i32 @strncpy(i8* %16, i8* %8, i64 %19)
%21 = call i32 @strlen(i8* %5)
%22 = sext i32 %21 to i64
%23 = sub nsw i64 %10, %22
%24 = getelementptr inbounds i8, i8* %16, i64 %23
store i8 0, i8* %24
%25 = call i32 @strcat(i8* %16, i8* %6)
%26 = call i32 @strcat(i8* %16, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%27 = call i32 @rename(i8* %8, i8* %16)
%28 = call i32 @strlen(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
%29 = call i32 @strlen(i8* %16)
%30 = shl nsw i32 %29, 1
%31 = add nsw i32 %30, %28
%32 = call i8* @malloc(i32 %31)
%33 = call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %32, i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i8* %16, i8* %16)
%34 = call i32 @system(i8* %32)
%35 = call i32 @cfree(i8* %32)
%36 = call i32 @cfree(i8* %8)
%37 = call i32 @cfree(i8* %16)
ret i32 %27
}