#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 dirent {
  char *d_name;
};
typedef int /*<<< orphan*/ FILE;
typedef int /*<<< orphan*/ DIR;

/* Variables and functions */
int atoi(char *);
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
int /*<<< orphan*/ execlp(char *, char *, char *, char *, char *, char *,
                          char *, char *, char *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char *);
int *malloc(int);
int /*<<< orphan*/ *opendir(char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
struct dirent *readdir(int /*<<< orphan*/ *);
char *strcat(char *, char *);
scalar_t__ strcmp(char *, char *);
scalar_t__ strlen(char *);
int /*<<< orphan*/ waitpid(int, int /*<<< orphan*/ *, int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  if (argc < 3) {
    perror("The number of args is wrong!\n");
    exit(0);
  }
  int pid = 0;
  int len = 0;
  char buf[10000] = {0};
  int max = atoi(argv[1]);
  int *maxptr = malloc(sizeof(int) * max);
  int i = 0;
  char *dirname = strcat(argv[2], "/");
  DIR *dir;
  FILE *fp;
  struct dirent *ptr;
  dir = opendir(argv[2]);
  fp = fopen("list.txt", "w+");
  while ((ptr = readdir(dir)) != NULL) {
    fprintf(fp, "%s\n", ptr->d_name);
  }
  closedir(dir);
  fclose(fp);
  fp = fopen("list.txt", "r");
  while (fgets(buf, 10000, fp) != NULL) {
    len = (int)strlen(buf) - 1;
    if ('\n' == buf[len]) {
      buf[len] = '\0';
    }
    if ((strcmp(buf, ".") != 0) && (strcmp(buf, "..") != 0)) {
      pid = fork();
      if (0 == pid) {
        execlp("sort", "-n", "-k", "1", "-u", "-o", strcat(dirname, buf),
               dirname, (char *)NULL);
        printf("error2\n");
        return 1;
      } else {
        maxptr[i++] = pid;
      }
      if (i >= max) {
        for (int j = 0; j != max; ++j) {
          waitpid(maxptr[j], NULL, 0);
        }
      }
    }
  }
  fclose(fp);
  execlp("sort", "-n", "-k", "1", "-u", "-o", "list.txt", "list.txt",
         (char *)NULL);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2790,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    1266 <main+0x36>
lea    0xda6(%rip),%rdi
call   1100 <perror@plt>
xor    %edi,%edi
call   1130 <exit@plt>
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
lea    -0x2730(%rbp),%rdi
xor    %esi,%esi
mov    $0x2710,%edx
call   1070 <memset@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1110 <atoi@plt>
mov    %eax,-0x2734(%rbp)
movslq -0x2734(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   10d0 <malloc@plt>
mov    %rax,-0x2740(%rbp)
movl   $0x0,-0x2744(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xd52(%rip),%rsi
call   1120 <strcat@plt>
mov    %rax,-0x2750(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1040 <opendir@plt>
mov    %rax,-0x2758(%rbp)
lea    0xd2d(%rip),%rdi
lea    0xd2f(%rip),%rsi
call   10f0 <fopen@plt>
mov    %rax,-0x2760(%rbp)
mov    -0x2758(%rbp),%rdi
call   10c0 <readdir@plt>
mov    %rax,-0x2768(%rbp)
cmp    $0x0,%rax
je     1345 <main+0x115>
mov    -0x2760(%rbp),%rdi
mov    -0x2768(%rbp),%rax
mov    (%rax),%rdx
lea    0xcf1(%rip),%rsi
call   10b0 <fprintf@plt>
jmp    1306 <main+0xd6>
mov    -0x2758(%rbp),%rdi
call   1080 <closedir@plt>
mov    -0x2760(%rbp),%rdi
call   1030 <fclose@plt>
lea    0xcbc(%rip),%rdi
lea    0xcc5(%rip),%rsi
call   10f0 <fopen@plt>
mov    %rax,-0x2760(%rbp)
lea    -0x2730(%rbp),%rdi
mov    -0x2760(%rbp),%rdx
mov    $0x2710,%esi
call   1090 <fgets@plt>
cmp    $0x0,%rax
je     1526 <main+0x2f6>
lea    -0x2730(%rbp),%rdi
call   1050 <strlen@plt>
sub    $0x1,%eax
mov    %eax,-0x18(%rbp)
movslq -0x18(%rbp),%rax
movsbl -0x2730(%rbp,%rax,1),%ecx
ff
mov    $0xa,%eax
cmp    %ecx,%eax
jne    13d0 <main+0x1a0>
movslq -0x18(%rbp),%rax
movb   $0x0,-0x2730(%rbp,%rax,1)
lea    -0x2730(%rbp),%rdi
lea    0xc55(%rip),%rsi
call   10a0 <strcmp@plt>
cmp    $0x0,%rax
je     1521 <main+0x2f1>
lea    -0x2730(%rbp),%rdi
lea    0xc37(%rip),%rsi
call   10a0 <strcmp@plt>
cmp    $0x0,%rax
je     1521 <main+0x2f1>
mov    $0x0,%al
call   1150 <fork@plt>
mov    %eax,-0x14(%rbp)
xor    %eax,%eax
cmp    -0x14(%rbp),%eax
jne    1498 <main+0x268>
mov    -0x2750(%rbp),%rdi
lea    -0x2730(%rbp),%rsi
call   1120 <strcat@plt>
mov    %rax,%r10
mov    -0x2750(%rbp),%rax
lea    0xbf2(%rip),%rdi
lea    0xbf0(%rip),%rsi
lea    0xbec(%rip),%rdx
lea    0xbe8(%rip),%rcx
lea    0xbe3(%rip),%r8
lea    0xbdf(%rip),%r9
xor    %r11d,%r11d
mov    %r10,(%rsp)
mov    %rax,0x8(%rsp)
movq   $0x0,0x10(%rsp)
call   1140 <execlp@plt>
lea    0xbc1(%rip),%rdi
call   1060 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1584 <main+0x354>
mov    -0x14(%rbp),%edx
mov    -0x2740(%rbp),%rax
mov    -0x2744(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x2744(%rbp)
movslq %ecx,%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x2744(%rbp),%eax
cmp    -0x2734(%rbp),%eax
jl     151c <main+0x2ec>
movl   $0x0,-0x276c(%rbp)
mov    -0x276c(%rbp),%eax
cmp    -0x2734(%rbp),%eax
je     1517 <main+0x2e7>
mov    -0x2740(%rbp),%rax
movslq -0x276c(%rbp),%rcx
mov    (%rax,%rcx,4),%edi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   10e0 <waitpid@plt>
mov    -0x276c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x276c(%rbp)
jmp    14d5 <main+0x2a5>
jmp    151c <main+0x2ec>
jmp    1521 <main+0x2f1>
jmp    1377 <main+0x147>
mov    -0x2760(%rbp),%rdi
call   1030 <fclose@plt>
lea    0xafc(%rip),%rdi
lea    0xafa(%rip),%rsi
lea    0xaf6(%rip),%rdx
lea    0xaf2(%rip),%rcx
lea    0xaed(%rip),%r8
lea    0xae9(%rip),%r9
lea    0xabd(%rip),%rax
xor    %r10d,%r10d
mov    %rax,(%rsp)
mov    %rax,0x8(%rsp)
movq   $0x0,0x10(%rsp)
call   1140 <execlp@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x2790,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x2728,%rsp
cmp    $0x2,%edi
jle    149d <main+0x26d>
mov    %rsi,%r14
lea    0x10(%rsp),%rdi
mov    $0x2710,%edx
xor    %esi,%esi
call   1070 <memset@plt>
mov    0x8(%r14),%rdi
call   1110 <atoi@plt>
mov    %rax,(%rsp)
lea    0x0(,%rax,4),%edi
call   10d0 <malloc@plt>
mov    %rax,%rbx
mov    0x10(%r14),%rbp
mov    %rbp,%rdi
call   1060 <strlen@plt>
mov    %rbp,0x8(%rsp)
movw   $0x2f,0x0(%rbp,%rax,1)
mov    0x10(%r14),%rdi
call   1050 <opendir@plt>
mov    %rax,%r14
lea    0xd79(%rip),%rdi
lea    0xd7b(%rip),%rsi
call   10f0 <fopen@plt>
mov    %rax,%rbp
mov    %r14,%rdi
call   10c0 <readdir@plt>
test   %rax,%rax
je     12eb <main+0xbb>
lea    0xd62(%rip),%r12
nopl   0x0(%rax,%rax,1)
mov    (%rax),%rdx
mov    %rbp,%rdi
mov    %r12,%rsi
call   10b0 <fprintf@plt>
mov    %r14,%rdi
call   10c0 <readdir@plt>
test   %rax,%rax
jne    12d0 <main+0xa0>
mov    %r14,%rdi
call   1080 <closedir@plt>
mov    %rbp,%rdi
call   1040 <fclose@plt>
lea    0xd1c(%rip),%rdi
lea    0xd25(%rip),%rsi
call   10f0 <fopen@plt>
mov    %rax,%r13
lea    0x10(%rsp),%rdi
mov    $0x2710,%esi
mov    %rax,%rdx
call   1090 <fgets@plt>
test   %rax,%rax
mov    (%rsp),%r12
je     13df <main+0x1af>
mov    %r12d,%r14d
lea    0x10(%rsp),%rbp
xor    %r15d,%r15d
jmp    1359 <main+0x129>
nopl   (%rax)
mov    %rbp,%rdi
mov    $0x2710,%esi
mov    %r13,%rdx
call   1090 <fgets@plt>
test   %rax,%rax
je     13df <main+0x1af>
mov    %rbp,%rdi
call   1060 <strlen@plt>
add    $0xffffffff,%eax
cltq
cmpb   $0xa,0x10(%rsp,%rax,1)
jne    1372 <main+0x142>
movb   $0x0,0x10(%rsp,%rax,1)
mov    %rbp,%rdi
lea    0xcb5(%rip),%rsi
call   10a0 <strcmp@plt>
test   %rax,%rax
je     1340 <main+0x110>
mov    %rbp,%rdi
lea    0xca0(%rip),%rsi
call   10a0 <strcmp@plt>
test   %rax,%rax
je     1340 <main+0x110>
xor    %eax,%eax
call   1150 <fork@plt>
test   %eax,%eax
je     143d <main+0x20d>
movslq %r15d,%rcx
add    $0x1,%r15d
mov    %eax,(%rbx,%rcx,4)
cmp    %r12d,%r15d
jl     1340 <main+0x110>
test   %r12d,%r12d
je     1340 <main+0x110>
xor    %r12d,%r12d
mov    (%rbx,%r12,4),%edi
xor    %esi,%esi
xor    %edx,%edx
call   10e0 <waitpid@plt>
add    $0x1,%r12
cmp    %r12,%r14
jne    13c0 <main+0x190>
mov    (%rsp),%r12
jmp    1340 <main+0x110>
mov    %r13,%rdi
call   1040 <fclose@plt>
sub    $0x8,%rsp
lea    0xc41(%rip),%rdi
lea    0xc3f(%rip),%rsi
lea    0xc3b(%rip),%rdx
lea    0xc37(%rip),%rcx
lea    0xc32(%rip),%r8
lea    0xc2e(%rip),%r9
push   $0x0
lea    0xc00(%rip),%rax
push   %rax
push   %rax
call   1140 <execlp@plt>
add    $0x20,%rsp
xor    %eax,%eax
add    $0x2728,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0x10(%rsp),%rsi
mov    0x8(%rsp),%rbx
mov    %rbx,%rdi
call   1120 <strcat@plt>
sub    $0x8,%rsp
lea    0xbd9(%rip),%rdi
lea    0xbd7(%rip),%rsi
lea    0xbd3(%rip),%rdx
lea    0xbcf(%rip),%rcx
lea    0xbca(%rip),%r8
lea    0xbc6(%rip),%r9
push   $0x0
push   %rbx
push   %rbx
call   1140 <execlp@plt>
add    $0x20,%rsp
lea    0xbb5(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%eax
jmp    142b <main+0x1fb>
lea    0xb5c(%rip),%rdi
call   1100 <perror@plt>
xor    %edi,%edi
call   1130 <exit@plt>

LLVM IR (-O0):
%struct.dirent = type { i8* }
@.str = [30 x i8] c"The number of args is wrong!\0A\00"
@.str.1 = [2 x i8] c"/\00"
@.str.2 = [9 x i8] c"list.txt\00"
@.str.3 = [3 x i8] c"w+\00"
@.str.4 = [4 x i8] c"%s\0A\00"
@.str.5 = [2 x i8] c"r\00"
@.str.6 = [2 x i8] c".\00"
@.str.7 = [3 x i8] c"..\00"
@.str.8 = [5 x i8] c"sort\00"
@.str.9 = [3 x i8] c"-n\00"
@.str.10 = [3 x i8] c"-k\00"
@.str.11 = [2 x i8] c"1\00"
@.str.12 = [3 x i8] c"-u\00"
@.str.13 = [3 x i8] c"-o\00"
@.str.14 = [8 x i8] c"error2\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 [10000 x i8]
%9 = alloca i32
%10 = alloca i32*
%11 = alloca i32
%12 = alloca i8*
%13 = alloca i32*
%14 = alloca i32*
%15 = alloca %struct.dirent*
%16 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%17 = load i32, i32* %4
%18 = icmp slt i32 %17, 3
br i1 %18, label %19, label %22
19: ; preds = %2
%20 = call i32 @perror(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
%21 = call i32 @exit(i32 0)
unreachable
22: ; preds = %2
store i32 0, i32* %6
store i32 0, i32* %7
%23 = bitcast [10000 x i8]* %8 to i8*
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 1
%26 = load i8*, i8** %25
%27 = call i32 @atoi(i8* %26)
store i32 %27, i32* %9
%28 = load i32, i32* %9
%29 = sext i32 %28 to i64
%30 = mul i64 4, %29
%31 = trunc i64 %30 to i32
%32 = call i32* @malloc(i32 %31)
store i32* %32, i32** %10
store i32 0, i32* %11
%33 = load i8**, i8*** %5
%34 = getelementptr inbounds i8*, i8** %33, i64 2
%35 = load i8*, i8** %34
%36 = call i8* @strcat(i8* %35, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i8* %36, i8** %12
%37 = load i8**, i8*** %5
%38 = getelementptr inbounds i8*, i8** %37, i64 2
%39 = load i8*, i8** %38
%40 = call i32* @opendir(i8* %39)
store i32* %40, i32** %13
%41 = call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
store i32* %41, i32** %14
br label %42
42: ; preds = %46, %22
%43 = load i32*, i32** %13
%44 = call %struct.dirent* @readdir(i32* %43)
store %struct.dirent* %44, %struct.dirent** %15
%45 = icmp ne %struct.dirent* %44, null
br i1 %45, label %46, label %52
46: ; preds = %42
%47 = load i32*, i32** %14
%48 = load %struct.dirent*, %struct.dirent** %15
%49 = getelementptr inbounds %struct.dirent, %struct.dirent* %48, i32 0, i32 0
%50 = load i8*, i8** %49
%51 = call i32 @fprintf(i32* %47, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %50)
br label %42
52: ; preds = %42
%53 = load i32*, i32** %13
%54 = call i32 @closedir(i32* %53)
%55 = load i32*, i32** %14
%56 = call i32 @fclose(i32* %55)
%57 = call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
store i32* %57, i32** %14
br label %58
58: ; preds = %125, %52
%59 = getelementptr inbounds [10000 x i8], [10000 x i8]* %8, i64 0, i64 0
%60 = load i32*, i32** %14
%61 = call i32* @fgets(i8* %59, i32 10000, i32* %60)
%62 = icmp ne i32* %61, null
br i1 %62, label %63, label %126
63: ; preds = %58
%64 = getelementptr inbounds [10000 x i8], [10000 x i8]* %8, i64 0, i64 0
%65 = call i64 @strlen(i8* %64)
%66 = trunc i64 %65 to i32
%67 = sub nsw i32 %66, 1
store i32 %67, i32* %7
%68 = load i32, i32* %7
%69 = sext i32 %68 to i64
%70 = getelementptr inbounds [10000 x i8], [10000 x i8]* %8, i64 0, i64 %69
%71 = load i8, i8* %70
%72 = sext i8 %71 to i32
%73 = icmp eq i32 10, %72
br i1 %73, label %74, label %78
74: ; preds = %63
%75 = load i32, i32* %7
%76 = sext i32 %75 to i64
%77 = getelementptr inbounds [10000 x i8], [10000 x i8]* %8, i64 0, i64 %76
store i8 0, i8* %77
br label %78
78: ; preds = %74, %63
%79 = getelementptr inbounds [10000 x i8], [10000 x i8]* %8, i64 0, i64 0
%80 = call i64 @strcmp(i8* %79, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%81 = icmp ne i64 %80, 0
br i1 %81, label %82, label %125
82: ; preds = %78
%83 = getelementptr inbounds [10000 x i8], [10000 x i8]* %8, i64 0, i64 0
%84 = call i64 @strcmp(i8* %83, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0))
%85 = icmp ne i64 %84, 0
br i1 %85, label %86, label %125
86: ; preds = %82
%87 = call i32 (...) @fork()
store i32 %87, i32* %6
%88 = load i32, i32* %6
%89 = icmp eq i32 0, %88
br i1 %89, label %90, label %97
90: ; preds = %86
%91 = load i8*, i8** %12
%92 = getelementptr inbounds [10000 x i8], [10000 x i8]* %8, i64 0, i64 0
%93 = call i8* @strcat(i8* %91, i8* %92)
%94 = load i8*, i8** %12
%95 = call i32 @execlp(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.10, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.11, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.12, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.13, i64 0, i64 0), i8* %93, i8* %94, i8* null)
%96 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.14, i64 0, i64 0))
store i32 1, i32* %3
br label %130
97: ; preds = %86
%98 = load i32, i32* %6
%99 = load i32*, i32** %10
%100 = load i32, i32* %11
%101 = add nsw i32 %100, 1
store i32 %101, i32* %11
%102 = sext i32 %100 to i64
%103 = getelementptr inbounds i32, i32* %99, i64 %102
store i32 %98, i32* %103
br label %104
104: ; preds = %97
%105 = load i32, i32* %11
%106 = load i32, i32* %9
%107 = icmp sge i32 %105, %106
br i1 %107, label %108, label %124
108: ; preds = %104
store i32 0, i32* %16
br label %109
109: ; preds = %120, %108
%110 = load i32, i32* %16
%111 = load i32, i32* %9
%112 = icmp ne i32 %110, %111
br i1 %112, label %113, label %123
113: ; preds = %109
%114 = load i32*, i32** %10
%115 = load i32, i32* %16
%116 = sext i32 %115 to i64
%117 = getelementptr inbounds i32, i32* %114, i64 %116
%118 = load i32, i32* %117
%119 = call i32 @waitpid(i32 %118, i32* null, i32 0)
br label %120
120: ; preds = %113
%121 = load i32, i32* %16
%122 = add nsw i32 %121, 1
store i32 %122, i32* %16
br label %109
123: ; preds = %109
br label %124
124: ; preds = %123, %104
br label %125
125: ; preds = %124, %82, %78
br label %58
126: ; preds = %58
%127 = load i32*, i32** %14
%128 = call i32 @fclose(i32* %127)
%129 = call i32 @execlp(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.10, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.11, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.12, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.13, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* null)
store i32 0, i32* %3
br label %130
130: ; preds = %126, %90
%131 = load i32, i32* %3
ret i32 %131
}

LLVM IR (-O2):
%struct.dirent = type { i8* }
@.str = [30 x i8] c"The number of args is wrong!\0A\00"
@.str.2 = [9 x i8] c"list.txt\00"
@.str.3 = [3 x i8] c"w+\00"
@.str.4 = [4 x i8] c"%s\0A\00"
@.str.5 = [2 x i8] c"r\00"
@.str.6 = [2 x i8] c".\00"
@.str.7 = [3 x i8] c"..\00"
@.str.8 = [5 x i8] c"sort\00"
@.str.9 = [3 x i8] c"-n\00"
@.str.10 = [3 x i8] c"-k\00"
@.str.11 = [2 x i8] c"1\00"
@.str.12 = [3 x i8] c"-u\00"
@.str.13 = [3 x i8] c"-o\00"
@str = [7 x i8] c"error2\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [10000 x i8]
%4 = icmp slt i32 %0, 3
br i1 %4, label %5, label %8
5: ; preds = %2
%6 = tail call i32 @perror(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
%7 = tail call i32 @exit(i32 0)
unreachable
8: ; preds = %2
%9 = getelementptr inbounds [10000 x i8], [10000 x i8]* %3, i64 0, i64 0
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = tail call i32 @atoi(i8* %11)
%13 = shl i32 %12, 2
%14 = tail call i32* @malloc(i32 %13)
%15 = getelementptr inbounds i8*, i8** %1, i64 2
%16 = load i8*, i8** %15
%17 = tail call i64 @strlen(i8* dereferenceable(1) %16)
%18 = getelementptr i8, i8* %16, i64 %17
%19 = bitcast i8* %18 to i16*
store i16 47, i16* %19
%20 = load i8*, i8** %15
%21 = tail call i32* @opendir(i8* %20)
%22 = tail call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%23 = tail call %struct.dirent* @readdir(i32* %21)
%24 = icmp eq %struct.dirent* %23, null
br i1 %24, label %32, label %25
25: ; preds = %8, %25
%26 = phi %struct.dirent* [ %30, %25 ], [ %23, %8 ]
%27 = getelementptr inbounds %struct.dirent, %struct.dirent* %26, i64 0, i32 0
%28 = load i8*, i8** %27
%29 = tail call i32 @fprintf(i32* %22, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %28)
%30 = tail call %struct.dirent* @readdir(i32* %21)
%31 = icmp eq %struct.dirent* %30, null
br i1 %31, label %32, label %25
32: ; preds = %25, %8
%33 = tail call i32 @closedir(i32* %21)
%34 = tail call i32 @fclose(i32* %22)
%35 = tail call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%36 = call i32* @fgets(i8* %9, i32 10000, i32* %35)
%37 = icmp eq i32* %36, null
br i1 %37, label %81, label %38
38: ; preds = %32
%39 = icmp eq i32 %12, 0
%40 = zext i32 %12 to i64
br label %41
41: ; preds = %38, %77
%42 = phi i32 [ 0, %38 ], [ %78, %77 ]
%43 = call i64 @strlen(i8* %9)
%44 = shl i64 %43, 32
%45 = add i64 %44, -4294967296
%46 = ashr exact i64 %45, 32
%47 = getelementptr inbounds [10000 x i8], [10000 x i8]* %3, i64 0, i64 %46
%48 = load i8, i8* %47
%49 = icmp eq i8 %48, 10
br i1 %49, label %50, label %51
50: ; preds = %41
store i8 0, i8* %47
br label %51
51: ; preds = %50, %41
%52 = call i64 @strcmp(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%53 = icmp eq i64 %52, 0
br i1 %53, label %77, label %54
54: ; preds = %51
%55 = call i64 @strcmp(i8* %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0))
%56 = icmp eq i64 %55, 0
br i1 %56, label %77, label %57
57: ; preds = %54
%58 = call i32 (...) @fork()
%59 = icmp eq i32 %58, 0
br i1 %59, label %60, label %64
60: ; preds = %57
%61 = call i8* @strcat(i8* dereferenceable(1) %16, i8* %9)
%62 = call i32 @execlp(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.10, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.11, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.12, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.13, i64 0, i64 0), i8* %16, i8* %16, i8* null)
%63 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str, i64 0, i64 0))
br label %84
64: ; preds = %57
%65 = add nsw i32 %42, 1
%66 = sext i32 %42 to i64
%67 = getelementptr inbounds i32, i32* %14, i64 %66
store i32 %58, i32* %67
%68 = icmp slt i32 %65, %12
%69 = or i1 %68, %39
br i1 %69, label %77, label %70
70: ; preds = %64, %70
%71 = phi i64 [ %75, %70 ], [ 0, %64 ]
%72 = getelementptr inbounds i32, i32* %14, i64 %71
%73 = load i32, i32* %72
%74 = call i32 @waitpid(i32 %73, i32* null, i32 0)
%75 = add nuw nsw i64 %71, 1
%76 = icmp eq i64 %75, %40
br i1 %76, label %77, label %70
77: ; preds = %70, %64, %54, %51
%78 = phi i32 [ %65, %64 ], [ %42, %54 ], [ %42, %51 ], [ %65, %70 ]
%79 = call i32* @fgets(i8* %9, i32 10000, i32* %35)
%80 = icmp eq i32* %79, null
br i1 %80, label %81, label %41
81: ; preds = %77, %32
%82 = call i32 @fclose(i32* %35)
%83 = call i32 @execlp(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.10, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.11, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.12, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.13, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* null)
br label %84
84: ; preds = %81, %60
%85 = phi i32 [ 1, %60 ], [ 0, %81 ]
ret i32 %85
}