#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*/ fh_cli_lmove(int *, int);
int /*<<< orphan*/ fh_cli_write(char *, ...);
void fh_cli_erase(char *cmd, int *cmd_len, int *pos) {
  if (*pos > 0) {
    int i, cnt = 0;
    fh_cli_write("");
    for (i = *pos; i < *cmd_len; i++) {
      cmd[i - 1] = cmd[i];
      fh_cli_write("%c", cmd[i]);
      (*pos)++;
      cnt++;
    }
    (*pos)--;
    (*cmd_len)--;
    cmd[*pos] = 0;
    fh_cli_write(" ");
    (*pos)++;
    cnt++;
    fh_cli_lmove(pos, cnt);
  }
}


x86 assembly (clang, -O0):
<fh_cli_erase>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmpl   $0x0,(%rax)
jle    1218 <fh_cli_erase+0xf8>
movl   $0x0,-0x20(%rbp)
lea    0xeb1(%rip),%rdi
mov    $0x0,%al
call   1030 <fh_cli_write@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    -0x10(%rbp),%rcx
cmp    (%rcx),%eax
jge    11c5 <fh_cli_erase+0xa5>
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x8(%rbp),%rax
mov    -0x1c(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%esi
lea    0xe66(%rip),%rdi
mov    $0x0,%al
call   1030 <fh_cli_write@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    %ecx,(%rax)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    115f <fh_cli_erase+0x3f>
mov    -0x18(%rbp),%rax
mov    (%rax),%ecx
add    $0xffffffff,%ecx
mov    %ecx,(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%ecx
add    $0xffffffff,%ecx
mov    %ecx,(%rax)
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
movslq (%rcx),%rcx
movb   $0x0,(%rax,%rcx,1)
lea    0xe14(%rip),%rdi
mov    $0x0,%al
call   1030 <fh_cli_write@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    %ecx,(%rax)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%esi
call   1040 <fh_cli_lmove@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fh_cli_erase>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
cmpl   $0x0,(%rdx)
jle    11dd <fh_cli_erase+0xbd>
mov    %rdx,%r13
mov    %rsi,%r15
mov    %rdi,%r14
lea    0xebc(%rip),%rdi
xor    %eax,%eax
call   1030 <fh_cli_write@plt>
mov    0x0(%r13),%eax
mov    $0x1,%ebp
cmp    (%r15),%eax
jge    119e <fh_cli_erase+0x7e>
movslq %eax,%rbx
mov    $0x1,%ebp
lea    0xe9a(%rip),%r12
nopl   0x0(%rax,%rax,1)
movsbl (%r14,%rbx,1),%esi
mov    %sil,-0x1(%r14,%rbx,1)
mov    %r12,%rdi
xor    %eax,%eax
call   1030 <fh_cli_write@plt>
mov    0x0(%r13),%eax
add    $0x1,%eax
mov    %eax,0x0(%r13)
add    $0x1,%rbx
add    $0x1,%ebp
movslq (%r15),%rcx
cmp    %rcx,%rbx
jl     1170 <fh_cli_erase+0x50>
add    $0xffffffff,%eax
mov    %eax,0x0(%r13)
addl   $0xffffffff,(%r15)
movslq 0x0(%r13),%rax
movb   $0x0,(%r14,%rax,1)
lea    0xe4c(%rip),%rdi
xor    %eax,%eax
call   1030 <fh_cli_write@plt>
addl   $0x1,0x0(%r13)
mov    %r13,%rdi
mov    %ebp,%esi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <fh_cli_lmove@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"\08\00"
@.str.1 = [3 x i8] c"%c\00"
@.str.2 = [2 x i8] c" \00"
define void @fh_cli_erase(i8* %0, i32* %1, i32* %2) {
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %4
store i32* %1, i32** %5
store i32* %2, i32** %6
%9 = load i32*, i32** %6
%10 = load i32, i32* %9
%11 = icmp sgt i32 %10, 0
br i1 %11, label %12, label %68
12: ; preds = %3
store i32 0, i32* %8
%13 = call i32 (i8*, ...) @fh_cli_write(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%14 = load i32*, i32** %6
%15 = load i32, i32* %14
store i32 %15, i32* %7
br label %16
16: ; preds = %44, %12
%17 = load i32, i32* %7
%18 = load i32*, i32** %5
%19 = load i32, i32* %18
%20 = icmp slt i32 %17, %19
br i1 %20, label %21, label %47
21: ; preds = %16
%22 = load i8*, i8** %4
%23 = load i32, i32* %7
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %22, i64 %24
%26 = load i8, i8* %25
%27 = load i8*, i8** %4
%28 = load i32, i32* %7
%29 = sub nsw i32 %28, 1
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i8, i8* %27, i64 %30
store i8 %26, i8* %31
%32 = load i8*, i8** %4
%33 = load i32, i32* %7
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i8, i8* %32, i64 %34
%36 = load i8, i8* %35
%37 = sext i8 %36 to i32
%38 = call i32 (i8*, ...) @fh_cli_write(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %37)
%39 = load i32*, i32** %6
%40 = load i32, i32* %39
%41 = add nsw i32 %40, 1
store i32 %41, i32* %39
%42 = load i32, i32* %8
%43 = add nsw i32 %42, 1
store i32 %43, i32* %8
br label %44
44: ; preds = %21
%45 = load i32, i32* %7
%46 = add nsw i32 %45, 1
store i32 %46, i32* %7
br label %16
47: ; preds = %16
%48 = load i32*, i32** %6
%49 = load i32, i32* %48
%50 = add nsw i32 %49, -1
store i32 %50, i32* %48
%51 = load i32*, i32** %5
%52 = load i32, i32* %51
%53 = add nsw i32 %52, -1
store i32 %53, i32* %51
%54 = load i8*, i8** %4
%55 = load i32*, i32** %6
%56 = load i32, i32* %55
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds i8, i8* %54, i64 %57
store i8 0, i8* %58
%59 = call i32 (i8*, ...) @fh_cli_write(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%60 = load i32*, i32** %6
%61 = load i32, i32* %60
%62 = add nsw i32 %61, 1
store i32 %62, i32* %60
%63 = load i32, i32* %8
%64 = add nsw i32 %63, 1
store i32 %64, i32* %8
%65 = load i32*, i32** %6
%66 = load i32, i32* %8
%67 = call i32 @fh_cli_lmove(i32* %65, i32 %66)
br label %68
68: ; preds = %47, %3
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"\08\00"
@.str.1 = [3 x i8] c"%c\00"
@.str.2 = [2 x i8] c" \00"
define void @fh_cli_erase(i8* nocapture %0, i32* nocapture %1, i32* %2) {
%4 = load i32, i32* %2
%5 = icmp sgt i32 %4, 0
br i1 %5, label %6, label %42
6: ; preds = %3
%7 = tail call i32 (i8*, ...) @fh_cli_write(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%8 = load i32, i32* %2
%9 = load i32, i32* %1
%10 = icmp slt i32 %8, %9
br i1 %10, label %11, label %29
11: ; preds = %6
%12 = sext i32 %8 to i64
br label %13
13: ; preds = %11, %13
%14 = phi i64 [ %12, %11 ], [ %24, %13 ]
%15 = phi i32 [ 1, %11 ], [ %25, %13 ]
%16 = getelementptr inbounds i8, i8* %0, i64 %14
%17 = load i8, i8* %16
%18 = add nsw i64 %14, -1
%19 = getelementptr inbounds i8, i8* %0, i64 %18
store i8 %17, i8* %19
%20 = sext i8 %17 to i32
%21 = tail call i32 (i8*, ...) @fh_cli_write(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %20)
%22 = load i32, i32* %2
%23 = add nsw i32 %22, 1
store i32 %23, i32* %2
%24 = add nsw i64 %14, 1
%25 = add i32 %15, 1
%26 = load i32, i32* %1
%27 = sext i32 %26 to i64
%28 = icmp slt i64 %24, %27
br i1 %28, label %13, label %29
29: ; preds = %13, %6
%30 = phi i32 [ %8, %6 ], [ %23, %13 ]
%31 = phi i32 [ 1, %6 ], [ %25, %13 ]
%32 = add nsw i32 %30, -1
store i32 %32, i32* %2
%33 = load i32, i32* %1
%34 = add nsw i32 %33, -1
store i32 %34, i32* %1
%35 = load i32, i32* %2
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i8, i8* %0, i64 %36
store i8 0, i8* %37
%38 = tail call i32 (i8*, ...) @fh_cli_write(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%39 = load i32, i32* %2
%40 = add nsw i32 %39, 1
store i32 %40, i32* %2
%41 = tail call i32 @fh_cli_lmove(i32* %2, i32 %31)
br label %42
42: ; preds = %29, %3
ret void
}