#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*/ my_isspace(int);
int stub1(void *);
int stub2(void *);
void stub3(void *);
int parse_chars(int (*peek)(void *userp), void (*pop)(void *userp), void *userp,
                char *vp, bool fake) {
  int n = 0;
  char *pt = vp;
  while (!my_isspace((*peek)(userp))) {
    if (fake == false)
      *(pt++) = (*peek)(userp);
    n++;
    (*pop)(userp);
  }
  if (fake == false)
    (*pt) = '\0';
  return n;
}


x86 assembly (clang, -O0):
<parse_chars>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rdi
call   *%rax
mov    %eax,%edi
call   1030 <my_isspace@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1161 <parse_chars+0x51>
jmp    11a0 <parse_chars+0x90>
cmpl   $0x0,-0x24(%rbp)
jne    1188 <parse_chars+0x78>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rdi
call   *%rax
mov    %al,%cl
mov    -0x30(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x30(%rbp)
mov    %cl,(%rax)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rdi
call   *%rax
jmp    113b <parse_chars+0x2b>
cmpl   $0x0,-0x24(%rbp)
jne    11b1 <parse_chars+0xa1>
mov    -0x30(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x28(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_chars>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r8d,%r14d
mov    %rcx,%r15
mov    %rdx,%rbp
mov    %rsi,%r12
mov    %rdi,%r13
mov    %rdx,%rdi
call   *%r13
mov    %eax,%edi
call   1030 <my_isspace@plt>
xor    %ebx,%ebx
test   %eax,%eax
je     1157 <parse_chars+0x47>
test   %r14d,%r14d
jne    1146 <parse_chars+0x36>
movb   $0x0,(%r15)
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %ebx,%ebx
jmp    117a <parse_chars+0x6a>
nopl   0x0(%rax,%rax,1)
add    $0x1,%ebx
mov    %rbp,%rdi
call   *%r12
mov    %rbp,%rdi
call   *%r13
mov    %eax,%edi
call   1030 <my_isspace@plt>
test   %eax,%eax
jne    113d <parse_chars+0x2d>
test   %r14d,%r14d
jne    1160 <parse_chars+0x50>
mov    %rbp,%rdi
call   *%r13
mov    %al,(%r15)
add    $0x1,%r15
jmp    1160 <parse_chars+0x50>

LLVM IR (-O0):
define i32 @parse_chars(i32 (i8*)* %0, void (i8*)* %1, i8* %2, i8* %3, i32 %4) {
%6 = alloca i32 (i8*)*
%7 = alloca void (i8*)*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i8*
store i32 (i8*)* %0, i32 (i8*)** %6
store void (i8*)* %1, void (i8*)** %7
store i8* %2, i8** %8
store i8* %3, i8** %9
store i32 %4, i32* %10
store i32 0, i32* %11
%13 = load i8*, i8** %9
store i8* %13, i8** %12
br label %14
14: ; preds = %31, %5
%15 = load i32 (i8*)*, i32 (i8*)** %6
%16 = load i8*, i8** %8
%17 = call i32 %15(i8* %16)
%18 = call i32 @my_isspace(i32 %17)
%19 = icmp ne i32 %18, 0
%20 = xor i1 %19, true
br i1 %20, label %21, label %36
21: ; preds = %14
%22 = load i32, i32* %10
%23 = icmp eq i32 %22, 0
br i1 %23, label %24, label %31
24: ; preds = %21
%25 = load i32 (i8*)*, i32 (i8*)** %6
%26 = load i8*, i8** %8
%27 = call i32 %25(i8* %26)
%28 = trunc i32 %27 to i8
%29 = load i8*, i8** %12
%30 = getelementptr inbounds i8, i8* %29, i32 1
store i8* %30, i8** %12
store i8 %28, i8* %29
br label %31
31: ; preds = %24, %21
%32 = load i32, i32* %11
%33 = add nsw i32 %32, 1
store i32 %33, i32* %11
%34 = load void (i8*)*, void (i8*)** %7
%35 = load i8*, i8** %8
br label %14
36: ; preds = %14
%37 = load i32, i32* %10
%38 = icmp eq i32 %37, 0
br i1 %38, label %39, label %41
39: ; preds = %36
%40 = load i8*, i8** %12
store i8 0, i8* %40
br label %41
41: ; preds = %39, %36
%42 = load i32, i32* %11
ret i32 %42
}

LLVM IR (-O2):
define i32 @parse_chars(i32 (i8*)* nocapture %0, void (i8*)* nocapture %1, i8* %2, i8* nocapture writeonly %3, i32 %4) {
%6 = tail call i32 %0(i8* %2)
%7 = tail call i32 @my_isspace(i32 %6)
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %24
9: ; preds = %5
%10 = icmp eq i32 %4, 0
br label %11
11: ; preds = %9, %18
%12 = phi i8* [ %3, %9 ], [ %19, %18 ]
%13 = phi i32 [ 0, %9 ], [ %20, %18 ]
br i1 %10, label %14, label %18
14: ; preds = %11
%15 = tail call i32 %0(i8* %2)
%16 = trunc i32 %15 to i8
%17 = getelementptr inbounds i8, i8* %12, i64 1
store i8 %16, i8* %12
br label %18
18: ; preds = %14, %11
%19 = phi i8* [ %17, %14 ], [ %12, %11 ]
%20 = add nuw nsw i32 %13, 1
tail call void %1(i8* %2)
%21 = tail call i32 %0(i8* %2)
%22 = tail call i32 @my_isspace(i32 %21)
%23 = icmp eq i32 %22, 0
br i1 %23, label %11, label %24
24: ; preds = %18, %5
%25 = phi i32 [ 0, %5 ], [ %20, %18 ]
%26 = phi i8* [ %3, %5 ], [ %19, %18 ]
%27 = icmp eq i32 %4, 0
br i1 %27, label %28, label %29
28: ; preds = %24
store i8 0, i8* %26
br label %29
29: ; preds = %28, %24
ret i32 %25
}