#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 /*<<< orphan*/ F_OK;
scalar_t__ access(char const *, int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ rename(char const *, char const *);
int /*<<< orphan*/ unlink(char const *);
int rotate(FILE **logFilePtr, const char **logFileNames,
           const int maxNbOfFiles) {
  if (*logFilePtr) {
    fclose(*logFilePtr);
    *logFilePtr = NULL;
  }
  if (access(logFileNames[maxNbOfFiles - 1], F_OK) == 0) {
    unlink(logFileNames[maxNbOfFiles - 1]);
  }
  int index = maxNbOfFiles - 2;
  while (index >= 0) {
    if (access(logFileNames[index], F_OK) == 0) {
      rename(logFileNames[index], logFileNames[index + 1]);
    }
    --index;
  }
  *logFilePtr = fopen(logFileNames[0], "w");
  return 1;
}


x86 assembly (clang, -O0):
<rotate>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%rax
cmpq   $0x0,(%rax)
je     1188 <rotate+0x38>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
call   1040 <fclose@plt>
mov    -0x8(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdi
mov    0x2e38(%rip),%rax
mov    (%rax),%esi
call   1050 <access@plt>
cmp    $0x0,%rax
jne    11c7 <rotate+0x77>
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdi
call   1030 <unlink@plt>
mov    -0x14(%rbp),%eax
sub    $0x2,%eax
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jl     122e <rotate+0xde>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    0x2deb(%rip),%rax
mov    (%rax),%esi
call   1050 <access@plt>
cmp    $0x0,%rax
jne    1220 <rotate+0xd0>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rsi
call   1070 <rename@plt>
mov    -0x18(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x18(%rbp)
jmp    11d0 <rotate+0x80>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
lea    0xdc4(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
mov    $0x1,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rotate>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %edx,%ebx
mov    %rsi,%r15
mov    %rdi,%r14
mov    (%rdi),%rdi
test   %rdi,%rdi
je     1175 <rotate+0x25>
call   1040 <fclose@plt>
movq   $0x0,(%r14)
movslq %ebx,%r13
mov    -0x8(%r15,%r13,8),%rdi
mov    0x2e54(%rip),%r12
mov    (%r12),%esi
call   1050 <access@plt>
test   %rax,%rax
je     1199 <rotate+0x49>
cmp    $0x2,%ebx
jge    11ab <rotate+0x5b>
jmp    11e9 <rotate+0x99>
add    $0xffffffffffffffff,%r13
mov    (%r15,%r13,8),%rdi
call   1030 <unlink@plt>
cmp    $0x2,%ebx
jl     11e9 <rotate+0x99>
add    $0xfffffffe,%ebx
add    $0x1,%rbx
jmp    11c6 <rotate+0x76>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
add    $0xffffffffffffffff,%rbx
jle    11e9 <rotate+0x99>
mov    -0x8(%r15,%rbx,8),%rdi
mov    (%r12),%esi
call   1050 <access@plt>
test   %rax,%rax
jne    11c0 <rotate+0x70>
mov    -0x8(%r15,%rbx,8),%rdi
mov    (%r15,%rbx,8),%rsi
call   1070 <rename@plt>
jmp    11c0 <rotate+0x70>
mov    (%r15),%rdi
lea    0xe0d(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,(%r14)
mov    $0x1,%eax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@F_OK = global i32 0
@.str = [2 x i8] c"w\00"
define i32 @rotate(i32** nocapture %0, i8** nocapture %1, i32 %2) {
%4 = load i32*, i32** %0
%5 = icmp eq i32* %4, null
br i1 %5, label %8, label %6
6: ; preds = %3
%7 = tail call i32 @fclose(i32* %4)
store i32* null, i32** %0
br label %8
8: ; preds = %6, %3
%9 = add nsw i32 %2, -1
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds i8*, i8** %1, i64 %10
%12 = load i8*, i8** %11
%13 = load i32, i32* @F_OK
%14 = tail call i64 @access(i8* %12, i32 %13)
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %8
%17 = load i8*, i8** %11
%18 = tail call i32 @unlink(i8* %17)
br label %19
19: ; preds = %16, %8
%20 = icmp sgt i32 %2, 1
br i1 %20, label %21, label %40
21: ; preds = %19
%22 = add nsw i32 %2, -2
%23 = zext i32 %22 to i64
br label %24
24: ; preds = %21, %37
%25 = phi i64 [ %23, %21 ], [ %38, %37 ]
%26 = getelementptr inbounds i8*, i8** %1, i64 %25
%27 = load i8*, i8** %26
%28 = load i32, i32* @F_OK
%29 = tail call i64 @access(i8* %27, i32 %28)
%30 = icmp eq i64 %29, 0
br i1 %30, label %31, label %37
31: ; preds = %24
%32 = load i8*, i8** %26
%33 = add nuw nsw i64 %25, 1
%34 = getelementptr inbounds i8*, i8** %1, i64 %33
%35 = load i8*, i8** %34
%36 = tail call i32 @rename(i8* %32, i8* %35)
br label %37
37: ; preds = %31, %24
%38 = add nsw i64 %25, -1
%39 = icmp sgt i64 %25, 0
br i1 %39, label %24, label %40
40: ; preds = %37, %19
%41 = load i8*, i8** %1
%42 = tail call i32* @fopen(i8* %41, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %42, i32** %0
ret i32 1
}