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

/* Variables and functions */
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ char_queue_dequeue(struct char_queue *);
size_t const char_queue_size(struct char_queue *);
size_t char_queue_dequeue_string(struct char_queue *queue, char *str,
                                 const size_t n) {
  assert((n - 1) <= char_queue_size(queue));
  for (size_t i = 0; i < (n - 1); ++i) {
    *str++ = char_queue_dequeue(queue);
  }
  *str = 0;
  return n - 1;
}


x86 assembly (clang, -O0):
<char_queue_dequeue_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x18(%rbp),%rax
sub    $0x1,%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <char_queue_size@plt>
mov    %rax,%rcx
mov    -0x28(%rbp),%rax
cmp    %rcx,%rax
setbe  %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
movq   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    -0x18(%rbp),%rcx
sub    $0x1,%rcx
cmp    %rcx,%rax
jae    11ba <char_queue_dequeue_string+0x8a>
mov    -0x8(%rbp),%rdi
call   1050 <char_queue_dequeue@plt>
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x10(%rbp)
mov    %cl,(%rax)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1178 <char_queue_dequeue_string+0x48>
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x18(%rbp),%rax
sub    $0x1,%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<char_queue_dequeue_string>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%r12
mov    %rdi,%r15
call   1030 <char_queue_size@plt>
lea    -0x1(%r14),%rcx
xor    %edi,%edi
cmp    %rax,%rcx
setbe  %dil
call   1040 <assert@plt>
add    $0xffffffffffffffff,%r14
je     1186 <char_queue_dequeue_string+0x56>
mov    %r14,%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r15,%rdi
call   1050 <char_queue_dequeue@plt>
mov    %al,(%r12)
add    $0x1,%r12
add    $0xffffffffffffffff,%rbx
jne    1170 <char_queue_dequeue_string+0x40>
movb   $0x0,(%r12)
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.char_queue = type { i32 }
define i64 @char_queue_dequeue_string(%struct.char_queue* %0, i8* %1, i64 %2) {
%4 = alloca %struct.char_queue*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i64
store %struct.char_queue* %0, %struct.char_queue** %4
store i8* %1, i8** %5
store i64 %2, i64* %6
%8 = load i64, i64* %6
%9 = sub i64 %8, 1
%10 = load %struct.char_queue*, %struct.char_queue** %4
%11 = call i64 @char_queue_size(%struct.char_queue* %10)
%12 = icmp ule i64 %9, %11
%13 = zext i1 %12 to i32
%14 = call i32 @assert(i32 %13)
store i64 0, i64* %7
br label %15
15: ; preds = %26, %3
%16 = load i64, i64* %7
%17 = load i64, i64* %6
%18 = sub i64 %17, 1
%19 = icmp ult i64 %16, %18
br i1 %19, label %20, label %29
20: ; preds = %15
%21 = load %struct.char_queue*, %struct.char_queue** %4
%22 = call i32 @char_queue_dequeue(%struct.char_queue* %21)
%23 = trunc i32 %22 to i8
%24 = load i8*, i8** %5
%25 = getelementptr inbounds i8, i8* %24, i32 1
store i8* %25, i8** %5
store i8 %23, i8* %24
br label %26
26: ; preds = %20
%27 = load i64, i64* %7
%28 = add i64 %27, 1
store i64 %28, i64* %7
br label %15
29: ; preds = %15
%30 = load i8*, i8** %5
store i8 0, i8* %30
%31 = load i64, i64* %6
%32 = sub i64 %31, 1
ret i64 %32
}

LLVM IR (-O2):
%struct.char_queue = type { i32 }
define i64 @char_queue_dequeue_string(%struct.char_queue* %0, i8* nocapture writeonly %1, i64 %2) {
%4 = add i64 %2, -1
%5 = tail call i64 @char_queue_size(%struct.char_queue* %0)
%6 = icmp ule i64 %4, %5
%7 = zext i1 %6 to i32
%8 = tail call i32 @assert(i32 %7)
%9 = icmp eq i64 %4, 0
br i1 %9, label %10, label %12
10: ; preds = %12, %3
%11 = phi i8* [ %1, %3 ], [ %17, %12 ]
store i8 0, i8* %11
ret i64 %4
12: ; preds = %3, %12
%13 = phi i64 [ %18, %12 ], [ 0, %3 ]
%14 = phi i8* [ %17, %12 ], [ %1, %3 ]
%15 = tail call i32 @char_queue_dequeue(%struct.char_queue* %0)
%16 = trunc i32 %15 to i8
%17 = getelementptr inbounds i8, i8* %14, i64 1
store i8 %16, i8* %14
%18 = add nuw i64 %13, 1
%19 = icmp eq i64 %18, %4
br i1 %19, label %10, label %12
}