#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 */
scalar_t__ ENOSPC;
int O_CREAT;
int O_RDWR;
int O_TRUNC;
int PATH_MAX;
int /*<<< orphan*/ close(int);
scalar_t__ errno;
int open(char *, int, int);
int /*<<< orphan*/ snprintf(char *, int, char *, int);
int /*<<< orphan*/ unlink(char *);
int /*<<< orphan*/ warn(char *, char *);
int /*<<< orphan*/ warnx(char *, char *, int);
void fill_inodes(void) {
  char path[PATH_MAX];
  int fd, i, max;
  i = 0;
  while (1) {
    snprintf(path, PATH_MAX, "%d", i);
    fd = open(path, O_CREAT | O_TRUNC | O_RDWR, 0600);
    if (fd < 0)
      break;
    close(fd);
    i++;
  }
  max = i;
  if (errno != ENOSPC) {
    warn("fill_inodes: open(%s)", path);
    goto teardown;
  }
  for (i = 0; i < 200; i++) {
    fd = open(path, O_CREAT | O_TRUNC | O_RDWR, 0600);
    if (fd < 0 && errno != ENOSPC) {
      warn("fill_inodes: open(%s) after ENOSPC", path);
      goto teardown;
    }
    if (fd >= 0) {
      warnx("fill_inodes: open(%s) after ENOSPC returned "
            " %d",
            path, fd);
      close(fd);
      goto teardown;
    }
  }
teardown:
  for (i = 0; i < max; i++) {
    snprintf(path, PATH_MAX, "%d", i);
    (void)unlink(path);
  }
}


