#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 buffer {
  int dummy;
};

/* Variables and functions */
scalar_t__ push(struct buffer *, int);
int rand();
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
void *enqueue(void *ptr) {
  struct buffer *buffer = (struct buffer *)ptr;
  int i = 0;
  int wait_time;
  int rnd;
  srand(time(NULL));
  while (i < 100) {
    wait_time = rand() % 10;
    sleep(wait_time);
    rnd = rand();
    while (0 == push(buffer, rnd)) {
      sleep(5);
    }
    i++;
  }
}


x86 assembly (clang, -O0):
<enqueue>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1040 <time@plt>
mov    %eax,%edi
call   1030 <srand@plt>
cmpl   $0x64,-0x1c(%rbp)
jge    11e0 <enqueue+0x90>
mov    $0x0,%al
call   1070 <rand@plt>
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %edx,-0x20(%rbp)
mov    -0x20(%rbp),%edi
call   1060 <sleep@plt>
mov    $0x0,%al
call   1070 <rand@plt>
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x24(%rbp),%esi
call   1050 <push@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    11d2 <enqueue+0x82>
mov    $0x5,%edi
call   1060 <sleep@plt>
jmp    11a9 <enqueue+0x59>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    117b <enqueue+0x2b>
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<enqueue>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%rbx
xor    %edi,%edi
call   1040 <time@plt>
mov    %eax,%edi
call   1030 <srand@plt>
xor    %r14d,%r14d
jmp    117a <enqueue+0x2a>
nopw   0x0(%rax,%rax,1)
add    $0x1,%r14d
cmp    $0x64,%r14d
je     11db <enqueue+0x8b>
xor    %eax,%eax
call   1070 <rand@plt>
movslq %eax,%rdi
imul   $0x66666667,%rdi,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x22,%rax
add    %ecx,%eax
add    %eax,%eax
lea    (%rax,%rax,4),%eax
sub    %eax,%edi
call   1060 <sleep@plt>
xor    %eax,%eax
call   1070 <rand@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
mov    %eax,%esi
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
call   1050 <push@plt>
test   %rax,%rax
jne    1170 <enqueue+0x20>
mov    $0x5,%edi
call   1060 <sleep@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
jmp    11c0 <enqueue+0x70>
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.buffer = type { i32 }
define i8* @enqueue(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca %struct.buffer*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %3
%8 = load i8*, i8** %3
%9 = bitcast i8* %8 to %struct.buffer*
store %struct.buffer* %9, %struct.buffer** %4
store i32 0, i32* %5
%10 = call i32 @time(i32* null)
%11 = call i32 @srand(i32 %10)
br label %12
12: ; preds = %28, %1
%13 = load i32, i32* %5
%14 = icmp slt i32 %13, 100
br i1 %14, label %15, label %31
15: ; preds = %12
%16 = call i32 (...) @rand()
%17 = srem i32 %16, 10
store i32 %17, i32* %6
%18 = load i32, i32* %6
%19 = call i32 @sleep(i32 %18)
%20 = call i32 (...) @rand()
store i32 %20, i32* %7
br label %21
21: ; preds = %26, %15
%22 = load %struct.buffer*, %struct.buffer** %4
%23 = load i32, i32* %7
%24 = call i64 @push(%struct.buffer* %22, i32 %23)
%25 = icmp eq i64 0, %24
br i1 %25, label %26, label %28
26: ; preds = %21
%27 = call i32 @sleep(i32 5)
br label %21
28: ; preds = %21
%29 = load i32, i32* %5
%30 = add nsw i32 %29, 1
store i32 %30, i32* %5
br label %12
31: ; preds = %12
%32 = load i8*, i8** %2
ret i8* %32
}

LLVM IR (-O2):
%struct.buffer = type { i32 }
define noalias i8* @enqueue(i8* %0) {
%2 = bitcast i8* %0 to %struct.buffer*
%3 = tail call i32 @time(i32* null)
%4 = tail call i32 @srand(i32 %3)
br label %5
5: ; preds = %1, %17
%6 = phi i32 [ 0, %1 ], [ %18, %17 ]
%7 = tail call i32 (...) @rand()
%8 = srem i32 %7, 10
%9 = tail call i32 @sleep(i32 %8)
%10 = tail call i32 (...) @rand()
%11 = tail call i64 @push(%struct.buffer* %2, i32 %10)
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %17
13: ; preds = %5, %13
%14 = tail call i32 @sleep(i32 5)
%15 = tail call i64 @push(%struct.buffer* %2, i32 %10)
%16 = icmp eq i64 %15, 0
br i1 %16, label %13, label %17
17: ; preds = %13, %5
%18 = add nuw nsw i32 %6, 1
%19 = icmp eq i32 %18, 100
br i1 %19, label %20, label %5
20: ; preds = %17
ret i8* undef
}