#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 m_len(int);
scalar_t__ mls(int, int);
int parser_next_char(int buf, int *p) {
  int c;
  if (*p >= m_len(buf))
    return -1;
  c = (*(char *)mls((buf), (*p)));
  if (c == 0)
    return -1;
  (*p)++;
  return c;
}


x86 assembly (clang, -O0):
<parser_next_char>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%edi
call   1030 <m_len@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%eax
cmp    %ecx,%eax
jl     1159 <parser_next_char+0x39>
movl   $0xffffffff,-0x4(%rbp)
jmp    1194 <parser_next_char+0x74>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%esi
call   1040 <mls@plt>
movsbl (%rax),%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    1183 <parser_next_char+0x63>
movl   $0xffffffff,-0x4(%rbp)
jmp    1194 <parser_next_char+0x74>
mov    -0x10(%rbp),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    %ecx,(%rax)
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parser_next_char>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %edi,%ebp
mov    (%rsi),%ebx
call   1030 <m_len@plt>
mov    $0xffffffff,%r14d
cmp    %eax,%ebx
jge    1155 <parser_next_char+0x35>
mov    (%r15),%esi
mov    %ebp,%edi
call   1040 <mls@plt>
movsbl (%rax),%eax
test   %eax,%eax
je     1155 <parser_next_char+0x35>
addl   $0x1,(%r15)
mov    %eax,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @parser_next_char(i32 %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32
store i32 %0, i32* %4
store i32* %1, i32** %5
%7 = load i32*, i32** %5
%8 = load i32, i32* %7
%9 = load i32, i32* %4
%10 = call i32 @m_len(i32 %9)
%11 = icmp sge i32 %8, %10
br i1 %11, label %12, label %13
12: ; preds = %2
store i32 -1, i32* %3
br label %29
13: ; preds = %2
%14 = load i32, i32* %4
%15 = load i32*, i32** %5
%16 = load i32, i32* %15
%17 = call i64 @mls(i32 %14, i32 %16)
%18 = inttoptr i64 %17 to i8*
%19 = load i8, i8* %18
%20 = sext i8 %19 to i32
store i32 %20, i32* %6
%21 = load i32, i32* %6
%22 = icmp eq i32 %21, 0
br i1 %22, label %23, label %24
23: ; preds = %13
store i32 -1, i32* %3
br label %29
24: ; preds = %13
%25 = load i32*, i32** %5
%26 = load i32, i32* %25
%27 = add nsw i32 %26, 1
store i32 %27, i32* %25
%28 = load i32, i32* %6
store i32 %28, i32* %3
br label %29
29: ; preds = %24, %23, %12
%30 = load i32, i32* %3
ret i32 %30
}

LLVM IR (-O2):
define i32 @parser_next_char(i32 %0, i32* nocapture %1) {
%3 = load i32, i32* %1
%4 = tail call i32 @m_len(i32 %0)
%5 = icmp slt i32 %3, %4
br i1 %5, label %6, label %16
6: ; preds = %2
%7 = load i32, i32* %1
%8 = tail call i64 @mls(i32 %0, i32 %7)
%9 = inttoptr i64 %8 to i8*
%10 = load i8, i8* %9
%11 = icmp eq i8 %10, 0
br i1 %11, label %16, label %12
12: ; preds = %6
%13 = sext i8 %10 to i32
%14 = load i32, i32* %1
%15 = add nsw i32 %14, 1
store i32 %15, i32* %1
br label %16
16: ; preds = %6, %2, %12
%17 = phi i32 [ %13, %12 ], [ -1, %2 ], [ -1, %6 ]
ret i32 %17
}