#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 */

/* Variables and functions */
int /*<<< orphan*/ lex_look_ahead(char const *, unsigned int, unsigned int *,
                                  char *, unsigned int);
scalar_t__ str_nlen(char *, unsigned int);
void lex_look_ahead_n(const char *input, unsigned int input_len,
                      unsigned int *pos, unsigned int num_ahead, char *output,
                      unsigned int output_size) {
  unsigned int i;
  output[0] = '\0';
  for (i = 0; i < num_ahead; i++) {
    *pos += str_nlen(output, output_size);
    lex_look_ahead(input, input_len, pos, output, output_size);
  }
}


x86 assembly (clang, -O0):
<lex_look_ahead_n>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9d,-0x2c(%rbp)
mov    -0x28(%rbp),%rax
movb   $0x0,(%rax)
movl   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jae    1198 <lex_look_ahead_n+0x78>
mov    -0x28(%rbp),%rdi
mov    -0x2c(%rbp),%esi
call   1040 <str_nlen@plt>
mov    %rax,%rdx
mov    -0x18(%rbp),%rax
mov    (%rax),%ecx
add    %rdx,%rcx
mov    %ecx,(%rax)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x18(%rbp),%rdx
mov    -0x28(%rbp),%rcx
mov    -0x2c(%rbp),%r8d
call   1030 <lex_look_ahead@plt>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    114c <lex_look_ahead_n+0x2c>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lex_look_ahead_n>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
movb   $0x0,(%r8)
test   %ecx,%ecx
je     1176 <lex_look_ahead_n+0x56>
mov    %r9d,%r14d
mov    %r8,%r15
mov    %ecx,%ebp
mov    %rdx,%rbx
mov    %esi,%r12d
mov    %rdi,%r13
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r15,%rdi
mov    %r14d,%esi
call   1040 <str_nlen@plt>
add    %eax,(%rbx)
mov    %r13,%rdi
mov    %r12d,%esi
mov    %rbx,%rdx
mov    %r15,%rcx
mov    %r14d,%r8d
call   1030 <lex_look_ahead@plt>
add    $0xffffffff,%ebp
jne    1150 <lex_look_ahead_n+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @lex_look_ahead_n(i8* %0, i32 %1, i32* %2, i32 %3, i8* %4, i32 %5) {
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32*
%10 = alloca i32
%11 = alloca i8*
%12 = alloca i32
%13 = alloca i32
store i8* %0, i8** %7
store i32 %1, i32* %8
store i32* %2, i32** %9
store i32 %3, i32* %10
store i8* %4, i8** %11
store i32 %5, i32* %12
%14 = load i8*, i8** %11
%15 = getelementptr inbounds i8, i8* %14, i64 0
store i8 0, i8* %15
store i32 0, i32* %13
br label %16
16: ; preds = %35, %6
%17 = load i32, i32* %13
%18 = load i32, i32* %10
%19 = icmp ult i32 %17, %18
br i1 %19, label %20, label %38
20: ; preds = %16
%21 = load i8*, i8** %11
%22 = load i32, i32* %12
%23 = call i64 @str_nlen(i8* %21, i32 %22)
%24 = load i32*, i32** %9
%25 = load i32, i32* %24
%26 = zext i32 %25 to i64
%27 = add nsw i64 %26, %23
%28 = trunc i64 %27 to i32
store i32 %28, i32* %24
%29 = load i8*, i8** %7
%30 = load i32, i32* %8
%31 = load i32*, i32** %9
%32 = load i8*, i8** %11
%33 = load i32, i32* %12
%34 = call i32 @lex_look_ahead(i8* %29, i32 %30, i32* %31, i8* %32, i32 %33)
br label %35
35: ; preds = %20
%36 = load i32, i32* %13
%37 = add i32 %36, 1
store i32 %37, i32* %13
br label %16
38: ; preds = %16
ret void
}

LLVM IR (-O2):
define void @lex_look_ahead_n(i8* %0, i32 %1, i32* %2, i32 %3, i8* %4, i32 %5) {
store i8 0, i8* %4
%7 = icmp eq i32 %3, 0
br i1 %7, label %17, label %8
8: ; preds = %6, %8
%9 = phi i32 [ %15, %8 ], [ 0, %6 ]
%10 = tail call i64 @str_nlen(i8* %4, i32 %5)
%11 = load i32, i32* %2
%12 = trunc i64 %10 to i32
%13 = add i32 %11, %12
store i32 %13, i32* %2
%14 = tail call i32 @lex_look_ahead(i8* %0, i32 %1, i32* %2, i8* %4, i32 %5)
%15 = add nuw i32 %9, 1
%16 = icmp eq i32 %15, %3
br i1 %16, label %17, label %8
17: ; preds = %8, %6
ret void
}