#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 */
scalar_t__ calloc(int, int);
int /*<<< orphan*/ free(int *);
int /*<<< orphan*/ producer_consumer_parallel(int *, int, int *, int, int);
int /*<<< orphan*/ scanf(char *, int *, ...);
int main() {
  int nThreads, nIter, n;
  int i;
  scanf(" %d %d %d", &nThreads, &nIter, &n);
  int *buffer = (int *)calloc(n, sizeof(int));
  int *vec = (int *)calloc(nIter, sizeof(int));
  for (i = 0; i < nIter; i++) {
    scanf(" %d", &vec[i]);
  }
  producer_consumer_parallel(buffer, n, vec, nIter, nThreads);
  free(buffer);
  free(vec);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeaa(%rip),%rdi
lea    -0x8(%rbp),%rsi
lea    -0xc(%rbp),%rdx
lea    -0x10(%rbp),%rcx
mov    $0x0,%al
call   1060 <scanf@plt>
mov    -0x10(%rbp),%edi
mov    $0x4,%esi
call   1050 <calloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0xc(%rbp),%edi
mov    $0x4,%esi
call   1050 <calloc@plt>
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11c9 <main+0x89>
mov    -0x28(%rbp),%rsi
movslq -0x14(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe52(%rip),%rdi
mov    $0x0,%al
call   1060 <scanf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1192 <main+0x52>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%esi
mov    -0x28(%rbp),%rdx
mov    -0xc(%rbp),%ecx
mov    -0x8(%rbp),%r8d
call   1040 <producer_consumer_parallel@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@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    $0x10,%rsp
lea    0xeac(%rip),%rdi
lea    0xc(%rsp),%rsi
lea    0x4(%rsp),%rdx
lea    0x8(%rsp),%rcx
xor    %eax,%eax
call   1060 <scanf@plt>
mov    0x8(%rsp),%edi
mov    $0x4,%esi
call   1050 <calloc@plt>
mov    %rax,%r14
mov    0x4(%rsp),%edi
mov    $0x4,%esi
call   1050 <calloc@plt>
mov    %rax,%r15
mov    0x4(%rsp),%ecx
test   %ecx,%ecx
jle    11bf <main+0x7f>
lea    0xe6b(%rip),%r12
mov    %r15,%r13
xor    %ebx,%ebx
mov    %r12,%rdi
mov    %r13,%rsi
xor    %eax,%eax
call   1060 <scanf@plt>
add    $0x1,%rbx
movslq 0x4(%rsp),%rcx
add    $0x4,%r13
cmp    %rcx,%rbx
jl     11a0 <main+0x60>
mov    0x8(%rsp),%esi
mov    0xc(%rsp),%r8d
mov    %r14,%rdi
mov    %r15,%rdx
call   1040 <producer_consumer_parallel@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %r15,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [10 x i8] c" %d %d %d\00"
@.str.1 = [4 x i8] c" %d\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*
store i32 0, i32* %1
%8 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32* %2, i32* %3, i32* %4)
%9 = load i32, i32* %4
%10 = call i64 @calloc(i32 %9, i32 4)
%11 = inttoptr i64 %10 to i32*
store i32* %11, i32** %6
%12 = load i32, i32* %3
%13 = call i64 @calloc(i32 %12, i32 4)
%14 = inttoptr i64 %13 to i32*
store i32* %14, i32** %7
store i32 0, i32* %5
br label %15
15: ; preds = %25, %0
%16 = load i32, i32* %5
%17 = load i32, i32* %3
%18 = icmp slt i32 %16, %17
br i1 %18, label %19, label %28
19: ; preds = %15
%20 = load i32*, i32** %7
%21 = load i32, i32* %5
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i32, i32* %20, i64 %22
%24 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32* %23)
br label %25
25: ; preds = %19
%26 = load i32, i32* %5
%27 = add nsw i32 %26, 1
store i32 %27, i32* %5
br label %15
28: ; preds = %15
%29 = load i32*, i32** %6
%30 = load i32, i32* %4
%31 = load i32*, i32** %7
%32 = load i32, i32* %3
%33 = load i32, i32* %2
%34 = call i32 @producer_consumer_parallel(i32* %29, i32 %30, i32* %31, i32 %32, i32 %33)
%35 = load i32*, i32** %6
%36 = call i32 @free(i32* %35)
%37 = load i32*, i32** %7
%38 = call i32 @free(i32* %37)
ret i32 0
}

LLVM IR (-O2):
@.str = [10 x i8] c" %d %d %d\00"
@.str.1 = [4 x i8] c" %d\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 ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32* %1, i32* %2, i32* %3)
%8 = load i32, i32* %3
%9 = call i64 @calloc(i32 %8, i32 4)
%10 = inttoptr i64 %9 to i32*
%11 = load i32, i32* %2
%12 = call i64 @calloc(i32 %11, i32 4)
%13 = inttoptr i64 %12 to i32*
%14 = load i32, i32* %2
%15 = icmp sgt i32 %14, 0
br i1 %15, label %16, label %24
16: ; preds = %0, %16
%17 = phi i64 [ %20, %16 ], [ 0, %0 ]
%18 = getelementptr inbounds i32, i32* %13, i64 %17
%19 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32* %18)
%20 = add nuw nsw i64 %17, 1
%21 = load i32, i32* %2
%22 = sext i32 %21 to i64
%23 = icmp slt i64 %20, %22
br i1 %23, label %16, label %24
24: ; preds = %16, %0
%25 = phi i32 [ %14, %0 ], [ %21, %16 ]
%26 = load i32, i32* %3
%27 = load i32, i32* %1
%28 = call i32 @producer_consumer_parallel(i32* %10, i32 %26, i32* %13, i32 %25, i32 %27)
%29 = call i32 @free(i32* %10)
%30 = call i32 @free(i32* %13)
ret i32 0
}