#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 buffer {
  int dummy;
};

/* Variables and functions */
char buffer_data_at(struct buffer *, int);
scalar_t__ is_position_in_buffer(int, struct buffer *);
int buffer_find_char(struct buffer *buf, int from, int way, const char *accept,
                     int *newlines) {
  int p = from;
  if (!is_position_in_buffer(p, buf))
    return -1;
  *newlines = 0;
  while (is_position_in_buffer(p, buf)) {
    const char *a = accept;
    char c;
    c = buffer_data_at(buf, p);
    while (*a != '\0') {
      if (*a++ == c)
        return p;
    }
    if (c == '\n')
      (*newlines)++;
    p += way;
  }
  return -1;
}


x86 assembly (clang, -O0):
<buffer_find_char>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1040 <is_position_in_buffer@plt>
cmp    $0x0,%rax
jne    1162 <buffer_find_char+0x42>
movl   $0xffffffff,-0x4(%rbp)
jmp    1204 <buffer_find_char+0xe4>
mov    -0x28(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x2c(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1040 <is_position_in_buffer@plt>
cmp    $0x0,%rax
je     11fd <buffer_find_char+0xdd>
mov    -0x20(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x2c(%rbp),%esi
call   1030 <buffer_data_at@plt>
mov    %al,-0x39(%rbp)
mov    -0x38(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11d7 <buffer_find_char+0xb7>
mov    -0x38(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x38(%rbp)
movsbl (%rax),%eax
movsbl -0x39(%rbp),%ecx
cmp    %ecx,%eax
jne    11d2 <buffer_find_char+0xb2>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1204 <buffer_find_char+0xe4>
jmp    1199 <buffer_find_char+0x79>
movsbl -0x39(%rbp),%eax
cmp    $0xa,%eax
jne    11ef <buffer_find_char+0xcf>
mov    -0x28(%rbp),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    %ecx,(%rax)
mov    -0x18(%rbp),%eax
add    -0x2c(%rbp),%eax
mov    %eax,-0x2c(%rbp)
jmp    116c <buffer_find_char+0x4c>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<buffer_find_char>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r8,%r14
mov    %rcx,%r15
mov    %edx,%r12d
mov    %esi,%ebp
mov    %rdi,%rbx
mov    %esi,%edi
mov    %rbx,%rsi
call   1040 <is_position_in_buffer@plt>
mov    $0xffffffff,%r13d
test   %rax,%rax
je     11b0 <buffer_find_char+0x90>
movl   $0x0,(%r14)
mov    %ebp,%edi
mov    %rbx,%rsi
call   1040 <is_position_in_buffer@plt>
test   %rax,%rax
je     11b0 <buffer_find_char+0x90>
mov    %rbx,%rdi
mov    %ebp,%esi
call   1030 <buffer_data_at@plt>
mov    %r15,%rcx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movzbl (%rcx),%edx
test   %dl,%dl
je     11a0 <buffer_find_char+0x80>
add    $0x1,%rcx
cmp    %al,%dl
jne    1180 <buffer_find_char+0x60>
jmp    11ad <buffer_find_char+0x8d>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
cmp    $0xa,%al
jne    11a8 <buffer_find_char+0x88>
addl   $0x1,(%r14)
add    %r12d,%ebp
jmp    1155 <buffer_find_char+0x35>
mov    %ebp,%r13d
mov    %r13d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.buffer = type { i32 }
define i32 @buffer_find_char(%struct.buffer* %0, i32 %1, i32 %2, i8* %3, i32* %4) {
%6 = alloca i32
%7 = alloca %struct.buffer*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i32*
%12 = alloca i32
%13 = alloca i8*
%14 = alloca i8
store %struct.buffer* %0, %struct.buffer** %7
store i32 %1, i32* %8
store i32 %2, i32* %9
store i8* %3, i8** %10
store i32* %4, i32** %11
%15 = load i32, i32* %8
store i32 %15, i32* %12
%16 = load i32, i32* %12
%17 = load %struct.buffer*, %struct.buffer** %7
%18 = call i64 @is_position_in_buffer(i32 %16, %struct.buffer* %17)
%19 = icmp ne i64 %18, 0
br i1 %19, label %21, label %20
20: ; preds = %5
store i32 -1, i32* %6
br label %62
21: ; preds = %5
%22 = load i32*, i32** %11
store i32 0, i32* %22
br label %23
23: ; preds = %57, %21
%24 = load i32, i32* %12
%25 = load %struct.buffer*, %struct.buffer** %7
%26 = call i64 @is_position_in_buffer(i32 %24, %struct.buffer* %25)
%27 = icmp ne i64 %26, 0
br i1 %27, label %28, label %61
28: ; preds = %23
%29 = load i8*, i8** %10
store i8* %29, i8** %13
%30 = load %struct.buffer*, %struct.buffer** %7
%31 = load i32, i32* %12
%32 = call signext i8 @buffer_data_at(%struct.buffer* %30, i32 %31)
store i8 %32, i8* %14
br label %33
33: ; preds = %48, %28
%34 = load i8*, i8** %13
%35 = load i8, i8* %34
%36 = sext i8 %35 to i32
%37 = icmp ne i32 %36, 0
br i1 %37, label %38, label %49
38: ; preds = %33
%39 = load i8*, i8** %13
%40 = getelementptr inbounds i8, i8* %39, i32 1
store i8* %40, i8** %13
%41 = load i8, i8* %39
%42 = sext i8 %41 to i32
%43 = load i8, i8* %14
%44 = sext i8 %43 to i32
%45 = icmp eq i32 %42, %44
br i1 %45, label %46, label %48
46: ; preds = %38
%47 = load i32, i32* %12
store i32 %47, i32* %6
br label %62
48: ; preds = %38
br label %33
49: ; preds = %33
%50 = load i8, i8* %14
%51 = sext i8 %50 to i32
%52 = icmp eq i32 %51, 10
br i1 %52, label %53, label %57
53: ; preds = %49
%54 = load i32*, i32** %11
%55 = load i32, i32* %54
%56 = add nsw i32 %55, 1
store i32 %56, i32* %54
br label %57
57: ; preds = %53, %49
%58 = load i32, i32* %9
%59 = load i32, i32* %12
%60 = add nsw i32 %59, %58
store i32 %60, i32* %12
br label %23
61: ; preds = %23
store i32 -1, i32* %6
br label %62
62: ; preds = %61, %46, %20
%63 = load i32, i32* %6
ret i32 %63
}

LLVM IR (-O2):
%struct.buffer = type { i32 }
define i32 @buffer_find_char(%struct.buffer* %0, i32 %1, i32 %2, i8* nocapture %3, i32* nocapture %4) {
%6 = tail call i64 @is_position_in_buffer(i32 %1, %struct.buffer* %0)
%7 = icmp eq i64 %6, 0
br i1 %7, label %30, label %8
8: ; preds = %5
store i32 0, i32* %4
%9 = tail call i64 @is_position_in_buffer(i32 %1, %struct.buffer* %0)
%10 = icmp eq i64 %9, 0
br i1 %10, label %30, label %11
11: ; preds = %8, %26
%12 = phi i32 [ %27, %26 ], [ %1, %8 ]
%13 = tail call signext i8 @buffer_data_at(%struct.buffer* %0, i32 %12)
br label %14
14: ; preds = %18, %11
%15 = phi i8* [ %3, %11 ], [ %19, %18 ]
%16 = load i8, i8* %15
%17 = icmp eq i8 %16, 0
br i1 %17, label %21, label %18
18: ; preds = %14
%19 = getelementptr inbounds i8, i8* %15, i64 1
%20 = icmp eq i8 %16, %13
br i1 %20, label %30, label %14
21: ; preds = %14
%22 = icmp eq i8 %13, 10
br i1 %22, label %23, label %26
23: ; preds = %21
%24 = load i32, i32* %4
%25 = add nsw i32 %24, 1
store i32 %25, i32* %4
br label %26
26: ; preds = %21, %23
%27 = add nsw i32 %12, %2
%28 = tail call i64 @is_position_in_buffer(i32 %27, %struct.buffer* %0)
%29 = icmp eq i64 %28, 0
br i1 %29, label %30, label %11
30: ; preds = %26, %18, %8, %5
%31 = phi i32 [ -1, %5 ], [ -1, %8 ], [ %12, %18 ], [ -1, %26 ]
ret i32 %31
}