#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;
scalar_t__ close(int /*<<< orphan*/);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, char *);
int /*<<< orphan*/ open(char *, int, int);
int /*<<< orphan*/ sprintf(char *, char *, int);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
void create_files() {
  int i;
  for (i = 0; i < 700; i++) {
    char fname[40];
    sprintf(fname,
            "test.dir"
            "/test%u.txt",
            i);
    close(open(fname, O_CREAT | O_RDWR, 0600)) == 0 ||
        (fprintf(stderr, "Failed for %s - %s\n", "close", strerror(errno)),
         exit(1), 1);
  }
}


x86 assembly (clang, -O0):
<create_files>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
cmpl   $0x2bc,-0x4(%rbp)
jge    120b <create_files+0xab>
lea    -0x30(%rbp),%rdi
mov    -0x4(%rbp),%edx
lea    0xe76(%rip),%rsi
call   1060 <sprintf@plt>
lea    -0x30(%rbp),%rdi
mov    0x2e5e(%rip),%rax
mov    (%rax),%esi
mov    0x2e3d(%rip),%rax
or     (%rax),%esi
mov    $0x180,%edx
call   1050 <open@plt>
mov    %eax,%edi
call   1030 <close@plt>
cmp    $0x0,%rax
je     11fd <create_files+0x9d>
mov    0x2e09(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    0x2df5(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    -0x34(%rbp),%edi
mov    %rax,%rcx
lea    0xe2d(%rip),%rsi
lea    0xe3a(%rip),%rdx
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    116f <create_files+0xf>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<create_files>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x30,%rsp
xor    %ebx,%ebx
lea    0xe8a(%rip),%r14
mov    %rsp,%r15
mov    0x2e78(%rip),%r12
mov    0x2e59(%rip),%r13
nopw   0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    %r14,%rsi
mov    %ebx,%edx
call   1060 <sprintf@plt>
mov    0x0(%r13),%esi
or     (%r12),%esi
mov    %r15,%rdi
mov    $0x180,%edx
call   1050 <open@plt>
mov    %eax,%edi
call   1030 <close@plt>
test   %rax,%rax
jne    11d7 <create_files+0x77>
add    $0x1,%ebx
cmp    $0x2bc,%ebx
jne    1190 <create_files+0x30>
add    $0x30,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
mov    0x2df2(%rip),%rax
mov    (%rax),%ebx
mov    0x2de1(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
lea    0xe1f(%rip),%rsi
lea    0xe2c(%rip),%rdx
mov    %ebx,%edi
mov    %rax,%rcx
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [20 x i8] c"test.dir/test%u.txt\00"
@O_CREAT = global i32 0
@O_RDWR = global i32 0
@stderr = global i32 0
@.str.1 = [20 x i8] c"Failed for %s - %s\0A\00"
@.str.2 = [6 x i8] c"close\00"
@errno = global i32 0
define void @create_files() {
%1 = alloca i32
%2 = alloca [40 x i8]
store i32 0, i32* %1
br label %3
3: ; preds = %27, %0
%4 = load i32, i32* %1
%5 = icmp slt i32 %4, 700
br i1 %5, label %6, label %30
6: ; preds = %3
%7 = getelementptr inbounds [40 x i8], [40 x i8]* %2, i64 0, i64 0
%8 = load i32, i32* %1
%9 = call i32 @sprintf(i8* %7, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 %8)
%10 = getelementptr inbounds [40 x i8], [40 x i8]* %2, i64 0, i64 0
%11 = load i32, i32* @O_CREAT
%12 = load i32, i32* @O_RDWR
%13 = or i32 %11, %12
%14 = call i32 @open(i8* %10, i32 %13, i32 384)
%15 = call i64 @close(i32 %14)
%16 = icmp eq i64 %15, 0
br i1 %16, label %24, label %17
17: ; preds = %6
%18 = load i32, i32* @stderr
%19 = load i32, i32* @errno
%20 = call i8* @strerror(i32 %19)
%21 = call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %20)
%22 = call i32 @exit(i32 1)
unreachable
23: ; No predecessors!
br label %24
24: ; preds = %23, %6
%25 = phi i1 [ true, %6 ], [ true, %23 ]
%26 = zext i1 %25 to i32
br label %27
27: ; preds = %24
%28 = load i32, i32* %1
%29 = add nsw i32 %28, 1
store i32 %29, i32* %1
br label %3
30: ; preds = %3
ret void
}

LLVM IR (-O2):
@.str = [20 x i8] c"test.dir/test%u.txt\00"
@O_CREAT = global i32 0
@O_RDWR = global i32 0
@stderr = global i32 0
@.str.1 = [20 x i8] c"Failed for %s - %s\0A\00"
@.str.2 = [6 x i8] c"close\00"
@errno = global i32 0
define void @create_files() {
%1 = alloca [40 x i8]
%2 = getelementptr inbounds [40 x i8], [40 x i8]* %1, i64 0, i64 0
br label %3
3: ; preds = %0, %18
%4 = phi i32 [ 0, %0 ], [ %19, %18 ]
%5 = call i32 @sprintf(i8* %2, i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 %4)
%6 = load i32, i32* @O_CREAT
%7 = load i32, i32* @O_RDWR
%8 = or i32 %7, %6
%9 = call i32 @open(i8* %2, i32 %8, i32 384)
%10 = tail call i64 @close(i32 %9)
%11 = icmp eq i64 %10, 0
br i1 %11, label %18, label %12
12: ; preds = %3
%13 = load i32, i32* @stderr
%14 = load i32, i32* @errno
%15 = tail call i8* @strerror(i32 %14)
%16 = tail call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %15)
%17 = tail call i32 @exit(i32 1)
unreachable
18: ; preds = %3
%19 = add nuw nsw i32 %4, 1
%20 = icmp eq i32 %19, 700
br i1 %20, label %21, label %3
21: ; preds = %18
ret void
}