#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 O_CREAT;
int O_RDWR;
int O_TRUNC;
int /*<<< orphan*/ SEEK_SET;
int S_IRGRP;
int S_IROTH;
int S_IRUSR;
int S_IWUSR;
int close(int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, char *, ...);
int lseek(int, int, int /*<<< orphan*/);
int open(char *, int, int);
int rename(char *, char *);
int /*<<< orphan*/ sprintf(char *, char *, int);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int write(int, char *, int);
int main(void) {
  int fd, i = 0;
  char file_name[20];
  for (;;) {
    (void)sprintf(file_name, ".%d", i);
    if ((fd = open(file_name, O_RDWR | O_CREAT | O_TRUNC,
                   S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH)) == -1) {
      (void)fprintf(stderr, "Failed to open() %s : %s\n", file_name,
                    strerror(errno));
      exit(1);
    }
    if (lseek(fd, 10240 - 1, SEEK_SET) == -1) {
      (void)fprintf(stderr, "Failed to lseek() in %s : %s\n", file_name,
                    strerror(errno));
      exit(1);
    }
    if (write(fd, "", 1) != 1) {
      (void)fprintf(stderr, "Failed to write() to %s : %s\n", file_name,
                    strerror(errno));
      exit(1);
    }
    if (close(fd) == -1) {
      (void)fprintf(stderr, "Failed to close() %s : %s\n", file_name,
                    strerror(errno));
    }
    if (rename(file_name, &file_name[1]) == -1) {
      (void)fprintf(stderr, "Failed to rename() %s to %s : %s\n", file_name,
                    &file_name[1], strerror(errno));
      exit(1);
    }
    i++;
    if (i == 10000) {
      i = 0;
    }
  }
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0xc(%rbp)
lea    -0x20(%rbp),%rdi
mov    -0xc(%rbp),%edx
lea    0xe49(%rip),%rsi
call   1090 <sprintf@plt>
lea    -0x20(%rbp),%rdi
mov    0x2e11(%rip),%rax
mov    (%rax),%esi
mov    0x2e28(%rip),%rax
or     (%rax),%esi
mov    0x2e17(%rip),%rax
or     (%rax),%esi
mov    0x2db6(%rip),%rax
mov    (%rax),%edx
mov    0x2de5(%rip),%rax
or     (%rax),%edx
mov    0x2db4(%rip),%rax
or     (%rax),%edx
mov    0x2da3(%rip),%rax
or     (%rax),%edx
call   1070 <open@plt>
mov    %eax,-0x8(%rbp)
cmp    $0xffffffff,%eax
jne    1254 <main+0xc4>
mov    0x2da9(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
lea    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    0x2d8d(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
mov    -0x2c(%rbp),%edi
mov    -0x28(%rbp),%rdx
mov    %rax,%rcx
lea    0xdc1(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x8(%rbp),%edi
mov    0x2d52(%rip),%rax
mov    (%rax),%edx
mov    $0x27ff,%esi
call   1040 <lseek@plt>
cmp    $0xffffffff,%eax
jne    12b7 <main+0x127>
mov    0x2d46(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x3c(%rbp)
lea    -0x20(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    0x2d2a(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
mov    -0x3c(%rbp),%edi
mov    -0x38(%rbp),%rdx
mov    %rax,%rcx
lea    0xd78(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x8(%rbp),%edi
lea    0xdb3(%rip),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
cmp    $0x1,%eax
je     1318 <main+0x188>
mov    0x2ce5(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4c(%rbp)
lea    -0x20(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    0x2cc9(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
mov    -0x4c(%rbp),%edi
mov    -0x48(%rbp),%rdx
mov    %rax,%rcx
lea    0xd35(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x8(%rbp),%edi
call   1050 <close@plt>
cmp    $0xffffffff,%eax
jne    1363 <main+0x1d3>
mov    0x2c90(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x5c(%rbp)
lea    -0x20(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    0x2c74(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
mov    -0x5c(%rbp),%edi
mov    -0x58(%rbp),%rdx
mov    %rax,%rcx
lea    0xcfe(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
lea    -0x20(%rbp),%rdi
lea    -0x20(%rbp),%rsi
add    $0x1,%rsi
call   1080 <rename@plt>
cmp    $0xffffffff,%eax
jne    13d1 <main+0x241>
mov    0x2c3c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x74(%rbp)
lea    -0x20(%rbp),%rax
mov    %rax,-0x70(%rbp)
lea    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x68(%rbp)
mov    0x2c14(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
mov    -0x74(%rbp),%edi
mov    -0x70(%rbp),%rdx
mov    -0x68(%rbp),%rcx
mov    %rax,%r8
lea    0xcb5(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
cmpl   $0x2710,-0xc(%rbp)
jne    13ee <main+0x25e>
movl   $0x0,-0xc(%rbp)
jmp    11a9 <main+0x19>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
lea    0x1(%rsp),%rbx
mov    %rsp,%r14
mov    0x2e03(%rip),%r15
lea    0xec0(%rip),%r12
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
mov    %r14,%rdi
lea    0xe36(%rip),%rsi
mov    %ebp,%edx
call   1090 <sprintf@plt>
mov    0x2e20(%rip),%rax
mov    (%rax),%esi
mov    0x2df7(%rip),%rax
or     (%rax),%esi
mov    0x2e06(%rip),%rax
or     (%rax),%esi
mov    0x2ddd(%rip),%rax
mov    (%rax),%edx
mov    0x2d9c(%rip),%rax
or     (%rax),%edx
mov    0x2da3(%rip),%rax
or     (%rax),%edx
mov    0x2d92(%rip),%rax
or     (%rax),%edx
mov    %r14,%rdi
call   1070 <open@plt>
cmp    $0xffffffff,%eax
je     12bf <main+0x12f>
mov    %eax,%r13d
mov    (%r15),%edx
mov    %eax,%edi
mov    $0x27ff,%esi
call   1040 <lseek@plt>
cmp    $0xffffffff,%eax
je     12df <main+0x14f>
mov    %r13d,%edi
mov    %r12,%rsi
mov    $0x1,%edx
call   1030 <write@plt>
cmp    $0x1,%eax
jne    12ff <main+0x16f>
mov    %r13d,%edi
call   1050 <close@plt>
cmp    $0xffffffff,%eax
jne    1295 <main+0x105>
mov    %rbx,%r13
mov    0x2d54(%rip),%rax
mov    (%rax),%ebx
mov    0x2d43(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
mov    %ebx,%edi
mov    %r13,%rbx
lea    0xdd2(%rip),%rsi
mov    %r14,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1080 <rename@plt>
cmp    $0xffffffff,%eax
je     1336 <main+0x1a6>
add    $0x1,%ebp
cmp    $0x2710,%ebp
mov    $0x0,%eax
cmove  %eax,%ebp
jmp    11c0 <main+0x30>
mov    0x2cfa(%rip),%rax
mov    (%rax),%ebx
mov    0x2ce9(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
lea    0xd27(%rip),%rsi
jmp    131d <main+0x18d>
mov    0x2cda(%rip),%rax
mov    (%rax),%ebx
mov    0x2cc9(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
lea    0xd21(%rip),%rsi
jmp    131d <main+0x18d>
mov    0x2cba(%rip),%rax
mov    (%rax),%ebx
mov    0x2ca9(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
lea    0xd1f(%rip),%rsi
mov    %rsp,%rdx
mov    %ebx,%edi
mov    %rax,%rcx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    %rbx,%rbp
mov    0x2c80(%rip),%rax
mov    (%rax),%ebx
mov    0x2c6f(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
lea    0xd1e(%rip),%rsi
mov    %rsp,%rdx
mov    %ebx,%edi
mov    %rbp,%rcx
mov    %rax,%r8
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [4 x i8] c".%d\00"
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@S_IRGRP = global i32 0
@S_IROTH = global i32 0
@stderr = global i32 0
@.str.1 = [26 x i8] c"Failed to open() %s : %s\0A\00"
@errno = global i32 0
@SEEK_SET = global i32 0
@.str.2 = [30 x i8] c"Failed to lseek() in %s : %s\0A\00"
@.str.3 = [1 x i8] zeroinitializer
@.str.4 = [30 x i8] c"Failed to write() to %s : %s\0A\00"
@.str.5 = [27 x i8] c"Failed to close() %s : %s\0A\00"
@.str.6 = [34 x i8] c"Failed to rename() %s to %s : %s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca [20 x i8]
store i32 0, i32* %1
store i32 0, i32* %3
br label %5
5: ; preds = %83, %0
%6 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 0
%7 = load i32, i32* %3
%8 = call i32 @sprintf(i8* %6, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %7)
%9 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 0
%10 = load i32, i32* @O_RDWR
%11 = load i32, i32* @O_CREAT
%12 = or i32 %10, %11
%13 = load i32, i32* @O_TRUNC
%14 = or i32 %12, %13
%15 = load i32, i32* @S_IRUSR
%16 = load i32, i32* @S_IWUSR
%17 = or i32 %15, %16
%18 = load i32, i32* @S_IRGRP
%19 = or i32 %17, %18
%20 = load i32, i32* @S_IROTH
%21 = or i32 %19, %20
%22 = call i32 @open(i8* %9, i32 %14, i32 %21)
store i32 %22, i32* %2
%23 = icmp eq i32 %22, -1
br i1 %23, label %24, label %31
24: ; preds = %5
%25 = load i32, i32* @stderr
%26 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 0
%27 = load i32, i32* @errno
%28 = call i8* @strerror(i32 %27)
%29 = call i32 (i32, i8*, i8*, i8*, ...) @fprintf(i32 %25, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* %26, i8* %28)
%30 = call i32 @exit(i32 1)
unreachable
31: ; preds = %5
%32 = load i32, i32* %2
%33 = load i32, i32* @SEEK_SET
%34 = call i32 @lseek(i32 %32, i32 10239, i32 %33)
%35 = icmp eq i32 %34, -1
br i1 %35, label %36, label %43
36: ; preds = %31
%37 = load i32, i32* @stderr
%38 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 0
%39 = load i32, i32* @errno
%40 = call i8* @strerror(i32 %39)
%41 = call i32 (i32, i8*, i8*, i8*, ...) @fprintf(i32 %37, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i8* %38, i8* %40)
%42 = call i32 @exit(i32 1)
unreachable
43: ; preds = %31
%44 = load i32, i32* %2
%45 = call i32 @write(i32 %44, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.3, i64 0, i64 0), i32 1)
%46 = icmp ne i32 %45, 1
br i1 %46, label %47, label %54
47: ; preds = %43
%48 = load i32, i32* @stderr
%49 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 0
%50 = load i32, i32* @errno
%51 = call i8* @strerror(i32 %50)
%52 = call i32 (i32, i8*, i8*, i8*, ...) @fprintf(i32 %48, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0), i8* %49, i8* %51)
%53 = call i32 @exit(i32 1)
unreachable
54: ; preds = %43
%55 = load i32, i32* %2
%56 = call i32 @close(i32 %55)
%57 = icmp eq i32 %56, -1
br i1 %57, label %58, label %64
58: ; preds = %54
%59 = load i32, i32* @stderr
%60 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 0
%61 = load i32, i32* @errno
%62 = call i8* @strerror(i32 %61)
%63 = call i32 (i32, i8*, i8*, i8*, ...) @fprintf(i32 %59, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0), i8* %60, i8* %62)
br label %64
64: ; preds = %58, %54
%65 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 0
%66 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 1
%67 = call i32 @rename(i8* %65, i8* %66)
%68 = icmp eq i32 %67, -1
br i1 %68, label %69, label %77
69: ; preds = %64
%70 = load i32, i32* @stderr
%71 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 0
%72 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 1
%73 = load i32, i32* @errno
%74 = call i8* @strerror(i32 %73)
%75 = call i32 (i32, i8*, i8*, i8*, ...) @fprintf(i32 %70, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.6, i64 0, i64 0), i8* %71, i8* %72, i8* %74)
%76 = call i32 @exit(i32 1)
unreachable
77: ; preds = %64
%78 = load i32, i32* %3
%79 = add nsw i32 %78, 1
store i32 %79, i32* %3
%80 = load i32, i32* %3
%81 = icmp eq i32 %80, 10000
br i1 %81, label %82, label %83
82: ; preds = %77
store i32 0, i32* %3
br label %83
83: ; preds = %82, %77
br label %5
}

LLVM IR (-O2):
@.str = [4 x i8] c".%d\00"
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@S_IRGRP = global i32 0
@S_IROTH = global i32 0
@stderr = global i32 0
@.str.1 = [26 x i8] c"Failed to open() %s : %s\0A\00"
@errno = global i32 0
@SEEK_SET = global i32 0
@.str.2 = [30 x i8] c"Failed to lseek() in %s : %s\0A\00"
@.str.3 = [1 x i8] zeroinitializer
@.str.4 = [30 x i8] c"Failed to write() to %s : %s\0A\00"
@.str.5 = [27 x i8] c"Failed to close() %s : %s\0A\00"
@.str.6 = [34 x i8] c"Failed to rename() %s to %s : %s\0A\00"
define i32 @main() {
%1 = alloca [20 x i8]
%2 = getelementptr inbounds [20 x i8], [20 x i8]* %1, i64 0, i64 0
%3 = getelementptr inbounds [20 x i8], [20 x i8]* %1, i64 0, i64 1
br label %4
4: ; preds = %63, %0
%5 = phi i32 [ 0, %0 ], [ %66, %63 ]
%6 = call i32 @sprintf(i8* %2, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %5)
%7 = load i32, i32* @O_RDWR
%8 = load i32, i32* @O_CREAT
%9 = or i32 %8, %7
%10 = load i32, i32* @O_TRUNC
%11 = or i32 %9, %10
%12 = load i32, i32* @S_IRUSR
%13 = load i32, i32* @S_IWUSR
%14 = or i32 %13, %12
%15 = load i32, i32* @S_IRGRP
%16 = or i32 %14, %15
%17 = load i32, i32* @S_IROTH
%18 = or i32 %16, %17
%19 = call i32 @open(i8* %2, i32 %11, i32 %18)
%20 = icmp eq i32 %19, -1
br i1 %20, label %21, label %27
21: ; preds = %4
%22 = load i32, i32* @stderr
%23 = load i32, i32* @errno
%24 = call i8* @strerror(i32 %23)
%25 = call i32 (i32, i8*, i8*, i8*, ...) @fprintf(i32 %22, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* %2, i8* %24)
%26 = call i32 @exit(i32 1)
unreachable
27: ; preds = %4
%28 = load i32, i32* @SEEK_SET
%29 = call i32 @lseek(i32 %19, i32 10239, i32 %28)
%30 = icmp eq i32 %29, -1
br i1 %30, label %31, label %37
31: ; preds = %27
%32 = load i32, i32* @stderr
%33 = load i32, i32* @errno
%34 = call i8* @strerror(i32 %33)
%35 = call i32 (i32, i8*, i8*, i8*, ...) @fprintf(i32 %32, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i8* %2, i8* %34)
%36 = call i32 @exit(i32 1)
unreachable
37: ; preds = %27
%38 = call i32 @write(i32 %19, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.3, i64 0, i64 0), i32 1)
%39 = icmp eq i32 %38, 1
br i1 %39, label %46, label %40
40: ; preds = %37
%41 = load i32, i32* @stderr
%42 = load i32, i32* @errno
%43 = call i8* @strerror(i32 %42)
%44 = call i32 (i32, i8*, i8*, i8*, ...) @fprintf(i32 %41, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0), i8* %2, i8* %43)
%45 = call i32 @exit(i32 1)
unreachable
46: ; preds = %37
%47 = call i32 @close(i32 %19)
%48 = icmp eq i32 %47, -1
br i1 %48, label %49, label %54
49: ; preds = %46
%50 = load i32, i32* @stderr
%51 = load i32, i32* @errno
%52 = call i8* @strerror(i32 %51)
%53 = call i32 (i32, i8*, i8*, i8*, ...) @fprintf(i32 %50, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0), i8* %2, i8* %52)
br label %54
54: ; preds = %49, %46
%55 = call i32 @rename(i8* %2, i8* %3)
%56 = icmp eq i32 %55, -1
br i1 %56, label %57, label %63
57: ; preds = %54
%58 = load i32, i32* @stderr
%59 = load i32, i32* @errno
%60 = call i8* @strerror(i32 %59)
%61 = call i32 (i32, i8*, i8*, i8*, ...) @fprintf(i32 %58, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.6, i64 0, i64 0), i8* %2, i8* %3, i8* %60)
%62 = call i32 @exit(i32 1)
unreachable
63: ; preds = %54
%64 = add nsw i32 %5, 1
%65 = icmp eq i32 %64, 10000
%66 = select i1 %65, i32 0, i32 %64
br label %4
}