#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*/ parallel_producer_consumer(int *, int, int *, int, int);
int /*<<< orphan*/ printf(char *, double);
int /*<<< orphan*/ scanf(char *, int *, ...);
int main(int argc, char *argv[]) {
  double start, end;
  int *buff, *vec, i, n, size, thread_count;
  scanf("%d %d %d", &thread_count, &n, &size);
  buff = (int *)malloc(size * sizeof(int));
  vec = (int *)malloc(n * sizeof(int));
  for (i = 0; i < n; i++)
    scanf("%d", &vec[i]);
  start = omp_get_wtime();
  parallel_producer_consumer(buff, size, vec, n, thread_count);
  end = omp_get_wtime();
  printf("%lf\n", end - start);
  free(buff);
  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    -0x40(%rbp),%rsi
lea    -0x38(%rbp),%rdx
lea    -0x3c(%rbp),%rcx
mov    $0x0,%al
call   1070 <scanf@plt>
movslq -0x3c(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x28(%rbp)
movslq -0x38(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x38(%rbp),%eax
jge    11f4 <main+0x94>
mov    -0x30(%rbp),%rsi
movslq -0x34(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe27(%rip),%rdi
mov    $0x0,%al
call   1070 <scanf@plt>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    11bd <main+0x5d>
mov    $0x0,%al
call   1040 <omp_get_wtime@plt>
movsd  %xmm0,-0x18(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x3c(%rbp),%esi
mov    -0x30(%rbp),%rdx
mov    -0x38(%rbp),%ecx
mov    -0x40(%rbp),%r8d
call   1080 <parallel_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    0xdd5(%rip),%rdi
call   1050 <printf@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x30(%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   %r13
push   %r12
push   %rbx
sub    $0x20,%rsp
lea    0xe8c(%rip),%rdi
lea    0x14(%rsp),%rsi
lea    0xc(%rsp),%rdx
lea    0x10(%rsp),%rcx
xor    %eax,%eax
call   1070 <scanf@plt>
mov    0x10(%rsp),%edi
shl    $0x2,%edi
call   1060 <malloc@plt>
mov    %rax,%r14
mov    0xc(%rsp),%edi
shl    $0x2,%edi
call   1060 <malloc@plt>
mov    %rax,%r15
cmpl   $0x0,0xc(%rsp)
jle    11df <main+0x7f>
lea    0xe50(%rip),%r12
mov    %r15,%r13
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
mov    %r12,%rdi
mov    %r13,%rsi
xor    %eax,%eax
call   1070 <scanf@plt>
add    $0x1,%rbx
movslq 0xc(%rsp),%rax
add    $0x4,%r13
cmp    %rax,%rbx
jl     11c0 <main+0x60>
xor    %eax,%eax
call   1040 <omp_get_wtime@plt>
movsd  %xmm0,0x18(%rsp)
mov    0x10(%rsp),%esi
mov    0xc(%rsp),%ecx
mov    0x14(%rsp),%r8d
mov    %r14,%rdi
mov    %r15,%rdx
call   1080 <parallel_producer_consumer@plt>
xor    %eax,%eax
call   1040 <omp_get_wtime@plt>
subsd  0x18(%rsp),%xmm0
lea    0xdf1(%rip),%rdi
call   1050 <printf@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %r15,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r12
pop    %r13
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
%13 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%14 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32* %13, i32* %11, i32* %12)
%15 = load i32, i32* %12
%16 = sext i32 %15 to i64
%17 = mul i64 %16, 4
%18 = trunc i64 %17 to i32
%19 = call i64 @malloc(i32 %18)
%20 = inttoptr i64 %19 to i32*
store i32* %20, i32** %8
%21 = load i32, i32* %11
%22 = sext i32 %21 to i64
%23 = mul i64 %22, 4
%24 = trunc i64 %23 to i32
%25 = call i64 @malloc(i32 %24)
%26 = inttoptr i64 %25 to i32*
store i32* %26, i32** %9
store i32 0, i32* %10
br label %27
27: ; preds = %37, %2
%28 = load i32, i32* %10
%29 = load i32, i32* %11
%30 = icmp slt i32 %28, %29
br i1 %30, label %31, label %40
31: ; preds = %27
%32 = load i32*, i32** %9
%33 = load i32, i32* %10
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i32, i32* %32, i64 %34
%36 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %35)
br label %37
37: ; preds = %31
%38 = load i32, i32* %10
%39 = add nsw i32 %38, 1
store i32 %39, i32* %10
br label %27
40: ; preds = %27
%41 = call double (...) @omp_get_wtime()
store double %41, double* %6
%42 = load i32*, i32** %8
%43 = load i32, i32* %12
%44 = load i32*, i32** %9
%45 = load i32, i32* %11
%46 = load i32, i32* %13
%47 = call i32 @parallel_producer_consumer(i32* %42, i32 %43, i32* %44, i32 %45, i32 %46)
%48 = call double (...) @omp_get_wtime()
store double %48, double* %7
%49 = load double, double* %7
%50 = load double, double* %6
%51 = fsub double %49, %50
%52 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), double %51)
%53 = load i32*, i32** %8
%54 = call i32 @free(i32* %53)
%55 = load i32*, i32** %9
%56 = call i32 @free(i32* %55)
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* %4
%11 = shl i32 %10, 2
%12 = call i64 @malloc(i32 %11)
%13 = inttoptr i64 %12 to i32*
%14 = load i32, i32* %3
%15 = shl i32 %14, 2
%16 = call i64 @malloc(i32 %15)
%17 = inttoptr i64 %16 to i32*
%18 = load i32, i32* %3
%19 = icmp sgt i32 %18, 0
br i1 %19, label %20, label %28
20: ; preds = %2, %20
%21 = phi i64 [ %24, %20 ], [ 0, %2 ]
%22 = getelementptr inbounds i32, i32* %17, i64 %21
%23 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %22)
%24 = add nuw nsw i64 %21, 1
%25 = load i32, i32* %3
%26 = sext i32 %25 to i64
%27 = icmp slt i64 %24, %26
br i1 %27, label %20, label %28
28: ; preds = %20, %2
%29 = call double (...) @omp_get_wtime()
%30 = load i32, i32* %4
%31 = load i32, i32* %3
%32 = load i32, i32* %5
%33 = call i32 @parallel_producer_consumer(i32* %13, i32 %30, i32* %17, i32 %31, i32 %32)
%34 = call double (...) @omp_get_wtime()
%35 = fsub double %34, %29
%36 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), double %35)
%37 = call i32 @free(i32* %13)
%38 = call i32 @free(i32* %17)
ret i32 0
}