#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 myremove();
int /*<<< orphan*/ printf(char *, int, ...);
int /*<<< orphan*/ pthread_exit(int /*<<< orphan*/ *);
void *consume(void *threadid) {
  int sum = 0;
  int ret = 0;
  int cont_c = 0;
  printf("Consumidor #%d iniciou...\n", (int)threadid);
  while (cont_c < 100) {
    ret = myremove();
    if (ret > 0) {
      sum += 10;
    }
    cont_c++;
  }
  printf("Soma do que foi consumido pelo Consumidor #%d : %d\n", (int)threadid,
         sum);
  pthread_exit(NULL);
  return 0;
}


x86 assembly (clang, -O0):
<consume>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x8(%rbp),%rax
mov    %eax,%esi
lea    0xea2(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
cmpl   $0x64,-0x14(%rbp)
jge    119a <consume+0x6a>
mov    $0x0,%al
call   1030 <myremove@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jle    118c <consume+0x5c>
mov    -0xc(%rbp),%eax
add    $0xa,%eax
mov    %eax,-0xc(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1165 <consume+0x35>
mov    -0x8(%rbp),%rax
mov    %eax,%esi
mov    -0xc(%rbp),%edx
lea    0xe71(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1050 <pthread_exit@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<consume>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%r14
lea    0xec2(%rip),%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x64,%ebp
xor    %edx,%edx
nop
mov    %edx,%ebx
xor    %eax,%eax
call   1030 <myremove@plt>
lea    0xa(%rbx),%edx
test   %eax,%eax
cmovle %ebx,%edx
add    $0xffffffff,%ebp
jne    1150 <consume+0x20>
lea    0xeae(%rip),%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %edi,%edi
call   1050 <pthread_exit@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [27 x i8] c"Consumidor #%d iniciou...\0A\00"
@.str.1 = [52 x i8] c"Soma do que foi consumido pelo Consumidor #%d : %d\0A\00"
define i8* @consume(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %2
store i32 0, i32* %3
store i32 0, i32* %4
store i32 0, i32* %5
%6 = load i8*, i8** %2
%7 = ptrtoint i8* %6 to i32
%8 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i32 %7)
br label %9
9: ; preds = %19, %1
%10 = load i32, i32* %5
%11 = icmp slt i32 %10, 100
br i1 %11, label %12, label %22
12: ; preds = %9
%13 = call i32 (...) @myremove()
store i32 %13, i32* %4
%14 = load i32, i32* %4
%15 = icmp sgt i32 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %12
%17 = load i32, i32* %3
%18 = add nsw i32 %17, 10
store i32 %18, i32* %3
br label %19
19: ; preds = %16, %12
%20 = load i32, i32* %5
%21 = add nsw i32 %20, 1
store i32 %21, i32* %5
br label %9
22: ; preds = %9
%23 = load i8*, i8** %2
%24 = ptrtoint i8* %23 to i32
%25 = load i32, i32* %3
%26 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.1, i64 0, i64 0), i32 %24, i32 %25)
%27 = call i32 @pthread_exit(i32* null)
ret i8* null
}

LLVM IR (-O2):
@.str = [27 x i8] c"Consumidor #%d iniciou...\0A\00"
@.str.1 = [52 x i8] c"Soma do que foi consumido pelo Consumidor #%d : %d\0A\00"
define noalias i8* @consume(i8* %0) {
%2 = ptrtoint i8* %0 to i64
%3 = trunc i64 %2 to i32
%4 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i32 %3)
br label %5
5: ; preds = %1, %5
%6 = phi i32 [ 0, %1 ], [ %12, %5 ]
%7 = phi i32 [ 0, %1 ], [ %11, %5 ]
%8 = tail call i32 (...) @myremove()
%9 = icmp sgt i32 %8, 0
%10 = add nsw i32 %7, 10
%11 = select i1 %9, i32 %10, i32 %7
%12 = add nuw nsw i32 %6, 1
%13 = icmp eq i32 %12, 100
br i1 %13, label %14, label %5
14: ; preds = %5
%15 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.1, i64 0, i64 0), i32 %3, i32 %11)
%16 = tail call i32 @pthread_exit(i32* null)
ret i8* null
}