#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*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int *malloc(int);
double omp_get_wtime();
int /*<<< orphan*/ omp_set_num_threads(int);
int /*<<< orphan*/ printf(char *, double);
int /*<<< orphan*/ producer_consumer(int *, int, int *, int);
int /*<<< orphan*/ scanf(char *, int *, ...);
int /*<<< orphan*/ stderr;
int main() {
  int num_threads, cycles, buf_size, *buf, *vec;
  int i;
  double start;
  scanf("%d %d %d", &num_threads, &buf_size, &cycles);
  buf = malloc(buf_size * sizeof(int));
  vec = malloc(buf_size * sizeof(int));
  if (buf == NULL) {
    fprintf(stderr, "Could not allocate buffer\n");
    exit(1);
  }
  for (i = 0; i < buf_size; i++) {
    scanf("%d", &vec[i]);
  }
  omp_set_num_threads(num_threads);
  start = omp_get_wtime();
  producer_consumer(buf, cycles, vec, buf_size);
  printf("%lf\n", omp_get_wtime() - start);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe6a(%rip),%rdi
lea    -0x8(%rbp),%rsi
lea    -0x10(%rbp),%rdx
lea    -0xc(%rbp),%rcx
mov    $0x0,%al
call   1090 <scanf@plt>
movslq -0x10(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x18(%rbp)
movslq -0x10(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11f9 <main+0x79>
mov    0x2dff(%rip),%rax
mov    (%rax),%edi
lea    0xe1f(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    1237 <main+0xb7>
mov    -0x20(%rbp),%rsi
movslq -0x24(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
lea    0xde4(%rip),%rdi
mov    $0x0,%al
call   1090 <scanf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1200 <main+0x80>
mov    -0x8(%rbp),%edi
call   1080 <omp_set_num_threads@plt>
mov    $0x0,%al
call   1030 <omp_get_wtime@plt>
movsd  %xmm0,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x20(%rbp),%rdx
mov    -0x10(%rbp),%ecx
call   1050 <producer_consumer@plt>
mov    $0x0,%al
call   1030 <omp_get_wtime@plt>
subsd  -0x30(%rbp),%xmm0
lea    0xdb3(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x20,%rsp
lea    0xe6c(%rip),%rdi
lea    0x14(%rsp),%rsi
lea    0xc(%rsp),%rdx
lea    0x10(%rsp),%rcx
xor    %eax,%eax
call   1090 <scanf@plt>
mov    0xc(%rsp),%r12d
lea    0x0(,%r12,4),%ebx
mov    %ebx,%edi
call   1070 <malloc@plt>
mov    %rax,%r15
mov    %ebx,%edi
call   1070 <malloc@plt>
test   %r15,%r15
je     1261 <main+0xe1>
mov    %rax,%r14
test   %r12d,%r12d
jle    120f <main+0x8f>
lea    0xe26(%rip),%r12
mov    %r14,%r13
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r12,%rdi
mov    %r13,%rsi
xor    %eax,%eax
call   1090 <scanf@plt>
add    $0x1,%rbx
movslq 0xc(%rsp),%rax
add    $0x4,%r13
cmp    %rax,%rbx
jl     11f0 <main+0x70>
mov    0x14(%rsp),%edi
call   1080 <omp_set_num_threads@plt>
xor    %eax,%eax
call   1030 <omp_get_wtime@plt>
movsd  %xmm0,0x18(%rsp)
mov    0x10(%rsp),%esi
mov    0xc(%rsp),%ecx
mov    %r15,%rdi
mov    %r14,%rdx
call   1050 <producer_consumer@plt>
xor    %eax,%eax
call   1030 <omp_get_wtime@plt>
subsd  0x18(%rsp),%xmm0
lea    0xdd8(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
mov    0x2d78(%rip),%rax
mov    (%rax),%edi
lea    0xd98(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [9 x i8] c"%d %d %d\00"
@stderr = global i32 0
@.str.1 = [27 x i8] c"Could not allocate buffer\0A\00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [5 x i8] c"%lf\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i32
%8 = alloca double
store i32 0, i32* %1
%9 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32* %2, i32* %4, i32* %3)
%10 = load i32, i32* %4
%11 = sext i32 %10 to i64
%12 = mul i64 %11, 4
%13 = trunc i64 %12 to i32
%14 = call i32* @malloc(i32 %13)
store i32* %14, i32** %5
%15 = load i32, i32* %4
%16 = sext i32 %15 to i64
%17 = mul i64 %16, 4
%18 = trunc i64 %17 to i32
%19 = call i32* @malloc(i32 %18)
store i32* %19, i32** %6
%20 = load i32*, i32** %5
%21 = icmp eq i32* %20, null
br i1 %21, label %22, label %26
22: ; preds = %0
%23 = load i32, i32* @stderr
%24 = call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
%25 = call i32 @exit(i32 1)
unreachable
26: ; preds = %0
store i32 0, i32* %7
br label %27
27: ; preds = %37, %26
%28 = load i32, i32* %7
%29 = load i32, i32* %4
%30 = icmp slt i32 %28, %29
br i1 %30, label %31, label %40
31: ; preds = %27
%32 = load i32*, i32** %6
%33 = load i32, i32* %7
%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.2, i64 0, i64 0), i32* %35)
br label %37
37: ; preds = %31
%38 = load i32, i32* %7
%39 = add nsw i32 %38, 1
store i32 %39, i32* %7
br label %27
40: ; preds = %27
%41 = load i32, i32* %2
%42 = call i32 @omp_set_num_threads(i32 %41)
%43 = call double (...) @omp_get_wtime()
store double %43, double* %8
%44 = load i32*, i32** %5
%45 = load i32, i32* %3
%46 = load i32*, i32** %6
%47 = load i32, i32* %4
%48 = call i32 @producer_consumer(i32* %44, i32 %45, i32* %46, i32 %47)
%49 = call double (...) @omp_get_wtime()
%50 = load double, double* %8
%51 = fsub double %49, %50
%52 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), double %51)
ret i32 0
}

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