#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*/ ConsumirDato(int, double *);
int SacarDato(int);
int /*<<< orphan*/ pthread_exit(int /*<<< orphan*/ *);
int /*<<< orphan*/ sem_post(int /*<<< orphan*/ *);
int /*<<< orphan*/ sem_wait(int /*<<< orphan*/ *);
void *consumidor(void *p) {
  extern sem_t mutex, entradas_ocupadas, entradas_libres;
  extern int ind_c, MAX_C;
  extern double total_c;
  int i;
  int dato;
  sem_wait(&mutex);
  while (MAX_C > 0) {
    sem_post(&mutex);
    sem_wait(&entradas_ocupadas);
    sem_wait(&mutex);
    dato = SacarDato(ind_c);
    ind_c = (ind_c + 1) % 100;
    MAX_C--;
    sem_post(&mutex);
    sem_post(&entradas_libres);
    ConsumirDato(dato, &total_c);
    sem_wait(&mutex);
  }
  sem_post(&mutex);
  pthread_exit(NULL);
}


x86 assembly (clang, -O0):
<consumidor>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    0x2e55(%rip),%rdi
call   1030 <sem_wait@plt>
mov    0x2e69(%rip),%rax
cmpl   $0x0,(%rax)
jle    1217 <consumidor+0xc7>
mov    0x2e39(%rip),%rdi
call   1050 <sem_post@plt>
mov    0x2e3d(%rip),%rdi
call   1030 <sem_wait@plt>
mov    0x2e21(%rip),%rdi
call   1030 <sem_wait@plt>
mov    0x2e45(%rip),%rax
mov    (%rax),%edi
call   1070 <SacarDato@plt>
mov    %eax,-0x18(%rbp)
mov    0x2e34(%rip),%rax
mov    (%rax),%eax
add    $0x1,%eax
mov    $0x64,%ecx
cltd
idiv   %ecx
mov    0x2e20(%rip),%rax
mov    %edx,(%rax)
mov    0x2e07(%rip),%rax
mov    (%rax),%ecx
add    $0xffffffff,%ecx
mov    0x2dfb(%rip),%rax
mov    %ecx,(%rax)
mov    0x2dd2(%rip),%rdi
call   1050 <sem_post@plt>
mov    0x2dde(%rip),%rdi
call   1050 <sem_post@plt>
mov    -0x18(%rbp),%edi
mov    0x2ddf(%rip),%rsi
call   1040 <ConsumirDato@plt>
mov    0x2dab(%rip),%rdi
call   1030 <sem_wait@plt>
jmp    1168 <consumidor+0x18>
mov    0x2d9a(%rip),%rdi
call   1050 <sem_post@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1060 <pthread_exit@plt>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<consumidor>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    0x2e56(%rip),%rdi
call   1030 <sem_wait@plt>
mov    0x2e6a(%rip),%r13
cmpl   $0x0,0x0(%r13)
jle    1220 <consumidor+0xd0>
mov    0x2e38(%rip),%rbx
mov    0x2e61(%rip),%r14
mov    0x2e42(%rip),%r15
mov    0x2e4b(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rbx,%rdi
call   1050 <sem_post@plt>
mov    0x2e19(%rip),%rdi
call   1030 <sem_wait@plt>
mov    %rbx,%rdi
call   1030 <sem_wait@plt>
mov    (%r14),%edi
call   1070 <SacarDato@plt>
mov    %eax,%ebp
mov    (%r14),%eax
mov    %eax,%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
imul   $0x51eb851f,%rcx,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x25,%rcx
add    %edx,%ecx
imul   $0x64,%ecx,%ecx
neg    %ecx
add    %ecx,%eax
add    $0x1,%eax
mov    %eax,(%r14)
addl   $0xffffffff,0x0(%r13)
mov    %rbx,%rdi
call   1050 <sem_post@plt>
mov    %r15,%rdi
call   1050 <sem_post@plt>
mov    %ebp,%edi
mov    %r12,%rsi
call   1040 <ConsumirDato@plt>
mov    %rbx,%rdi
call   1030 <sem_wait@plt>
cmpl   $0x0,0x0(%r13)
jg     11a0 <consumidor+0x50>
mov    0x2d91(%rip),%rdi
call   1050 <sem_post@plt>
xor    %edi,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1060 <pthread_exit@plt>

LLVM IR (-O0):
@mutex = external global i32
@MAX_C = external global i32
@entradas_ocupadas = external global i32
@ind_c = external global i32
@entradas_libres = external global i32
@total_c = external global double
define i8* @consumidor(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %3
%6 = call i32 @sem_wait(i32* @mutex)
br label %7
7: ; preds = %10, %1
%8 = load i32, i32* @MAX_C
%9 = icmp sgt i32 %8, 0
br i1 %9, label %10, label %26
10: ; preds = %7
%11 = call i32 @sem_post(i32* @mutex)
%12 = call i32 @sem_wait(i32* @entradas_ocupadas)
%13 = call i32 @sem_wait(i32* @mutex)
%14 = load i32, i32* @ind_c
%15 = call i32 @SacarDato(i32 %14)
store i32 %15, i32* %5
%16 = load i32, i32* @ind_c
%17 = add nsw i32 %16, 1
%18 = srem i32 %17, 100
store i32 %18, i32* @ind_c
%19 = load i32, i32* @MAX_C
%20 = add nsw i32 %19, -1
store i32 %20, i32* @MAX_C
%21 = call i32 @sem_post(i32* @mutex)
%22 = call i32 @sem_post(i32* @entradas_libres)
%23 = load i32, i32* %5
%24 = call i32 @ConsumirDato(i32 %23, double* @total_c)
%25 = call i32 @sem_wait(i32* @mutex)
br label %7
26: ; preds = %7
%27 = call i32 @sem_post(i32* @mutex)
%28 = call i32 @pthread_exit(i32* null)
%29 = load i8*, i8** %2
ret i8* %29
}

LLVM IR (-O2):
@mutex = external global i32
@MAX_C = external global i32
@entradas_ocupadas = external global i32
@ind_c = external global i32
@entradas_libres = external global i32
@total_c = external global double
define noalias i8* @consumidor(i8* nocapture readnone %0) {
%2 = tail call i32 @sem_wait(i32* @mutex)
%3 = load i32, i32* @MAX_C
%4 = icmp sgt i32 %3, 0
br i1 %4, label %5, label %22
5: ; preds = %1, %5
%6 = tail call i32 @sem_post(i32* @mutex)
%7 = tail call i32 @sem_wait(i32* @entradas_ocupadas)
%8 = tail call i32 @sem_wait(i32* @mutex)
%9 = load i32, i32* @ind_c
%10 = tail call i32 @SacarDato(i32 %9)
%11 = load i32, i32* @ind_c
%12 = add nsw i32 %11, 1
%13 = srem i32 %12, 100
store i32 %13, i32* @ind_c
%14 = load i32, i32* @MAX_C
%15 = add nsw i32 %14, -1
store i32 %15, i32* @MAX_C
%16 = tail call i32 @sem_post(i32* @mutex)
%17 = tail call i32 @sem_post(i32* @entradas_libres)
%18 = tail call i32 @ConsumirDato(i32 %10, double* @total_c)
%19 = tail call i32 @sem_wait(i32* @mutex)
%20 = load i32, i32* @MAX_C
%21 = icmp sgt i32 %20, 0
br i1 %21, label %5, label %22
22: ; preds = %5, %1
%23 = tail call i32 @sem_post(i32* @mutex)
%24 = tail call i32 @pthread_exit(i32* null)
ret i8* undef
}