#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*/ copyFile(char *, char *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int getCountFiles(char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ pclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ *popen(char *, char *);
int /*<<< orphan*/ printf(char *, int, int);
int rand();
int /*<<< orphan*/ sprintf(char *, char *, char *);
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int strlen(char *);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
void generate() {
  int total_files = getCountFiles("ls db/stage1_input/ -1 | wc -l");
  srand(time(NULL));
  int r1 = rand() % total_files;
  int r2 = rand() % total_files;
  printf("Two Numberd: %d and %d\n", r1, r2);
  FILE *fp1;
  fp1 = popen("ls db/stage1_input -1", "r");
  if (fp1 == 0)
    perror("ls db/stage1_input -1");
  char *line = (char *)malloc(25 * sizeof(char));
  char *new_name = (char *)malloc(35 * sizeof(char));
  int i = 0;
  while (fgets(line, 25, fp1)) {
    line[strlen(line) - 1] = '\0';
    sprintf(new_name, "%s_0", line);
    copyFile(line, new_name);
    if (i++ > 20000)
      break;
  }
  pclose(fp1);
}


x86 assembly (clang, -O0):
<generate>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
lea    0xe21(%rip),%rdi
call   1080 <getCountFiles@plt>
mov    %eax,-0x4(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1090 <time@plt>
mov    %eax,%edi
call   1060 <srand@plt>
mov    $0x0,%al
call   10f0 <rand@plt>
cltd
idivl  -0x4(%rbp)
mov    %edx,-0x8(%rbp)
mov    $0x0,%al
call   10f0 <rand@plt>
cltd
idivl  -0x4(%rbp)
mov    %edx,-0xc(%rbp)
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
lea    0xdff(%rip),%rdi
call   1040 <printf@plt>
lea    0xe0b(%rip),%rdi
lea    0xe1a(%rip),%rsi
call   10c0 <popen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1253 <generate+0x83>
lea    0xde9(%rip),%rdi
call   10d0 <perror@plt>
mov    $0x19,%edi
call   10a0 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    $0x23,%edi
call   10a0 <malloc@plt>
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x19,%esi
call   1070 <fgets@plt>
cmp    $0x0,%rax
je     12f4 <generate+0x124>
mov    -0x20(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x38(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rdx
lea    0xd8d(%rip),%rsi
call   10e0 <sprintf@plt>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   10b0 <copyFile@plt>
mov    -0x2c(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x2c(%rbp)
cmp    $0x4e20,%eax
jle    12ef <generate+0x11f>
jmp    12f4 <generate+0x124>
jmp    1276 <generate+0xa6>
mov    -0x18(%rbp),%rdi
call   1050 <pclose@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<generate>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
lea    0xe21(%rip),%rdi
call   1080 <getCountFiles@plt>
mov    %eax,%ebx
xor    %edi,%edi
call   1090 <time@plt>
mov    %eax,%edi
call   1060 <srand@plt>
xor    %eax,%eax
call   10f0 <rand@plt>
cltd
idiv   %ebx
mov    %edx,%ebp
xor    %eax,%eax
call   10f0 <rand@plt>
cltd
idiv   %ebx
lea    0xe0e(%rip),%rdi
mov    %ebp,%esi
call   1040 <printf@plt>
lea    0xe18(%rip),%rdi
lea    0xe27(%rip),%rsi
call   10c0 <popen@plt>
mov    %rax,%r14
test   %rax,%rax
je     12b2 <generate+0xe2>
mov    $0x19,%edi
call   10a0 <malloc@plt>
mov    %rax,%rbx
mov    $0x23,%edi
call   10a0 <malloc@plt>
mov    %rax,%r15
mov    $0x4e22,%ebp
lea    0xdf6(%rip),%r12
nopl   0x0(%rax)
mov    %rbx,%rdi
mov    $0x19,%esi
mov    %r14,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
je     12a2 <generate+0xd2>
mov    %rbx,%rdi
call   1030 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%rbx,1)
mov    %r15,%rdi
mov    %r12,%rsi
mov    %rbx,%rdx
call   10e0 <sprintf@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   10b0 <copyFile@plt>
add    $0xffffffff,%ebp
jne    1260 <generate+0x90>
mov    %r14,%rdi
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <pclose@plt>
lea    0xd7e(%rip),%rdi
call   10d0 <perror@plt>
jmp    1233 <generate+0x63>

LLVM IR (-O0):
@.str = [31 x i8] c"ls db/stage1_input/ -1 | wc -l\00"
@.str.1 = [24 x i8] c"Two Numberd: %d and %d\0A\00"
@.str.2 = [22 x i8] c"ls db/stage1_input -1\00"
@.str.3 = [2 x i8] c"r\00"
@.str.4 = [5 x i8] c"%s_0\00"
define void @generate() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = call i32 @getCountFiles(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
store i32 %8, i32* %1
%9 = call i32 @time(i32* null)
%10 = call i32 @srand(i32 %9)
%11 = call i32 (...) @rand()
%12 = load i32, i32* %1
%13 = srem i32 %11, %12
store i32 %13, i32* %2
%14 = call i32 (...) @rand()
%15 = load i32, i32* %1
%16 = srem i32 %14, %15
store i32 %16, i32* %3
%17 = load i32, i32* %2
%18 = load i32, i32* %3
%19 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i32 %17, i32 %18)
%20 = call i32* @popen(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %20, i32** %4
%21 = load i32*, i32** %4
%22 = icmp eq i32* %21, null
br i1 %22, label %23, label %25
23: ; preds = %0
%24 = call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0))
br label %25
25: ; preds = %23, %0
%26 = call i64 @malloc(i32 25)
%27 = inttoptr i64 %26 to i8*
store i8* %27, i8** %5
%28 = call i64 @malloc(i32 35)
%29 = inttoptr i64 %28 to i8*
store i8* %29, i8** %6
store i32 0, i32* %7
br label %30
30: ; preds = %52, %25
%31 = load i8*, i8** %5
%32 = load i32*, i32** %4
%33 = call i64 @fgets(i8* %31, i32 25, i32* %32)
%34 = icmp ne i64 %33, 0
br i1 %34, label %35, label %53
35: ; preds = %30
%36 = load i8*, i8** %5
%37 = load i8*, i8** %5
%38 = call i32 @strlen(i8* %37)
%39 = sub nsw i32 %38, 1
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i8, i8* %36, i64 %40
store i8 0, i8* %41
%42 = load i8*, i8** %6
%43 = load i8*, i8** %5
%44 = call i32 @sprintf(i8* %42, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i8* %43)
%45 = load i8*, i8** %5
%46 = load i8*, i8** %6
%47 = call i32 @copyFile(i8* %45, i8* %46)
%48 = load i32, i32* %7
%49 = add nsw i32 %48, 1
store i32 %49, i32* %7
%50 = icmp sgt i32 %48, 20000
br i1 %50, label %51, label %52
51: ; preds = %35
br label %53
52: ; preds = %35
br label %30
53: ; preds = %51, %30
%54 = load i32*, i32** %4
%55 = call i32 @pclose(i32* %54)
ret void
}

LLVM IR (-O2):
@.str = [31 x i8] c"ls db/stage1_input/ -1 | wc -l\00"
@.str.1 = [24 x i8] c"Two Numberd: %d and %d\0A\00"
@.str.2 = [22 x i8] c"ls db/stage1_input -1\00"
@.str.3 = [2 x i8] c"r\00"
@.str.4 = [5 x i8] c"%s_0\00"
define void @generate() {
%1 = tail call i32 @getCountFiles(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
%2 = tail call i32 @time(i32* null)
%3 = tail call i32 @srand(i32 %2)
%4 = tail call i32 (...) @rand()
%5 = srem i32 %4, %1
%6 = tail call i32 (...) @rand()
%7 = srem i32 %6, %1
%8 = tail call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i32 %5, i32 %7)
%9 = tail call i32* @popen(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %13
11: ; preds = %0
%12 = tail call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0))
br label %13
13: ; preds = %11, %0
%14 = tail call i64 @malloc(i32 25)
%15 = inttoptr i64 %14 to i8*
%16 = tail call i64 @malloc(i32 35)
%17 = inttoptr i64 %16 to i8*
br label %18
18: ; preds = %22, %13
%19 = phi i32 [ 0, %13 ], [ %29, %22 ]
%20 = tail call i64 @fgets(i8* %15, i32 25, i32* %9)
%21 = icmp eq i64 %20, 0
br i1 %21, label %31, label %22
22: ; preds = %18
%23 = tail call i32 @strlen(i8* %15)
%24 = add nsw i32 %23, -1
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8, i8* %15, i64 %25
store i8 0, i8* %26
%27 = tail call i32 @sprintf(i8* dereferenceable(1) %17, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i8* %15)
%28 = tail call i32 @copyFile(i8* %15, i8* %17)
%29 = add nuw nsw i32 %19, 1
%30 = icmp eq i32 %29, 20002
br i1 %30, label %31, label %18
31: ; preds = %22, %18
%32 = tail call i32 @pclose(i32* %9)
ret void
}