int main(void) {
  printf("At the beginning the queue is: %s\n", isEmpty() ? "empty" : "full");
  add(1);
  printf("Add 1 to the queue. Peek() returns: %i\n", peek());
  add(2);
  printf("Add 2 to the queue. Peek() returns: %i\n", peek());
  add(3);
  printf("Add 3 to the queue. Peek() returns: %i\n", peek());
  printf("take() test. Expect 1, returns: %i\n", take());
  printf("take() test. Expect 2, returns: %i\n", take());
  printf("take() test. Expect 3, returns: %i\n", take());
  printf("At the end the queue is: %s\n", isEmpty() ? "empty" : "full");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1060 <isEmpty@plt>
mov    %eax,%ecx
lea    0xeba(%rip),%rsi
lea    0xead(%rip),%rax
cmp    $0x0,%ecx
cmovne %rax,%rsi
lea    0xe7c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%edi
mov    $0x0,%al
call   1040 <add@plt>
mov    $0x0,%al
call   1030 <peek@plt>
mov    %eax,%esi
lea    0xe87(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x2,%edi
mov    $0x0,%al
call   1040 <add@plt>
mov    $0x0,%al
call   1030 <peek@plt>
mov    %eax,%esi
lea    0xe8c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x3,%edi
mov    $0x0,%al
call   1040 <add@plt>
mov    $0x0,%al
call   1030 <peek@plt>
mov    %eax,%esi
lea    0xe91(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x0,%al
call   1070 <take@plt>
mov    %eax,%esi
lea    0xea2(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x0,%al
call   1070 <take@plt>
mov    %eax,%esi
lea    0xeaf(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x0,%al
call   1070 <take@plt>
mov    %eax,%esi
lea    0xebc(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x0,%al
call   1060 <isEmpty@plt>
mov    %eax,%ecx
lea    0xde0(%rip),%rsi
lea    0xdd3(%rip),%rax
cmp    $0x0,%ecx
cmovne %rax,%rsi
lea    0xeb4(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
xor    %eax,%eax
call   1060 <isEmpty@plt>
test   %eax,%eax
lea    0xec5(%rip),%r14
lea    0xeb8(%rip),%rbx
mov    %rbx,%rsi
cmove  %r14,%rsi
lea    0xe87(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x1,%edi
xor    %eax,%eax
call   1040 <add@plt>
xor    %eax,%eax
call   1030 <peek@plt>
lea    0xe94(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x2,%edi
xor    %eax,%eax
call   1040 <add@plt>
xor    %eax,%eax
call   1030 <peek@plt>
lea    0xe99(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x3,%edi
xor    %eax,%eax
call   1040 <add@plt>
xor    %eax,%eax
call   1030 <peek@plt>
lea    0xe9e(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
call   1070 <take@plt>
lea    0xeaf(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
call   1070 <take@plt>
lea    0xebc(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
call   1070 <take@plt>
lea    0xec9(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
call   1060 <isEmpty@plt>
test   %eax,%eax
cmove  %r14,%rbx
lea    0xed0(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [35 x i8] c"At the beginning the queue is: %s\0A\00"
@.str.1 = [6 x i8] c"empty\00"
@.str.2 = [5 x i8] c"full\00"
@.str.3 = [40 x i8] c"Add 1 to the queue. Peek() returns: %i\0A\00"
@.str.4 = [40 x i8] c"Add 2 to the queue. Peek() returns: %i\0A\00"
@.str.5 = [40 x i8] c"Add 3 to the queue. Peek() returns: %i\0A\00"
@.str.6 = [36 x i8] c"take() test. Expect 1, returns: %i\0A\00"
@.str.7 = [36 x i8] c"take() test. Expect 2, returns: %i\0A\00"
@.str.8 = [36 x i8] c"take() test. Expect 3, returns: %i\0A\00"
@.str.9 = [29 x i8] c"At the end the queue is: %s\0A\00"
define i32 @main() {
%1 = alloca i32
store i32 0, i32* %1
%2 = call i32 (...) @isEmpty()
%3 = icmp ne i32 %2, 0
%4 = zext i1 %3 to i64
%5 = select i1 %3, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0)
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i8* %5)
%7 = call i32 (i32, ...) bitcast (i32 (...)* @add to i32 (i32, ...)*)(i32 1)
%8 = call i32 (...) @peek()
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.3, i64 0, i64 0), i32 %8)
%10 = call i32 (i32, ...) bitcast (i32 (...)* @add to i32 (i32, ...)*)(i32 2)
%11 = call i32 (...) @peek()
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.4, i64 0, i64 0), i32 %11)
%13 = call i32 (i32, ...) bitcast (i32 (...)* @add to i32 (i32, ...)*)(i32 3)
%14 = call i32 (...) @peek()
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.5, i64 0, i64 0), i32 %14)
%16 = call i32 (...) @take()
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.6, i64 0, i64 0), i32 %16)
%18 = call i32 (...) @take()
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.7, i64 0, i64 0), i32 %18)
%20 = call i32 (...) @take()
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.8, i64 0, i64 0), i32 %20)
%22 = call i32 (...) @isEmpty()
%23 = icmp ne i32 %22, 0
%24 = zext i1 %23 to i64
%25 = select i1 %23, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0)
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.9, i64 0, i64 0), i8* %25)
ret i32 0
}

LLVM IR (-O2):
@.str = [35 x i8] c"At the beginning the queue is: %s\0A\00"
@.str.1 = [6 x i8] c"empty\00"
@.str.2 = [5 x i8] c"full\00"
@.str.3 = [40 x i8] c"Add 1 to the queue. Peek() returns: %i\0A\00"
@.str.4 = [40 x i8] c"Add 2 to the queue. Peek() returns: %i\0A\00"
@.str.5 = [40 x i8] c"Add 3 to the queue. Peek() returns: %i\0A\00"
@.str.6 = [36 x i8] c"take() test. Expect 1, returns: %i\0A\00"
@.str.7 = [36 x i8] c"take() test. Expect 2, returns: %i\0A\00"
@.str.8 = [36 x i8] c"take() test. Expect 3, returns: %i\0A\00"
@.str.9 = [29 x i8] c"At the end the queue is: %s\0A\00"
define i32 @main() {
%1 = tail call i32 (...) @isEmpty()
%2 = icmp eq i32 %1, 0
%3 = select i1 %2, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0)
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i8* %3)
%5 = tail call i32 (i32, ...) bitcast (i32 (...)* @add to i32 (i32, ...)*)(i32 1)
%6 = tail call i32 (...) @peek()
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str.3, i64 0, i64 0), i32 %6)
%8 = tail call i32 (i32, ...) bitcast (i32 (...)* @add to i32 (i32, ...)*)(i32 2)
%9 = tail call i32 (...) @peek()
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str.4, i64 0, i64 0), i32 %9)
%11 = tail call i32 (i32, ...) bitcast (i32 (...)* @add to i32 (i32, ...)*)(i32 3)
%12 = tail call i32 (...) @peek()
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str.5, i64 0, i64 0), i32 %12)
%14 = tail call i32 (...) @take()
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.6, i64 0, i64 0), i32 %14)
%16 = tail call i32 (...) @take()
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.7, i64 0, i64 0), i32 %16)
%18 = tail call i32 (...) @take()
%19 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.8, i64 0, i64 0), i32 %18)
%20 = tail call i32 (...) @isEmpty()
%21 = icmp eq i32 %20, 0
%22 = select i1 %21, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0)
%23 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.9, i64 0, i64 0), i8* %22)
ret i32 0
}