#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*/ strncmp(char *, char *, int);
void fill_line_to_max(char *line, char *p, int n) {
  int nc = 0, nmax = n;
  while (*p && nc < nmax) {
    if (!strncmp(p, "<@ref", 5)) {
      nmax += 9;
    }
    line[nc++] = *p++;
  }
  line[nc] = '\0';
}


x86 assembly (clang, -O0):
<fill_line_to_max>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x1d(%rbp)
je     1151 <fill_line_to_max+0x41>
mov    -0x18(%rbp),%eax
cmp    -0x1c(%rbp),%eax
setl   %al
mov    %al,-0x1d(%rbp)
mov    -0x1d(%rbp),%al
test   $0x1,%al
jne    1161 <fill_line_to_max+0x51>
jmp    11b3 <fill_line_to_max+0xa3>
mov    -0x10(%rbp),%rdi
lea    0xe94(%rip),%rsi
mov    $0x5,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    1188 <fill_line_to_max+0x78>
mov    -0x1c(%rbp),%eax
add    $0x9,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
mov    (%rax),%dl
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x18(%rbp)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
jmp    1130 <fill_line_to_max+0x20>
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fill_line_to_max>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdi,%r14
xor    %eax,%eax
cmpb   $0x0,(%rsi)
je     117e <fill_line_to_max+0x6e>
test   %edx,%edx
jle    117e <fill_line_to_max+0x6e>
mov    %rsi,%r12
xor    %eax,%eax
lea    0xecd(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %edx,%r13d
mov    %rax,%rbx
lea    (%r12,%rax,1),%rdi
mov    %r15,%rsi
mov    $0x5,%edx
call   1030 <strncmp@plt>
lea    0x9(%r13),%edx
test   %eax,%eax
cmovne %r13d,%edx
movzbl (%r12,%rbx,1),%ecx
lea    0x1(%rbx),%rax
mov    %cl,(%r14,%rbx,1)
cmpb   $0x0,0x1(%r12,%rbx,1)
je     117e <fill_line_to_max+0x6e>
movslq %edx,%rcx
cmp    %rcx,%rax
jl     1140 <fill_line_to_max+0x30>
movb   $0x0,(%r14,%rax,1)
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [6 x i8] c"<@ref\00"
define void @fill_line_to_max(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
store i32 0, i32* %7
%9 = load i32, i32* %6
store i32 %9, i32* %8
br label %10
10: ; preds = %28, %3
%11 = load i8*, i8** %5
%12 = load i8, i8* %11
%13 = sext i8 %12 to i32
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %19
15: ; preds = %10
%16 = load i32, i32* %7
%17 = load i32, i32* %8
%18 = icmp slt i32 %16, %17
br label %19
19: ; preds = %15, %10
%20 = phi i1 [ false, %10 ], [ %18, %15 ]
br i1 %20, label %21, label %37
21: ; preds = %19
%22 = load i8*, i8** %5
%23 = call i32 @strncmp(i8* %22, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 5)
%24 = icmp ne i32 %23, 0
br i1 %24, label %28, label %25
25: ; preds = %21
%26 = load i32, i32* %8
%27 = add nsw i32 %26, 9
store i32 %27, i32* %8
br label %28
28: ; preds = %25, %21
%29 = load i8*, i8** %5
%30 = getelementptr inbounds i8, i8* %29, i32 1
store i8* %30, i8** %5
%31 = load i8, i8* %29
%32 = load i8*, i8** %4
%33 = load i32, i32* %7
%34 = add nsw i32 %33, 1
store i32 %34, i32* %7
%35 = sext i32 %33 to i64
%36 = getelementptr inbounds i8, i8* %32, i64 %35
store i8 %31, i8* %36
br label %10
37: ; preds = %19
%38 = load i8*, i8** %4
%39 = load i32, i32* %7
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i8, i8* %38, i64 %40
store i8 0, i8* %41
ret void
}

LLVM IR (-O2):
@.str = [6 x i8] c"<@ref\00"
define void @fill_line_to_max(i8* nocapture writeonly %0, i8* %1, i32 %2) {
%4 = load i8, i8* %1
%5 = icmp ne i8 %4, 0
%6 = icmp sgt i32 %2, 0
%7 = and i1 %5, %6
br i1 %7, label %8, label %27
8: ; preds = %3, %8
%9 = phi i64 [ %18, %8 ], [ 0, %3 ]
%10 = phi i32 [ %15, %8 ], [ %2, %3 ]
%11 = phi i8* [ %16, %8 ], [ %1, %3 ]
%12 = tail call i32 @strncmp(i8* %11, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 5)
%13 = icmp eq i32 %12, 0
%14 = add nsw i32 %10, 9
%15 = select i1 %13, i32 %14, i32 %10
%16 = getelementptr inbounds i8, i8* %11, i64 1
%17 = load i8, i8* %11
%18 = add nuw nsw i64 %9, 1
%19 = getelementptr inbounds i8, i8* %0, i64 %9
store i8 %17, i8* %19
%20 = load i8, i8* %16
%21 = icmp ne i8 %20, 0
%22 = sext i32 %15 to i64
%23 = icmp slt i64 %18, %22
%24 = select i1 %21, i1 %23, i1 false
br i1 %24, label %8, label %25
25: ; preds = %8
%26 = and i64 %18, 4294967295
br label %27
27: ; preds = %25, %3
%28 = phi i64 [ 0, %3 ], [ %26, %25 ]
%29 = getelementptr inbounds i8, i8* %0, i64 %28
store i8 0, i8* %29
ret void
}