#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 */
scalar_t__ remove_char(struct current *, int);
int remove_chars(struct current *current, int pos, int n) {
  int removed = 0;
  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    -0x10(%rbp),%ecx
mov    %ecx,%eax
add    $0xffffffff,%eax
mov    %eax,-0x10(%rbp)
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x15(%rbp)
je     1158 <remove_chars+0x48>
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    1168 <remove_chars+0x58>
jmp    1176 <remove_chars+0x66>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1129 <remove_chars+0x19>
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
test   %edx,%edx
je     114b <remove_chars+0x3b>
mov    %edx,%ebp
mov    %esi,%r14d
mov    %rdi,%r15
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r15,%rdi
mov    %r14d,%esi
call   1030 <remove_char@plt>
test   %rax,%rax
je     114d <remove_chars+0x3d>
add    $0x1,%ebx
cmp    %ebx,%ebp
jne    1130 <remove_chars+0x20>
mov    %ebp,%ebx
jmp    114d <remove_chars+0x3d>
xor    %ebx,%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
br label %8
8: ; preds = %19, %3
%9 = load i32, i32* %6
%10 = add nsw i32 %9, -1
store i32 %10, i32* %6
%11 = icmp ne i32 %9, 0
br i1 %11, label %12, label %17
12: ; preds = %8
%13 = load %struct.current*, %struct.current** %4
%14 = load i32, i32* %5
%15 = call i64 @remove_char(%struct.current* %13, i32 %14)
%16 = icmp ne i64 %15, 0
br label %17
17: ; preds = %12, %8
%18 = phi i1 [ false, %8 ], [ %16, %12 ]
br i1 %18, label %19, label %22
19: ; preds = %17
%20 = load i32, i32* %7
%21 = add nsw i32 %20, 1
store i32 %21, i32* %7
br label %8
22: ; preds = %17
%23 = load i32, i32* %7
ret i32 %23
}

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