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

/* Variables and functions */
struct fifo *fifo_init();
int get_fif0(struct fifo *);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ put_fif0(struct fifo *, int);
scalar_t__ queue_empty(struct fifo *);
int rand();
int main() {
  struct fifo *queue = NULL;
  int count = 100;
  int read_count = 0;
  int value = 0;
  queue = fifo_init();
  while (count || (queue_empty(queue) == 0)) {
    value = rand() % 50;
    if (value % 2) {
      printf("put_fif0 %d\n", value);
      put_fif0(queue, value);
    } else {
      value = get_fif0(queue);
      printf("get_fif0 %d\n", value);
      read_count++;
    }
  }
  printf("read_count:  %d\n", read_count);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x0,-0x10(%rbp)
movl   $0x64,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    $0x0,%al
call   1070 <fifo_init@plt>
mov    %rax,-0x10(%rbp)
mov    $0x1,%al
cmpl   $0x0,-0x14(%rbp)
mov    %al,-0x1d(%rbp)
jne    11b9 <main+0x59>
mov    -0x10(%rbp),%rdi
call   1030 <queue_empty@plt>
cmp    $0x0,%rax
sete   %al
mov    %al,-0x1d(%rbp)
mov    -0x1d(%rbp),%al
test   $0x1,%al
jne    11c9 <main+0x69>
jmp    1238 <main+0xd8>
mov    $0x0,%al
call   1080 <rand@plt>
mov    $0x32,%ecx
cltd
idiv   %ecx
mov    %edx,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
je     120f <main+0xaf>
mov    -0x1c(%rbp),%esi
lea    0xe07(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1050 <put_fif0@plt>
jmp    1233 <main+0xd3>
mov    -0x10(%rbp),%rdi
call   1060 <get_fif0@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%esi
lea    0xde8(%rip),%rdi
call   1040 <printf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1197 <main+0x37>
mov    -0x18(%rbp),%esi
lea    0xdd8(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
xor    %eax,%eax
call   1060 <fifo_init@plt>
mov    %rax,%r12
lea    0xea4(%rip),%r14
lea    0xe90(%rip),%r15
jmp    1194 <main+0x44>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r15,%rdi
mov    %ebx,%esi
call   1030 <printf@plt>
mov    %r12,%rdi
mov    %ebx,%esi
call   1040 <put_fif0@plt>
xor    %eax,%eax
call   1070 <rand@plt>
movslq %eax,%rbx
imul   $0x51eb851f,%rbx,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x24,%rax
add    %ecx,%eax
imul   $0x32,%eax,%eax
sub    %eax,%ebx
test   $0x1,%bl
jne    1180 <main+0x30>
mov    %r12,%rdi
call   1050 <get_fif0@plt>
mov    %r14,%rdi
mov    %eax,%esi
call   1030 <printf@plt>
jmp    1194 <main+0x44>

LLVM IR (-O0):
%struct.fifo = type { i32 }
@.str = [13 x i8] c"put_fif0 %d\0A\00"
@.str.1 = [13 x i8] c"get_fif0 %d\0A\00"
@.str.2 = [17 x i8] c"read_count: %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.fifo*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
store %struct.fifo* null, %struct.fifo** %2
store i32 100, i32* %3
store i32 0, i32* %4
store i32 0, i32* %5
%6 = call %struct.fifo* (...) @fifo_init()
store %struct.fifo* %6, %struct.fifo** %2
br label %7
7: ; preds = %35, %0
%8 = load i32, i32* %3
%9 = icmp ne i32 %8, 0
br i1 %9, label %14, label %10
10: ; preds = %7
%11 = load %struct.fifo*, %struct.fifo** %2
%12 = call i64 @queue_empty(%struct.fifo* %11)
%13 = icmp eq i64 %12, 0
br label %14
14: ; preds = %10, %7
%15 = phi i1 [ true, %7 ], [ %13, %10 ]
br i1 %15, label %16, label %36
16: ; preds = %14
%17 = call i32 (...) @rand()
%18 = srem i32 %17, 50
store i32 %18, i32* %5
%19 = load i32, i32* %5
%20 = srem i32 %19, 2
%21 = icmp ne i32 %20, 0
br i1 %21, label %22, label %28
22: ; preds = %16
%23 = load i32, i32* %5
%24 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %23)
%25 = load %struct.fifo*, %struct.fifo** %2
%26 = load i32, i32* %5
%27 = call i32 @put_fif0(%struct.fifo* %25, i32 %26)
br label %35
28: ; preds = %16
%29 = load %struct.fifo*, %struct.fifo** %2
%30 = call i32 @get_fif0(%struct.fifo* %29)
store i32 %30, i32* %5
%31 = load i32, i32* %5
%32 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 %31)
%33 = load i32, i32* %4
%34 = add nsw i32 %33, 1
store i32 %34, i32* %4
br label %35
35: ; preds = %28, %22
br label %7
36: ; preds = %14
%37 = load i32, i32* %4
%38 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i32 %37)
ret i32 0
}

LLVM IR (-O2):
%struct.fifo = type { i32 }
@.str = [13 x i8] c"put_fif0 %d\0A\00"
@.str.1 = [13 x i8] c"get_fif0 %d\0A\00"
define i32 @main() {
%1 = tail call %struct.fifo* (...) @fifo_init()
br label %2
2: ; preds = %13, %0
%3 = tail call i32 (...) @rand()
%4 = srem i32 %3, 50
%5 = and i32 %4, 1
%6 = icmp eq i32 %5, 0
br i1 %6, label %10, label %7
7: ; preds = %2
%8 = tail call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %4)
%9 = tail call i32 @put_fif0(%struct.fifo* %1, i32 %4)
br label %13
10: ; preds = %2
%11 = tail call i32 @get_fif0(%struct.fifo* %1)
%12 = tail call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 %11)
br label %13
13: ; preds = %10, %7
br label %2
}