#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, int *);
int SacarDato(int);
int /*<<< orphan*/ printf(char *, 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;
  int i;
  int ind_c = 0;
  int dato, total_c = 0;
  for (i = 0; i < 1000; i++) {
    sem_wait(&entradas_ocupadas);
    sem_wait(&mutex);
    dato = SacarDato(ind_c);
    sem_post(&mutex);
    sem_post(&entradas_libres);
    ConsumirDato(dato, &total_c);
    ind_c = (ind_c + 1) % 100;
  }
  printf("Total consumidor: %d\n", total_c);
  pthread_exit(NULL);
}


x86 assembly (clang, -O0):
<consumidor>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x3e8,-0x14(%rbp)
jge    11f4 <consumidor+0x94>
mov    0x2e4b(%rip),%rdi
call   1030 <sem_wait@plt>
mov    0x2e2f(%rip),%rdi
call   1030 <sem_wait@plt>
mov    -0x18(%rbp),%edi
call   1080 <SacarDato@plt>
mov    %eax,-0x1c(%rbp)
mov    0x2e18(%rip),%rdi
call   1060 <sem_post@plt>
mov    0x2e24(%rip),%rdi
call   1060 <sem_post@plt>
mov    -0x1c(%rbp),%edi
lea    -0x20(%rbp),%rsi
call   1040 <ConsumirDato@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    $0x64,%ecx
cltd
idiv   %ecx
mov    %edx,-0x18(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1181 <consumidor+0x21>
mov    -0x20(%rbp),%esi
lea    0xe02(%rip),%rdi
call   1050 <printf@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1070 <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
movl   $0x0,0x4(%rsp)
xor    %ebx,%ebx
mov    $0x3e8,%r14d
mov    0x2e4e(%rip),%r15
mov    0x2e5f(%rip),%r12
lea    0x4(%rsp),%r13
xchg   %ax,%ax
mov    0x2e49(%rip),%rdi
call   1030 <sem_wait@plt>
mov    %r15,%rdi
call   1030 <sem_wait@plt>
mov    %ebx,%edi
call   1080 <SacarDato@plt>
mov    %eax,%ebp
mov    %r15,%rdi
call   1060 <sem_post@plt>
mov    %r12,%rdi
call   1060 <sem_post@plt>
mov    %ebp,%edi
mov    %r13,%rsi
call   1040 <ConsumirDato@plt>
mov    %ebx,%eax
add    $0x1,%eax
cltq
imul   $0x51eb851f,%rax,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x25,%rax
add    %ecx,%eax
imul   $0x64,%eax,%eax
neg    %eax
add    %eax,%ebx
add    $0x1,%ebx
add    $0xffffffff,%r14d
jne    1190 <consumidor+0x30>
mov    0x4(%rsp),%esi
lea    0xe03(%rip),%rdi
call   1050 <printf@plt>
xor    %edi,%edi
call   1070 <pthread_exit@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@entradas_ocupadas = external global i32
@mutex = external global i32
@entradas_libres = external global i32
@.str = [22 x i8] c"Total consumidor: %d\0A\00"
define i8* @consumidor(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %3
store i32 0, i32* %5
store i32 0, i32* %7
store i32 0, i32* %4
br label %8
8: ; preds = %23, %1
%9 = load i32, i32* %4
%10 = icmp slt i32 %9, 1000
br i1 %10, label %11, label %26
11: ; preds = %8
%12 = call i32 @sem_wait(i32* @entradas_ocupadas)
%13 = call i32 @sem_wait(i32* @mutex)
%14 = load i32, i32* %5
%15 = call i32 @SacarDato(i32 %14)
store i32 %15, i32* %6
%16 = call i32 @sem_post(i32* @mutex)
%17 = call i32 @sem_post(i32* @entradas_libres)
%18 = load i32, i32* %6
%19 = call i32 @ConsumirDato(i32 %18, i32* %7)
%20 = load i32, i32* %5
%21 = add nsw i32 %20, 1
%22 = srem i32 %21, 100
store i32 %22, i32* %5
br label %23
23: ; preds = %11
%24 = load i32, i32* %4
%25 = add nsw i32 %24, 1
store i32 %25, i32* %4
br label %8
26: ; preds = %8
%27 = load i32, i32* %7
%28 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 %27)
%29 = call i32 @pthread_exit(i32* null)
%30 = load i8*, i8** %2
ret i8* %30
}

LLVM IR (-O2):
@entradas_ocupadas = external global i32
@mutex = external global i32
@entradas_libres = external global i32
@.str = [22 x i8] c"Total consumidor: %d\0A\00"
define noalias i8* @consumidor(i8* nocapture readnone %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
store i32 0, i32* %2
br label %4
4: ; preds = %1, %4
%5 = phi i32 [ 0, %1 ], [ %15, %4 ]
%6 = phi i32 [ 0, %1 ], [ %14, %4 ]
%7 = call i32 @sem_wait(i32* @entradas_ocupadas)
%8 = call i32 @sem_wait(i32* @mutex)
%9 = call i32 @SacarDato(i32 %6)
%10 = call i32 @sem_post(i32* @mutex)
%11 = call i32 @sem_post(i32* @entradas_libres)
%12 = call i32 @ConsumirDato(i32 %9, i32* %2)
%13 = add nsw i32 %6, 1
%14 = srem i32 %13, 100
%15 = add nuw nsw i32 %5, 1
%16 = icmp eq i32 %15, 1000
br i1 %16, label %17, label %4
17: ; preds = %4
%18 = load i32, i32* %2
%19 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 %18)
%20 = call i32 @pthread_exit(i32* null)
ret i8* undef
}