#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 token {
  int dummy;
};
struct list {
  int dummy;
};
struct lexer {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ cctools_list_first_item(struct list *);
struct token *cctools_list_pop_head(struct list *);
int /*<<< orphan*/ lexer_push_token(struct lexer *, struct token *);
int lexer_append_tokens(struct lexer *lx, struct list *tokens) {
  struct token *t;
  int count = 0;
  cctools_list_first_item(tokens);
  while ((t = cctools_list_pop_head(tokens))) {
    lexer_push_token(lx, t);
    count++;
  }
  return count;
}


x86 assembly (clang, -O0):
<lexer_append_tokens>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <cctools_list_first_item@plt>
mov    -0x10(%rbp),%rdi
call   1050 <cctools_list_pop_head@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     1182 <lexer_append_tokens+0x52>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <lexer_push_token@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1150 <lexer_append_tokens+0x20>
mov    -0x1c(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lexer_append_tokens>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%rbx
mov    %rdi,%r14
mov    %rsi,%rdi
call   1040 <cctools_list_first_item@plt>
mov    %rbx,%rdi
call   1050 <cctools_list_pop_head@plt>
xor    %ebp,%ebp
test   %rax,%rax
je     117b <lexer_append_tokens+0x4b>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %rax,%rsi
call   1030 <lexer_push_token@plt>
add    $0x1,%ebp
mov    %rbx,%rdi
call   1050 <cctools_list_pop_head@plt>
test   %rax,%rax
jne    1160 <lexer_append_tokens+0x30>
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.lexer = type { i32 }
%struct.list = type { i32 }
%struct.token = type { i32 }
define i32 @lexer_append_tokens(%struct.lexer* %0, %struct.list* %1) {
%3 = alloca %struct.lexer*
%4 = alloca %struct.list*
%5 = alloca %struct.token*
%6 = alloca i32
store %struct.lexer* %0, %struct.lexer** %3
store %struct.list* %1, %struct.list** %4
store i32 0, i32* %6
%7 = load %struct.list*, %struct.list** %4
%8 = call i32 @cctools_list_first_item(%struct.list* %7)
br label %9
9: ; preds = %13, %2
%10 = load %struct.list*, %struct.list** %4
%11 = call %struct.token* @cctools_list_pop_head(%struct.list* %10)
store %struct.token* %11, %struct.token** %5
%12 = icmp ne %struct.token* %11, null
br i1 %12, label %13, label %19
13: ; preds = %9
%14 = load %struct.lexer*, %struct.lexer** %3
%15 = load %struct.token*, %struct.token** %5
%16 = call i32 @lexer_push_token(%struct.lexer* %14, %struct.token* %15)
%17 = load i32, i32* %6
%18 = add nsw i32 %17, 1
store i32 %18, i32* %6
br label %9
19: ; preds = %9
%20 = load i32, i32* %6
ret i32 %20
}

LLVM IR (-O2):
%struct.lexer = type { i32 }
%struct.list = type { i32 }
%struct.token = type { i32 }
define i32 @lexer_append_tokens(%struct.lexer* %0, %struct.list* %1) {
%3 = tail call i32 @cctools_list_first_item(%struct.list* %1)
%4 = tail call %struct.token* @cctools_list_pop_head(%struct.list* %1)
%5 = icmp eq %struct.token* %4, null
br i1 %5, label %13, label %6
6: ; preds = %2, %6
%7 = phi %struct.token* [ %11, %6 ], [ %4, %2 ]
%8 = phi i32 [ %10, %6 ], [ 0, %2 ]
%9 = tail call i32 @lexer_push_token(%struct.lexer* %0, %struct.token* %7)
%10 = add nuw nsw i32 %8, 1
%11 = tail call %struct.token* @cctools_list_pop_head(%struct.list* %1)
%12 = icmp eq %struct.token* %11, null
br i1 %12, label %13, label %6
13: ; preds = %6, %2
%14 = phi i32 [ 0, %2 ], [ %10, %6 ]
ret i32 %14
}