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

/* Variables and functions */
int /*<<< orphan*/ capture_chars(struct current *, int, int);
scalar_t__ remove_char(struct current *, int);
int remove_chars(struct current *current, int pos, int n) {
  int removed = 0;
  capture_chars(current, pos, n);
  while (n-- && remove_char(current, pos)) {
    removed++;
  }
  return removed;
}


x86 assembly (clang, -O0):
<remove_chars>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
call   1040 <capture_chars@plt>
mov    -0x10(%rbp),%ecx
mov    %ecx,%eax
add    $0xffffffff,%eax
mov    %eax,-0x10(%rbp)
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x15(%rbp)
je     1177 <remove_chars+0x57>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1030 <remove_char@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x15(%rbp)
mov    -0x15(%rbp),%al
test   $0x1,%al
jne    1187 <remove_chars+0x67>
jmp    1195 <remove_chars+0x75>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1148 <remove_chars+0x28>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<remove_chars>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%ebp
mov    %esi,%r14d
mov    %rdi,%r15
call   1040 <capture_chars@plt>
xor    %ebx,%ebx
test   %ebp,%ebp
je     1159 <remove_chars+0x39>
nopw   0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    %r14d,%esi
call   1030 <remove_char@plt>
test   %rax,%rax
je     1159 <remove_chars+0x39>
add    $0x1,%ebx
cmp    %ebx,%ebp
jne    1140 <remove_chars+0x20>
mov    %ebp,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.current = type { i32 }
define i32 @remove_chars(%struct.current* %0, i32 %1, i32 %2) {
%4 = alloca %struct.current*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store %struct.current* %0, %struct.current** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
store i32 0, i32* %7
%8 = load %struct.current*, %struct.current** %4
%9 = load i32, i32* %5
%10 = load i32, i32* %6
%11 = call i32 @capture_chars(%struct.current* %8, i32 %9, i32 %10)
br label %12
12: ; preds = %23, %3
%13 = load i32, i32* %6
%14 = add nsw i32 %13, -1
store i32 %14, i32* %6
%15 = icmp ne i32 %13, 0
br i1 %15, label %16, label %21
16: ; preds = %12
%17 = load %struct.current*, %struct.current** %4
%18 = load i32, i32* %5
%19 = call i64 @remove_char(%struct.current* %17, i32 %18)
%20 = icmp ne i64 %19, 0
br label %21
21: ; preds = %16, %12
%22 = phi i1 [ false, %12 ], [ %20, %16 ]
br i1 %22, label %23, label %26
23: ; preds = %21
%24 = load i32, i32* %7
%25 = add nsw i32 %24, 1
store i32 %25, i32* %7
br label %12
26: ; preds = %21
%27 = load i32, i32* %7
ret i32 %27
}

LLVM IR (-O2):
%struct.current = type { i32 }
define i32 @remove_chars(%struct.current* %0, i32 %1, i32 %2) {
%4 = tail call i32 @capture_chars(%struct.current* %0, i32 %1, i32 %2)
%5 = icmp eq i32 %2, 0
br i1 %5, label %15, label %6
6: ; preds = %3, %12
%7 = phi i32 [ %9, %12 ], [ %2, %3 ]
%8 = phi i32 [ %13, %12 ], [ 0, %3 ]
%9 = add nsw i32 %7, -1
%10 = tail call i64 @remove_char(%struct.current* %0, i32 %1)
%11 = icmp eq i64 %10, 0
br i1 %11, label %15, label %12
12: ; preds = %6
%13 = add nuw nsw i32 %8, 1
%14 = icmp eq i32 %9, 0
br i1 %14, label %15, label %6
15: ; preds = %6, %12, %3
%16 = phi i32 [ 0, %3 ], [ %2, %12 ], [ %8, %6 ]
ret i32 %16
}