#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 */
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ sprintf(char *, char *, int, char *, int);
int /*<<< orphan*/ system(char *);
void grep_car_serial(char *file_name, int num_cars) {
  int i;
  char grep_cmd[1000];
  printf("starting data segregation serial...\n");
  for (i = 0; i < num_cars; ++i) {
    sprintf(grep_cmd, "grep -E \"^%d,\" %s > car_%d.csv", i, file_name, i);
    system(grep_cmd);
  }
}


x86 assembly (clang, -O0):
<grep_car_serial>:
push   %rbp
mov    %rsp,%rbp
sub    $0x400,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
lea    0xeb7(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1199 <grep_car_serial+0x69>
lea    -0x400(%rbp),%rdi
mov    -0x10(%rbp),%edx
mov    -0x8(%rbp),%rcx
mov    -0x10(%rbp),%r8d
lea    0xeab(%rip),%rsi
call   1050 <sprintf@plt>
lea    -0x400(%rbp),%rdi
call   1030 <system@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1155 <grep_car_serial+0x25>
add    $0x400,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<grep_car_serial>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x3f0,%rsp
mov    %esi,%r12d
mov    %rdi,%r14
lea    0xed3(%rip),%rdi
call   1030 <puts@plt>
test   %r12d,%r12d
jle    1193 <grep_car_serial+0x63>
xor    %ebp,%ebp
lea    0xea1(%rip),%r15
mov    %rsp,%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %ebp,%edx
mov    %r14,%rcx
mov    %ebp,%r8d
call   1050 <sprintf@plt>
mov    %rbx,%rdi
call   1040 <system@plt>
add    $0x1,%ebp
cmp    %ebp,%r12d
jne    1170 <grep_car_serial+0x40>
add    $0x3f0,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str.1 = [31 x i8] c"grep -E \22^%d,\22 %s > car_%d.csv\00"
@str = [36 x i8] c"starting data segregation serial...\00"
define void @grep_car_serial(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 i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @str, i64 0, i64 0))
%6 = icmp sgt i32 %1, 0
br i1 %6, label %7, label %13
7: ; preds = %2, %7
%8 = phi i32 [ %11, %7 ], [ 0, %2 ]
%9 = call i32 @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i32 %8, i8* %0, i32 %8)
%10 = call i32 @system(i8* %4)
%11 = add nuw nsw i32 %8, 1
%12 = icmp eq i32 %11, %1
br i1 %12, label %13, label %7
13: ; preds = %7, %2
ret void
}