#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 */
struct LamportQueue {
  int dummy;
};

/* Variables and functions */
scalar_t__ LamportQueue_pop(struct LamportQueue *, int *);
int /*<<< orphan*/ assert(int);
void *consumer(void *p) {
  struct LamportQueue *queue = (struct LamportQueue *)p;
  int i;
  for (i = 0; i < 100;) {
    int v;
    if (LamportQueue_pop(queue, &v)) {
      ++i;
      assert(v == 36);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<consumer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x64,-0x14(%rbp)
jge    117b <consumer+0x5b>
mov    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1040 <LamportQueue_pop@plt>
cmp    $0x0,%rax
je     1176 <consumer+0x56>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x24,-0x18(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
jmp    113b <consumer+0x1b>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<consumer>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
xor    %ebp,%ebp
lea    0xc(%rsp),%r14
jmp    1145 <consumer+0x25>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
cmp    $0x64,%ebp
jge    116a <consumer+0x4a>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <LamportQueue_pop@plt>
test   %rax,%rax
je     1140 <consumer+0x20>
add    $0x1,%ebp
xor    %edi,%edi
cmpl   $0x24,0xc(%rsp)
sete   %dil
call   1030 <assert@plt>
jmp    1140 <consumer+0x20>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.LamportQueue = type { i32 }
define i8* @consumer(i8* %0) {
%2 = alloca i8*
%3 = alloca %struct.LamportQueue*
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = bitcast i8* %6 to %struct.LamportQueue*
store %struct.LamportQueue* %7, %struct.LamportQueue** %3
store i32 0, i32* %4
br label %8
8: ; preds = %22, %1
%9 = load i32, i32* %4
%10 = icmp slt i32 %9, 100
br i1 %10, label %11, label %23
11: ; preds = %8
%12 = load %struct.LamportQueue*, %struct.LamportQueue** %3
%13 = call i64 @LamportQueue_pop(%struct.LamportQueue* %12, i32* %5)
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %22
15: ; preds = %11
%16 = load i32, i32* %4
%17 = add nsw i32 %16, 1
store i32 %17, i32* %4
%18 = load i32, i32* %5
%19 = icmp eq i32 %18, 36
%20 = zext i1 %19 to i32
%21 = call i32 @assert(i32 %20)
br label %22
22: ; preds = %15, %11
br label %8
23: ; preds = %8
ret i8* null
}

LLVM IR (-O2):
%struct.LamportQueue = type { i32 }
define noalias i8* @consumer(i8* %0) {
%2 = alloca i32
%3 = bitcast i8* %0 to %struct.LamportQueue*
%4 = bitcast i32* %2 to i8*
br label %5
5: ; preds = %1, %15
%6 = phi i32 [ 0, %1 ], [ %16, %15 ]
%7 = call i64 @LamportQueue_pop(%struct.LamportQueue* %3, i32* %2)
%8 = icmp eq i64 %7, 0
br i1 %8, label %15, label %9
9: ; preds = %5
%10 = add nsw i32 %6, 1
%11 = load i32, i32* %2
%12 = icmp eq i32 %11, 36
%13 = zext i1 %12 to i32
%14 = call i32 @assert(i32 %13)
br label %15
15: ; preds = %9, %5
%16 = phi i32 [ %10, %9 ], [ %6, %5 ]
%17 = icmp slt i32 %16, 100
br i1 %17, label %5, label %18
18: ; preds = %15
ret i8* null
}