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

/* Variables and functions */
int PATH_MAX;
int /*<<< orphan*/ *dofopen(char const *, char *);
int /*<<< orphan*/ dorename(char *, char *);
int /*<<< orphan*/ dounlink(char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ fileexists(char *);
int /*<<< orphan*/ sprintf(char *, char *, char *, int);
int /*<<< orphan*/ strcpy(char *, char const *);
void rotate(const char *rootname) {
  FILE *fpo;
  char thenames[8][PATH_MAX];
  strcpy(thenames[0], rootname);
  int i;
  for (i = 1; i < 8; i++) {
    sprintf(thenames[i], "%s.%d", thenames[0], i);
  }
  if (fileexists(thenames[7]) == 0)
    dounlink(thenames[7]);
  for (i = 6; i > -1; i--) {
    if (fileexists(thenames[i]) == 0)
      dorename(thenames[i], thenames[i + 1]);
  }
  fpo = dofopen(rootname, "w");
  fclose(fpo);
}


x86 assembly (clang, -O0):
<rotate>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    0x2e6d(%rip),%rax
mov    (%rax),%eax
mov    %rax,-0x38(%rbp)
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
lea    0xf(,%rax,8),%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x30(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x20(%rbp)
imul   $0x0,%rax,%rax
add    %rax,%rdi
mov    -0x8(%rbp),%rsi
call   1030 <strcpy@plt>
movl   $0x1,-0x24(%rbp)
cmpl   $0x8,-0x24(%rbp)
jge    1208 <rotate+0x98>
mov    -0x30(%rbp),%rdx
mov    -0x38(%rbp),%rax
movslq -0x24(%rbp),%rcx
imul   %rax,%rcx
mov    %rdx,%rdi
add    %rcx,%rdi
imul   $0x0,%rax,%rax
add    %rax,%rdx
mov    -0x24(%rbp),%ecx
lea    0xe0b(%rip),%rsi
call   1090 <sprintf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11c4 <rotate+0x54>
mov    -0x30(%rbp),%rdi
mov    -0x38(%rbp),%rax
imul   $0x7,%rax,%rax
add    %rax,%rdi
call   1070 <fileexists@plt>
cmp    $0x0,%rax
jne    123a <rotate+0xca>
mov    -0x30(%rbp),%rdi
mov    -0x38(%rbp),%rax
imul   $0x7,%rax,%rax
add    %rax,%rdi
call   1080 <dounlink@plt>
movl   $0x6,-0x24(%rbp)
cmpl   $0xffffffff,-0x24(%rbp)
jle    12aa <rotate+0x13a>
mov    -0x30(%rbp),%rdi
mov    -0x38(%rbp),%rcx
movslq -0x24(%rbp),%rax
imul   %rcx,%rax
add    %rax,%rdi
call   1070 <fileexists@plt>
cmp    $0x0,%rax
jne    1297 <rotate+0x127>
mov    -0x30(%rbp),%rsi
mov    -0x38(%rbp),%rcx
movslq -0x24(%rbp),%rax
imul   %rcx,%rax
mov    %rsi,%rdi
add    %rax,%rdi
mov    -0x24(%rbp),%eax
add    $0x1,%eax
cltq
imul   %rcx,%rax
add    %rax,%rsi
call   1060 <dorename@plt>
jmp    129c <rotate+0x12c>
mov    -0x24(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x24(%rbp)
jmp    1241 <rotate+0xd1>
mov    -0x8(%rbp),%rdi
lea    0xd51(%rip),%rsi
call   1040 <dofopen@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rotate>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rdi,%rsi
mov    0x2e65(%rip),%rax
mov    (%rax),%r14d
lea    0x0(,%r14,8),%r15
mov    %rsp,%rbx
lea    0xf(,%r14,8),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %rbx,%rdi
mov    %rsi,-0x50(%rbp)
call   1030 <strcpy@plt>
lea    (%rbx,%r14,1),%rdi
lea    0xe3e(%rip),%r12
mov    %rdi,-0x48(%rbp)
mov    %r12,%rsi
mov    %rbx,%rdx
mov    $0x1,%ecx
call   1090 <sprintf@plt>
lea    (%rbx,%r14,2),%rdi
mov    %rdi,-0x40(%rbp)
mov    %r12,%rsi
mov    %rbx,%rdx
mov    $0x2,%ecx
call   1090 <sprintf@plt>
lea    (%r14,%r14,2),%r13
lea    (%rbx,%r13,1),%rdi
mov    %rdi,-0x38(%rbp)
mov    %r12,%rsi
mov    %rbx,%rdx
mov    $0x3,%ecx
call   1090 <sprintf@plt>
lea    (%rbx,%r14,4),%rdi
mov    %rdi,-0x30(%rbp)
mov    %r12,%rsi
mov    %rbx,%rdx
mov    $0x4,%ecx
call   1090 <sprintf@plt>
lea    (%r14,%r14,4),%r12
add    %rbx,%r12
mov    %r12,%rdi
lea    0xdcd(%rip),%rsi
mov    %rbx,%rdx
mov    $0x5,%ecx
call   1090 <sprintf@plt>
lea    (%rbx,%r13,2),%r13
mov    %r13,%rdi
lea    0xdb2(%rip),%rsi
mov    %rbx,%rdx
mov    $0x6,%ecx
call   1090 <sprintf@plt>
sub    %r14,%r15
add    %rbx,%r15
mov    %r15,%rdi
lea    0xd95(%rip),%rsi
mov    %rbx,%rdx
mov    $0x7,%ecx
call   1090 <sprintf@plt>
mov    %r15,%rdi
call   1070 <fileexists@plt>
test   %rax,%rax
jne    128d <rotate+0x11d>
mov    %r15,%rdi
call   1080 <dounlink@plt>
mov    %r13,%rdi
call   1070 <fileexists@plt>
test   %rax,%rax
jne    12a5 <rotate+0x135>
mov    %r13,%rdi
mov    %r15,%rsi
call   1060 <dorename@plt>
mov    %r13,%r15
mov    %r12,%rdi
call   1070 <fileexists@plt>
test   %rax,%rax
mov    -0x48(%rbp),%r14
mov    -0x30(%rbp),%r13
jne    12c8 <rotate+0x158>
mov    %r12,%rdi
mov    %r15,%rsi
call   1060 <dorename@plt>
mov    %r13,%rdi
call   1070 <fileexists@plt>
test   %rax,%rax
mov    -0x40(%rbp),%r15
jne    12e4 <rotate+0x174>
mov    %r13,%rdi
mov    %r12,%rsi
call   1060 <dorename@plt>
mov    -0x38(%rbp),%r12
mov    %r12,%rdi
call   1070 <fileexists@plt>
test   %rax,%rax
jne    1300 <rotate+0x190>
mov    %r12,%rdi
mov    %r13,%rsi
call   1060 <dorename@plt>
mov    %r15,%rdi
call   1070 <fileexists@plt>
test   %rax,%rax
jne    1318 <rotate+0x1a8>
mov    %r15,%rdi
mov    %r12,%rsi
call   1060 <dorename@plt>
mov    %r14,%rdi
call   1070 <fileexists@plt>
test   %rax,%rax
jne    1330 <rotate+0x1c0>
mov    %r14,%rdi
mov    %r15,%rsi
call   1060 <dorename@plt>
mov    %rbx,%rdi
call   1070 <fileexists@plt>
test   %rax,%rax
jne    1348 <rotate+0x1d8>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1060 <dorename@plt>
lea    0xcb7(%rip),%rsi
mov    -0x50(%rbp),%rdi
call   1040 <dofopen@plt>
mov    %rax,%rdi
call   1050 <fclose@plt>
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@PATH_MAX = global i32 0
@.str = [6 x i8] c"%s.%d\00"
@.str.1 = [2 x i8] c"w\00"
define void @rotate(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i32
store i8* %0, i8** %2
%7 = load i32, i32* @PATH_MAX
%8 = zext i32 %7 to i64
%9 = call i8* @llvm.stacksave()
store i8* %9, i8** %4
%10 = mul nuw i64 8, %8
%11 = alloca i8, i64 %10
store i64 %8, i64* %5
%12 = mul nsw i64 0, %8
%13 = getelementptr inbounds i8, i8* %11, i64 %12
%14 = load i8*, i8** %2
%15 = call i32 @strcpy(i8* %13, i8* %14)
store i32 1, i32* %6
br label %16
16: ; preds = %28, %1
%17 = load i32, i32* %6
%18 = icmp slt i32 %17, 8
br i1 %18, label %19, label %31
19: ; preds = %16
%20 = load i32, i32* %6
%21 = sext i32 %20 to i64
%22 = mul nsw i64 %21, %8
%23 = getelementptr inbounds i8, i8* %11, i64 %22
%24 = mul nsw i64 0, %8
%25 = getelementptr inbounds i8, i8* %11, i64 %24
%26 = load i32, i32* %6
%27 = call i32 @sprintf(i8* %23, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %25, i32 %26)
br label %28
28: ; preds = %19
%29 = load i32, i32* %6
%30 = add nsw i32 %29, 1
store i32 %30, i32* %6
br label %16
31: ; preds = %16
%32 = mul nsw i64 7, %8
%33 = getelementptr inbounds i8, i8* %11, i64 %32
%34 = call i64 @fileexists(i8* %33)
%35 = icmp eq i64 %34, 0
br i1 %35, label %36, label %40
36: ; preds = %31
%37 = mul nsw i64 7, %8
%38 = getelementptr inbounds i8, i8* %11, i64 %37
%39 = call i32 @dounlink(i8* %38)
br label %40
40: ; preds = %36, %31
store i32 6, i32* %6
br label %41
41: ; preds = %63, %40
%42 = load i32, i32* %6
%43 = icmp sgt i32 %42, -1
br i1 %43, label %44, label %66
44: ; preds = %41
%45 = load i32, i32* %6
%46 = sext i32 %45 to i64
%47 = mul nsw i64 %46, %8
%48 = getelementptr inbounds i8, i8* %11, i64 %47
%49 = call i64 @fileexists(i8* %48)
%50 = icmp eq i64 %49, 0
br i1 %50, label %51, label %62
51: ; preds = %44
%52 = load i32, i32* %6
%53 = sext i32 %52 to i64
%54 = mul nsw i64 %53, %8
%55 = getelementptr inbounds i8, i8* %11, i64 %54
%56 = load i32, i32* %6
%57 = add nsw i32 %56, 1
%58 = sext i32 %57 to i64
%59 = mul nsw i64 %58, %8
%60 = getelementptr inbounds i8, i8* %11, i64 %59
%61 = call i32 @dorename(i8* %55, i8* %60)
br label %62
62: ; preds = %51, %44
br label %63
63: ; preds = %62
%64 = load i32, i32* %6
%65 = add nsw i32 %64, -1
store i32 %65, i32* %6
br label %41
66: ; preds = %41
%67 = load i8*, i8** %2
%68 = call i32* @dofopen(i8* %67, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %68, i32** %3
%69 = load i32*, i32** %3
%70 = call i32 @fclose(i32* %69)
%71 = load i8*, i8** %4
ret void
}

LLVM IR (-O2):
@PATH_MAX = global i32 0
@.str = [6 x i8] c"%s.%d\00"
@.str.1 = [2 x i8] c"w\00"
define void @rotate(i8* %0) {
%2 = load i32, i32* @PATH_MAX
%3 = zext i32 %2 to i64
%4 = shl nuw nsw i64 %3, 3
%5 = alloca i8, i64 %4
%6 = call i32 @strcpy(i8* %5, i8* %0)
%7 = getelementptr inbounds i8, i8* %5, i64 %3
%8 = call i32 @sprintf(i8* %7, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %5, i32 1)
%9 = shl nuw nsw i64 %3, 1
%10 = getelementptr inbounds i8, i8* %5, i64 %9
%11 = call i32 @sprintf(i8* %10, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %5, i32 2)
%12 = mul nuw nsw i64 %3, 3
%13 = getelementptr inbounds i8, i8* %5, i64 %12
%14 = call i32 @sprintf(i8* %13, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %5, i32 3)
%15 = shl nuw nsw i64 %3, 2
%16 = getelementptr inbounds i8, i8* %5, i64 %15
%17 = call i32 @sprintf(i8* %16, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %5, i32 4)
%18 = mul nuw nsw i64 %3, 5
%19 = getelementptr inbounds i8, i8* %5, i64 %18
%20 = call i32 @sprintf(i8* %19, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %5, i32 5)
%21 = mul nuw nsw i64 %3, 6
%22 = getelementptr inbounds i8, i8* %5, i64 %21
%23 = call i32 @sprintf(i8* %22, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %5, i32 6)
%24 = mul nuw nsw i64 %3, 7
%25 = getelementptr inbounds i8, i8* %5, i64 %24
%26 = call i32 @sprintf(i8* %25, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %5, i32 7)
%27 = call i64 @fileexists(i8* %25)
%28 = icmp eq i64 %27, 0
br i1 %28, label %29, label %31
29: ; preds = %1
%30 = call i32 @dounlink(i8* %25)
br label %31
31: ; preds = %29, %1
%32 = call i64 @fileexists(i8* %22)
%33 = icmp eq i64 %32, 0
br i1 %33, label %34, label %36
34: ; preds = %31
%35 = call i32 @dorename(i8* %22, i8* %25)
br label %36
36: ; preds = %31, %34
%37 = call i64 @fileexists(i8* %19)
%38 = icmp eq i64 %37, 0
br i1 %38, label %39, label %41
39: ; preds = %36
%40 = call i32 @dorename(i8* %19, i8* %22)
br label %41
41: ; preds = %39, %36
%42 = call i64 @fileexists(i8* %16)
%43 = icmp eq i64 %42, 0
br i1 %43, label %44, label %46
44: ; preds = %41
%45 = call i32 @dorename(i8* %16, i8* %19)
br label %46
46: ; preds = %44, %41
%47 = call i64 @fileexists(i8* %13)
%48 = icmp eq i64 %47, 0
br i1 %48, label %49, label %51
49: ; preds = %46
%50 = call i32 @dorename(i8* %13, i8* %16)
br label %51
51: ; preds = %49, %46
%52 = call i64 @fileexists(i8* %10)
%53 = icmp eq i64 %52, 0
br i1 %53, label %54, label %56
54: ; preds = %51
%55 = call i32 @dorename(i8* %10, i8* %13)
br label %56
56: ; preds = %54, %51
%57 = call i64 @fileexists(i8* %7)
%58 = icmp eq i64 %57, 0
br i1 %58, label %59, label %61
59: ; preds = %56
%60 = call i32 @dorename(i8* %7, i8* %10)
br label %61
61: ; preds = %59, %56
%62 = call i64 @fileexists(i8* %5)
%63 = icmp eq i64 %62, 0
br i1 %63, label %64, label %66
64: ; preds = %61
%65 = call i32 @dorename(i8* %5, i8* %7)
br label %66
66: ; preds = %64, %61
%67 = call i32* @dofopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%68 = call i32 @fclose(i32* %67)
ret void
}