#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 /*<<< orphan*/ st_mode;
};
struct rlimit {
  int rlim_cur;
  int rlim_max;
};
typedef int /*<<< orphan*/ name;

/* Variables and functions */
int O_CREAT;
int O_WRONLY;
int /*<<< orphan*/ RLIMIT_NOFILE;
int R_OK;
int /*<<< orphan*/ S_ISDIR(int /*<<< orphan*/);
int W_OK;
scalar_t__ access(char *, int);
int atoi(char *);
scalar_t__ chdir(char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int *malloc(int);
int open(char *, int, int);
scalar_t__ setrlimit(int /*<<< orphan*/, struct rlimit *);
int /*<<< orphan*/ snprintf(char *, int, char *, int);
scalar_t__ stat(char *, struct stat *);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  int i;
  int nfiles;
  int *fds;
  char *dir;
  struct stat statbuf;
  char name[16];
  struct rlimit rlim;
  if (argc != 3) {
    fprintf(stderr, "Usage: opentest <directory> <num_files>\n");
    exit(1);
  }
  dir = argv[1];
  nfiles = atoi(argv[2]);
  if ((nfiles <= 0) || (nfiles > 65536)) {
    fprintf(stderr, "num_files must be between 1 and 65536\n");
    exit(1);
  }
  if (stat(dir, &statbuf)) {
    fprintf(stderr, "Cannot stat %s\n", dir);
    exit(1);
  }
  if (!S_ISDIR(statbuf.st_mode)) {
    fprintf(stderr, "%s is not a directory!\n", dir);
    exit(1);
  }
  if (access(dir, R_OK | W_OK)) {
    fprintf(stderr, "No access to %s\n", dir);
    exit(1);
  }
  fds = malloc(nfiles * sizeof(int));
  if (fds == 0) {
    fprintf(stderr, "Unable to malloc array of %d fds\n", nfiles);
    exit(1);
  }
  if (chdir(dir)) {
    fprintf(stderr, "Cannot chdir to %s\n", dir);
    exit(1);
  }
  rlim.rlim_cur = nfiles + 10;
  rlim.rlim_max = nfiles + 10;
  if (setrlimit(RLIMIT_NOFILE, &rlim)) {
    fprintf(stderr, "Unable to raise RLIMIT_NOFILE to %ld\n", rlim.rlim_cur);
    exit(1);
  }
  for (i = 0; i < nfiles; i++) {
    snprintf(name, sizeof(name), "%d", i);
    fds[i] = open(name, O_WRONLY | O_CREAT, 0666);
    if (fds[i] < 0) {
      fprintf(stderr, "Unable to open %d fd\n", i);
      exit(1);
    }
  }
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     11f1 <main+0x41>
mov    0x2df1(%rip),%rax
mov    (%rax),%edi
lea    0xe20(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   10c0 <atoi@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jle    1224 <main+0x74>
cmpl   $0x10000,-0x18(%rbp)
jle    1245 <main+0x95>
mov    0x2d9d(%rip),%rax
mov    (%rax),%edi
lea    0xdf5(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    -0x28(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1070 <stat@plt>
cmp    $0x0,%rax
je     1281 <main+0xd1>
mov    0x2d65(%rip),%rax
mov    (%rax),%edi
mov    -0x28(%rbp),%rdx
lea    0xde0(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    -0x30(%rbp),%edi
call   1040 <S_ISDIR@plt>
cmp    $0x0,%eax
jne    12b7 <main+0x107>
mov    0x2d2f(%rip),%rax
mov    (%rax),%edi
mov    -0x28(%rbp),%rdx
lea    0xdba(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    -0x28(%rbp),%rdi
mov    0x2cfe(%rip),%rax
mov    (%rax),%esi
mov    0x2d0d(%rip),%rax
or     (%rax),%esi
call   10b0 <access@plt>
cmp    $0x0,%rax
je     1301 <main+0x151>
mov    0x2ce5(%rip),%rax
mov    (%rax),%edi
mov    -0x28(%rbp),%rdx
lea    0xd88(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
movslq -0x18(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1080 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1343 <main+0x193>
mov    0x2ca2(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%edx
lea    0xd57(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    -0x28(%rbp),%rdi
call   1030 <chdir@plt>
cmp    $0x0,%rax
je     137b <main+0x1cb>
mov    0x2c6b(%rip),%rax
mov    (%rax),%edi
mov    -0x28(%rbp),%rdx
lea    0xd41(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    -0x18(%rbp),%eax
add    $0xa,%eax
mov    %eax,-0x48(%rbp)
mov    -0x18(%rbp),%eax
add    $0xa,%eax
mov    %eax,-0x44(%rbp)
mov    0x2c4c(%rip),%rax
mov    (%rax),%edi
lea    -0x48(%rbp),%rsi
call   1090 <setrlimit@plt>
cmp    $0x0,%rax
je     13cd <main+0x21d>
mov    0x2c18(%rip),%rax
mov    (%rax),%edi
mov    -0x48(%rbp),%edx
lea    0xd03(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    146e <main+0x2be>
lea    -0x40(%rbp),%rdi
mov    -0x14(%rbp),%ecx
mov    $0x10,%esi
lea    0xcf2(%rip),%rdx
call   1050 <snprintf@plt>
lea    -0x40(%rbp),%rdi
mov    0x2bad(%rip),%rax
mov    (%rax),%esi
mov    0x2bec(%rip),%rax
or     (%rax),%esi
mov    $0x1b6,%edx
call   10a0 <open@plt>
mov    %eax,%edx
mov    -0x20(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x20(%rbp),%rax
movslq -0x14(%rbp),%rcx
cmpl   $0x0,(%rax,%rcx,4)
jge    145b <main+0x2ab>
mov    0x2b8a(%rip),%rax
mov    (%rax),%edi
mov    -0x14(%rbp),%edx
lea    0xc9e(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
jmp    1460 <main+0x2b0>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    13d4 <main+0x224>
xor    %edi,%edi
call   10d0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
cmp    $0x3,%edi
jne    11f3 <main+0x43>
mov    0x8(%rsi),%r14
mov    0x10(%rsi),%rdi
call   10c0 <atoi@plt>
mov    %eax,%r15d
lea    -0x10001(%r15),%eax
cmp    $0xfffeffff,%eax
ja     1214 <main+0x64>
mov    0x2de0(%rip),%rax
mov    (%rax),%edi
lea    0xe38(%rip),%rsi
jmp    1203 <main+0x53>
mov    0x2dce(%rip),%rax
mov    (%rax),%edi
lea    0xdfd(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
lea    0x8(%rsp),%rsi
mov    %r14,%rdi
call   1070 <stat@plt>
test   %rax,%rax
jne    1248 <main+0x98>
mov    0x8(%rsp),%edi
call   1040 <S_ISDIR@plt>
test   %eax,%eax
jne    125d <main+0xad>
mov    0x2d8e(%rip),%rax
mov    (%rax),%edi
lea    0xe1d(%rip),%rsi
jmp    1361 <main+0x1b1>
mov    0x2d79(%rip),%rax
mov    (%rax),%edi
lea    0xdf8(%rip),%rsi
jmp    1361 <main+0x1b1>
mov    0x2d5c(%rip),%rax
mov    0x2d6d(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    %r14,%rdi
call   10b0 <access@plt>
test   %rax,%rax
jne    12a6 <main+0xf6>
lea    0x0(,%r15,4),%edi
call   1080 <malloc@plt>
test   %rax,%rax
jne    12bb <main+0x10b>
mov    0x2d33(%rip),%rax
mov    (%rax),%edi
lea    0xdeb(%rip),%rsi
mov    %r15d,%edx
jmp    139c <main+0x1ec>
mov    0x2d1b(%rip),%rax
mov    (%rax),%edi
lea    0xdc2(%rip),%rsi
jmp    1361 <main+0x1b1>
mov    %rax,%r12
mov    %r14,%rdi
call   1030 <chdir@plt>
test   %rax,%rax
jne    1351 <main+0x1a1>
lea    0xa(%r15),%eax
mov    %eax,(%rsp)
mov    %eax,0x4(%rsp)
mov    0x2cff(%rip),%rax
mov    (%rax),%edi
mov    %rsp,%rsi
call   1090 <setrlimit@plt>
test   %rax,%rax
jne    1375 <main+0x1c5>
mov    %r15d,%r13d
xor    %ebx,%ebx
lea    0x10(%rsp),%r15
mov    0x2cab(%rip),%rbp
mov    0x2cec(%rip),%r14
nopl   0x0(%rax)
mov    %r15,%rdi
mov    $0x10,%esi
lea    0xdc6(%rip),%rdx
mov    %ebx,%ecx
call   1050 <snprintf@plt>
mov    (%r14),%esi
or     0x0(%rbp),%esi
mov    %r15,%rdi
mov    $0x1b6,%edx
call   10a0 <open@plt>
mov    %eax,(%r12,%rbx,4)
test   %eax,%eax
js     138a <main+0x1da>
add    $0x1,%rbx
cmp    %rbx,%r13
jne    1310 <main+0x160>
xor    %edi,%edi
call   10d0 <exit@plt>
mov    0x2c70(%rip),%rax
mov    (%rax),%edi
lea    0xd4a(%rip),%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    0x2c4c(%rip),%rax
mov    (%rax),%edi
mov    (%rsp),%edx
lea    0xd37(%rip),%rsi
jmp    139c <main+0x1ec>
mov    0x2c37(%rip),%rax
mov    (%rax),%edi
lea    0xd4e(%rip),%rsi
mov    %ebx,%edx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>

LLVM IR (-O0):
%struct.stat = type { i32 }
%struct.rlimit = type { i32, i32 }
@stderr = global i32 0
@.str = [41 x i8] c"Usage: opentest <directory> <num_files>\0A\00"
@.str.1 = [39 x i8] c"num_files must be between 1 and 65536\0A\00"
@.str.2 = [16 x i8] c"Cannot stat %s\0A\00"
@.str.3 = [24 x i8] c"%s is not a directory!\0A\00"
@R_OK = global i32 0
@W_OK = global i32 0
@.str.4 = [17 x i8] c"No access to %s\0A\00"
@.str.5 = [34 x i8] c"Unable to malloc array of %d fds\0A\00"
@.str.6 = [20 x i8] c"Cannot chdir to %s\0A\00"
@RLIMIT_NOFILE = global i32 0
@.str.7 = [38 x i8] c"Unable to raise RLIMIT_NOFILE to %ld\0A\00"
@.str.8 = [3 x i8] c"%d\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@.str.9 = [22 x i8] c"Unable to open %d fd\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 i32*
%9 = alloca i8*
%10 = alloca %struct.stat
%11 = alloca [16 x i8]
%12 = alloca %struct.rlimit
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = load i32, i32* %4
%14 = icmp ne i32 %13, 3
br i1 %14, label %15, label %19
15: ; preds = %2
%16 = load i32, i32* @stderr
%17 = call i32 (i32, i8*, ...) @fprintf(i32 %16, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0))
%18 = call i32 @exit(i32 1)
unreachable
19: ; preds = %2
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
store i8* %22, i8** %9
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 2
%25 = load i8*, i8** %24
%26 = call i32 @atoi(i8* %25)
store i32 %26, i32* %7
%27 = load i32, i32* %7
%28 = icmp sle i32 %27, 0
br i1 %28, label %32, label %29
29: ; preds = %19
%30 = load i32, i32* %7
%31 = icmp sgt i32 %30, 65536
br i1 %31, label %32, label %36
32: ; preds = %29, %19
%33 = load i32, i32* @stderr
%34 = call i32 (i32, i8*, ...) @fprintf(i32 %33, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0))
%35 = call i32 @exit(i32 1)
unreachable
36: ; preds = %29
%37 = load i8*, i8** %9
%38 = call i64 @stat(i8* %37, %struct.stat* %10)
%39 = icmp ne i64 %38, 0
br i1 %39, label %40, label %45
40: ; preds = %36
%41 = load i32, i32* @stderr
%42 = load i8*, i8** %9
%43 = call i32 (i32, i8*, ...) @fprintf(i32 %41, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i8* %42)
%44 = call i32 @exit(i32 1)
unreachable
45: ; preds = %36
%46 = getelementptr inbounds %struct.stat, %struct.stat* %10, i32 0, i32 0
%47 = load i32, i32* %46
%48 = call i32 @S_ISDIR(i32 %47)
%49 = icmp ne i32 %48, 0
br i1 %49, label %55, label %50
50: ; preds = %45
%51 = load i32, i32* @stderr
%52 = load i8*, i8** %9
%53 = call i32 (i32, i8*, ...) @fprintf(i32 %51, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i8* %52)
%54 = call i32 @exit(i32 1)
unreachable
55: ; preds = %45
%56 = load i8*, i8** %9
%57 = load i32, i32* @R_OK
%58 = load i32, i32* @W_OK
%59 = or i32 %57, %58
%60 = call i64 @access(i8* %56, i32 %59)
%61 = icmp ne i64 %60, 0
br i1 %61, label %62, label %67
62: ; preds = %55
%63 = load i32, i32* @stderr
%64 = load i8*, i8** %9
%65 = call i32 (i32, i8*, ...) @fprintf(i32 %63, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0), i8* %64)
%66 = call i32 @exit(i32 1)
unreachable
67: ; preds = %55
%68 = load i32, i32* %7
%69 = sext i32 %68 to i64
%70 = mul i64 %69, 4
%71 = trunc i64 %70 to i32
%72 = call i32* @malloc(i32 %71)
store i32* %72, i32** %8
%73 = load i32*, i32** %8
%74 = icmp eq i32* %73, null
br i1 %74, label %75, label %80
75: ; preds = %67
%76 = load i32, i32* @stderr
%77 = load i32, i32* %7
%78 = call i32 (i32, i8*, ...) @fprintf(i32 %76, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.5, i64 0, i64 0), i32 %77)
%79 = call i32 @exit(i32 1)
unreachable
80: ; preds = %67
%81 = load i8*, i8** %9
%82 = call i64 @chdir(i8* %81)
%83 = icmp ne i64 %82, 0
br i1 %83, label %84, label %89
84: ; preds = %80
%85 = load i32, i32* @stderr
%86 = load i8*, i8** %9
%87 = call i32 (i32, i8*, ...) @fprintf(i32 %85, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.6, i64 0, i64 0), i8* %86)
%88 = call i32 @exit(i32 1)
unreachable
89: ; preds = %80
%90 = load i32, i32* %7
%91 = add nsw i32 %90, 10
%92 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %12, i32 0, i32 0
store i32 %91, i32* %92
%93 = load i32, i32* %7
%94 = add nsw i32 %93, 10
%95 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %12, i32 0, i32 1
store i32 %94, i32* %95
%96 = load i32, i32* @RLIMIT_NOFILE
%97 = call i64 @setrlimit(i32 %96, %struct.rlimit* %12)
%98 = icmp ne i64 %97, 0
br i1 %98, label %99, label %105
99: ; preds = %89
%100 = load i32, i32* @stderr
%101 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %12, i32 0, i32 0
%102 = load i32, i32* %101
%103 = call i32 (i32, i8*, ...) @fprintf(i32 %100, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.7, i64 0, i64 0), i32 %102)
%104 = call i32 @exit(i32 1)
unreachable
105: ; preds = %89
store i32 0, i32* %6
br label %106
106: ; preds = %135, %105
%107 = load i32, i32* %6
%108 = load i32, i32* %7
%109 = icmp slt i32 %107, %108
br i1 %109, label %110, label %138
110: ; preds = %106
%111 = getelementptr inbounds [16 x i8], [16 x i8]* %11, i64 0, i64 0
%112 = load i32, i32* %6
%113 = call i32 @snprintf(i8* %111, i32 16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0), i32 %112)
%114 = getelementptr inbounds [16 x i8], [16 x i8]* %11, i64 0, i64 0
%115 = load i32, i32* @O_WRONLY
%116 = load i32, i32* @O_CREAT
%117 = or i32 %115, %116
%118 = call i32 @open(i8* %114, i32 %117, i32 438)
%119 = load i32*, i32** %8
%120 = load i32, i32* %6
%121 = sext i32 %120 to i64
%122 = getelementptr inbounds i32, i32* %119, i64 %121
store i32 %118, i32* %122
%123 = load i32*, i32** %8
%124 = load i32, i32* %6
%125 = sext i32 %124 to i64
%126 = getelementptr inbounds i32, i32* %123, i64 %125
%127 = load i32, i32* %126
%128 = icmp slt i32 %127, 0
br i1 %128, label %129, label %134
129: ; preds = %110
%130 = load i32, i32* @stderr
%131 = load i32, i32* %6
%132 = call i32 (i32, i8*, ...) @fprintf(i32 %130, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.9, i64 0, i64 0), i32 %131)
%133 = call i32 @exit(i32 1)
unreachable
134: ; preds = %110
br label %135
135: ; preds = %134
%136 = load i32, i32* %6
%137 = add nsw i32 %136, 1
store i32 %137, i32* %6
br label %106
138: ; preds = %106
%139 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
%struct.stat = type { i32 }
%struct.rlimit = type { i32, i32 }
@stderr = global i32 0
@.str = [41 x i8] c"Usage: opentest <directory> <num_files>\0A\00"
@.str.1 = [39 x i8] c"num_files must be between 1 and 65536\0A\00"
@.str.2 = [16 x i8] c"Cannot stat %s\0A\00"
@.str.3 = [24 x i8] c"%s is not a directory!\0A\00"
@R_OK = global i32 0
@W_OK = global i32 0
@.str.4 = [17 x i8] c"No access to %s\0A\00"
@.str.5 = [34 x i8] c"Unable to malloc array of %d fds\0A\00"
@.str.6 = [20 x i8] c"Cannot chdir to %s\0A\00"
@RLIMIT_NOFILE = global i32 0
@.str.7 = [38 x i8] c"Unable to raise RLIMIT_NOFILE to %ld\0A\00"
@.str.8 = [3 x i8] c"%d\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@.str.9 = [22 x i8] c"Unable to open %d fd\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.stat
%4 = alloca [16 x i8]
%5 = alloca %struct.rlimit
%6 = bitcast %struct.stat* %3 to i8*
%7 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 0
%8 = bitcast %struct.rlimit* %5 to i8*
%9 = icmp eq i32 %0, 3
br i1 %9, label %14, label %10
10: ; preds = %2
%11 = load i32, i32* @stderr
%12 = tail call i32 (i32, i8*, ...) @fprintf(i32 %11, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0))
%13 = tail call i32 @exit(i32 1)
unreachable
14: ; preds = %2
%15 = getelementptr inbounds i8*, i8** %1, i64 1
%16 = load i8*, i8** %15
%17 = getelementptr inbounds i8*, i8** %1, i64 2
%18 = load i8*, i8** %17
%19 = tail call i32 @atoi(i8* %18)
%20 = add i32 %19, -65537
%21 = icmp ult i32 %20, -65536
br i1 %21, label %22, label %26
22: ; preds = %14
%23 = load i32, i32* @stderr
%24 = tail call i32 (i32, i8*, ...) @fprintf(i32 %23, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0))
%25 = tail call i32 @exit(i32 1)
unreachable
26: ; preds = %14
%27 = call i64 @stat(i8* %16, %struct.stat* %3)
%28 = icmp eq i64 %27, 0
br i1 %28, label %33, label %29
29: ; preds = %26
%30 = load i32, i32* @stderr
%31 = call i32 (i32, i8*, ...) @fprintf(i32 %30, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i8* %16)
%32 = call i32 @exit(i32 1)
unreachable
33: ; preds = %26
%34 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%35 = load i32, i32* %34
%36 = call i32 @S_ISDIR(i32 %35)
%37 = icmp eq i32 %36, 0
br i1 %37, label %38, label %42
38: ; preds = %33
%39 = load i32, i32* @stderr
%40 = call i32 (i32, i8*, ...) @fprintf(i32 %39, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i8* %16)
%41 = call i32 @exit(i32 1)
unreachable
42: ; preds = %33
%43 = load i32, i32* @R_OK
%44 = load i32, i32* @W_OK
%45 = or i32 %44, %43
%46 = call i64 @access(i8* %16, i32 %45)
%47 = icmp eq i64 %46, 0
br i1 %47, label %52, label %48
48: ; preds = %42
%49 = load i32, i32* @stderr
%50 = call i32 (i32, i8*, ...) @fprintf(i32 %49, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0), i8* %16)
%51 = call i32 @exit(i32 1)
unreachable
52: ; preds = %42
%53 = shl nuw nsw i32 %19, 2
%54 = call i32* @malloc(i32 %53)
%55 = icmp eq i32* %54, null
br i1 %55, label %56, label %60
56: ; preds = %52
%57 = load i32, i32* @stderr
%58 = call i32 (i32, i8*, ...) @fprintf(i32 %57, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.5, i64 0, i64 0), i32 %19)
%59 = call i32 @exit(i32 1)
unreachable
60: ; preds = %52
%61 = call i64 @chdir(i8* %16)
%62 = icmp eq i64 %61, 0
br i1 %62, label %67, label %63
63: ; preds = %60
%64 = load i32, i32* @stderr
%65 = call i32 (i32, i8*, ...) @fprintf(i32 %64, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.6, i64 0, i64 0), i8* %16)
%66 = call i32 @exit(i32 1)
unreachable
67: ; preds = %60
%68 = add nuw nsw i32 %19, 10
%69 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %5, i64 0, i32 0
store i32 %68, i32* %69
%70 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %5, i64 0, i32 1
store i32 %68, i32* %70
%71 = load i32, i32* @RLIMIT_NOFILE
%72 = call i64 @setrlimit(i32 %71, %struct.rlimit* %5)
%73 = icmp eq i64 %72, 0
br i1 %73, label %74, label %76
74: ; preds = %67
%75 = zext i32 %19 to i64
br label %81
76: ; preds = %67
%77 = load i32, i32* @stderr
%78 = load i32, i32* %69
%79 = call i32 (i32, i8*, ...) @fprintf(i32 %77, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.7, i64 0, i64 0), i32 %78)
%80 = call i32 @exit(i32 1)
unreachable
81: ; preds = %74, %96
%82 = phi i64 [ 0, %74 ], [ %97, %96 ]
%83 = trunc i64 %82 to i32
%84 = call i32 @snprintf(i8* %7, i32 16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0), i32 %83)
%85 = load i32, i32* @O_WRONLY
%86 = load i32, i32* @O_CREAT
%87 = or i32 %86, %85
%88 = call i32 @open(i8* %7, i32 %87, i32 438)
%89 = getelementptr inbounds i32, i32* %54, i64 %82
store i32 %88, i32* %89
%90 = icmp slt i32 %88, 0
br i1 %90, label %91, label %96
91: ; preds = %81
%92 = trunc i64 %82 to i32
%93 = load i32, i32* @stderr
%94 = call i32 (i32, i8*, ...) @fprintf(i32 %93, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.9, i64 0, i64 0), i32 %92)
%95 = call i32 @exit(i32 1)
unreachable
96: ; preds = %81
%97 = add nuw nsw i64 %82, 1
%98 = icmp eq i64 %97, %75
br i1 %98, label %99, label %81
99: ; preds = %96
%100 = call i32 @exit(i32 0)
unreachable
}