#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*/ *fopen(char *, char *);
int /*<<< orphan*/ **malloc(int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ sprintf(char *, char *, int);
int main(int argc, char *argv[]) {
  FILE **fps = malloc(sizeof(FILE *) * 65535);
  int i;
  for (i = 0; i < 65536; i++) {
    char filename[13 + i];
    sprintf(filename, "./tmp/fdtest.%d", i);
    fps[i] = fopen(filename, "w+");
  }
  printf("Created Files, Waiting...\n");
  while (1)
    ;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x7fff8,%edi
call   1040 <malloc@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x10000,-0x1c(%rbp)
jge    11e4 <main+0xa4>
mov    -0x1c(%rbp),%eax
add    $0xd,%eax
mov    %rsp,%rcx
mov    %rcx,-0x28(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x38(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x30(%rbp)
mov    -0x1c(%rbp),%edx
lea    0xe55(%rip),%rsi
call   1060 <sprintf@plt>
mov    -0x38(%rbp),%rdi
lea    0xe55(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,%rdx
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x28(%rbp),%rax
mov    %rax,%rsp
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    116b <main+0x2b>
lea    0xe28(%rip),%rdi
call   1030 <printf@plt>
jmp    11f0 <main+0xb0>

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    $0x7fff8,%edi
call   1040 <malloc@plt>
mov    %rax,%r14
xor    %r13d,%r13d
lea    0xeab(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rsp,%r15
mov    %rsp,%rbx
lea    0x1c(%r13),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %rbx,%rdi
lea    0xe72(%rip),%rsi
mov    %r13d,%edx
call   1060 <sprintf@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
call   1050 <fopen@plt>
mov    %rax,(%r14,%r13,8)
mov    %r15,%rsp
add    $0x1,%r13
cmp    $0x10000,%r13
jne    1170 <main+0x30>
lea    0xe57(%rip),%rdi
call   1030 <puts@plt>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
jmp    11d0 <main+0x90>

LLVM IR (-O0):
@.str = [16 x i8] c"./tmp/fdtest.%d\00"
@.str.1 = [3 x i8] c"w+\00"
@.str.2 = [27 x i8] c"Created Files, Waiting...\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32**
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = call i32** @malloc(i32 524280)
store i32** %10, i32*** %6
store i32 0, i32* %7
br label %11
11: ; preds = %28, %2
%12 = load i32, i32* %7
%13 = icmp slt i32 %12, 65536
br i1 %13, label %14, label %31
14: ; preds = %11
%15 = load i32, i32* %7
%16 = add nsw i32 13, %15
%17 = zext i32 %16 to i64
%18 = call i8* @llvm.stacksave()
store i8* %18, i8** %8
%19 = alloca i8, i64 %17
store i64 %17, i64* %9
%20 = load i32, i32* %7
%21 = call i32 @sprintf(i8* %19, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 %20)
%22 = call i32* @fopen(i8* %19, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%23 = load i32**, i32*** %6
%24 = load i32, i32* %7
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i32*, i32** %23, i64 %25
store i32* %22, i32** %26
%27 = load i8*, i8** %8
br label %28
28: ; preds = %14
%29 = load i32, i32* %7
%30 = add nsw i32 %29, 1
store i32 %30, i32* %7
br label %11
31: ; preds = %11
%32 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
br label %33
33: ; preds = %31, %33
br label %33
}

LLVM IR (-O2):
@.str = [16 x i8] c"./tmp/fdtest.%d\00"
@.str.1 = [3 x i8] c"w+\00"
@str = [26 x i8] c"Created Files, Waiting...\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32** @malloc(i32 524280)
br label %4
4: ; preds = %2, %4
%5 = phi i64 [ 0, %2 ], [ %13, %4 ]
%6 = add nuw nsw i64 %5, 13
%7 = tail call i8* @llvm.stacksave()
%8 = alloca i8, i64 %6
%9 = trunc i64 %5 to i32
%10 = call i32 @sprintf(i8* %8, i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 %9)
%11 = call i32* @fopen(i8* %8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%12 = getelementptr inbounds i32*, i32** %3, i64 %5
store i32* %11, i32** %12
tail call void @llvm.stackrestore(i8* %7)
%13 = add nuw nsw i64 %5, 1
%14 = icmp eq i64 %13, 65536
br i1 %14, label %15, label %4
15: ; preds = %4
%16 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str, i64 0, i64 0))
br label %17
17: ; preds = %17, %15
br label %17
}