#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 */
double omp_get_wtime();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sprintf(char *, char *, int, char *, int);
int /*<<< orphan*/ system(char *);
void grep_car_parallel(char *file_name, int num_cars) {
  int i;
  char grep_cmd[1000];
  double start_time = omp_get_wtime();
  printf("starting data segregation parallel...\n");
#pragma omp parallel for private(i, grep_cmd) shared(file_name)
  for (i = 0; i < num_cars; ++i) {
    sprintf(grep_cmd, "grep -E \"^%d,\" %s > car_%d.csv", i, file_name, i);
    system(grep_cmd);
  }
  printf("data segregation complete total time: %f\n",
         omp_get_wtime() - start_time);
}


x86 assembly (clang, -O0):
<grep_car_parallel>:
push   %rbp
mov    %rsp,%rbp
sub    $0x410,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    $0x0,%al
call   1030 <omp_get_wtime@plt>
movsd  %xmm0,-0x408(%rbp)
ff
lea    0xe98(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11ba <grep_car_parallel+0x7a>
lea    -0x400(%rbp),%rdi
mov    -0x10(%rbp),%edx
mov    -0x8(%rbp),%rcx
mov    -0x10(%rbp),%r8d
lea    0xe8c(%rip),%rsi
call   1060 <sprintf@plt>
lea    -0x400(%rbp),%rdi
call   1040 <system@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1176 <grep_car_parallel+0x36>
mov    $0x0,%al
call   1030 <omp_get_wtime@plt>
subsd  -0x408(%rbp),%xmm0
ff
lea    0xe76(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
add    $0x410,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<grep_car_parallel>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x400,%rsp
mov    %esi,%r12d
mov    %rdi,%r14
xor    %ebp,%ebp
xor    %eax,%eax
call   1040 <omp_get_wtime@plt>
movsd  %xmm0,0x8(%rsp)
lea    0xece(%rip),%rdi
call   1030 <puts@plt>
test   %r12d,%r12d
jle    11c3 <grep_car_parallel+0x73>
lea    0xe74(%rip),%r15
lea    0x10(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %ebp,%edx
mov    %r14,%rcx
mov    %ebp,%r8d
call   1070 <sprintf@plt>
mov    %rbx,%rdi
call   1050 <system@plt>
add    $0x1,%ebp
cmp    %ebp,%r12d
jne    11a0 <grep_car_parallel+0x50>
xor    %eax,%eax
call   1040 <omp_get_wtime@plt>
subsd  0x8(%rsp),%xmm0
lea    0xe48(%rip),%rdi
mov    $0x1,%al
add    $0x400,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1060 <printf@plt>

LLVM IR (-O0):
@.str = [39 x i8] c"starting data segregation parallel...\0A\00"
@.str.1 = [31 x i8] c"grep -E \22^%d,\22 %s > car_%d.csv\00"
@.str.2 = [42 x i8] c"data segregation complete total time: %f\0A\00"
define void @grep_car_parallel(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca [1000 x i8]
%7 = alloca double
store i8* %0, i8** %3
store i32 %1, i32* %4
%8 = call double (...) @omp_get_wtime()
store double %8, double* %7
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %5
br label %10
10: ; preds = %22, %2
%11 = load i32, i32* %5
%12 = load i32, i32* %4
%13 = icmp slt i32 %11, %12
br i1 %13, label %14, label %25
14: ; preds = %10
%15 = getelementptr inbounds [1000 x i8], [1000 x i8]* %6, i64 0, i64 0
%16 = load i32, i32* %5
%17 = load i8*, i8** %3
%18 = load i32, i32* %5
%19 = call i32 @sprintf(i8* %15, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i32 %16, i8* %17, i32 %18)
%20 = getelementptr inbounds [1000 x i8], [1000 x i8]* %6, i64 0, i64 0
%21 = call i32 @system(i8* %20)
br label %22
22: ; preds = %14
%23 = load i32, i32* %5
%24 = add nsw i32 %23, 1
store i32 %24, i32* %5
br label %10
25: ; preds = %10
%26 = call double (...) @omp_get_wtime()
%27 = load double, double* %7
%28 = fsub double %26, %27
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0), double %28)
ret void
}

LLVM IR (-O2):
@.str.1 = [31 x i8] c"grep -E \22^%d,\22 %s > car_%d.csv\00"
@.str.2 = [42 x i8] c"data segregation complete total time: %f\0A\00"
@str = [38 x i8] c"starting data segregation parallel...\00"
define void @grep_car_parallel(i8* %0, i32 %1) {
%3 = alloca [1000 x i8]
%4 = getelementptr inbounds [1000 x i8], [1000 x i8]* %3, i64 0, i64 0
%5 = tail call double (...) @omp_get_wtime()
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @str, i64 0, i64 0))
%7 = icmp sgt i32 %1, 0
br i1 %7, label %8, label %14
8: ; preds = %2, %8
%9 = phi i32 [ %12, %8 ], [ 0, %2 ]
%10 = call i32 @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i32 %9, i8* %0, i32 %9)
%11 = call i32 @system(i8* %4)
%12 = add nuw nsw i32 %9, 1
%13 = icmp eq i32 %12, %1
br i1 %13, label %14, label %8
14: ; preds = %8, %2
%15 = tail call double (...) @omp_get_wtime()
%16 = fsub double %15, %5
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0), double %16)
ret void
}