#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 */
struct stat {
  int dummy;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ sprintf(char *, char *, int);
scalar_t__ stat(char *, struct stat *);
int /*<<< orphan*/ unlink(char *);
void test_rotation() {
  int i;
  char file[32];
  struct stat s;
  for (i = 0; i < 7; i++) {
    FILE *fp;
    sprintf(file, "test%d", i);
    fp = fopen(file, "w");
    fclose(fp);
    sleep(1);
  }
  assert(stat("test0", &s) != 0);
  assert(stat("test1", &s) != 0);
  for (i = 2; i < 7; i++) {
    sprintf(file, "test%d", i);
    assert(stat(file, &s) == 0);
    unlink(file);
  }
}


x86 assembly (clang, -O0):
<test_rotation>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
cmpl   $0x7,-0x4(%rbp)
jge    11d1 <test_rotation+0x61>
lea    -0x30(%rbp),%rdi
mov    -0x4(%rbp),%edx
lea    0xe69(%rip),%rsi
call   1080 <sprintf@plt>
lea    -0x30(%rbp),%rdi
lea    0xe60(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rdi
call   1040 <fclose@plt>
mov    $0x1,%edi
call   1090 <sleep@plt>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    117f <test_rotation+0xf>
lea    0xe31(%rip),%rdi
lea    -0x38(%rbp),%rsi
call   1060 <stat@plt>
cmp    $0x0,%rax
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
lea    0xe16(%rip),%rdi
lea    -0x38(%rbp),%rsi
call   1060 <stat@plt>
cmp    $0x0,%rax
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
movl   $0x2,-0x4(%rbp)
cmpl   $0x7,-0x4(%rbp)
jge    126c <test_rotation+0xfc>
lea    -0x30(%rbp),%rdi
mov    -0x4(%rbp),%edx
lea    0xdce(%rip),%rsi
call   1080 <sprintf@plt>
lea    -0x30(%rbp),%rdi
lea    -0x38(%rbp),%rsi
call   1060 <stat@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
lea    -0x30(%rbp),%rdi
call   1030 <unlink@plt>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    121a <test_rotation+0xaa>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_rotation>:
push   %r15
push   %r14
push   %rbx
sub    $0x30,%rsp
lea    0xe80(%rip),%r14
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    %r14,%rsi
xor    %edx,%edx
call   1080 <sprintf@plt>
lea    0xe6e(%rip),%r15
mov    %rbx,%rdi
mov    %r15,%rsi
call   1070 <fopen@plt>
mov    %rax,%rdi
call   1040 <fclose@plt>
mov    $0x1,%edi
call   1090 <sleep@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x1,%edx
call   1080 <sprintf@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1070 <fopen@plt>
mov    %rax,%rdi
call   1040 <fclose@plt>
mov    $0x1,%edi
call   1090 <sleep@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x2,%edx
call   1080 <sprintf@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1070 <fopen@plt>
mov    %rax,%rdi
call   1040 <fclose@plt>
mov    $0x1,%edi
call   1090 <sleep@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x3,%edx
call   1080 <sprintf@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1070 <fopen@plt>
mov    %rax,%rdi
call   1040 <fclose@plt>
mov    $0x1,%edi
call   1090 <sleep@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x4,%edx
call   1080 <sprintf@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1070 <fopen@plt>
mov    %rax,%rdi
call   1040 <fclose@plt>
mov    $0x1,%edi
call   1090 <sleep@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x5,%edx
call   1080 <sprintf@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1070 <fopen@plt>
mov    %rax,%rdi
call   1040 <fclose@plt>
mov    $0x1,%edi
call   1090 <sleep@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x6,%edx
call   1080 <sprintf@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1070 <fopen@plt>
mov    %rax,%rdi
call   1040 <fclose@plt>
mov    $0x1,%edi
call   1090 <sleep@plt>
lea    0xd3e(%rip),%rdi
lea    0x8(%rsp),%r15
mov    %r15,%rsi
call   1060 <stat@plt>
xor    %edi,%edi
test   %rax,%rax
setne  %dil
call   1050 <assert@plt>
lea    0xd22(%rip),%rdi
mov    %r15,%rsi
call   1060 <stat@plt>
xor    %edi,%edi
test   %rax,%rax
setne  %dil
call   1050 <assert@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x2,%edx
call   1080 <sprintf@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1060 <stat@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1050 <assert@plt>
mov    %rbx,%rdi
call   1030 <unlink@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x3,%edx
call   1080 <sprintf@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1060 <stat@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1050 <assert@plt>
mov    %rbx,%rdi
call   1030 <unlink@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x4,%edx
call   1080 <sprintf@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1060 <stat@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1050 <assert@plt>
mov    %rbx,%rdi
call   1030 <unlink@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x5,%edx
call   1080 <sprintf@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1060 <stat@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1050 <assert@plt>
mov    %rbx,%rdi
call   1030 <unlink@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x6,%edx
call   1080 <sprintf@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1060 <stat@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1050 <assert@plt>
mov    %rbx,%rdi
call   1030 <unlink@plt>
add    $0x30,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [7 x i8] c"test%d\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [6 x i8] c"test0\00"
@.str.3 = [6 x i8] c"test1\00"
define void @test_rotation() {
%1 = alloca i32
%2 = alloca [32 x i8]
%3 = alloca %struct.stat
%4 = alloca i32*
store i32 0, i32* %1
br label %5
5: ; preds = %17, %0
%6 = load i32, i32* %1
%7 = icmp slt i32 %6, 7
br i1 %7, label %8, label %20
8: ; preds = %5
%9 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 0
%10 = load i32, i32* %1
%11 = call i32 @sprintf(i8* %9, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %10)
%12 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 0
%13 = call i32* @fopen(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %13, i32** %4
%14 = load i32*, i32** %4
%15 = call i32 @fclose(i32* %14)
%16 = call i32 @sleep(i32 1)
br label %17
17: ; preds = %8
%18 = load i32, i32* %1
%19 = add nsw i32 %18, 1
store i32 %19, i32* %1
br label %5
20: ; preds = %5
%21 = call i64 @stat(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), %struct.stat* %3)
%22 = icmp ne i64 %21, 0
%23 = zext i1 %22 to i32
%24 = call i32 @assert(i32 %23)
%25 = call i64 @stat(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), %struct.stat* %3)
%26 = icmp ne i64 %25, 0
%27 = zext i1 %26 to i32
%28 = call i32 @assert(i32 %27)
store i32 2, i32* %1
br label %29
29: ; preds = %43, %20
%30 = load i32, i32* %1
%31 = icmp slt i32 %30, 7
br i1 %31, label %32, label %46
32: ; preds = %29
%33 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 0
%34 = load i32, i32* %1
%35 = call i32 @sprintf(i8* %33, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %34)
%36 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 0
%37 = call i64 @stat(i8* %36, %struct.stat* %3)
%38 = icmp eq i64 %37, 0
%39 = zext i1 %38 to i32
%40 = call i32 @assert(i32 %39)
%41 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 0
%42 = call i32 @unlink(i8* %41)
br label %43
43: ; preds = %32
%44 = load i32, i32* %1
%45 = add nsw i32 %44, 1
store i32 %45, i32* %1
br label %29
46: ; preds = %29
ret void
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [7 x i8] c"test%d\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [6 x i8] c"test0\00"
@.str.3 = [6 x i8] c"test1\00"
define void @test_rotation() {
%1 = alloca [32 x i8]
%2 = alloca %struct.stat
%3 = getelementptr inbounds [32 x i8], [32 x i8]* %1, i64 0, i64 0
%4 = bitcast %struct.stat* %2 to i8*
%5 = call i32 @sprintf(i8* %3, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 0)
%6 = call i32* @fopen(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%7 = tail call i32 @fclose(i32* %6)
%8 = tail call i32 @sleep(i32 1)
%9 = call i32 @sprintf(i8* %3, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 1)
%10 = call i32* @fopen(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%11 = tail call i32 @fclose(i32* %10)
%12 = tail call i32 @sleep(i32 1)
%13 = call i32 @sprintf(i8* %3, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 2)
%14 = call i32* @fopen(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%15 = tail call i32 @fclose(i32* %14)
%16 = tail call i32 @sleep(i32 1)
%17 = call i32 @sprintf(i8* %3, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 3)
%18 = call i32* @fopen(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%19 = tail call i32 @fclose(i32* %18)
%20 = tail call i32 @sleep(i32 1)
%21 = call i32 @sprintf(i8* %3, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 4)
%22 = call i32* @fopen(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%23 = tail call i32 @fclose(i32* %22)
%24 = tail call i32 @sleep(i32 1)
%25 = call i32 @sprintf(i8* %3, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 5)
%26 = call i32* @fopen(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%27 = tail call i32 @fclose(i32* %26)
%28 = tail call i32 @sleep(i32 1)
%29 = call i32 @sprintf(i8* %3, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 6)
%30 = call i32* @fopen(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%31 = tail call i32 @fclose(i32* %30)
%32 = tail call i32 @sleep(i32 1)
%33 = call i64 @stat(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), %struct.stat* %2)
%34 = icmp ne i64 %33, 0
%35 = zext i1 %34 to i32
%36 = call i32 @assert(i32 %35)
%37 = call i64 @stat(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), %struct.stat* %2)
%38 = icmp ne i64 %37, 0
%39 = zext i1 %38 to i32
%40 = call i32 @assert(i32 %39)
%41 = call i32 @sprintf(i8* %3, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 2)
%42 = call i64 @stat(i8* %3, %struct.stat* %2)
%43 = icmp eq i64 %42, 0
%44 = zext i1 %43 to i32
%45 = call i32 @assert(i32 %44)
%46 = call i32 @unlink(i8* %3)
%47 = call i32 @sprintf(i8* %3, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 3)
%48 = call i64 @stat(i8* %3, %struct.stat* %2)
%49 = icmp eq i64 %48, 0
%50 = zext i1 %49 to i32
%51 = call i32 @assert(i32 %50)
%52 = call i32 @unlink(i8* %3)
%53 = call i32 @sprintf(i8* %3, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 4)
%54 = call i64 @stat(i8* %3, %struct.stat* %2)
%55 = icmp eq i64 %54, 0
%56 = zext i1 %55 to i32
%57 = call i32 @assert(i32 %56)
%58 = call i32 @unlink(i8* %3)
%59 = call i32 @sprintf(i8* %3, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 5)
%60 = call i64 @stat(i8* %3, %struct.stat* %2)
%61 = icmp eq i64 %60, 0
%62 = zext i1 %61 to i32
%63 = call i32 @assert(i32 %62)
%64 = call i32 @unlink(i8* %3)
%65 = call i32 @sprintf(i8* %3, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 6)
%66 = call i64 @stat(i8* %3, %struct.stat* %2)
%67 = icmp eq i64 %66, 0
%68 = zext i1 %67 to i32
%69 = call i32 @assert(i32 %68)
%70 = call i32 @unlink(i8* %3)
ret void
}