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

/* Variables and functions */
int mrb_bufsize(struct mrb *);
int mrb_peek(struct mrb *, int *);
int find_newline(struct mrb *c, int *pos) {
  int ch;
  for (;;) {
    ch = mrb_peek(c, pos);
    if (ch == 10)
      return 1;
    if (ch < 0) {
      if (*pos == mrb_bufsize(c))
        return 1;
      return 0;
    }
  }
}


x86 assembly (clang, -O0):
<find_newline>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <mrb_peek@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xa,-0x1c(%rbp)
jne    1156 <find_newline+0x36>
movl   $0x1,-0x4(%rbp)
jmp    119c <find_newline+0x7c>
cmpl   $0x0,-0x1c(%rbp)
jge    1197 <find_newline+0x77>
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <mrb_bufsize@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%eax
cmp    %ecx,%eax
jne    118b <find_newline+0x6b>
movl   $0x1,-0x4(%rbp)
jmp    119c <find_newline+0x7c>
movl   $0x0,-0x4(%rbp)
jmp    119c <find_newline+0x7c>
jmp    1130 <find_newline+0x10>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<find_newline>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
nopw   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %rbx,%rsi
call   1040 <mrb_peek@plt>
cmp    $0xa,%eax
je     1159 <find_newline+0x39>
test   %eax,%eax
jns    1130 <find_newline+0x10>
mov    (%rbx),%ebx
mov    %r14,%rdi
call   1030 <mrb_bufsize@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    %ecx,%ebx
sete   %al
jmp    115e <find_newline+0x3e>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.mrb = type { i32 }
define i32 @find_newline(%struct.mrb* %0, i32* %1) {
%3 = alloca i32
%4 = alloca %struct.mrb*
%5 = alloca i32*
%6 = alloca i32
store %struct.mrb* %0, %struct.mrb** %4
store i32* %1, i32** %5
br label %7
7: ; preds = %25, %2
%8 = load %struct.mrb*, %struct.mrb** %4
%9 = load i32*, i32** %5
%10 = call i32 @mrb_peek(%struct.mrb* %8, i32* %9)
store i32 %10, i32* %6
%11 = load i32, i32* %6
%12 = icmp eq i32 %11, 10
br i1 %12, label %13, label %14
13: ; preds = %7
store i32 1, i32* %3
br label %26
14: ; preds = %7
%15 = load i32, i32* %6
%16 = icmp slt i32 %15, 0
br i1 %16, label %17, label %25
17: ; preds = %14
%18 = load i32*, i32** %5
%19 = load i32, i32* %18
%20 = load %struct.mrb*, %struct.mrb** %4
%21 = call i32 @mrb_bufsize(%struct.mrb* %20)
%22 = icmp eq i32 %19, %21
br i1 %22, label %23, label %24
23: ; preds = %17
store i32 1, i32* %3
br label %26
24: ; preds = %17
store i32 0, i32* %3
br label %26
25: ; preds = %14
br label %7
26: ; preds = %24, %23, %13
%27 = load i32, i32* %3
ret i32 %27
}

LLVM IR (-O2):
%struct.mrb = type { i32 }
define i32 @find_newline(%struct.mrb* %0, i32* %1) {
br label %3
3: ; preds = %6, %2
%4 = tail call i32 @mrb_peek(%struct.mrb* %0, i32* %1)
%5 = icmp eq i32 %4, 10
br i1 %5, label %13, label %6
6: ; preds = %3
%7 = icmp slt i32 %4, 0
br i1 %7, label %8, label %3
8: ; preds = %6
%9 = load i32, i32* %1
%10 = tail call i32 @mrb_bufsize(%struct.mrb* %0)
%11 = icmp eq i32 %9, %10
%12 = zext i1 %11 to i32
br label %13
13: ; preds = %3, %8
%14 = phi i32 [ %12, %8 ], [ 1, %3 ]
ret i32 %14
}