#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_enqueue(struct char_queue *, int /*<<< orphan*/);
size_t const char_queue_free(struct char_queue *);
size_t strlen(char const *);
size_t char_queue_enqueue_string(struct char_queue *queue, const char *str) {
  const size_t len = strlen(str);
  assert(len <= char_queue_free(queue));
  while (*str) {
    char_queue_enqueue(queue, *str++);
  }
  return len;
}


x86 assembly (clang, -O0):
<char_queue_enqueue_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <char_queue_free@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
cmp    %rcx,%rax
setbe  %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
je     11b2 <char_queue_enqueue_string+0x72>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movsbl (%rax),%esi
call   1060 <char_queue_enqueue@plt>
jmp    1185 <char_queue_enqueue_string+0x45>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<char_queue_enqueue_string>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%rbx
mov    %rdi,%r14
mov    %rsi,%rdi
call   1040 <strlen@plt>
mov    %rax,%r15
mov    %r14,%rdi
call   1030 <char_queue_free@plt>
xor    %edi,%edi
cmp    %rax,%r15
setbe  %dil
call   1050 <assert@plt>
mov    (%rbx),%al
test   %al,%al
je     1196 <char_queue_enqueue_string+0x56>
add    $0x1,%rbx
cs nopw 0x0(%rax,%rax,1)
movsbl %al,%esi
mov    %r14,%rdi
call   1060 <char_queue_enqueue@plt>
movzbl (%rbx),%eax
add    $0x1,%rbx
test   %al,%al
jne    1180 <char_queue_enqueue_string+0x40>
mov    %r15,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.char_queue = type { i32 }
define i64 @char_queue_enqueue_string(%struct.char_queue* %0, i8* %1) {
%3 = alloca %struct.char_queue*
%4 = alloca i8*
%5 = alloca i64
store %struct.char_queue* %0, %struct.char_queue** %3
store i8* %1, i8** %4
%6 = load i8*, i8** %4
%7 = call i64 @strlen(i8* %6)
store i64 %7, i64* %5
%8 = load i64, i64* %5
%9 = load %struct.char_queue*, %struct.char_queue** %3
%10 = call i64 @char_queue_free(%struct.char_queue* %9)
%11 = icmp ule i64 %8, %10
%12 = zext i1 %11 to i32
%13 = call i32 @assert(i32 %12)
br label %14
14: ; preds = %18, %2
%15 = load i8*, i8** %4
%16 = load i8, i8* %15
%17 = icmp ne i8 %16, 0
br i1 %17, label %18, label %25
18: ; preds = %14
%19 = load %struct.char_queue*, %struct.char_queue** %3
%20 = load i8*, i8** %4
%21 = getelementptr inbounds i8, i8* %20, i32 1
store i8* %21, i8** %4
%22 = load i8, i8* %20
%23 = sext i8 %22 to i32
%24 = call i32 @char_queue_enqueue(%struct.char_queue* %19, i32 %23)
br label %14
25: ; preds = %14
%26 = load i64, i64* %5
ret i64 %26
}

LLVM IR (-O2):
%struct.char_queue = type { i32 }
define i64 @char_queue_enqueue_string(%struct.char_queue* %0, i8* nocapture %1) {
%3 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%4 = tail call i64 @char_queue_free(%struct.char_queue* %0)
%5 = icmp ule i64 %3, %4
%6 = zext i1 %5 to i32
%7 = tail call i32 @assert(i32 %6)
%8 = load i8, i8* %1
%9 = icmp eq i8 %8, 0
br i1 %9, label %18, label %10
10: ; preds = %2, %10
%11 = phi i8 [ %16, %10 ], [ %8, %2 ]
%12 = phi i8* [ %13, %10 ], [ %1, %2 ]
%13 = getelementptr inbounds i8, i8* %12, i64 1
%14 = sext i8 %11 to i32
%15 = tail call i32 @char_queue_enqueue(%struct.char_queue* %0, i32 %14)
%16 = load i8, i8* %13
%17 = icmp eq i8 %16, 0
br i1 %17, label %18, label %10
18: ; preds = %10, %2
ret i64 %3
}