#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 */
typedef int /*<<< orphan*/ sem_t;

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int, double);
double *malloc(int);
int /*<<< orphan*/ pthread_exit(void *);
int /*<<< orphan*/ sem_post(int /*<<< orphan*/ *);
int /*<<< orphan*/ sem_wait(int /*<<< orphan*/ *);
int /*<<< orphan*/ stdout;
void *Consumidor(void *p) {
  extern sem_t mutex, full, empty;
  extern double bufer[10];
  int *it;
  extern int c_index;
  double valor = 0, *suma;
  it = (int *)p;
  suma = malloc(sizeof(double));
  *suma = 0.0;
  while (valor != -1) {
    sem_wait(&full);
    sem_wait(&mutex);
    valor = bufer[c_index];
    c_index = (c_index + 1) % 10;
    sem_post(&mutex);
    sem_post(&empty);
    fprintf(stdout, "C(%d): %f\n", *it, valor);
    *suma += valor;
  }
  *suma += 1.0;
  fprintf(stdout, "C(%d) Suma: %f\n", *it, *suma);
  pthread_exit((void *)suma);
}


x86 assembly (clang, -O0):
<Consumidor>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    $0x8,%edi
call   1070 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax)
movsd  -0x20(%rbp),%xmm0
movsd  0xe6e(%rip),%xmm1
ucomisd %xmm1,%xmm0
jne    11a7 <Consumidor+0x57>
jp     11a7 <Consumidor+0x57>
jmp    1245 <Consumidor+0xf5>
mov    0x2e3a(%rip),%rdi
call   1030 <sem_wait@plt>
mov    0x2dfe(%rip),%rdi
call   1030 <sem_wait@plt>
mov    0x2e02(%rip),%rax
movslq (%rax),%rcx
mov    0x2e10(%rip),%rax
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    0x2de7(%rip),%rax
mov    (%rax),%eax
add    $0x1,%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    0x2dd3(%rip),%rax
mov    %edx,(%rax)
mov    0x2dba(%rip),%rdi
call   1040 <sem_post@plt>
mov    0x2dc6(%rip),%rdi
call   1040 <sem_post@plt>
mov    0x2daa(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rax
mov    (%rax),%edx
movsd  -0x20(%rbp),%xmm0
lea    0xde6(%rip),%rsi
call   1050 <fprintf@plt>
movsd  -0x20(%rbp),%xmm0
mov    -0x28(%rbp),%rax
addsd  (%rax),%xmm0
movsd  %xmm0,(%rax)
jmp    1185 <Consumidor+0x35>
mov    -0x28(%rbp),%rax
movsd  0xdb7(%rip),%xmm0
addsd  (%rax),%xmm0
movsd  %xmm0,(%rax)
mov    0x2d60(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rax
mov    (%rax),%edx
mov    -0x28(%rbp),%rax
movsd  (%rax),%xmm0
lea    0xda4(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x28(%rbp),%rdi
call   1060 <pthread_exit@plt>
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Consumidor>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%r12
mov    $0x8,%edi
call   1070 <malloc@plt>
mov    %rax,0x8(%rsp)
xorpd  %xmm0,%xmm0
mov    0x2e3d(%rip),%rbx
mov    0x2e46(%rip),%r15
mov    0x2e47(%rip),%r13
mov    0x2e30(%rip),%r14
lea    0xe79(%rip),%rbp
nopw   0x0(%rax,%rax,1)
movsd  %xmm0,0x10(%rsp)
mov    0x2e3b(%rip),%rdi
call   1030 <sem_wait@plt>
mov    %rbx,%rdi
call   1030 <sem_wait@plt>
movslq (%r15),%rax
mov    0x2e1c(%rip),%rcx
movsd  (%rcx,%rax,8),%xmm0
movsd  %xmm0,(%rsp)
add    $0x1,%eax
cltq
imul   $0x66666667,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x22,%rcx
add    %edx,%ecx
add    %ecx,%ecx
lea    (%rcx,%rcx,4),%ecx
sub    %ecx,%eax
mov    %eax,(%r15)
mov    %rbx,%rdi
call   1040 <sem_post@plt>
mov    %r13,%rdi
call   1040 <sem_post@plt>
mov    (%r14),%edi
mov    (%r12),%edx
mov    %rbp,%rsi
movsd  (%rsp),%xmm0
call   1050 <fprintf@plt>
movsd  0x10(%rsp),%xmm0
movsd  (%rsp),%xmm1
addsd  %xmm1,%xmm0
ucomisd 0xdd4(%rip),%xmm1
jne    11a0 <Consumidor+0x50>
jp     11a0 <Consumidor+0x50>
addsd  0xdc8(%rip),%xmm0
mov    0x8(%rsp),%rbx
movsd  %xmm0,(%rbx)
mov    (%r14),%edi
mov    (%r12),%edx
lea    0xdc4(%rip),%rsi
call   1050 <fprintf@plt>
mov    %rbx,%rdi
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1060 <pthread_exit@plt>

LLVM IR (-O0):
@full = external global i32
@mutex = external global i32
@bufer = external global [10 x double]
@c_index = external global i32
@empty = external global i32
@stdout = global i32 0
@.str = [11 x i8] c"C(%d): %f\0A\00"
@.str.1 = [16 x i8] c"C(%d) Suma: %f\0A\00"
define i8* @Consumidor(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca double
%6 = alloca double*
store i8* %0, i8** %3
store double 0.000000e+00, double* %5
%7 = load i8*, i8** %3
%8 = bitcast i8* %7 to i32*
store i32* %8, i32** %4
%9 = call double* @malloc(i32 8)
store double* %9, double** %6
%10 = load double*, double** %6
store double 0.000000e+00, double* %10
br label %11
11: ; preds = %14, %1
%12 = load double, double* %5
%13 = fcmp une double %12, -1.000000e+00
br i1 %13, label %14, label %35
14: ; preds = %11
%15 = call i32 @sem_wait(i32* @full)
%16 = call i32 @sem_wait(i32* @mutex)
%17 = load i32, i32* @c_index
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds [10 x double], [10 x double]* @bufer, i64 0, i64 %18
%20 = load double, double* %19
store double %20, double* %5
%21 = load i32, i32* @c_index
%22 = add nsw i32 %21, 1
%23 = srem i32 %22, 10
store i32 %23, i32* @c_index
%24 = call i32 @sem_post(i32* @mutex)
%25 = call i32 @sem_post(i32* @empty)
%26 = load i32, i32* @stdout
%27 = load i32*, i32** %4
%28 = load i32, i32* %27
%29 = load double, double* %5
%30 = call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %28, double %29)
%31 = load double, double* %5
%32 = load double*, double** %6
%33 = load double, double* %32
%34 = fadd double %33, %31
store double %34, double* %32
br label %11
35: ; preds = %11
%36 = load double*, double** %6
%37 = load double, double* %36
%38 = fadd double %37, 1.000000e+00
store double %38, double* %36
%39 = load i32, i32* @stdout
%40 = load i32*, i32** %4
%41 = load i32, i32* %40
%42 = load double*, double** %6
%43 = load double, double* %42
%44 = call i32 @fprintf(i32 %39, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i32 %41, double %43)
%45 = load double*, double** %6
%46 = bitcast double* %45 to i8*
%47 = call i32 @pthread_exit(i8* %46)
%48 = load i8*, i8** %2
ret i8* %48
}

LLVM IR (-O2):
@full = external global i32
@mutex = external global i32
@bufer = external global [10 x double]
@c_index = external global i32
@empty = external global i32
@stdout = global i32 0
@.str = [11 x i8] c"C(%d): %f\0A\00"
@.str.1 = [16 x i8] c"C(%d) Suma: %f\0A\00"
define noalias i8* @Consumidor(i8* nocapture %0) {
%2 = bitcast i8* %0 to i32*
%3 = tail call double* @malloc(i32 8)
br label %4
4: ; preds = %1, %4
%5 = phi double [ 0.000000e+00, %1 ], [ %19, %4 ]
%6 = tail call i32 @sem_wait(i32* @full)
%7 = tail call i32 @sem_wait(i32* @mutex)
%8 = load i32, i32* @c_index
%9 = sext i32 %8 to i64
%10 = getelementptr inbounds [10 x double], [10 x double]* @bufer, i64 0, i64 %9
%11 = load double, double* %10
%12 = add nsw i32 %8, 1
%13 = srem i32 %12, 10
store i32 %13, i32* @c_index
%14 = tail call i32 @sem_post(i32* @mutex)
%15 = tail call i32 @sem_post(i32* @empty)
%16 = load i32, i32* @stdout
%17 = load i32, i32* %2
%18 = tail call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %17, double %11)
%19 = fadd double %11, %5
%20 = fcmp une double %11, -1.000000e+00
br i1 %20, label %4, label %21
21: ; preds = %4
%22 = fadd double %19, 1.000000e+00
store double %22, double* %3
%23 = load i32, i32* @stdout
%24 = load i32, i32* %2
%25 = tail call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i32 %24, double %22)
%26 = bitcast double* %3 to i8*
%27 = tail call i32 @pthread_exit(i8* %26)
ret i8* undef
}