#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 {
  long tv_sec;
  unsigned long tv_usec;
};

/* Variables and functions */
int conta(int *, int);
int /*<<< orphan*/ exit(int);
int gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, unsigned long, unsigned long);
scalar_t__ random();
int /*<<< orphan*/ srandom(int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int main(int argc, char *argv[]) {
  int vetor[2000000], i, pares, impares, rc;
  struct timeval tv_ini, tv_fim;
  unsigned long time_diff, sec_diff, usec_diff, msec_diff;
  srandom(time(NULL));
  for (i = 0; i < 2000000; i++) {
    vetor[i] = (int)random();
  }
  rc = gettimeofday(&tv_ini, NULL);
  if (rc != 0) {
    perror("erro em gettimeofday()");
    exit(1);
  }
  pares = conta(vetor, 1);
  impares = conta(vetor, 2);
  rc = gettimeofday(&tv_fim, NULL);
  if (rc != 0) {
    perror("erro em gettimeofday()");
    exit(1);
  }
  time_diff = (1000000L * tv_fim.tv_sec + tv_fim.tv_usec) -
              (1000000L * tv_ini.tv_sec + tv_ini.tv_usec);
  sec_diff = time_diff / 1000000L;
  usec_diff = time_diff % 1000000L;
  msec_diff = time_diff / 1000;
  printf("O vetor tem %d numeros pares e %d numeros impares.\n", pares,
         impares);
  printf("Tempo de execucao: %lu.%03lu mseg\n", msec_diff, usec_diff % 1000);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x7a1260,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1070 <time@plt>
mov    %eax,%edi
call   1030 <srandom@plt>
movl   $0x0,-0x7a1214(%rbp)
cmpl   $0x1e8480,-0x7a1214(%rbp)
jge    11ee <main+0x6e>
mov    $0x0,%al
call   1080 <random@plt>
mov    %eax,%ecx
movslq -0x7a1214(%rbp),%rax
mov    %ecx,-0x7a1210(%rbp,%rax,4)
mov    -0x7a1214(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x7a1214(%rbp)
jmp    11b3 <main+0x33>
lea    -0x7a1230(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1060 <gettimeofday@plt>
mov    %eax,-0x7a1220(%rbp)
cmpl   $0x0,-0x7a1220(%rbp)
je     1227 <main+0xa7>
lea    0xde8(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
lea    -0x7a1210(%rbp),%rdi
mov    $0x1,%esi
call   1040 <conta@plt>
mov    %eax,-0x7a1218(%rbp)
lea    -0x7a1210(%rbp),%rdi
mov    $0x2,%esi
call   1040 <conta@plt>
mov    %eax,-0x7a121c(%rbp)
lea    -0x7a1240(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1060 <gettimeofday@plt>
mov    %eax,-0x7a1220(%rbp)
cmpl   $0x0,-0x7a1220(%rbp)
je     128e <main+0x10e>
lea    0xd81(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
imul   $0xf4240,-0x7a1240(%rbp),%rax
add    -0x7a1238(%rbp),%rax
imul   $0xf4240,-0x7a1230(%rbp),%rcx
add    -0x7a1228(%rbp),%rcx
sub    %rcx,%rax
mov    %rax,-0x7a1248(%rbp)
mov    -0x7a1248(%rbp),%rax
mov    $0xf4240,%ecx
xor    %edx,%edx
div    %rcx
mov    %rax,-0x7a1250(%rbp)
mov    -0x7a1248(%rbp),%rax
mov    $0xf4240,%ecx
xor    %edx,%edx
div    %rcx
mov    %rdx,-0x7a1258(%rbp)
mov    -0x7a1248(%rbp),%rax
mov    $0x3e8,%ecx
xor    %edx,%edx
div    %rcx
mov    %rax,-0x7a1260(%rbp)
movslq -0x7a1218(%rbp),%rsi
movslq -0x7a121c(%rbp),%rdx
lea    0xcfe(%rip),%rdi
call   1050 <printf@plt>
mov    -0x7a1260(%rbp),%rsi
mov    -0x7a1258(%rbp),%rax
mov    $0x3e8,%ecx
xor    %edx,%edx
div    %rcx
lea    0xd0e(%rip),%rdi
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x7a1260,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x7a1228,%rsp
xor    %edi,%edi
call   1070 <time@plt>
mov    %eax,%edi
call   1030 <srandom@plt>
xor    %ebx,%ebx
nopl   (%rax)
xor    %eax,%eax
call   1080 <random@plt>
mov    %eax,0x20(%rsp,%rbx,4)
add    $0x1,%rbx
cmp    $0x1e8480,%rbx
jne    11a0 <main+0x20>
lea    0x10(%rsp),%rdi
xor    %esi,%esi
call   1060 <gettimeofday@plt>
test   %eax,%eax
jne    12a6 <main+0x126>
lea    0x20(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x1,%esi
call   1040 <conta@plt>
mov    %eax,%r14d
mov    %rbx,%rdi
mov    $0x2,%esi
call   1040 <conta@plt>
mov    %eax,%r15d
mov    %rsp,%rdi
xor    %esi,%esi
call   1060 <gettimeofday@plt>
test   %eax,%eax
jne    12a6 <main+0x126>
mov    (%rsp),%rax
mov    0x8(%rsp),%rcx
sub    0x10(%rsp),%rax
imul   $0xf4240,%rax,%rax
sub    0x18(%rsp),%rcx
add    %rax,%rcx
movabs $0x431bde82d7b634db,%rdx
de 1b 43
mov    %rcx,%rax
mul    %rdx
mov    %rdx,%rsi
mov    %rcx,%rbx
shr    $0x3,%rcx
movabs $0x20c49ba5e353f7cf,%rdx
9b c4 20
mov    %rcx,%rax
mul    %rdx
mov    %rdx,%rbp
shr    $0x12,%rsi
imul   $0xf4240,%rsi,%rax
sub    %rax,%rbx
shr    $0x4,%rbp
movslq %r14d,%rsi
movslq %r15d,%rdx
lea    0xdab(%rip),%rdi
call   1050 <printf@plt>
imul   $0x10624dd3,%rbx,%rax
shr    $0x26,%rax
imul   $0x3e8,%eax,%eax
sub    %eax,%ebx
lea    0xdc0(%rip),%rdi
mov    %rbp,%rsi
mov    %rbx,%rdx
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x7a1228,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd53(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
%struct.timeval = type { i64, i64 }
@.str = [23 x i8] c"erro em gettimeofday()\00"
@.str.1 = [52 x i8] c"O vetor tem %d numeros pares e %d numeros impares.\0A\00"
@.str.2 = [35 x i8] c"Tempo de execucao: %lu.%03lu mseg\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [2000000 x i32]
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca %struct.timeval
%12 = alloca %struct.timeval
%13 = alloca i64
%14 = alloca i64
%15 = alloca i64
%16 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%17 = call i32 @time(i32* null)
%18 = call i32 @srandom(i32 %17)
store i32 0, i32* %7
br label %19
19: ; preds = %28, %2
%20 = load i32, i32* %7
%21 = icmp slt i32 %20, 2000000
br i1 %21, label %22, label %31
22: ; preds = %19
%23 = call i64 (...) @random()
%24 = trunc i64 %23 to i32
%25 = load i32, i32* %7
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds [2000000 x i32], [2000000 x i32]* %6, i64 0, i64 %26
store i32 %24, i32* %27
br label %28
28: ; preds = %22
%29 = load i32, i32* %7
%30 = add nsw i32 %29, 1
store i32 %30, i32* %7
br label %19
31: ; preds = %19
%32 = call i32 @gettimeofday(%struct.timeval* %11, i32* null)
store i32 %32, i32* %10
%33 = load i32, i32* %10
%34 = icmp ne i32 %33, 0
br i1 %34, label %35, label %38
35: ; preds = %31
%36 = call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%37 = call i32 @exit(i32 1)
unreachable
38: ; preds = %31
%39 = getelementptr inbounds [2000000 x i32], [2000000 x i32]* %6, i64 0, i64 0
%40 = call i32 @conta(i32* %39, i32 1)
store i32 %40, i32* %8
%41 = getelementptr inbounds [2000000 x i32], [2000000 x i32]* %6, i64 0, i64 0
%42 = call i32 @conta(i32* %41, i32 2)
store i32 %42, i32* %9
%43 = call i32 @gettimeofday(%struct.timeval* %12, i32* null)
store i32 %43, i32* %10
%44 = load i32, i32* %10
%45 = icmp ne i32 %44, 0
br i1 %45, label %46, label %49
46: ; preds = %38
%47 = call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%48 = call i32 @exit(i32 1)
unreachable
49: ; preds = %38
%50 = getelementptr inbounds %struct.timeval, %struct.timeval* %12, i32 0, i32 0
%51 = load i64, i64* %50
%52 = mul nsw i64 1000000, %51
%53 = getelementptr inbounds %struct.timeval, %struct.timeval* %12, i32 0, i32 1
%54 = load i64, i64* %53
%55 = add i64 %52, %54
%56 = getelementptr inbounds %struct.timeval, %struct.timeval* %11, i32 0, i32 0
%57 = load i64, i64* %56
%58 = mul nsw i64 1000000, %57
%59 = getelementptr inbounds %struct.timeval, %struct.timeval* %11, i32 0, i32 1
%60 = load i64, i64* %59
%61 = add i64 %58, %60
%62 = sub i64 %55, %61
store i64 %62, i64* %13
%63 = load i64, i64* %13
%64 = udiv i64 %63, 1000000
store i64 %64, i64* %14
%65 = load i64, i64* %13
%66 = urem i64 %65, 1000000
store i64 %66, i64* %15
%67 = load i64, i64* %13
%68 = udiv i64 %67, 1000
store i64 %68, i64* %16
%69 = load i32, i32* %8
%70 = sext i32 %69 to i64
%71 = load i32, i32* %9
%72 = sext i32 %71 to i64
%73 = call i32 @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.1, i64 0, i64 0), i64 %70, i64 %72)
%74 = load i64, i64* %16
%75 = load i64, i64* %15
%76 = urem i64 %75, 1000
%77 = call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0), i64 %74, i64 %76)
ret i32 0
}

LLVM IR (-O2):
%struct.timeval = type { i64, i64 }
@.str = [23 x i8] c"erro em gettimeofday()\00"
@.str.1 = [52 x i8] c"O vetor tem %d numeros pares e %d numeros impares.\0A\00"
@.str.2 = [35 x i8] c"Tempo de execucao: %lu.%03lu mseg\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [2000000 x i32]
%4 = alloca %struct.timeval
%5 = alloca %struct.timeval
%6 = bitcast [2000000 x i32]* %3 to i8*
%7 = bitcast %struct.timeval* %4 to i8*
%8 = bitcast %struct.timeval* %5 to i8*
%9 = tail call i32 @time(i32* null)
%10 = tail call i32 @srandom(i32 %9)
br label %11
11: ; preds = %2, %11
%12 = phi i64 [ 0, %2 ], [ %16, %11 ]
%13 = tail call i64 (...) @random()
%14 = trunc i64 %13 to i32
%15 = getelementptr inbounds [2000000 x i32], [2000000 x i32]* %3, i64 0, i64 %12
store i32 %14, i32* %15
%16 = add nuw nsw i64 %12, 1
%17 = icmp eq i64 %16, 2000000
br i1 %17, label %18, label %11
18: ; preds = %11
%19 = call i32 @gettimeofday(%struct.timeval* %4, i32* null)
%20 = icmp eq i32 %19, 0
br i1 %20, label %24, label %21
21: ; preds = %18
%22 = tail call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%23 = tail call i32 @exit(i32 1)
unreachable
24: ; preds = %18
%25 = getelementptr inbounds [2000000 x i32], [2000000 x i32]* %3, i64 0, i64 0
%26 = call i32 @conta(i32* %25, i32 1)
%27 = call i32 @conta(i32* %25, i32 2)
%28 = call i32 @gettimeofday(%struct.timeval* %5, i32* null)
%29 = icmp eq i32 %28, 0
br i1 %29, label %33, label %30
30: ; preds = %24
%31 = call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%32 = call i32 @exit(i32 1)
unreachable
33: ; preds = %24
%34 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i64 0, i32 0
%35 = load i64, i64* %34
%36 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i64 0, i32 1
%37 = load i64, i64* %36
%38 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 0
%39 = load i64, i64* %38
%40 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 1
%41 = load i64, i64* %40
%42 = sub i64 %35, %39
%43 = mul i64 %42, 1000000
%44 = sub i64 %37, %41
%45 = add i64 %44, %43
%46 = urem i64 %45, 1000000
%47 = udiv i64 %45, 1000
%48 = sext i32 %26 to i64
%49 = sext i32 %27 to i64
%50 = call i32 @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.1, i64 0, i64 0), i64 %48, i64 %49)
%51 = trunc i64 %46 to i32
%52 = urem i32 %51, 1000
%53 = zext i32 %52 to i64
%54 = call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0), i64 %47, i64 %53)
ret i32 0
}