#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 */
int /*<<< orphan*/ assert(int /*<<< orphan*/);
int /*<<< orphan*/ exit(int);
int get_queue(struct fifo *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ put_queue(struct fifo *, int);
struct fifo *queue_init(int);
int main() {
  struct fifo *data_queue = NULL;
  int count = 50;
  int value = 0;
  data_queue = queue_init(100);
  if (data_queue == NULL) {
    perror("ENOMEM\n");
    exit(1);
  }
  while (count) {
    put_queue(data_queue, count);
    count--;
  }
  count = 50;
  while (count) {
    value = get_queue(data_queue);
    printf("%d : ", value);
    if (value != count) {
      printf("error\n");
      assert(0);
    }
    count--;
  }
  printf("\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x0,-0x10(%rbp)
movl   $0x32,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    $0x64,%edi
call   1090 <queue_init@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11c4 <main+0x54>
lea    0xe4b(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
jmp    11c9 <main+0x59>
cmpl   $0x0,-0x14(%rbp)
je     11ed <main+0x7d>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1060 <put_queue@plt>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
jmp    11c9 <main+0x59>
movl   $0x32,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     124a <main+0xda>
mov    -0x10(%rbp),%rdi
call   1030 <get_queue@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%esi
lea    0xdf4(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
je     123c <main+0xcc>
lea    0xde0(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %edi,%edi
call   1050 <assert@plt>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
jmp    11f4 <main+0x84>
lea    0xdb5(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    $0x64,%edi
call   10b0 <queue_init@plt>
test   %rax,%rax
je     1225 <main+0x95>
mov    %rax,%r12
mov    $0x32,%ebp
nop
mov    %r12,%rdi
mov    %ebp,%esi
call   1080 <put_queue@plt>
add    $0xffffffff,%ebp
jne    11b0 <main+0x20>
mov    $0x32,%ebx
lea    0xe3d(%rip),%r14
lea    0xe3c(%rip),%r15
jmp    11e5 <main+0x55>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
add    $0xffffffff,%ebx
je     1210 <main+0x80>
mov    %r12,%rdi
call   1050 <get_queue@plt>
mov    %eax,%ebp
mov    %r14,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
cmp    %ebp,%ebx
je     11e0 <main+0x50>
mov    %r15,%rdi
call   1040 <puts@plt>
xor    %edi,%edi
call   1070 <assert@plt>
jmp    11e0 <main+0x50>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdd4(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>

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

LLVM IR (-O2):
%struct.fifo = type { i32 }
@.str = [8 x i8] c"ENOMEM\0A\00"
@.str.1 = [6 x i8] c"%d : \00"
@str = [6 x i8] c"error\00"
define i32 @main() {
%1 = tail call %struct.fifo* @queue_init(i32 100)
%2 = icmp eq %struct.fifo* %1, null
br i1 %2, label %3, label %6
3: ; preds = %0
%4 = tail call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%5 = tail call i32 @exit(i32 1)
unreachable
6: ; preds = %0, %6
%7 = phi i32 [ %9, %6 ], [ 50, %0 ]
%8 = tail call i32 @put_queue(%struct.fifo* %1, i32 %7)
%9 = add nsw i32 %7, -1
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %6
11: ; preds = %6, %19
%12 = phi i32 [ %20, %19 ], [ 50, %6 ]
%13 = tail call i32 @get_queue(%struct.fifo* %1)
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %13)
%15 = icmp eq i32 %13, %12
br i1 %15, label %19, label %16
16: ; preds = %11
%17 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @str, i64 0, i64 0))
%18 = tail call i32 @assert(i32 0)
br label %19
19: ; preds = %16, %11
%20 = add nsw i32 %12, -1
%21 = icmp eq i32 %20, 0
br i1 %21, label %22, label %11
22: ; preds = %19
%23 = tail call i32 @putchar(i32 10)
ret i32 0
}