x86 assembly (clang, -O0):
<fill_inodes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    0x2e71(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x8(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x28(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
jmp    11a0 <fill_inodes+0x40>
mov    -0x28(%rbp),%rdi
mov    0x2e35(%rip),%rax
mov    (%rax),%esi
mov    -0x18(%rbp),%ecx
lea    0xeaf(%rip),%rdx
call   1060 <snprintf@plt>
mov    -0x28(%rbp),%rdi
mov    0x2e31(%rip),%rax
mov    (%rax),%esi
mov    0x2e20(%rip),%rax
or     (%rax),%esi
mov    0x2df7(%rip),%rax
or     (%rax),%esi
mov    $0x180,%edx
call   1080 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    11f7 <fill_inodes+0x97>
jmp    120d <fill_inodes+0xad>
mov    -0x14(%rbp),%edi
call   1070 <close@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    119b <fill_inodes+0x3b>
mov    -0x18(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    0x2da6(%rip),%rax
mov    (%rax),%rax
mov    0x2d94(%rip),%rcx
cmp    (%rcx),%rax
je     1242 <fill_inodes+0xe2>
mov    -0x28(%rbp),%rsi
lea    0xdc8(%rip),%rdi
call   1040 <warn@plt>
jmp    12fd <fill_inodes+0x19d>
movl   $0x0,-0x18(%rbp)
cmpl   $0xc8,-0x18(%rbp)
jge    12f8 <fill_inodes+0x198>
mov    -0x28(%rbp),%rdi
mov    0x2d97(%rip),%rax
mov    (%rax),%esi
mov    0x2d86(%rip),%rax
or     (%rax),%esi
mov    0x2d5d(%rip),%rax
or     (%rax),%esi
mov    $0x180,%edx
call   1080 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    12bb <fill_inodes+0x15b>
mov    0x2d2d(%rip),%rax
mov    (%rax),%rax
mov    0x2d1b(%rip),%rcx
cmp    (%rcx),%rax
je     12bb <fill_inodes+0x15b>
mov    -0x28(%rbp),%rsi
lea    0xd65(%rip),%rdi
call   1040 <warn@plt>
jmp    12fd <fill_inodes+0x19d>
cmpl   $0x0,-0x14(%rbp)
jl     12e5 <fill_inodes+0x185>
mov    -0x28(%rbp),%rsi
mov    -0x14(%rbp),%edx
lea    0xd66(%rip),%rdi
call   1050 <warnx@plt>
mov    -0x14(%rbp),%edi
call   1070 <close@plt>
jmp    12fd <fill_inodes+0x19d>
jmp    12ea <fill_inodes+0x18a>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1249 <fill_inodes+0xe9>
jmp    12fd <fill_inodes+0x19d>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1343 <fill_inodes+0x1e3>
mov    -0x28(%rbp),%rdi
mov    0x2cc5(%rip),%rax
mov    (%rax),%esi
mov    -0x18(%rbp),%ecx
lea    0xd3f(%rip),%rdx
call   1060 <snprintf@plt>
mov    -0x28(%rbp),%rdi
call   1030 <unlink@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1304 <fill_inodes+0x1a4>
mov    -0x8(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fill_inodes>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    0x2e6b(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%r14
mov    %rsi,%rax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r14
mov    %r14,%rsp
lea    0xed4(%rip),%rdx
xor    %r12d,%r12d
mov    %r14,%rdi
xor    %ecx,%ecx
call   1060 <snprintf@plt>
mov    0x2e52(%rip),%rax
mov    0x2e43(%rip),%r13
mov    0x0(%r13),%esi
or     (%rax),%esi
mov    0x2e16(%rip),%rbx
or     (%rbx),%esi
mov    %r14,%rdi
mov    $0x180,%edx
call   1080 <open@plt>
test   %eax,%eax
js     1222 <fill_inodes+0xc2>
xor    %r12d,%r12d
lea    0xe8f(%rip),%r15
nopw   0x0(%rax,%rax,1)
mov    %eax,%edi
call   1070 <close@plt>
add    $0x1,%r12d
mov    0x2dee(%rip),%rax
mov    (%rax),%esi
mov    %r14,%rdi
mov    %r15,%rdx
mov    %r12d,%ecx
call   1060 <snprintf@plt>
mov    0x0(%r13),%esi
mov    0x2deb(%rip),%rax
or     (%rax),%esi
or     (%rbx),%esi
mov    %r14,%rdi
mov    $0x180,%edx
call   1080 <open@plt>
test   %eax,%eax
jns    11e0 <fill_inodes+0x80>
mov    0x2d97(%rip),%rax
mov    (%rax),%rax
mov    0x2d85(%rip),%rcx
cmp    (%rcx),%rax
jne    1294 <fill_inodes+0x134>
mov    %rcx,%r13
mov    $0xc8,%r15d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    0x2d99(%rip),%rax
mov    (%rax),%esi
mov    0x2d98(%rip),%rax
or     (%rax),%esi
mov    0x2d67(%rip),%rax
or     (%rax),%esi
mov    %r14,%rdi
mov    $0x180,%edx
call   1080 <open@plt>
test   %eax,%eax
jns    129d <fill_inodes+0x13d>
mov    0x2d3d(%rip),%rax
mov    (%rax),%rax
cmp    0x0(%r13),%rax
jne    12b9 <fill_inodes+0x159>
add    $0xffffffff,%r15d
jne    1250 <fill_inodes+0xf0>
jmp    12c8 <fill_inodes+0x168>
lea    0xd65(%rip),%rdi
jmp    12c0 <fill_inodes+0x160>
mov    %eax,%ebx
lea    0xd93(%rip),%rdi
mov    %r14,%rsi
mov    %eax,%edx
call   1050 <warnx@plt>
mov    %ebx,%edi
call   1070 <close@plt>
jmp    12c8 <fill_inodes+0x168>
lea    0xd56(%rip),%rdi
mov    %r14,%rsi
call   1040 <warn@plt>
test   %r12d,%r12d
mov    0x2d0e(%rip),%r13
je     1301 <fill_inodes+0x1a1>
xor    %ebx,%ebx
lea    0xd89(%rip),%r15
nopl   (%rax)
mov    0x0(%r13),%esi
mov    %r14,%rdi
mov    %r15,%rdx
mov    %ebx,%ecx
call   1060 <snprintf@plt>
mov    %r14,%rdi
call   1030 <unlink@plt>
add    $0x1,%ebx
cmp    %ebx,%r12d
jne    12e0 <fill_inodes+0x180>
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@PATH_MAX = global i32 0
@.str = [3 x i8] c"%d\00"
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@O_RDWR = global i32 0
@errno = global i64 0
@ENOSPC = global i64 0
@.str.1 = [22 x i8] c"fill_inodes: open(%s)\00"
@.str.2 = [35 x i8] c"fill_inodes: open(%s) after ENOSPC\00"
@.str.3 = [48 x i8] c"fill_inodes: open(%s) after ENOSPC returned %d\00"
define void @fill_inodes() {
%1 = alloca i8*
%2 = alloca i64
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = load i32, i32* @PATH_MAX
%7 = zext i32 %6 to i64
%8 = call i8* @llvm.stacksave()
store i8* %8, i8** %1
%9 = alloca i8, i64 %7
store i64 %7, i64* %2
store i32 0, i32* %4
br label %10
10: ; preds = %24, %0
br label %11
11: ; preds = %10
%12 = load i32, i32* @PATH_MAX
%13 = load i32, i32* %4
%14 = call i32 @snprintf(i8* %9, i32 %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %13)
%15 = load i32, i32* @O_CREAT
%16 = load i32, i32* @O_TRUNC
%17 = or i32 %15, %16
%18 = load i32, i32* @O_RDWR
%19 = or i32 %17, %18
%20 = call i32 @open(i8* %9, i32 %19, i32 384)
store i32 %20, i32* %3
%21 = load i32, i32* %3
%22 = icmp slt i32 %21, 0
br i1 %22, label %23, label %24
23: ; preds = %11
br label %29
24: ; preds = %11
%25 = load i32, i32* %3
%26 = call i32 @close(i32 %25)
%27 = load i32, i32* %4
%28 = add nsw i32 %27, 1
store i32 %28, i32* %4
br label %10
29: ; preds = %23
%30 = load i32, i32* %4
store i32 %30, i32* %5
%31 = load i64, i64* @errno
%32 = load i64, i64* @ENOSPC
%33 = icmp ne i64 %31, %32
br i1 %33, label %34, label %36
34: ; preds = %29
%35 = call i32 @warn(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8* %9)
br label %68
36: ; preds = %29
store i32 0, i32* %4
br label %37
37: ; preds = %64, %36
%38 = load i32, i32* %4
%39 = icmp slt i32 %38, 200
br i1 %39, label %40, label %67
40: ; preds = %37
%41 = load i32, i32* @O_CREAT
%42 = load i32, i32* @O_TRUNC
%43 = or i32 %41, %42
%44 = load i32, i32* @O_RDWR
%45 = or i32 %43, %44
%46 = call i32 @open(i8* %9, i32 %45, i32 384)
store i32 %46, i32* %3
%47 = load i32, i32* %3
%48 = icmp slt i32 %47, 0
br i1 %48, label %49, label %55
49: ; preds = %40
%50 = load i64, i64* @errno
%51 = load i64, i64* @ENOSPC
%52 = icmp ne i64 %50, %51
br i1 %52, label %53, label %55
53: ; preds = %49
%54 = call i32 @warn(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0), i8* %9)
br label %68
55: ; preds = %49, %40
%56 = load i32, i32* %3
%57 = icmp sge i32 %56, 0
br i1 %57, label %58, label %63
58: ; preds = %55
%59 = load i32, i32* %3
%60 = call i32 @warnx(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.3, i64 0, i64 0), i8* %9, i32 %59)
%61 = load i32, i32* %3
%62 = call i32 @close(i32 %61)
br label %68
63: ; preds = %55
br label %64
64: ; preds = %63
%65 = load i32, i32* %4
%66 = add nsw i32 %65, 1
store i32 %66, i32* %4
br label %37
67: ; preds = %37
br label %68
68: ; preds = %67, %58, %53, %34
store i32 0, i32* %4
br label %69
69: ; preds = %78, %68
%70 = load i32, i32* %4
%71 = load i32, i32* %5
%72 = icmp slt i32 %70, %71
br i1 %72, label %73, label %81
73: ; preds = %69
%74 = load i32, i32* @PATH_MAX
%75 = load i32, i32* %4
%76 = call i32 @snprintf(i8* %9, i32 %74, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %75)
%77 = call i32 @unlink(i8* %9)
br label %78
78: ; preds = %73
%79 = load i32, i32* %4
%80 = add nsw i32 %79, 1
store i32 %80, i32* %4
br label %69
81: ; preds = %69
%82 = load i8*, i8** %1
ret void
}

LLVM IR (-O2):
@PATH_MAX = global i32 0
@.str = [3 x i8] c"%d\00"
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@O_RDWR = global i32 0
@errno = global i64 0
@ENOSPC = global i64 0
@.str.1 = [22 x i8] c"fill_inodes: open(%s)\00"
@.str.2 = [35 x i8] c"fill_inodes: open(%s) after ENOSPC\00"
@.str.3 = [48 x i8] c"fill_inodes: open(%s) after ENOSPC returned %d\00"
define void @fill_inodes() {
%1 = load i32, i32* @PATH_MAX
%2 = zext i32 %1 to i64
%3 = alloca i8, i64 %2
%4 = call i32 @snprintf(i8* %3, i32 %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 0)
%5 = load i32, i32* @O_CREAT
%6 = load i32, i32* @O_TRUNC
%7 = or i32 %6, %5
%8 = load i32, i32* @O_RDWR
%9 = or i32 %7, %8
%10 = call i32 @open(i8* %3, i32 %9, i32 384)
%11 = icmp slt i32 %10, 0
br i1 %11, label %26, label %12
12: ; preds = %0, %12
%13 = phi i32 [ %24, %12 ], [ %10, %0 ]
%14 = phi i32 [ %16, %12 ], [ 0, %0 ]
%15 = call i32 @close(i32 %13)
%16 = add nuw nsw i32 %14, 1
%17 = load i32, i32* @PATH_MAX
%18 = call i32 @snprintf(i8* %3, i32 %17, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %16)
%19 = load i32, i32* @O_CREAT
%20 = load i32, i32* @O_TRUNC
%21 = or i32 %20, %19
%22 = load i32, i32* @O_RDWR
%23 = or i32 %21, %22
%24 = call i32 @open(i8* %3, i32 %23, i32 384)
%25 = icmp slt i32 %24, 0
br i1 %25, label %26, label %12
26: ; preds = %12, %0
%27 = phi i32 [ 0, %0 ], [ %16, %12 ]
%28 = load i64, i64* @errno
%29 = load i64, i64* @ENOSPC
%30 = icmp eq i64 %28, %29
br i1 %30, label %36, label %31
31: ; preds = %26
%32 = call i32 @warn(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8* %3)
br label %54
33: ; preds = %45
%34 = add nuw nsw i32 %37, 1
%35 = icmp eq i32 %34, 200
br i1 %35, label %54, label %36
36: ; preds = %26, %33
%37 = phi i32 [ %34, %33 ], [ 0, %26 ]
%38 = load i32, i32* @O_CREAT
%39 = load i32, i32* @O_TRUNC
%40 = or i32 %39, %38
%41 = load i32, i32* @O_RDWR
%42 = or i32 %40, %41
%43 = call i32 @open(i8* %3, i32 %42, i32 384)
%44 = icmp slt i32 %43, 0
br i1 %44, label %45, label %51
45: ; preds = %36
%46 = load i64, i64* @errno
%47 = load i64, i64* @ENOSPC
%48 = icmp eq i64 %46, %47
br i1 %48, label %33, label %49
49: ; preds = %45
%50 = call i32 @warn(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0), i8* %3)
br label %54
51: ; preds = %36
%52 = call i32 @warnx(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.3, i64 0, i64 0), i8* %3, i32 %43)
%53 = call i32 @close(i32 %43)
br label %54
54: ; preds = %33, %51, %49, %31
%55 = icmp eq i32 %27, 0
br i1 %55, label %63, label %56
56: ; preds = %54, %56
%57 = phi i32 [ %61, %56 ], [ 0, %54 ]
%58 = load i32, i32* @PATH_MAX
%59 = call i32 @snprintf(i8* %3, i32 %58, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %57)
%60 = call i32 @unlink(i8* %3)
%61 = add nuw nsw i32 %57, 1
%62 = icmp eq i32 %61, %27
br i1 %62, label %63, label %56
63: ; preds = %56, %54
ret void
}