#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 */
int /*<<< orphan*/ rename(char *, char *);
int /*<<< orphan*/ sprintf(char *, char *, int);
int /*<<< orphan*/ unlink(char *);
void RotateLogs(void) {
  unlink("/var/log/pitabd.log"
         ".9");
  for (int i = 8; i >= 1; --i) {
    char from[80], to[80];
    sprintf(from,
            "/var/log/pitabd.log"
            ".%d",
            i);
    sprintf(to,
            "/var/log/pitabd.log"
            ".%d",
            i + 1);
    rename(from, to);
  }
  rename("/var/log/pitabd.log", "/var/log/pitabd.log"
                                ".1");
}


x86 assembly (clang, -O0):
<RotateLogs>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
lea    0xebe(%rip),%rdi
call   1030 <unlink@plt>
movl   $0x8,-0x4(%rbp)
cmpl   $0x1,-0x4(%rbp)
jl     11a2 <RotateLogs+0x72>
lea    -0x60(%rbp),%rdi
mov    -0x4(%rbp),%edx
lea    0xeb0(%rip),%rsi
call   1050 <sprintf@plt>
lea    -0xb0(%rbp),%rdi
mov    -0x4(%rbp),%edx
add    $0x1,%edx
lea    0xe97(%rip),%rsi
call   1050 <sprintf@plt>
lea    -0x60(%rbp),%rdi
lea    -0xb0(%rbp),%rsi
call   1040 <rename@plt>
mov    -0x4(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x4(%rbp)
jmp    114e <RotateLogs+0x1e>
lea    0xe84(%rip),%rdi
lea    0xe91(%rip),%rsi
call   1040 <rename@plt>
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<RotateLogs>:
push   %r15
push   %r14
push   %rbx
sub    $0xa0,%rsp
lea    0xebd(%rip),%rdi
call   1030 <unlink@plt>
lea    0xec7(%rip),%r15
lea    0x50(%rsp),%r14
mov    %r14,%rdi
mov    %r15,%rsi
mov    $0x8,%edx
call   1050 <sprintf@plt>
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    %r15,%rsi
mov    $0x9,%edx
call   1050 <sprintf@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1040 <rename@plt>
mov    %r14,%rdi
mov    %r15,%rsi
mov    $0x7,%edx
call   1050 <sprintf@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    $0x8,%edx
call   1050 <sprintf@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1040 <rename@plt>
mov    %r14,%rdi
mov    %r15,%rsi
mov    $0x6,%edx
call   1050 <sprintf@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    $0x7,%edx
call   1050 <sprintf@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1040 <rename@plt>
mov    %r14,%rdi
mov    %r15,%rsi
mov    $0x5,%edx
call   1050 <sprintf@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    $0x6,%edx
call   1050 <sprintf@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1040 <rename@plt>
mov    %r14,%rdi
mov    %r15,%rsi
mov    $0x4,%edx
call   1050 <sprintf@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    $0x5,%edx
call   1050 <sprintf@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1040 <rename@plt>
mov    %r14,%rdi
mov    %r15,%rsi
mov    $0x3,%edx
call   1050 <sprintf@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    $0x4,%edx
call   1050 <sprintf@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1040 <rename@plt>
mov    %r14,%rdi
mov    %r15,%rsi
mov    $0x2,%edx
call   1050 <sprintf@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    $0x3,%edx
call   1050 <sprintf@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1040 <rename@plt>
mov    %r14,%rdi
mov    %r15,%rsi
mov    $0x1,%edx
call   1050 <sprintf@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    $0x2,%edx
call   1050 <sprintf@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1040 <rename@plt>
lea    0xd77(%rip),%rdi
lea    0xd84(%rip),%rsi
add    $0xa0,%rsp
pop    %rbx
pop    %r14
pop    %r15
jmp    1040 <rename@plt>

LLVM IR (-O0):
@.str = [22 x i8] c"/var/log/pitabd.log.9\00"
@.str.1 = [23 x i8] c"/var/log/pitabd.log.%d\00"
@.str.2 = [20 x i8] c"/var/log/pitabd.log\00"
@.str.3 = [22 x i8] c"/var/log/pitabd.log.1\00"
define void @RotateLogs() {
%1 = alloca i32
%2 = alloca [80 x i8]
%3 = alloca [80 x i8]
%4 = call i32 @unlink(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
store i32 8, i32* %1
br label %5
5: ; preds = %19, %0
%6 = load i32, i32* %1
%7 = icmp sge i32 %6, 1
br i1 %7, label %8, label %22
8: ; preds = %5
%9 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 0
%10 = load i32, i32* %1
%11 = call i32 @sprintf(i8* %9, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 %10)
%12 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%13 = load i32, i32* %1
%14 = add nsw i32 %13, 1
%15 = call i32 @sprintf(i8* %12, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 %14)
%16 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 0
%17 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%18 = call i32 @rename(i8* %16, i8* %17)
br label %19
19: ; preds = %8
%20 = load i32, i32* %1
%21 = add nsw i32 %20, -1
store i32 %21, i32* %1
br label %5
22: ; preds = %5
%23 = call i32 @rename(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [22 x i8] c"/var/log/pitabd.log.9\00"
@.str.1 = [23 x i8] c"/var/log/pitabd.log.%d\00"
@.str.2 = [20 x i8] c"/var/log/pitabd.log\00"
@.str.3 = [22 x i8] c"/var/log/pitabd.log.1\00"
define void @RotateLogs() {
%1 = alloca [80 x i8]
%2 = alloca [80 x i8]
%3 = tail call i32 @unlink(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%4 = getelementptr inbounds [80 x i8], [80 x i8]* %1, i64 0, i64 0
%5 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 0
%6 = call i32 @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 8)
%7 = call i32 @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 9)
%8 = call i32 @rename(i8* %4, i8* %5)
%9 = call i32 @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 7)
%10 = call i32 @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 8)
%11 = call i32 @rename(i8* %4, i8* %5)
%12 = call i32 @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 6)
%13 = call i32 @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 7)
%14 = call i32 @rename(i8* %4, i8* %5)
%15 = call i32 @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 5)
%16 = call i32 @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 6)
%17 = call i32 @rename(i8* %4, i8* %5)
%18 = call i32 @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 4)
%19 = call i32 @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 5)
%20 = call i32 @rename(i8* %4, i8* %5)
%21 = call i32 @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 3)
%22 = call i32 @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 4)
%23 = call i32 @rename(i8* %4, i8* %5)
%24 = call i32 @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 2)
%25 = call i32 @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 3)
%26 = call i32 @rename(i8* %4, i8* %5)
%27 = call i32 @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 1)
%28 = call i32 @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 2)
%29 = call i32 @rename(i8* %4, i8* %5)
%30 = tail call i32 @rename(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0))
ret void
}