#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 */
scalar_t__ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ sprintf(char *, char *, char *, ...);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
int /*<<< orphan*/ system(char *);
int main(int argv, char *args[]) {
  if (argv != 2) {
    return 1;
  }
  char cmd[1024];
  sprintf(cmd, "ls $HOME/%s>lsresult.txt", args[1]);
  system(cmd);
  FILE *fp = fopen("lsresult.txt", "r");
  if (feof(fp))
    printf("something\'s bad\n");
  sprintf(cmd, "mkdir \"$HOME/%s Sorted\"", args[1]);
  system(cmd);
  char filename[1024], f1[1024] = "______";
  while (1) {
    fscanf(fp, " %[^\n]s", filename);
    if (strcmp(f1, filename) == 0)
      break;
    int ext = strlen(filename) - 4;
    if (strcmp(".txt", filename + ext) == 0 ||
        strcmp(".dat", filename + ext) == 0) {
      sprintf(cmd, "sort -n \"$HOME/%s/%s\" -o \"$HOME/%s Sorted/%s\"", args[1],
              filename, args[1], filename);
      system(cmd);
    }
    strcpy(f1, filename);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11cf <main+0x2f>
movl   $0x1,-0x4(%rbp)
jmp    1397 <main+0x1f7>
lea    -0x410(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xe1b(%rip),%rsi
mov    $0x0,%al
call   10c0 <sprintf@plt>
lea    -0x410(%rbp),%rdi
call   1050 <system@plt>
lea    0xe0d(%rip),%rdi
lea    0xe13(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x418(%rbp)
mov    -0x418(%rbp),%rdi
call   10a0 <feof@plt>
cmp    $0x0,%rax
je     1234 <main+0x94>
lea    0xdec(%rip),%rdi
call   1060 <printf@plt>
lea    -0x410(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xde2(%rip),%rsi
mov    $0x0,%al
call   10c0 <sprintf@plt>
lea    -0x410(%rbp),%rdi
call   1050 <system@plt>
lea    -0xc20(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1070 <memset@plt>
movb   $0x5f,-0xc20(%rbp)
movb   $0x5f,-0xc1f(%rbp)
movb   $0x5f,-0xc1e(%rbp)
movb   $0x5f,-0xc1d(%rbp)
movb   $0x5f,-0xc1c(%rbp)
movb   $0x5f,-0xc1b(%rbp)
mov    -0x418(%rbp),%rdi
lea    -0x820(%rbp),%rdx
lea    0xd95(%rip),%rsi
call   1080 <fscanf@plt>
lea    -0xc20(%rbp),%rdi
lea    -0x820(%rbp),%rsi
call   1090 <strcmp@plt>
cmp    $0x0,%rax
jne    12d6 <main+0x136>
jmp    1390 <main+0x1f0>
lea    -0x820(%rbp),%rdi
call   1040 <strlen@plt>
sub    $0x4,%eax
mov    %eax,-0xc24(%rbp)
lea    -0x820(%rbp),%rsi
movslq -0xc24(%rbp),%rax
add    %rax,%rsi
lea    0xd11(%rip),%rdi
call   1090 <strcmp@plt>
cmp    $0x0,%rax
je     1339 <main+0x199>
lea    -0x820(%rbp),%rsi
movslq -0xc24(%rbp),%rax
add    %rax,%rsi
lea    0xd22(%rip),%rdi
call   1090 <strcmp@plt>
cmp    $0x0,%rax
jne    1378 <main+0x1d8>
lea    -0x410(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    -0x820(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%r8
lea    -0x820(%rbp),%r9
lea    0xcec(%rip),%rsi
mov    $0x0,%al
call   10c0 <sprintf@plt>
lea    -0x410(%rbp),%rdi
call   1050 <system@plt>
lea    -0xc20(%rbp),%rdi
lea    -0x820(%rbp),%rsi
call   1030 <strcpy@plt>
jmp    129a <main+0xfa>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xc30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
mov    $0x1,%eax
cmp    $0x2,%edi
jne    1356 <main+0x1b6>
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xc18,%rsp
mov    %rsi,%rbp
mov    0x8(%rsi),%rdx
lea    0xe33(%rip),%rsi
lea    0x410(%rsp),%rbx
mov    %rbx,%rdi
xor    %eax,%eax
call   10c0 <sprintf@plt>
mov    %rbx,%rdi
call   1060 <system@plt>
lea    0xe1e(%rip),%rdi
lea    0xe24(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   10a0 <feof@plt>
test   %rax,%rax
je     1216 <main+0x76>
lea    0xe5d(%rip),%rdi
call   1040 <puts@plt>
mov    %rbp,0x8(%rsp)
mov    0x8(%rbp),%rdx
lea    0xdf5(%rip),%rsi
lea    0x410(%rsp),%rbp
mov    %rbp,%rdi
xor    %eax,%eax
call   10c0 <sprintf@plt>
mov    %rbp,%rdi
call   1060 <system@plt>
lea    0x10(%rsp),%r14
mov    $0x400,%edx
mov    %r14,%rdi
xor    %esi,%esi
call   1070 <memset@plt>
movl   $0x5f5f5f5f,0x10(%rsp)
5f
movw   $0x5f5f,0x14(%rsp)
lea    0xdc9(%rip),%rsi
lea    0x810(%rsp),%rbp
mov    %rbx,%rdi
mov    %rbp,%rdx
call   1080 <fscanf@plt>
mov    %r14,%rdi
mov    %rbp,%rsi
call   1090 <strcmp@plt>
test   %rax,%rax
je     1343 <main+0x1a3>
lea    0x410(%rsp),%r15
lea    0x10(%rsp),%r13
lea    0xd8e(%rip),%r14
jmp    1304 <main+0x164>
nopw   0x0(%rax,%rax,1)
mov    0x8(%rsp),%rax
mov    0x8(%rax),%rdx
mov    %r15,%rdi
lea    0xd7d(%rip),%rsi
mov    %rbp,%rcx
mov    %rdx,%r8
mov    %rbp,%r9
xor    %eax,%eax
call   10c0 <sprintf@plt>
mov    %r15,%rdi
call   1060 <system@plt>
mov    %r13,%rdi
mov    %rbp,%rsi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %rbp,%rdx
call   1080 <fscanf@plt>
mov    %r13,%rdi
mov    %rbp,%rsi
call   1090 <strcmp@plt>
test   %rax,%rax
je     1343 <main+0x1a3>
mov    %rbp,%rdi
call   1050 <strlen@plt>
cltq
lea    (%rax,%rbp,1),%r12
add    $0xfffffffffffffffc,%r12
lea    0xcf7(%rip),%rdi
mov    %r12,%rsi
call   1090 <strcmp@plt>
test   %rax,%rax
je     12b0 <main+0x110>
lea    0xd0a(%rip),%rdi
mov    %r12,%rsi
call   1090 <strcmp@plt>
test   %rax,%rax
jne    12db <main+0x13b>
jmp    12b0 <main+0x110>
xor    %eax,%eax
add    $0xc18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [25 x i8] c"ls $HOME/%s>lsresult.txt\00"
@.str.1 = [13 x i8] c"lsresult.txt\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [17 x i8] c"something's bad\0A\00"
@.str.4 = [24 x i8] c"mkdir \22$HOME/%s Sorted\22\00"
@.str.5 = [8 x i8] c" %[^\0A]s\00"
@.str.6 = [5 x i8] c".txt\00"
@.str.7 = [5 x i8] c".dat\00"
@.str.8 = [46 x i8] c"sort -n \22$HOME/%s/%s\22 -o \22$HOME/%s Sorted/%s\22\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [1024 x i8]
%7 = alloca i32*
%8 = alloca [1024 x i8]
%9 = alloca [1024 x i8]
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* %4
%12 = icmp ne i32 %11, 2
br i1 %12, label %13, label %14
13: ; preds = %2
store i32 1, i32* %3
br label %88
14: ; preds = %2
%15 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
%19 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %15, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %18)
%20 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%21 = call i32 @system(i8* %20)
%22 = call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %22, i32** %7
%23 = load i32*, i32** %7
%24 = call i64 @feof(i32* %23)
%25 = icmp ne i64 %24, 0
br i1 %25, label %26, label %28
26: ; preds = %14
%27 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
br label %28
28: ; preds = %26, %14
%29 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%30 = load i8**, i8*** %5
%31 = getelementptr inbounds i8*, i8** %30, i64 1
%32 = load i8*, i8** %31
%33 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %29, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0), i8* %32)
%34 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%35 = call i32 @system(i8* %34)
%36 = bitcast [1024 x i8]* %9 to i8*
%37 = bitcast i8* %36 to [1024 x i8]*
%38 = getelementptr inbounds [1024 x i8], [1024 x i8]* %37, i32 0, i32 0
store i8 95, i8* %38
%39 = getelementptr inbounds [1024 x i8], [1024 x i8]* %37, i32 0, i32 1
store i8 95, i8* %39
%40 = getelementptr inbounds [1024 x i8], [1024 x i8]* %37, i32 0, i32 2
store i8 95, i8* %40
%41 = getelementptr inbounds [1024 x i8], [1024 x i8]* %37, i32 0, i32 3
store i8 95, i8* %41
%42 = getelementptr inbounds [1024 x i8], [1024 x i8]* %37, i32 0, i32 4
store i8 95, i8* %42
%43 = getelementptr inbounds [1024 x i8], [1024 x i8]* %37, i32 0, i32 5
store i8 95, i8* %43
br label %44
44: ; preds = %28, %83
%45 = load i32*, i32** %7
%46 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%47 = call i32 @fscanf(i32* %45, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i8* %46)
%48 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%49 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%50 = call i64 @strcmp(i8* %48, i8* %49)
%51 = icmp eq i64 %50, 0
br i1 %51, label %52, label %53
52: ; preds = %44
br label %87
53: ; preds = %44
%54 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%55 = call i32 @strlen(i8* %54)
%56 = sub nsw i32 %55, 4
store i32 %56, i32* %10
%57 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%58 = load i32, i32* %10
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds i8, i8* %57, i64 %59
%61 = call i64 @strcmp(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0), i8* %60)
%62 = icmp eq i64 %61, 0
br i1 %62, label %70, label %63
63: ; preds = %53
%64 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%65 = load i32, i32* %10
%66 = sext i32 %65 to i64
%67 = getelementptr inbounds i8, i8* %64, i64 %66
%68 = call i64 @strcmp(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0), i8* %67)
%69 = icmp eq i64 %68, 0
br i1 %69, label %70, label %83
70: ; preds = %63, %53
%71 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%72 = load i8**, i8*** %5
%73 = getelementptr inbounds i8*, i8** %72, i64 1
%74 = load i8*, i8** %73
%75 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%76 = load i8**, i8*** %5
%77 = getelementptr inbounds i8*, i8** %76, i64 1
%78 = load i8*, i8** %77
%79 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%80 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %71, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.8, i64 0, i64 0), i8* %74, i8* %75, i8* %78, i8* %79)
%81 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%82 = call i32 @system(i8* %81)
br label %83
83: ; preds = %70, %63
%84 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%85 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%86 = call i32 @strcpy(i8* %84, i8* %85)
br label %44
87: ; preds = %52
store i32 0, i32* %3
br label %88
88: ; preds = %87, %13
%89 = load i32, i32* %3
ret i32 %89
}

LLVM IR (-O2):
@.str = [25 x i8] c"ls $HOME/%s>lsresult.txt\00"
@.str.1 = [13 x i8] c"lsresult.txt\00"
@.str.2 = [2 x i8] c"r\00"
@.str.4 = [24 x i8] c"mkdir \22$HOME/%s Sorted\22\00"
@.str.5 = [8 x i8] c" %[^\0A]s\00"
@.str.6 = [5 x i8] c".txt\00"
@.str.7 = [5 x i8] c".dat\00"
@.str.8 = [46 x i8] c"sort -n \22$HOME/%s/%s\22 -o \22$HOME/%s Sorted/%s\22\00"
@str = [16 x i8] c"something's bad\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [1024 x i8]
%4 = alloca [1024 x i8]
%5 = alloca [1024 x i8]
%6 = icmp eq i32 %0, 2
br i1 %6, label %7, label %47
7: ; preds = %2
%8 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %8, i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %10)
%12 = call i32 @system(i8* %8)
%13 = tail call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%14 = tail call i64 @feof(i32* %13)
%15 = icmp eq i64 %14, 0
br i1 %15, label %18, label %16
16: ; preds = %7
%17 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str, i64 0, i64 0))
br label %18
18: ; preds = %16, %7
%19 = load i8*, i8** %9
%20 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %8, i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0), i8* %19)
%21 = call i32 @system(i8* %8)
%22 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%23 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%24 = call i32 @fscanf(i32* %13, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i8* %22)
%25 = call i64 @strcmp(i8* %23, i8* %22)
%26 = icmp eq i64 %25, 0
br i1 %26, label %46, label %27
27: ; preds = %18, %41
%28 = call i32 @strlen(i8* %22)
%29 = add nsw i32 %28, -4
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 %30
%32 = call i64 @strcmp(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0), i8* %31)
%33 = icmp eq i64 %32, 0
br i1 %33, label %37, label %34
34: ; preds = %27
%35 = call i64 @strcmp(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0), i8* %31)
%36 = icmp eq i64 %35, 0
br i1 %36, label %37, label %41
37: ; preds = %34, %27
%38 = load i8*, i8** %9
%39 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %8, i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @.str.8, i64 0, i64 0), i8* %38, i8* %22, i8* %38, i8* %22)
%40 = call i32 @system(i8* %8)
br label %41
41: ; preds = %37, %34
%42 = call i32 @strcpy(i8* %23, i8* %22)
%43 = call i32 @fscanf(i32* %13, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i8* %22)
%44 = call i64 @strcmp(i8* %23, i8* %22)
%45 = icmp eq i64 %44, 0
br i1 %45, label %46, label %27
46: ; preds = %41, %18
br label %47
47: ; preds = %2, %46
%48 = phi i32 [ 0, %46 ], [ 1, %2 ]
ret i32 %48
}