#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 timeval {
  int tv_sec;
  scalar_t__ tv_usec;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
char EOF;
int atoi(char *);
scalar_t__ calloc(int, int);
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ strcmp(char *, char *);
int main(int argc, char *argv[]) {
  FILE *inputFile = NULL;
  char *filename, *input, *rank_or_select;
  int length = 0, bound, Rank, Select, i;
  char c, s_char;
  int header_line = 0;
  struct timeval start_time, end_time;
  long us;
  if (argc != 5) {
    printf("Wrong number of parameters: char_counter.exe filename "
           "rank_or_select char bound expected\n");
    return -1;
  }
  filename = argv[1];
  rank_or_select = argv[2];
  s_char = argv[3][0];
  bound = atoi(argv[4]);
  inputFile = fopen(filename, "r");
  if (inputFile == NULL) {
    printf("%s doesn't exist\n", filename);
    return -1;
  }
  input = (char *)calloc(10000000, sizeof(char));
  while ((c = fgetc(inputFile)) != EOF) {
    if (c == '>') {
      header_line = 1;
    }
    if (c == '\n') {
      header_line = 0;
      continue;
    }
    if (header_line == 0) {
      input[length] = c;
      length++;
    }
  }
  length--;
  if (!strcmp(rank_or_select, "rank")) {
    gettimeofday(&start_time, NULL);
    if (bound > length) {
      printf("Boundary too high: input length is %d\n", length);
      return -1;
    }
    Rank = 0;
    for (i = 0; i < bound; ++i) {
      if (s_char == input[i]) {
        Rank++;
      }
    }
    gettimeofday(&end_time, NULL);
    us = (long)((1000000 * end_time.tv_sec + end_time.tv_usec) -
                (1000000 * start_time.tv_sec + start_time.tv_usec));
    printf("Expected Rank value is %d\n", Rank);
    printf("Calculating rank operation took %ld us\n", us);
  } else if (!strcmp(rank_or_select, "select")) {
    gettimeofday(&start_time, NULL);
    Select = 0;
    Rank = 0;
    for (i = 0; i < length; ++i) {
      if (s_char == input[i]) {
        Rank++;
      }
      Select++;
      if (Rank == bound) {
        break;
      }
    }
    gettimeofday(&end_time, NULL);
    us = (long)((1000000 * end_time.tv_sec + end_time.tv_usec) -
                (1000000 * start_time.tv_sec + start_time.tv_usec));
    printf("Expected Select value is %d\n", Select);
    printf("Calculating Select operation took %ld us\n", us);
  } else {
    printf("Second argument can be either rank or select\n");
    return -1;
  }
  free(input);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movl   $0x0,-0x34(%rbp)
movl   $0x0,-0x4c(%rbp)
cmpl   $0x5,-0x8(%rbp)
je     11d3 <main+0x53>
lea    0xe40(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    14dd <main+0x35d>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rax
mov    (%rax),%al
mov    %al,-0x46(%rbp)
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rdi
call   10a0 <atoi@plt>
mov    %eax,-0x38(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xe47(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1245 <main+0xc5>
mov    -0x20(%rbp),%rsi
lea    0xe2a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    14dd <main+0x35d>
mov    $0x989680,%edi
mov    $0x1,%esi
call   1070 <calloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1060 <fgetc@plt>
mov    %al,-0x45(%rbp)
movsbl %al,%eax
mov    0x2d7a(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     12cc <main+0x14c>
movsbl -0x45(%rbp),%eax
cmp    $0x3e,%eax
jne    128d <main+0x10d>
movl   $0x1,-0x4c(%rbp)
movsbl -0x45(%rbp),%eax
cmp    $0xa,%eax
jne    12a6 <main+0x126>
movl   $0x0,-0x4c(%rbp)
jmp    1258 <main+0xd8>
cmpl   $0x0,-0x4c(%rbp)
jne    12c7 <main+0x147>
mov    -0x45(%rbp),%dl
mov    -0x28(%rbp),%rax
movslq -0x34(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1258 <main+0xd8>
mov    -0x34(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x34(%rbp)
mov    -0x30(%rbp),%rdi
lea    0xd8e(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%eax
jne    13c9 <main+0x249>
lea    -0x60(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <gettimeofday@plt>
mov    -0x38(%rbp),%eax
cmp    -0x34(%rbp),%eax
jle    1324 <main+0x1a4>
mov    -0x34(%rbp),%esi
lea    0xd62(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    14dd <main+0x35d>
movl   $0x0,-0x3c(%rbp)
movl   $0x0,-0x44(%rbp)
mov    -0x44(%rbp),%eax
cmp    -0x38(%rbp),%eax
jge    1372 <main+0x1f2>
movsbl -0x46(%rbp),%eax
mov    -0x28(%rbp),%rcx
movslq -0x44(%rbp),%rdx
movsbl (%rcx,%rdx,1),%ecx
cmp    %ecx,%eax
jne    135f <main+0x1df>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    1364 <main+0x1e4>
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    1332 <main+0x1b2>
lea    -0x70(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <gettimeofday@plt>
imul   $0xf4240,-0x70(%rbp),%eax
cltq
add    -0x68(%rbp),%rax
imul   $0xf4240,-0x60(%rbp),%ecx
movslq %ecx,%rcx
add    -0x58(%rbp),%rcx
sub    %rcx,%rax
mov    %rax,-0x78(%rbp)
mov    -0x3c(%rbp),%esi
lea    0xcef(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x78(%rbp),%rsi
lea    0xcf8(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    14d4 <main+0x354>
mov    -0x30(%rbp),%rdi
lea    0xd09(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%eax
jne    14b5 <main+0x335>
lea    -0x60(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <gettimeofday@plt>
movl   $0x0,-0x40(%rbp)
movl   $0x0,-0x3c(%rbp)
movl   $0x0,-0x44(%rbp)
mov    -0x44(%rbp),%eax
cmp    -0x34(%rbp),%eax
jge    145e <main+0x2de>
movsbl -0x46(%rbp),%eax
mov    -0x28(%rbp),%rcx
movslq -0x44(%rbp),%rdx
movsbl (%rcx,%rdx,1),%ecx
cmp    %ecx,%eax
jne    1431 <main+0x2b1>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
mov    -0x40(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x40(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0x38(%rbp),%eax
jne    144b <main+0x2cb>
jmp    145e <main+0x2de>
jmp    1450 <main+0x2d0>
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    1404 <main+0x284>
lea    -0x70(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <gettimeofday@plt>
imul   $0xf4240,-0x70(%rbp),%eax
cltq
add    -0x68(%rbp),%rax
imul   $0xf4240,-0x60(%rbp),%ecx
movslq %ecx,%rcx
add    -0x58(%rbp),%rcx
sub    %rcx,%rax
mov    %rax,-0x78(%rbp)
mov    -0x40(%rbp),%esi
lea    0xc4d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x78(%rbp),%rsi
lea    0xc58(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    14cf <main+0x34f>
lea    0xc6f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    14dd <main+0x35d>
jmp    14d4 <main+0x354>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x4(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
cmp    $0x5,%edi
jne    1241 <main+0xb1>
mov    0x8(%rsi),%rbp
mov    0x10(%rsi),%r14
mov    0x18(%rsi),%rax
mov    (%rax),%r15b
mov    0x20(%rsi),%rdi
call   10b0 <atoi@plt>
mov    %eax,%r13d
lea    0xe47(%rip),%rsi
mov    %rbp,%rdi
call   10a0 <fopen@plt>
test   %rax,%rax
je     1292 <main+0x102>
mov    %rax,%rbx
mov    %r14,0x30(%rsp)
mov    %r15b,0xf(%rsp)
mov    $0x989680,%edi
mov    $0x1,%esi
call   1080 <calloc@plt>
mov    %rax,%r15
xor    %r14d,%r14d
mov    0x2de5(%rip),%r12
xor    %ebp,%ebp
mov    %ebp,%ecx
nopw   0x0(%rax,%rax,1)
mov    %ecx,%ebp
mov    %rbx,%rdi
call   1070 <fgetc@plt>
cmp    (%r12),%al
je     1252 <main+0xc2>
xor    %ecx,%ecx
cmp    $0xa,%al
je     1210 <main+0x80>
cmp    $0x3e,%al
mov    $0x1,%ecx
cmove  %ecx,%ebp
test   %ebp,%ebp
jne    1205 <main+0x75>
mov    %r14d,%ecx
mov    %al,(%r15,%rcx,1)
add    $0x1,%r14d
jmp    1205 <main+0x75>
lea    0xebf(%rip),%rdi
call   1040 <puts@plt>
jmp    1388 <main+0x1f8>
lea    -0x1(%r14),%ebp
lea    0xdc7(%rip),%rsi
mov    0x30(%rsp),%rbx
mov    %rbx,%rdi
call   1090 <strcmp@plt>
test   %eax,%eax
je     12a8 <main+0x118>
lea    0xe8b(%rip),%rsi
mov    %rbx,%rdi
call   1090 <strcmp@plt>
test   %eax,%eax
je     12e3 <main+0x153>
lea    0xe52(%rip),%rdi
call   1040 <puts@plt>
jmp    1388 <main+0x1f8>
lea    0xd79(%rip),%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    1388 <main+0x1f8>
xor    %ebx,%ebx
lea    0x20(%rsp),%rdi
xor    %esi,%esi
call   1060 <gettimeofday@plt>
cmp    %r14d,%r13d
jge    1378 <main+0x1e8>
test   %r13d,%r13d
mov    0xf(%rsp),%r8b
jle    14f4 <main+0x364>
mov    %r13d,%eax
cmp    $0x8,%r13d
jae    139c <main+0x20c>
xor    %ecx,%ecx
xor    %ebx,%ebx
jmp    14e0 <main+0x350>
xor    %ebx,%ebx
lea    0x20(%rsp),%rdi
xor    %esi,%esi
call   1060 <gettimeofday@plt>
cmp    $0x2,%r14d
jb     132b <main+0x19b>
mov    %ebp,%esi
xor    %ebx,%ebx
xor    %ecx,%ecx
mov    0xf(%rsp),%al
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %ecx,%edx
xor    %ecx,%ecx
cmp    (%r15,%rbx,1),%al
sete   %cl
add    %edx,%ecx
add    $0x1,%rbx
cmp    %r13d,%ecx
je     132b <main+0x19b>
cmp    %rsi,%rbx
jb     1310 <main+0x180>
lea    0x10(%rsp),%rdi
xor    %esi,%esi
call   1060 <gettimeofday@plt>
movslq 0x10(%rsp),%rax
imul   $0xf4240,%rax,%rbp
movslq 0x20(%rsp),%rax
add    0x18(%rsp),%rbp
imul   $0xf4240,%rax,%rax
add    0x28(%rsp),%rax
sub    %rax,%rbp
lea    0xd30(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xd3d(%rip),%rdi
jmp    153c <main+0x3ac>
lea    0xcaa(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xffffffff,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %eax,%ecx
and    $0xfffffff8,%ecx
movzbl %r8b,%edx
movd   %edx,%xmm0
punpcklbw %xmm0,%xmm0
pshuflw $0x0,%xmm0,%xmm0
lea    -0x8(%rcx),%rsi
mov    %rsi,%rdx
shr    $0x3,%rdx
add    $0x1,%rdx
test   %rsi,%rsi
je     1467 <main+0x2d7>
mov    %rdx,%rdi
and    $0xfffffffffffffffe,%rdi
pxor   %xmm1,%xmm1
xor    %esi,%esi
movdqa 0xc21(%rip),%xmm3
pxor   %xmm2,%xmm2
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movd   (%r15,%rsi,1),%xmm5
movd   0x4(%r15,%rsi,1),%xmm4
pcmpeqb %xmm0,%xmm5
punpcklbw %xmm5,%xmm5
punpcklwd %xmm5,%xmm5
pand   %xmm3,%xmm5
paddd  %xmm1,%xmm5
pcmpeqb %xmm0,%xmm4
punpcklbw %xmm4,%xmm4
punpcklwd %xmm4,%xmm4
pand   %xmm3,%xmm4
paddd  %xmm2,%xmm4
movd   0x8(%r15,%rsi,1),%xmm1
movd   0xc(%r15,%rsi,1),%xmm2
pcmpeqb %xmm0,%xmm1
punpcklbw %xmm1,%xmm1
punpcklwd %xmm1,%xmm1
pand   %xmm3,%xmm1
paddd  %xmm5,%xmm1
pcmpeqb %xmm0,%xmm2
punpcklbw %xmm2,%xmm2
punpcklwd %xmm2,%xmm2
pand   %xmm3,%xmm2
paddd  %xmm4,%xmm2
add    $0x10,%rsi
add    $0xfffffffffffffffe,%rdi
jne    13f0 <main+0x260>
jmp    1471 <main+0x2e1>
pxor   %xmm1,%xmm1
xor    %esi,%esi
pxor   %xmm2,%xmm2
test   $0x1,%dl
je     14b3 <main+0x323>
movd   (%r15,%rsi,1),%xmm3
movd   0x4(%r15,%rsi,1),%xmm4
pcmpeqb %xmm0,%xmm3
punpcklbw %xmm3,%xmm3
punpcklwd %xmm3,%xmm3
movdqa 0xb69(%rip),%xmm5
pand   %xmm5,%xmm3
paddd  %xmm3,%xmm1
pcmpeqb %xmm0,%xmm4
punpcklbw %xmm4,%xmm4
punpcklwd %xmm4,%xmm4
pand   %xmm5,%xmm4
paddd  %xmm4,%xmm2
paddd  %xmm2,%xmm1
pshufd $0xee,%xmm1,%xmm0
paddd  %xmm1,%xmm0
pshufd $0x55,%xmm0,%xmm1
paddd  %xmm0,%xmm1
movd   %xmm1,%ebx
cmp    %rax,%rcx
je     14f4 <main+0x364>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
xor    %edx,%edx
cmp    (%r15,%rcx,1),%r8b
sete   %dl
add    %edx,%ebx
add    $0x1,%rcx
cmp    %rcx,%rax
jne    14e0 <main+0x350>
lea    0x10(%rsp),%rdi
xor    %esi,%esi
call   1060 <gettimeofday@plt>
movslq 0x10(%rsp),%rax
imul   $0xf4240,%rax,%rbp
movslq 0x20(%rsp),%rax
add    0x18(%rsp),%rbp
imul   $0xf4240,%rax,%rax
add    0x28(%rsp),%rax
sub    %rax,%rbp
lea    0xb24(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xb2f(%rip),%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r15,%rdi
call   1030 <free@plt>
xor    %eax,%eax
jmp    138d <main+0x1fd>

LLVM IR (-O0):
%struct.timeval = type { i32, i64 }
@.str = [90 x i8] c"Wrong number of parameters: char_counter.exe filename rank_or_select char bound expected\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [18 x i8] c"%s doesn't exist\0A\00"
@EOF = global i8 0
@.str.3 = [5 x i8] c"rank\00"
@.str.4 = [39 x i8] c"Boundary too high: input length is %d\0A\00"
@.str.5 = [27 x i8] c"Expected Rank value is %d\0A\00"
@.str.6 = [40 x i8] c"Calculating rank operation took %ld us\0A\00"
@.str.7 = [7 x i8] c"select\00"
@.str.8 = [29 x i8] c"Expected Select value is %d\0A\00"
@.str.9 = [42 x i8] c"Calculating Select operation took %ld us\0A\00"
@.str.10 = [46 x i8] c"Second argument can be either rank or select\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i8
%16 = alloca i8
%17 = alloca i32
%18 = alloca %struct.timeval
%19 = alloca %struct.timeval
%20 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32* null, i32** %6
store i32 0, i32* %10
store i32 0, i32* %17
%21 = load i32, i32* %4
%22 = icmp ne i32 %21, 5
br i1 %22, label %23, label %25
23: ; preds = %2
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([90 x i8], [90 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %198
25: ; preds = %2
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 1
%28 = load i8*, i8** %27
store i8* %28, i8** %7
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 2
%31 = load i8*, i8** %30
store i8* %31, i8** %9
%32 = load i8**, i8*** %5
%33 = getelementptr inbounds i8*, i8** %32, i64 3
%34 = load i8*, i8** %33
%35 = getelementptr inbounds i8, i8* %34, i64 0
%36 = load i8, i8* %35
store i8 %36, i8* %16
%37 = load i8**, i8*** %5
%38 = getelementptr inbounds i8*, i8** %37, i64 4
%39 = load i8*, i8** %38
%40 = call i32 @atoi(i8* %39)
store i32 %40, i32* %11
%41 = load i8*, i8** %7
%42 = call i32* @fopen(i8* %41, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %42, i32** %6
%43 = load i32*, i32** %6
%44 = icmp eq i32* %43, null
br i1 %44, label %45, label %48
45: ; preds = %25
%46 = load i8*, i8** %7
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* %46)
store i32 -1, i32* %3
br label %198
48: ; preds = %25
%49 = call i64 @calloc(i32 10000000, i32 1)
%50 = inttoptr i64 %49 to i8*
store i8* %50, i8** %8
br label %51
51: ; preds = %79, %67, %48
%52 = load i32*, i32** %6
%53 = call signext i8 @fgetc(i32* %52)
store i8 %53, i8* %15
%54 = sext i8 %53 to i32
%55 = load i8, i8* @EOF
%56 = sext i8 %55 to i32
%57 = icmp ne i32 %54, %56
br i1 %57, label %58, label %80
58: ; preds = %51
%59 = load i8, i8* %15
%60 = sext i8 %59 to i32
%61 = icmp eq i32 %60, 62
br i1 %61, label %62, label %63
62: ; preds = %58
store i32 1, i32* %17
br label %63
63: ; preds = %62, %58
%64 = load i8, i8* %15
%65 = sext i8 %64 to i32
%66 = icmp eq i32 %65, 10
br i1 %66, label %67, label %68
67: ; preds = %63
store i32 0, i32* %17
br label %51
68: ; preds = %63
%69 = load i32, i32* %17
%70 = icmp eq i32 %69, 0
br i1 %70, label %71, label %79
71: ; preds = %68
%72 = load i8, i8* %15
%73 = load i8*, i8** %8
%74 = load i32, i32* %10
%75 = sext i32 %74 to i64
%76 = getelementptr inbounds i8, i8* %73, i64 %75
store i8 %72, i8* %76
%77 = load i32, i32* %10
%78 = add nsw i32 %77, 1
store i32 %78, i32* %10
br label %79
79: ; preds = %71, %68
br label %51
80: ; preds = %51
%81 = load i32, i32* %10
%82 = add nsw i32 %81, -1
store i32 %82, i32* %10
%83 = load i8*, i8** %9
%84 = call i32 @strcmp(i8* %83, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%85 = icmp ne i32 %84, 0
br i1 %85, label %137, label %86
86: ; preds = %80
%87 = call i32 @gettimeofday(%struct.timeval* %18, i32* null)
%88 = load i32, i32* %11
%89 = load i32, i32* %10
%90 = icmp sgt i32 %88, %89
br i1 %90, label %91, label %94
91: ; preds = %86
%92 = load i32, i32* %10
%93 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.4, i64 0, i64 0), i32 %92)
store i32 -1, i32* %3
br label %198
94: ; preds = %86
store i32 0, i32* %12
store i32 0, i32* %14
br label %95
95: ; preds = %113, %94
%96 = load i32, i32* %14
%97 = load i32, i32* %11
%98 = icmp slt i32 %96, %97
br i1 %98, label %99, label %116
99: ; preds = %95
%100 = load i8, i8* %16
%101 = sext i8 %100 to i32
%102 = load i8*, i8** %8
%103 = load i32, i32* %14
%104 = sext i32 %103 to i64
%105 = getelementptr inbounds i8, i8* %102, i64 %104
%106 = load i8, i8* %105
%107 = sext i8 %106 to i32
%108 = icmp eq i32 %101, %107
br i1 %108, label %109, label %112
109: ; preds = %99
%110 = load i32, i32* %12
%111 = add nsw i32 %110, 1
store i32 %111, i32* %12
br label %112
112: ; preds = %109, %99
br label %113
113: ; preds = %112
%114 = load i32, i32* %14
%115 = add nsw i32 %114, 1
store i32 %115, i32* %14
br label %95
116: ; preds = %95
%117 = call i32 @gettimeofday(%struct.timeval* %19, i32* null)
%118 = getelementptr inbounds %struct.timeval, %struct.timeval* %19, i32 0, i32 0
%119 = load i32, i32* %118
%120 = mul nsw i32 1000000, %119
%121 = sext i32 %120 to i64
%122 = getelementptr inbounds %struct.timeval, %struct.timeval* %19, i32 0, i32 1
%123 = load i64, i64* %122
%124 = add nsw i64 %121, %123
%125 = getelementptr inbounds %struct.timeval, %struct.timeval* %18, i32 0, i32 0
%126 = load i32, i32* %125
%127 = mul nsw i32 1000000, %126
%128 = sext i32 %127 to i64
%129 = getelementptr inbounds %struct.timeval, %struct.timeval* %18, i32 0, i32 1
%130 = load i64, i64* %129
%131 = add nsw i64 %128, %130
%132 = sub nsw i64 %124, %131
store i64 %132, i64* %20
%133 = load i32, i32* %12
%134 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0), i32 %133)
%135 = load i64, i64* %20
%136 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.6, i64 0, i64 0), i64 %135)
br label %195
137: ; preds = %80
%138 = load i8*, i8** %9
%139 = call i32 @strcmp(i8* %138, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0))
%140 = icmp ne i32 %139, 0
br i1 %140, label %192, label %141
141: ; preds = %137
%142 = call i32 @gettimeofday(%struct.timeval* %18, i32* null)
store i32 0, i32* %13
store i32 0, i32* %12
store i32 0, i32* %14
br label %143
143: ; preds = %168, %141
%144 = load i32, i32* %14
%145 = load i32, i32* %10
%146 = icmp slt i32 %144, %145
br i1 %146, label %147, label %171
147: ; preds = %143
%148 = load i8, i8* %16
%149 = sext i8 %148 to i32
%150 = load i8*, i8** %8
%151 = load i32, i32* %14
%152 = sext i32 %151 to i64
%153 = getelementptr inbounds i8, i8* %150, i64 %152
%154 = load i8, i8* %153
%155 = sext i8 %154 to i32
%156 = icmp eq i32 %149, %155
br i1 %156, label %157, label %160
157: ; preds = %147
%158 = load i32, i32* %12
%159 = add nsw i32 %158, 1
store i32 %159, i32* %12
br label %160
160: ; preds = %157, %147
%161 = load i32, i32* %13
%162 = add nsw i32 %161, 1
store i32 %162, i32* %13
%163 = load i32, i32* %12
%164 = load i32, i32* %11
%165 = icmp eq i32 %163, %164
br i1 %165, label %166, label %167
166: ; preds = %160
br label %171
167: ; preds = %160
br label %168
168: ; preds = %167
%169 = load i32, i32* %14
%170 = add nsw i32 %169, 1
store i32 %170, i32* %14
br label %143
171: ; preds = %166, %143
%172 = call i32 @gettimeofday(%struct.timeval* %19, i32* null)
%173 = getelementptr inbounds %struct.timeval, %struct.timeval* %19, i32 0, i32 0
%174 = load i32, i32* %173
%175 = mul nsw i32 1000000, %174
%176 = sext i32 %175 to i64
%177 = getelementptr inbounds %struct.timeval, %struct.timeval* %19, i32 0, i32 1
%178 = load i64, i64* %177
%179 = add nsw i64 %176, %178
%180 = getelementptr inbounds %struct.timeval, %struct.timeval* %18, i32 0, i32 0
%181 = load i32, i32* %180
%182 = mul nsw i32 1000000, %181
%183 = sext i32 %182 to i64
%184 = getelementptr inbounds %struct.timeval, %struct.timeval* %18, i32 0, i32 1
%185 = load i64, i64* %184
%186 = add nsw i64 %183, %185
%187 = sub nsw i64 %179, %186
store i64 %187, i64* %20
%188 = load i32, i32* %13
%189 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.8, i64 0, i64 0), i32 %188)
%190 = load i64, i64* %20
%191 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.9, i64 0, i64 0), i64 %190)
br label %194
192: ; preds = %137
%193 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.10, i64 0, i64 0))
store i32 -1, i32* %3
br label %198
194: ; preds = %171
br label %195
195: ; preds = %194, %116
%196 = load i8*, i8** %8
%197 = call i32 @free(i8* %196)
br label %198
198: ; preds = %195, %192, %91, %45, %23
%199 = load i32, i32* %3
ret i32 %199
}

LLVM IR (-O2):
%struct.timeval = type { i32, i64 }
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [18 x i8] c"%s doesn't exist\0A\00"
@EOF = global i8 0
@.str.3 = [5 x i8] c"rank\00"
@.str.4 = [39 x i8] c"Boundary too high: input length is %d\0A\00"
@.str.5 = [27 x i8] c"Expected Rank value is %d\0A\00"
@.str.6 = [40 x i8] c"Calculating rank operation took %ld us\0A\00"
@.str.7 = [7 x i8] c"select\00"
@.str.8 = [29 x i8] c"Expected Select value is %d\0A\00"
@.str.9 = [42 x i8] c"Calculating Select operation took %ld us\0A\00"
@str = [45 x i8] c"Second argument can be either rank or select\00"
@str.11 = [89 x i8] c"Wrong number of parameters: char_counter.exe filename rank_or_select char bound expected\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.timeval
%4 = alloca %struct.timeval
%5 = bitcast %struct.timeval* %3 to i8*
%6 = bitcast %struct.timeval* %4 to i8*
%7 = icmp eq i32 %0, 5
br i1 %7, label %10, label %8
8: ; preds = %2
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([89 x i8], [89 x i8]* @str.11, i64 0, i64 0))
br label %213
10: ; preds = %2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = getelementptr inbounds i8*, i8** %1, i64 2
%14 = load i8*, i8** %13
%15 = getelementptr inbounds i8*, i8** %1, i64 3
%16 = load i8*, i8** %15
%17 = load i8, i8* %16
%18 = getelementptr inbounds i8*, i8** %1, i64 4
%19 = load i8*, i8** %18
%20 = tail call i32 @atoi(i8* %19)
%21 = tail call i32* @fopen(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%22 = icmp eq i32* %21, null
br i1 %22, label %23, label %25
23: ; preds = %10
%24 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* %12)
br label %213
25: ; preds = %10
%26 = tail call i64 @calloc(i32 10000000, i32 1)
%27 = inttoptr i64 %26 to i8*
br label %28
28: ; preds = %44, %25
%29 = phi i32 [ %47, %44 ], [ 0, %25 ]
%30 = phi i32 [ %42, %44 ], [ 0, %25 ]
br label %31
31: ; preds = %28, %40
%32 = phi i32 [ %42, %40 ], [ %30, %28 ]
br label %33
33: ; preds = %31, %38
%34 = phi i32 [ 0, %38 ], [ %32, %31 ]
%35 = tail call signext i8 @fgetc(i32* %21)
%36 = load i8, i8* @EOF
%37 = icmp eq i8 %35, %36
br i1 %37, label %48, label %38
38: ; preds = %33
%39 = icmp eq i8 %35, 10
br i1 %39, label %33, label %40
40: ; preds = %38
%41 = icmp eq i8 %35, 62
%42 = select i1 %41, i32 1, i32 %34
%43 = icmp eq i32 %42, 0
br i1 %43, label %44, label %31
44: ; preds = %40
%45 = zext i32 %29 to i64
%46 = getelementptr inbounds i8, i8* %27, i64 %45
store i8 %35, i8* %46
%47 = add nuw nsw i32 %29, 1
br label %28
48: ; preds = %33
%49 = add nsw i32 %29, -1
%50 = tail call i32 @strcmp(i8* dereferenceable(1) %14, i8* dereferenceable(5) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%51 = icmp eq i32 %50, 0
br i1 %51, label %52, label %167
52: ; preds = %48
%53 = call i32 @gettimeofday(%struct.timeval* %3, i32* null)
%54 = icmp slt i32 %20, %29
br i1 %54, label %55, label %135
55: ; preds = %52
%56 = icmp sgt i32 %20, 0
br i1 %56, label %57, label %147
57: ; preds = %55
%58 = zext i32 %20 to i64
%59 = icmp ult i32 %20, 8
br i1 %59, label %132, label %60
60: ; preds = %57
%61 = and i64 %58, 4294967288
%62 = insertelement <4 x i8> poison, i8 %17, i64 0
%63 = shufflevector <4 x i8> %62, <4 x i8> poison, <4 x i32> zeroinitializer
%64 = insertelement <4 x i8> poison, i8 %17, i64 0
%65 = shufflevector <4 x i8> %64, <4 x i8> poison, <4 x i32> zeroinitializer
%66 = add nsw i64 %61, -8
%67 = lshr exact i64 %66, 3
%68 = add nuw nsw i64 %67, 1
%69 = and i64 %68, 1
%70 = icmp eq i64 %66, 0
br i1 %70, label %106, label %71
71: ; preds = %60
%72 = and i64 %68, 4611686018427387902
br label %73
73: ; preds = %73, %71
%74 = phi i64 [ 0, %71 ], [ %103, %73 ]
%75 = phi <4 x i32> [ zeroinitializer, %71 ], [ %101, %73 ]
%76 = phi <4 x i32> [ zeroinitializer, %71 ], [ %102, %73 ]
%77 = phi i64 [ 0, %71 ], [ %104, %73 ]
%78 = getelementptr inbounds i8, i8* %27, i64 %74
%79 = bitcast i8* %78 to <4 x i8>*
%80 = load <4 x i8>, <4 x i8>* %79
%81 = getelementptr inbounds i8, i8* %78, i64 4
%82 = bitcast i8* %81 to <4 x i8>*
%83 = load <4 x i8>, <4 x i8>* %82
%84 = icmp eq <4 x i8> %63, %80
%85 = icmp eq <4 x i8> %65, %83
%86 = zext <4 x i1> %84 to <4 x i32>
%87 = zext <4 x i1> %85 to <4 x i32>
%88 = add <4 x i32> %75, %86
%89 = add <4 x i32> %76, %87
%90 = or i64 %74, 8
%91 = getelementptr inbounds i8, i8* %27, i64 %90
%92 = bitcast i8* %91 to <4 x i8>*
%93 = load <4 x i8>, <4 x i8>* %92
%94 = getelementptr inbounds i8, i8* %91, i64 4
%95 = bitcast i8* %94 to <4 x i8>*
%96 = load <4 x i8>, <4 x i8>* %95
%97 = icmp eq <4 x i8> %63, %93
%98 = icmp eq <4 x i8> %65, %96
%99 = zext <4 x i1> %97 to <4 x i32>
%100 = zext <4 x i1> %98 to <4 x i32>
%101 = add <4 x i32> %88, %99
%102 = add <4 x i32> %89, %100
%103 = add nuw i64 %74, 16
%104 = add i64 %77, 2
%105 = icmp eq i64 %104, %72
br i1 %105, label %106, label %73
106: ; preds = %73, %60
%107 = phi <4 x i32> [ undef, %60 ], [ %101, %73 ]
%108 = phi <4 x i32> [ undef, %60 ], [ %102, %73 ]
%109 = phi i64 [ 0, %60 ], [ %103, %73 ]
%110 = phi <4 x i32> [ zeroinitializer, %60 ], [ %101, %73 ]
%111 = phi <4 x i32> [ zeroinitializer, %60 ], [ %102, %73 ]
%112 = icmp eq i64 %69, 0
br i1 %112, label %126, label %113
113: ; preds = %106
%114 = getelementptr inbounds i8, i8* %27, i64 %109
%115 = bitcast i8* %114 to <4 x i8>*
%116 = load <4 x i8>, <4 x i8>* %115
%117 = getelementptr inbounds i8, i8* %114, i64 4
%118 = bitcast i8* %117 to <4 x i8>*
%119 = load <4 x i8>, <4 x i8>* %118
%120 = icmp eq <4 x i8> %63, %116
%121 = icmp eq <4 x i8> %65, %119
%122 = zext <4 x i1> %120 to <4 x i32>
%123 = zext <4 x i1> %121 to <4 x i32>
%124 = add <4 x i32> %110, %122
%125 = add <4 x i32> %111, %123
br label %126
126: ; preds = %106, %113
%127 = phi <4 x i32> [ %107, %106 ], [ %124, %113 ]
%128 = phi <4 x i32> [ %108, %106 ], [ %125, %113 ]
%129 = add <4 x i32> %128, %127
%130 = call i32 @llvm.vector.reduce.add.v4i32(<4 x i32> %129)
%131 = icmp eq i64 %61, %58
br i1 %131, label %147, label %132
132: ; preds = %57, %126
%133 = phi i64 [ 0, %57 ], [ %61, %126 ]
%134 = phi i32 [ 0, %57 ], [ %130, %126 ]
br label %137
135: ; preds = %52
%136 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @.str.4, i64 0, i64 0), i32 %49)
br label %213
137: ; preds = %132, %137
%138 = phi i64 [ %145, %137 ], [ %133, %132 ]
%139 = phi i32 [ %144, %137 ], [ %134, %132 ]
%140 = getelementptr inbounds i8, i8* %27, i64 %138
%141 = load i8, i8* %140
%142 = icmp eq i8 %17, %141
%143 = zext i1 %142 to i32
%144 = add nuw nsw i32 %139, %143
%145 = add nuw nsw i64 %138, 1
%146 = icmp eq i64 %145, %58
br i1 %146, label %147, label %137
147: ; preds = %137, %126, %55
%148 = phi i32 [ 0, %55 ], [ %130, %126 ], [ %144, %137 ]
%149 = call i32 @gettimeofday(%struct.timeval* %4, i32* null)
%150 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 0
%151 = load i32, i32* %150
%152 = mul nsw i32 %151, 1000000
%153 = sext i32 %152 to i64
%154 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 1
%155 = load i64, i64* %154
%156 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 0
%157 = load i32, i32* %156
%158 = mul nsw i32 %157, 1000000
%159 = sext i32 %158 to i64
%160 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 1
%161 = load i64, i64* %160
%162 = add i64 %155, %153
%163 = add i64 %161, %159
%164 = sub i64 %162, %163
%165 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0), i32 %148)
%166 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str.6, i64 0, i64 0), i64 %164)
br label %211
167: ; preds = %48
%168 = tail call i32 @strcmp(i8* dereferenceable(1) %14, i8* dereferenceable(7) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0))
%169 = icmp eq i32 %168, 0
br i1 %169, label %170, label %209
170: ; preds = %167
%171 = call i32 @gettimeofday(%struct.timeval* %3, i32* null)
%172 = icmp ugt i32 %29, 1
br i1 %172, label %173, label %189
173: ; preds = %170
%174 = zext i32 %49 to i64
br label %175
175: ; preds = %175, %173
%176 = phi i64 [ %183, %175 ], [ 0, %173 ]
%177 = phi i32 [ %182, %175 ], [ 0, %173 ]
%178 = getelementptr inbounds i8, i8* %27, i64 %176
%179 = load i8, i8* %178
%180 = icmp eq i8 %17, %179
%181 = zext i1 %180 to i32
%182 = add nuw nsw i32 %177, %181
%183 = add nuw nsw i64 %176, 1
%184 = icmp ne i32 %182, %20
%185 = icmp ult i64 %183, %174
%186 = select i1 %184, i1 %185, i1 false
br i1 %186, label %175, label %187
187: ; preds = %175
%188 = trunc i64 %183 to i32
br label %189
189: ; preds = %187, %170
%190 = phi i32 [ 0, %170 ], [ %188, %187 ]
%191 = call i32 @gettimeofday(%struct.timeval* %4, i32* null)
%192 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 0
%193 = load i32, i32* %192
%194 = mul nsw i32 %193, 1000000
%195 = sext i32 %194 to i64
%196 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 1
%197 = load i64, i64* %196
%198 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 0
%199 = load i32, i32* %198
%200 = mul nsw i32 %199, 1000000
%201 = sext i32 %200 to i64
%202 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 1
%203 = load i64, i64* %202
%204 = add i64 %197, %195
%205 = add i64 %203, %201
%206 = sub i64 %204, %205
%207 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.8, i64 0, i64 0), i32 %190)
%208 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str.9, i64 0, i64 0), i64 %206)
br label %211
209: ; preds = %167
%210 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @str, i64 0, i64 0))
br label %213
211: ; preds = %189, %147
%212 = tail call i32 @free(i8* %27)
br label %213
213: ; preds = %211, %209, %135, %23, %8
%214 = phi i32 [ -1, %8 ], [ -1, %23 ], [ -1, %209 ], [ 0, %211 ], [ -1, %135 ]
ret i32 %214
}