#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*/ free(int *);
scalar_t__ malloc(int);
double omp_get_wtime();
int /*<<< orphan*/ printf(char *, double);
int /*<<< orphan*/ producer_consumer(int, int *, int, int);
int /*<<< orphan*/ scanf(char *, int *, ...);
int main(int argc, char *argv[]) {
  double start, end;
  int i, n, size, nt;
  int *vec;
  scanf("%d %d %d", &nt, &n, &size);
  vec = (int *)malloc(n * sizeof(int));
  for (i = 0; i < n; i++)
    scanf("%d", &vec[i]);
  start = omp_get_wtime();
  producer_consumer(size, vec, n, nt);
  end = omp_get_wtime();
  printf("%lf\n", end - start);
  free(vec);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe83(%rip),%rdi
lea    -0x30(%rbp),%rsi
lea    -0x28(%rbp),%rdx
lea    -0x2c(%rbp),%rcx
mov    $0x0,%al
call   1080 <scanf@plt>
movslq -0x28(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x38(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x28(%rbp),%eax
jge    11e1 <main+0x81>
mov    -0x38(%rbp),%rsi
movslq -0x24(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe3a(%rip),%rdi
mov    $0x0,%al
call   1080 <scanf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11aa <main+0x4a>
mov    $0x0,%al
call   1040 <omp_get_wtime@plt>
movsd  %xmm0,-0x18(%rbp)
mov    -0x2c(%rbp),%edi
mov    -0x38(%rbp),%rsi
mov    -0x28(%rbp),%edx
mov    -0x30(%rbp),%ecx
call   1060 <producer_consumer@plt>
mov    $0x0,%al
call   1040 <omp_get_wtime@plt>
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
subsd  -0x18(%rbp),%xmm0
lea    0xded(%rip),%rdi
call   1050 <printf@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
lea    0xe8e(%rip),%rdi
lea    0x8(%rsp),%rsi
lea    0x4(%rsp),%rdx
lea    0xc(%rsp),%rcx
xor    %eax,%eax
call   1080 <scanf@plt>
mov    0x4(%rsp),%edi
shl    $0x2,%edi
call   1070 <malloc@plt>
mov    %rax,%r14
cmpl   $0x0,0x4(%rsp)
jle    11cf <main+0x6f>
lea    0xe61(%rip),%r15
mov    %r14,%r12
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1080 <scanf@plt>
add    $0x1,%rbx
movslq 0x4(%rsp),%rax
add    $0x4,%r12
cmp    %rax,%rbx
jl     11b0 <main+0x50>
xor    %eax,%eax
call   1040 <omp_get_wtime@plt>
movsd  %xmm0,0x10(%rsp)
mov    0xc(%rsp),%edi
mov    0x4(%rsp),%edx
mov    0x8(%rsp),%ecx
mov    %r14,%rsi
call   1060 <producer_consumer@plt>
xor    %eax,%eax
call   1040 <omp_get_wtime@plt>
subsd  0x10(%rsp),%xmm0
lea    0xe05(%rip),%rdi
call   1050 <printf@plt>
mov    %r14,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [9 x i8] c"%d %d %d\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [5 x i8] c"%lf\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca double
%7 = alloca double
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32* %11, i32* %9, i32* %10)
%14 = load i32, i32* %9
%15 = sext i32 %14 to i64
%16 = mul i64 %15, 4
%17 = trunc i64 %16 to i32
%18 = call i64 @malloc(i32 %17)
%19 = inttoptr i64 %18 to i32*
store i32* %19, i32** %12
store i32 0, i32* %8
br label %20
20: ; preds = %30, %2
%21 = load i32, i32* %8
%22 = load i32, i32* %9
%23 = icmp slt i32 %21, %22
br i1 %23, label %24, label %33
24: ; preds = %20
%25 = load i32*, i32** %12
%26 = load i32, i32* %8
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i32, i32* %25, i64 %27
%29 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %28)
br label %30
30: ; preds = %24
%31 = load i32, i32* %8
%32 = add nsw i32 %31, 1
store i32 %32, i32* %8
br label %20
33: ; preds = %20
%34 = call double (...) @omp_get_wtime()
store double %34, double* %6
%35 = load i32, i32* %10
%36 = load i32*, i32** %12
%37 = load i32, i32* %9
%38 = load i32, i32* %11
%39 = call i32 @producer_consumer(i32 %35, i32* %36, i32 %37, i32 %38)
%40 = call double (...) @omp_get_wtime()
store double %40, double* %7
%41 = load double, double* %7
%42 = load double, double* %6
%43 = fsub double %41, %42
%44 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), double %43)
%45 = load i32*, i32** %12
%46 = call i32 @free(i32* %45)
ret i32 0
}

LLVM IR (-O2):
@.str = [9 x i8] c"%d %d %d\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [5 x i8] c"%lf\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = bitcast i32* %3 to i8*
%7 = bitcast i32* %4 to i8*
%8 = bitcast i32* %5 to i8*
%9 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32* %5, i32* %3, i32* %4)
%10 = load i32, i32* %3
%11 = shl i32 %10, 2
%12 = call i64 @malloc(i32 %11)
%13 = inttoptr i64 %12 to i32*
%14 = load i32, i32* %3
%15 = icmp sgt i32 %14, 0
br i1 %15, label %16, label %24
16: ; preds = %2, %16
%17 = phi i64 [ %20, %16 ], [ 0, %2 ]
%18 = getelementptr inbounds i32, i32* %13, i64 %17
%19 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %18)
%20 = add nuw nsw i64 %17, 1
%21 = load i32, i32* %3
%22 = sext i32 %21 to i64
%23 = icmp slt i64 %20, %22
br i1 %23, label %16, label %24
24: ; preds = %16, %2
%25 = call double (...) @omp_get_wtime()
%26 = load i32, i32* %4
%27 = load i32, i32* %3
%28 = load i32, i32* %5
%29 = call i32 @producer_consumer(i32 %26, i32* %13, i32 %27, i32 %28)
%30 = call double (...) @omp_get_wtime()
%31 = fsub double %30, %25
%32 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), double %31)
%33 = call i32 @free(i32* %13)
ret i32 0
}