#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 queue {
  int dummy;
};
struct arrayStack {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ DeQueue(struct queue *);
int /*<<< orphan*/ EnQueue(struct queue *, int /*<<< orphan*/);
struct arrayStack *createStack(int);
int getQSize(struct queue *);
int /*<<< orphan*/ pop(struct arrayStack *);
int /*<<< orphan*/ push(struct arrayStack *, int /*<<< orphan*/);
void interleavingQueue(struct queue *Q) {
  int s = getQSize(Q);
  if (s % 2 != 0)
    return;
  int half = s / 2;
  int i;
  struct arrayStack *S = createStack(half);
  for (i = 0; i < half; i++) {
    push(S, DeQueue(Q));
  }
  for (i = 0; i < half; i++) {
    EnQueue(Q, pop(S));
  }
  for (i = 0; i < half; i++) {
    EnQueue(Q, DeQueue(Q));
  }
  for (i = 0; i < half; i++) {
    push(S, DeQueue(Q));
  }
  for (i = 0; i < half; i++) {
    EnQueue(Q, pop(S));
    EnQueue(Q, DeQueue(Q));
  }
}


x86 assembly (clang, -O0):
<interleavingQueue>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1080 <getQSize@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
je     1191 <interleavingQueue+0x31>
jmp    12f8 <interleavingQueue+0x198>
mov    -0xc(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%edi
call   1060 <createStack@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    11e8 <interleavingQueue+0x88>
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <DeQueue@plt>
mov    -0x28(%rbp),%rdi
mov    %eax,%esi
call   1070 <push@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11b2 <interleavingQueue+0x52>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    1225 <interleavingQueue+0xc5>
mov    -0x8(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rdi
call   1050 <pop@plt>
mov    -0x30(%rbp),%rdi
mov    %eax,%esi
call   1030 <EnQueue@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11ef <interleavingQueue+0x8f>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    1262 <interleavingQueue+0x102>
mov    -0x8(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <DeQueue@plt>
mov    -0x38(%rbp),%rdi
mov    %eax,%esi
call   1030 <EnQueue@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    122c <interleavingQueue+0xcc>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    129f <interleavingQueue+0x13f>
mov    -0x20(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <DeQueue@plt>
mov    -0x40(%rbp),%rdi
mov    %eax,%esi
call   1070 <push@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1269 <interleavingQueue+0x109>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    12f8 <interleavingQueue+0x198>
mov    -0x8(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x20(%rbp),%rdi
call   1050 <pop@plt>
mov    -0x50(%rbp),%rdi
mov    %eax,%esi
call   1030 <EnQueue@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <DeQueue@plt>
mov    -0x48(%rbp),%rdi
mov    %eax,%esi
call   1030 <EnQueue@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    12a6 <interleavingQueue+0x146>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<interleavingQueue>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdi,%rbx
call   1080 <getQSize@plt>
mov    %eax,%r15d
test   $0x1,%r15b
jne    126a <interleavingQueue+0x10a>
mov    %r15d,%r14d
shr    $0x1f,%r14d
add    %r15d,%r14d
sar    %r14d
mov    %r14d,%edi
call   1060 <createStack@plt>
cmp    $0x2,%r15d
jl     126a <interleavingQueue+0x10a>
mov    %rax,%r12
mov    %r14d,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rbx,%rdi
call   1040 <DeQueue@plt>
mov    %r12,%rdi
mov    %eax,%esi
call   1070 <push@plt>
add    $0xffffffff,%ebp
jne    11b0 <interleavingQueue+0x50>
cmp    $0x2,%r15d
jl     126a <interleavingQueue+0x10a>
mov    %r14d,%ebp
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r12,%rdi
call   1050 <pop@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1030 <EnQueue@plt>
add    $0xffffffff,%ebp
jne    11e0 <interleavingQueue+0x80>
cmp    $0x2,%r15d
jl     126a <interleavingQueue+0x10a>
mov    %r14d,%ebp
mov    %rbx,%rdi
call   1040 <DeQueue@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1030 <EnQueue@plt>
add    $0xffffffff,%ebp
jne    1200 <interleavingQueue+0xa0>
cmp    $0x2,%r15d
jl     126a <interleavingQueue+0x10a>
mov    %r14d,%ebp
mov    %rbx,%rdi
call   1040 <DeQueue@plt>
mov    %r12,%rdi
mov    %eax,%esi
call   1070 <push@plt>
add    $0xffffffff,%ebp
jne    1220 <interleavingQueue+0xc0>
cmp    $0x2,%r15d
jl     126a <interleavingQueue+0x10a>
nopl   (%rax)
mov    %r12,%rdi
call   1050 <pop@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1030 <EnQueue@plt>
mov    %rbx,%rdi
call   1040 <DeQueue@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1030 <EnQueue@plt>
add    $0xffffffff,%r14d
jne    1240 <interleavingQueue+0xe0>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.queue = type { i32 }
%struct.arrayStack = type { i32 }
define void @interleavingQueue(%struct.queue* %0) {
%2 = alloca %struct.queue*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca %struct.arrayStack*
store %struct.queue* %0, %struct.queue** %2
%7 = load %struct.queue*, %struct.queue** %2
%8 = call i32 @getQSize(%struct.queue* %7)
store i32 %8, i32* %3
%9 = load i32, i32* %3
%10 = srem i32 %9, 2
%11 = icmp ne i32 %10, 0
br i1 %11, label %12, label %13
12: ; preds = %1
br label %86
13: ; preds = %1
%14 = load i32, i32* %3
%15 = sdiv i32 %14, 2
store i32 %15, i32* %4
%16 = load i32, i32* %4
%17 = call %struct.arrayStack* @createStack(i32 %16)
store %struct.arrayStack* %17, %struct.arrayStack** %6
store i32 0, i32* %5
br label %18
18: ; preds = %27, %13
%19 = load i32, i32* %5
%20 = load i32, i32* %4
%21 = icmp slt i32 %19, %20
br i1 %21, label %22, label %30
22: ; preds = %18
%23 = load %struct.arrayStack*, %struct.arrayStack** %6
%24 = load %struct.queue*, %struct.queue** %2
%25 = call i32 @DeQueue(%struct.queue* %24)
%26 = call i32 @push(%struct.arrayStack* %23, i32 %25)
br label %27
27: ; preds = %22
%28 = load i32, i32* %5
%29 = add nsw i32 %28, 1
store i32 %29, i32* %5
br label %18
30: ; preds = %18
store i32 0, i32* %5
br label %31
31: ; preds = %40, %30
%32 = load i32, i32* %5
%33 = load i32, i32* %4
%34 = icmp slt i32 %32, %33
br i1 %34, label %35, label %43
35: ; preds = %31
%36 = load %struct.queue*, %struct.queue** %2
%37 = load %struct.arrayStack*, %struct.arrayStack** %6
%38 = call i32 @pop(%struct.arrayStack* %37)
%39 = call i32 @EnQueue(%struct.queue* %36, i32 %38)
br label %40
40: ; preds = %35
%41 = load i32, i32* %5
%42 = add nsw i32 %41, 1
store i32 %42, i32* %5
br label %31
43: ; preds = %31
store i32 0, i32* %5
br label %44
44: ; preds = %53, %43
%45 = load i32, i32* %5
%46 = load i32, i32* %4
%47 = icmp slt i32 %45, %46
br i1 %47, label %48, label %56
48: ; preds = %44
%49 = load %struct.queue*, %struct.queue** %2
%50 = load %struct.queue*, %struct.queue** %2
%51 = call i32 @DeQueue(%struct.queue* %50)
%52 = call i32 @EnQueue(%struct.queue* %49, i32 %51)
br label %53
53: ; preds = %48
%54 = load i32, i32* %5
%55 = add nsw i32 %54, 1
store i32 %55, i32* %5
br label %44
56: ; preds = %44
store i32 0, i32* %5
br label %57
57: ; preds = %66, %56
%58 = load i32, i32* %5
%59 = load i32, i32* %4
%60 = icmp slt i32 %58, %59
br i1 %60, label %61, label %69
61: ; preds = %57
%62 = load %struct.arrayStack*, %struct.arrayStack** %6
%63 = load %struct.queue*, %struct.queue** %2
%64 = call i32 @DeQueue(%struct.queue* %63)
%65 = call i32 @push(%struct.arrayStack* %62, i32 %64)
br label %66
66: ; preds = %61
%67 = load i32, i32* %5
%68 = add nsw i32 %67, 1
store i32 %68, i32* %5
br label %57
69: ; preds = %57
store i32 0, i32* %5
br label %70
70: ; preds = %83, %69
%71 = load i32, i32* %5
%72 = load i32, i32* %4
%73 = icmp slt i32 %71, %72
br i1 %73, label %74, label %86
74: ; preds = %70
%75 = load %struct.queue*, %struct.queue** %2
%76 = load %struct.arrayStack*, %struct.arrayStack** %6
%77 = call i32 @pop(%struct.arrayStack* %76)
%78 = call i32 @EnQueue(%struct.queue* %75, i32 %77)
%79 = load %struct.queue*, %struct.queue** %2
%80 = load %struct.queue*, %struct.queue** %2
%81 = call i32 @DeQueue(%struct.queue* %80)
%82 = call i32 @EnQueue(%struct.queue* %79, i32 %81)
br label %83
83: ; preds = %74
%84 = load i32, i32* %5
%85 = add nsw i32 %84, 1
store i32 %85, i32* %5
br label %70
86: ; preds = %12, %70
ret void
}

LLVM IR (-O2):
%struct.queue = type { i32 }
%struct.arrayStack = type { i32 }
define void @interleavingQueue(%struct.queue* %0) {
%2 = tail call i32 @getQSize(%struct.queue* %0)
%3 = and i32 %2, 1
%4 = icmp eq i32 %3, 0
br i1 %4, label %5, label %45
5: ; preds = %1
%6 = sdiv i32 %2, 2
%7 = tail call %struct.arrayStack* @createStack(i32 %6)
%8 = icmp sgt i32 %2, 1
br i1 %8, label %10, label %45
9: ; preds = %10
br i1 %8, label %17, label %45
10: ; preds = %5, %10
%11 = phi i32 [ %14, %10 ], [ 0, %5 ]
%12 = tail call i32 @DeQueue(%struct.queue* %0)
%13 = tail call i32 @push(%struct.arrayStack* %7, i32 %12)
%14 = add nuw nsw i32 %11, 1
%15 = icmp eq i32 %14, %6
br i1 %15, label %9, label %10
16: ; preds = %17
br i1 %8, label %24, label %45
17: ; preds = %9, %17
%18 = phi i32 [ %21, %17 ], [ 0, %9 ]
%19 = tail call i32 @pop(%struct.arrayStack* %7)
%20 = tail call i32 @EnQueue(%struct.queue* %0, i32 %19)
%21 = add nuw nsw i32 %18, 1
%22 = icmp eq i32 %21, %6
br i1 %22, label %16, label %17
23: ; preds = %24
br i1 %8, label %31, label %45
24: ; preds = %16, %24
%25 = phi i32 [ %28, %24 ], [ 0, %16 ]
%26 = tail call i32 @DeQueue(%struct.queue* %0)
%27 = tail call i32 @EnQueue(%struct.queue* %0, i32 %26)
%28 = add nuw nsw i32 %25, 1
%29 = icmp eq i32 %28, %6
br i1 %29, label %23, label %24
30: ; preds = %31
br i1 %8, label %37, label %45
31: ; preds = %23, %31
%32 = phi i32 [ %35, %31 ], [ 0, %23 ]
%33 = tail call i32 @DeQueue(%struct.queue* %0)
%34 = tail call i32 @push(%struct.arrayStack* %7, i32 %33)
%35 = add nuw nsw i32 %32, 1
%36 = icmp eq i32 %35, %6
br i1 %36, label %30, label %31
37: ; preds = %30, %37
%38 = phi i32 [ %43, %37 ], [ 0, %30 ]
%39 = tail call i32 @pop(%struct.arrayStack* %7)
%40 = tail call i32 @EnQueue(%struct.queue* %0, i32 %39)
%41 = tail call i32 @DeQueue(%struct.queue* %0)
%42 = tail call i32 @EnQueue(%struct.queue* %0, i32 %41)
%43 = add nuw nsw i32 %38, 1
%44 = icmp eq i32 %43, %6
br i1 %44, label %45, label %37
45: ; preds = %37, %5, %9, %16, %23, %30, %1
ret void
}