#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 iptrie {
  int dummy;
};
struct amp_asn_info {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ add_parsed_line(struct iptrie *, char *,
                                   struct amp_asn_info *);
int /*<<< orphan*/ memmove(char *, char *, int);
int /*<<< orphan*/ *strchr(char *, char);
int strlen(char *);
scalar_t__ strncmp(char *, char *, int);
char *strtok_r(char *, char *, char **);
void process_buffer(struct iptrie *result, char *buffer, int buflen,
                    int *offset, struct amp_asn_info *info, int *outstanding) {
  char *line;
  char *lineptr = NULL;
  int linelen;
  while (strchr(buffer, '\n') != NULL) {
    line = strtok_r(buffer, "\n", &lineptr);
    linelen = strlen(line) + 1;
    if (strncmp(line, "Bulk", 4) == 0 || strncmp(line, "Error", 5) == 0) {
      memmove(buffer, buffer + linelen, buflen - linelen);
      *offset = *offset - linelen;
      buffer[*offset] = '\0';
      continue;
    }
    add_parsed_line(result, line, info);
    memmove(buffer, buffer + linelen, buflen - linelen);
    *offset = *offset - linelen;
    buffer[*offset] = '\0';
    if (outstanding) {
      (*outstanding)--;
    }
  }
}


x86 assembly (clang, -O0):
<process_buffer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
movq   $0x0,-0x40(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0xa,%esi
call   1050 <strchr@plt>
cmp    $0x0,%rax
je     12a5 <process_buffer+0x145>
mov    -0x10(%rbp),%rdi
lea    0xe56(%rip),%rsi
lea    -0x40(%rbp),%rdx
call   1060 <strtok_r@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
call   1040 <strlen@plt>
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
mov    -0x38(%rbp),%rdi
lea    0xe31(%rip),%rsi
mov    $0x4,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
je     1204 <process_buffer+0xa4>
mov    -0x38(%rbp),%rdi
lea    0xe17(%rip),%rsi
mov    $0x5,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    1241 <process_buffer+0xe1>
mov    -0x10(%rbp),%rdi
mov    -0x10(%rbp),%rsi
movslq -0x44(%rbp),%rax
add    %rax,%rsi
mov    -0x14(%rbp),%edx
sub    -0x44(%rbp),%edx
call   1080 <memmove@plt>
mov    -0x20(%rbp),%rax
mov    (%rax),%ecx
sub    -0x44(%rbp),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
movslq (%rcx),%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    1187 <process_buffer+0x27>
mov    -0x8(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1070 <add_parsed_line@plt>
mov    -0x10(%rbp),%rdi
mov    -0x10(%rbp),%rsi
movslq -0x44(%rbp),%rax
add    %rax,%rsi
mov    -0x14(%rbp),%edx
sub    -0x44(%rbp),%edx
call   1080 <memmove@plt>
mov    -0x20(%rbp),%rax
mov    (%rax),%ecx
sub    -0x44(%rbp),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
movslq (%rcx),%rcx
movb   $0x0,(%rax,%rcx,1)
cmpq   $0x0,-0x30(%rbp)
je     12a0 <process_buffer+0x140>
mov    -0x30(%rbp),%rax
mov    (%rax),%ecx
add    $0xffffffff,%ecx
mov    %ecx,(%rax)
jmp    1187 <process_buffer+0x27>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<process_buffer>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %r9,0x8(%rsp)
mov    %r8,0x18(%rsp)
mov    %rcx,%r15
mov    %edx,%r12d
mov    %rsi,%rbp
mov    %rdi,0x10(%rsp)
movq   $0x0,0x20(%rsp)
mov    %rsi,%rdi
mov    $0xa,%esi
call   1050 <strchr@plt>
test   %rax,%rax
je     1293 <process_buffer+0x133>
lea    0xe54(%rip),%rbx
jmp    11e8 <process_buffer+0x88>
xchg   %ax,%ax
movslq %r14d,%rsi
add    %rbp,%rsi
mov    %r12d,%edx
sub    %r14d,%edx
mov    %rbp,%rdi
call   1080 <memmove@plt>
movslq (%r15),%rax
sub    %r14,%rax
mov    %eax,(%r15)
movb   $0x0,0x0(%rbp,%rax,1)
mov    %rbp,%rdi
mov    $0xa,%esi
call   1050 <strchr@plt>
test   %rax,%rax
je     1293 <process_buffer+0x133>
mov    %rbp,%rdi
mov    %rbx,%rsi
lea    0x20(%rsp),%rdx
call   1060 <strtok_r@plt>
mov    %rax,%r13
mov    %rax,%rdi
call   1040 <strlen@plt>
movslq %eax,%r14
add    $0x1,%r14
mov    %r13,%rdi
lea    0xdee(%rip),%rsi
mov    $0x4,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     11b0 <process_buffer+0x50>
mov    %r13,%rdi
lea    0xdda(%rip),%rsi
mov    $0x5,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     11b0 <process_buffer+0x50>
mov    0x10(%rsp),%rdi
mov    %r13,%rsi
mov    0x18(%rsp),%rdx
call   1070 <add_parsed_line@plt>
mov    %rbx,%r13
movslq %r14d,%rbx
lea    (%rbx,%rbp,1),%rsi
mov    %r12d,%edx
sub    %ebx,%edx
mov    %rbp,%rdi
call   1080 <memmove@plt>
movslq (%r15),%rax
sub    %rbx,%rax
mov    %r13,%rbx
mov    %eax,(%r15)
movb   $0x0,0x0(%rbp,%rax,1)
cmpq   $0x0,0x8(%rsp)
je     11d2 <process_buffer+0x72>
mov    0x8(%rsp),%rax
addl   $0xffffffff,(%rax)
jmp    11d2 <process_buffer+0x72>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.iptrie = type { i32 }
%struct.amp_asn_info = type { i32 }
@.str = [2 x i8] c"\0A\00"
@.str.1 = [5 x i8] c"Bulk\00"
@.str.2 = [6 x i8] c"Error\00"
define void @process_buffer(%struct.iptrie* %0, i8* %1, i32 %2, i32* %3, %struct.amp_asn_info* %4, i32* %5) {
%7 = alloca %struct.iptrie*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32*
%11 = alloca %struct.amp_asn_info*
%12 = alloca i32*
%13 = alloca i8*
%14 = alloca i8*
%15 = alloca i32
store %struct.iptrie* %0, %struct.iptrie** %7
store i8* %1, i8** %8
store i32 %2, i32* %9
store i32* %3, i32** %10
store %struct.amp_asn_info* %4, %struct.amp_asn_info** %11
store i32* %5, i32** %12
store i8* null, i8** %14
br label %16
16: ; preds = %83, %33, %6
%17 = load i8*, i8** %8
%18 = call i32* @strchr(i8* %17, i8 signext 10)
%19 = icmp ne i32* %18, null
br i1 %19, label %20, label %84
20: ; preds = %16
%21 = load i8*, i8** %8
%22 = call i8* @strtok_r(i8* %21, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8** %14)
store i8* %22, i8** %13
%23 = load i8*, i8** %13
%24 = call i32 @strlen(i8* %23)
%25 = add nsw i32 %24, 1
store i32 %25, i32* %15
%26 = load i8*, i8** %13
%27 = call i64 @strncmp(i8* %26, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 4)
%28 = icmp eq i64 %27, 0
br i1 %28, label %33, label %29
29: ; preds = %20
%30 = load i8*, i8** %13
%31 = call i64 @strncmp(i8* %30, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 5)
%32 = icmp eq i64 %31, 0
br i1 %32, label %33, label %53
33: ; preds = %29, %20
%34 = load i8*, i8** %8
%35 = load i8*, i8** %8
%36 = load i32, i32* %15
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i8, i8* %35, i64 %37
%39 = load i32, i32* %9
%40 = load i32, i32* %15
%41 = sub nsw i32 %39, %40
%42 = call i32 @memmove(i8* %34, i8* %38, i32 %41)
%43 = load i32*, i32** %10
%44 = load i32, i32* %43
%45 = load i32, i32* %15
%46 = sub nsw i32 %44, %45
%47 = load i32*, i32** %10
store i32 %46, i32* %47
%48 = load i8*, i8** %8
%49 = load i32*, i32** %10
%50 = load i32, i32* %49
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds i8, i8* %48, i64 %51
store i8 0, i8* %52
br label %16
53: ; preds = %29
%54 = load %struct.iptrie*, %struct.iptrie** %7
%55 = load i8*, i8** %13
%56 = load %struct.amp_asn_info*, %struct.amp_asn_info** %11
%57 = call i32 @add_parsed_line(%struct.iptrie* %54, i8* %55, %struct.amp_asn_info* %56)
%58 = load i8*, i8** %8
%59 = load i8*, i8** %8
%60 = load i32, i32* %15
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds i8, i8* %59, i64 %61
%63 = load i32, i32* %9
%64 = load i32, i32* %15
%65 = sub nsw i32 %63, %64
%66 = call i32 @memmove(i8* %58, i8* %62, i32 %65)
%67 = load i32*, i32** %10
%68 = load i32, i32* %67
%69 = load i32, i32* %15
%70 = sub nsw i32 %68, %69
%71 = load i32*, i32** %10
store i32 %70, i32* %71
%72 = load i8*, i8** %8
%73 = load i32*, i32** %10
%74 = load i32, i32* %73
%75 = sext i32 %74 to i64
%76 = getelementptr inbounds i8, i8* %72, i64 %75
store i8 0, i8* %76
%77 = load i32*, i32** %12
%78 = icmp ne i32* %77, null
br i1 %78, label %79, label %83
79: ; preds = %53
%80 = load i32*, i32** %12
%81 = load i32, i32* %80
%82 = add nsw i32 %81, -1
store i32 %82, i32* %80
br label %83
83: ; preds = %79, %53
br label %16
84: ; preds = %16
ret void
}

LLVM IR (-O2):
%struct.iptrie = type { i32 }
%struct.amp_asn_info = type { i32 }
@.str = [2 x i8] c"\0A\00"
@.str.1 = [5 x i8] c"Bulk\00"
@.str.2 = [6 x i8] c"Error\00"
define void @process_buffer(%struct.iptrie* %0, i8* %1, i32 %2, i32* nocapture %3, %struct.amp_asn_info* %4, i32* %5) {
%7 = alloca i8*
%8 = bitcast i8** %7 to i8*
store i8* null, i8** %7
%9 = call i32* @strchr(i8* %1, i8 signext 10)
%10 = icmp eq i32* %9, null
br i1 %10, label %47, label %11
11: ; preds = %6
%12 = icmp eq i32* %5, null
br label %13
13: ; preds = %11, %31
%14 = call i8* @strtok_r(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8** %7)
%15 = call i32 @strlen(i8* %14)
%16 = add nsw i32 %15, 1
%17 = call i64 @strncmp(i8* %14, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 4)
%18 = icmp eq i64 %17, 0
br i1 %18, label %22, label %19
19: ; preds = %13
%20 = call i64 @strncmp(i8* %14, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 5)
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %34
22: ; preds = %19, %13
%23 = sext i32 %16 to i64
%24 = getelementptr inbounds i8, i8* %1, i64 %23
%25 = sub nsw i32 %2, %16
%26 = call i32 @memmove(i8* %1, i8* %24, i32 %25)
%27 = load i32, i32* %3
%28 = sub nsw i32 %27, %16
store i32 %28, i32* %3
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %1, i64 %29
store i8 0, i8* %30
br label %31
31: ; preds = %34, %44, %22
%32 = call i32* @strchr(i8* %1, i8 signext 10)
%33 = icmp eq i32* %32, null
br i1 %33, label %47, label %13
34: ; preds = %19
%35 = call i32 @add_parsed_line(%struct.iptrie* %0, i8* %14, %struct.amp_asn_info* %4)
%36 = sext i32 %16 to i64
%37 = getelementptr inbounds i8, i8* %1, i64 %36
%38 = sub nsw i32 %2, %16
%39 = call i32 @memmove(i8* %1, i8* %37, i32 %38)
%40 = load i32, i32* %3
%41 = sub nsw i32 %40, %16
store i32 %41, i32* %3
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i8, i8* %1, i64 %42
store i8 0, i8* %43
br i1 %12, label %31, label %44
44: ; preds = %34
%45 = load i32, i32* %5
%46 = add nsw i32 %45, -1
store i32 %46, i32* %5
br label %31
47: ; preds = %31, %6
ret void
}