#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 /*<<< orphan*/ printf(char *, ...);
int random();
int /*<<< orphan*/ sleep(long);
int /*<<< orphan*/ srand(int /*<<< orphan*/);
long syscall(int, int /*<<< orphan*/, int /*<<< orphan*/ *);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int main() {
  srand(time(NULL));
  while (1) {
    long value;
    long waitTime = random() % 10 + 5;
    value = syscall(375, 0, NULL);
    if (value == -1) {
      printf("[remove] Could not fetch value from queue\n");
    } else {
      printf("[remove] Remove returned value %lu\n", value);
    }
    sleep(waitTime);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1060 <time@plt>
mov    %eax,%edi
call   1040 <srand@plt>
mov    $0x0,%al
call   1070 <random@plt>
mov    $0xa,%ecx
cltd
idiv   %ecx
add    $0x5,%edx
movslq %edx,%rax
mov    %rax,-0x18(%rbp)
mov    $0x177,%edi
xor    %esi,%esi
xor    %eax,%eax
mov    %eax,%edx
call   1050 <syscall@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0xffffffffffffffff,-0x10(%rbp)
jne    11ca <main+0x6a>
lea    0xe42(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11dc <main+0x7c>
mov    -0x10(%rbp),%rsi
lea    0xe56(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1080 <sleep@plt>
jmp    117f <main+0x1f>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
xor    %edi,%edi
call   1070 <time@plt>
mov    %eax,%edi
call   1050 <srand@plt>
lea    0xe9b(%rip),%r14
lea    0xe70(%rip),%rbx
jmp    11d8 <main+0x68>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rbx,%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
movslq %ebp,%rax
imul   $0x66666667,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x22,%rcx
add    %edx,%ecx
add    %ecx,%ecx
lea    (%rcx,%rcx,4),%ecx
neg    %ecx
add    %ecx,%eax
add    $0x5,%eax
movslq %eax,%rdi
call   1090 <sleep@plt>
xor    %eax,%eax
call   1080 <random@plt>
mov    %eax,%ebp
mov    $0x177,%edi
xor    %esi,%esi
xor    %edx,%edx
call   1060 <syscall@plt>
cmp    $0xffffffffffffffff,%rax
jne    11a0 <main+0x30>
mov    %r14,%rdi
call   1030 <puts@plt>
jmp    11ad <main+0x3d>

LLVM IR (-O0):
@.str = [43 x i8] c"[remove] Could not fetch value from queue\0A\00"
@.str.1 = [36 x i8] c"[remove] Remove returned value %lu\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca i64
store i32 0, i32* %1
%4 = call i32 @time(i32* null)
%5 = call i32 @srand(i32 %4)
br label %6
6: ; preds = %0, %19
%7 = call i32 (...) @random()
%8 = srem i32 %7, 10
%9 = add nsw i32 %8, 5
%10 = sext i32 %9 to i64
store i64 %10, i64* %3
%11 = call i64 @syscall(i32 375, i32 0, i32* null)
store i64 %11, i64* %2
%12 = load i64, i64* %2
%13 = icmp eq i64 %12, -1
br i1 %13, label %14, label %16
14: ; preds = %6
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0))
br label %19
16: ; preds = %6
%17 = load i64, i64* %2
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0), i64 %17)
br label %19
19: ; preds = %16, %14
%20 = load i64, i64* %3
%21 = call i32 @sleep(i64 %20)
br label %6
}

LLVM IR (-O2):
@.str.1 = [36 x i8] c"[remove] Remove returned value %lu\0A\00"
@str = [42 x i8] c"[remove] Could not fetch value from queue\00"
define i32 @main() {
%1 = tail call i32 @time(i32* null)
%2 = tail call i32 @srand(i32 %1)
br label %3
3: ; preds = %0, %14
%4 = tail call i32 (...) @random()
%5 = srem i32 %4, 10
%6 = add nsw i32 %5, 5
%7 = sext i32 %6 to i64
%8 = tail call i64 @syscall(i32 375, i32 0, i32* null)
%9 = icmp eq i64 %8, -1
br i1 %9, label %10, label %12
10: ; preds = %3
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @str, i64 0, i64 0))
br label %14
12: ; preds = %3
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0), i64 %8)
br label %14
14: ; preds = %12, %10
%15 = tail call i32 @sleep(i64 %7)
br label %3
}