#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 */
size_t strlen(char const *);
int /*<<< orphan*/ term_addch(char);
int /*<<< orphan*/ term_addnstr(char const *, size_t);
int /*<<< orphan*/ term_clrtoeol();
scalar_t__ term_height();
int /*<<< orphan*/ term_move(scalar_t__, size_t);
int /*<<< orphan*/ term_refresh();
size_t term_width();
int /*<<< orphan*/ xminibuf_write(char const *);
void draw_minibuf_read(const char *prompt, const char *value, size_t prompt_len,
                       char *match, size_t pointo) {
  int margin = 1, n = 0;
  term_move(term_height() - 1, 0);
  term_clrtoeol();
  xminibuf_write(prompt);
  if (prompt_len + pointo + 1 >= term_width()) {
    margin++;
    term_addch('$');
    n = pointo - pointo % (term_width() - prompt_len - 2);
  }
  term_addnstr(value + n,
               ((term_width() - prompt_len - margin) < (strlen(value) - n)
                    ? (term_width() - prompt_len - margin)
                    : (strlen(value) - n)));
  term_addnstr(match, strlen(match));
  if (strlen(value + n) >= term_width() - prompt_len - margin) {
    term_move(term_height() - 1, term_width() - 1);
    term_addch('$');
  }
  term_move(term_height() - 1,
            prompt_len + margin - 1 +
                pointo % (term_width() - prompt_len - margin));
  term_refresh();
}


x86 assembly (clang, -O0):
<draw_minibuf_read>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
movl   $0x1,-0x2c(%rbp)
movl   $0x0,-0x30(%rbp)
mov    $0x0,%al
call   1090 <term_height@plt>
mov    %rax,%rdi
sub    $0x1,%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <term_move@plt>
mov    $0x0,%al
call   1070 <term_clrtoeol@plt>
mov    -0x8(%rbp),%rdi
call   10a0 <xminibuf_write@plt>
mov    -0x18(%rbp),%rax
add    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
mov    $0x0,%al
call   10b0 <term_width@plt>
mov    %rax,%rcx
mov    -0x38(%rbp),%rax
cmp    %rcx,%rax
jb     1253 <draw_minibuf_read+0xc3>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
mov    $0x24,%edi
call   1060 <term_addch@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    $0x0,%al
call   10b0 <term_width@plt>
mov    %rax,%rcx
mov    -0x48(%rbp),%rax
sub    -0x18(%rbp),%rcx
sub    $0x2,%rcx
xor    %edx,%edx
div    %rcx
mov    -0x40(%rbp),%rax
sub    %rdx,%rax
mov    %eax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x30(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x58(%rbp)
mov    $0x0,%al
call   10b0 <term_width@plt>
sub    -0x18(%rbp),%rax
movslq -0x2c(%rbp),%rcx
sub    %rcx,%rax
mov    %rax,-0x50(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,%rcx
mov    -0x50(%rbp),%rax
movslq -0x30(%rbp),%rdx
sub    %rdx,%rcx
cmp    %rcx,%rax
jae    12b3 <draw_minibuf_read+0x123>
mov    $0x0,%al
call   10b0 <term_width@plt>
sub    -0x18(%rbp),%rax
movslq -0x2c(%rbp),%rcx
sub    %rcx,%rax
mov    %rax,-0x60(%rbp)
jmp    12c7 <draw_minibuf_read+0x137>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
movslq -0x30(%rbp),%rcx
sub    %rcx,%rax
mov    %rax,-0x60(%rbp)
mov    -0x58(%rbp),%rdi
mov    -0x60(%rbp),%rsi
call   1050 <term_addnstr@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x70(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x70(%rbp),%rdi
mov    %rax,%rsi
call   1050 <term_addnstr@plt>
mov    -0x10(%rbp),%rdi
movslq -0x30(%rbp),%rax
add    %rax,%rdi
call   1030 <strlen@plt>
mov    %rax,-0x68(%rbp)
mov    $0x0,%al
call   10b0 <term_width@plt>
mov    %rax,%rcx
mov    -0x68(%rbp),%rax
sub    -0x18(%rbp),%rcx
movslq -0x2c(%rbp),%rdx
sub    %rdx,%rcx
cmp    %rcx,%rax
jb     1357 <draw_minibuf_read+0x1c7>
mov    $0x0,%al
call   1090 <term_height@plt>
sub    $0x1,%rax
mov    %rax,-0x78(%rbp)
mov    $0x0,%al
call   10b0 <term_width@plt>
mov    -0x78(%rbp),%rdi
mov    %rax,%rsi
sub    $0x1,%rsi
call   1040 <term_move@plt>
mov    $0x24,%edi
call   1060 <term_addch@plt>
mov    $0x0,%al
call   1090 <term_height@plt>
sub    $0x1,%rax
mov    %rax,-0x88(%rbp)
mov    -0x18(%rbp),%rax
movslq -0x2c(%rbp),%rcx
add    %rcx,%rax
sub    $0x1,%rax
mov    %rax,-0x90(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x80(%rbp)
mov    $0x0,%al
call   10b0 <term_width@plt>
mov    -0x90(%rbp),%rsi
mov    -0x88(%rbp),%rdi
mov    %rax,%rcx
mov    -0x80(%rbp),%rax
sub    -0x18(%rbp),%rcx
movslq -0x2c(%rbp),%rdx
sub    %rdx,%rcx
xor    %edx,%edx
div    %rcx
add    %rdx,%rsi
call   1040 <term_move@plt>
mov    $0x0,%al
call   1080 <term_refresh@plt>
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<draw_minibuf_read>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r8,%rbp
mov    %rcx,0x8(%rsp)
mov    %rdx,%r13
mov    %rsi,%r12
mov    %rdi,%rbx
xor    %r14d,%r14d
xor    %eax,%eax
call   1090 <term_height@plt>
lea    -0x1(%rax),%rdi
xor    %esi,%esi
call   1040 <term_move@plt>
xor    %eax,%eax
call   1070 <term_clrtoeol@plt>
mov    %rbx,%rdi
call   10a0 <xminibuf_write@plt>
lea    0x1(,%rbp,1),%rbx
add    %r13,%rbx
xor    %eax,%eax
call   10b0 <term_width@plt>
mov    $0x1,%r15d
cmp    %rax,%rbx
jb     1234 <draw_minibuf_read+0xa4>
mov    $0x24,%edi
call   1060 <term_addch@plt>
xor    %eax,%eax
call   10b0 <term_width@plt>
mov    %rax,%rcx
sub    %r13,%rcx
add    $0xfffffffffffffffe,%rcx
mov    %rbp,%rax
or     %rcx,%rax
shr    $0x20,%rax
je     1221 <draw_minibuf_read+0x91>
mov    %rbp,%rax
xor    %edx,%edx
div    %rcx
jmp    1227 <draw_minibuf_read+0x97>
mov    %ebp,%eax
xor    %edx,%edx
div    %ecx
mov    %ebp,%eax
sub    %edx,%eax
movslq %eax,%r14
mov    $0x2,%r15d
mov    %rbp,0x10(%rsp)
lea    (%r12,%r14,1),%rbx
xor    %eax,%eax
call   10b0 <term_width@plt>
mov    %rax,%rbp
add    %r13,%r15
sub    %r15,%rbp
mov    %r12,%rdi
call   1030 <strlen@plt>
sub    %r14,%rax
cmp    %rax,%rbp
jae    1267 <draw_minibuf_read+0xd7>
xor    %eax,%eax
call   10b0 <term_width@plt>
sub    %r15,%rax
mov    %rbx,%rdi
mov    %rax,%rsi
call   1050 <term_addnstr@plt>
mov    0x8(%rsp),%rbp
mov    %rbp,%rdi
call   1030 <strlen@plt>
mov    %rbp,%rdi
mov    %rax,%rsi
call   1050 <term_addnstr@plt>
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   10b0 <term_width@plt>
sub    %r15,%rax
cmp    %rax,%rbx
mov    0x10(%rsp),%rbp
jb     12d1 <draw_minibuf_read+0x141>
xor    %eax,%eax
call   1090 <term_height@plt>
lea    -0x1(%rax),%rbx
xor    %eax,%eax
call   10b0 <term_width@plt>
lea    -0x1(%rax),%rsi
mov    %rbx,%rdi
call   1040 <term_move@plt>
mov    $0x24,%edi
call   1060 <term_addch@plt>
xor    %eax,%eax
call   1090 <term_height@plt>
mov    %rax,%r14
add    $0xffffffffffffffff,%r14
lea    -0x1(%r15),%rbx
xor    %eax,%eax
call   10b0 <term_width@plt>
mov    %rax,%rcx
sub    %r15,%rcx
mov    %rbp,%rax
or     %rcx,%rax
shr    $0x20,%rax
je     1306 <draw_minibuf_read+0x176>
mov    %rbp,%rax
xor    %edx,%edx
div    %rcx
jmp    130c <draw_minibuf_read+0x17c>
mov    %ebp,%eax
xor    %edx,%edx
div    %ecx
add    %rdx,%rbx
mov    %r14,%rdi
mov    %rbx,%rsi
call   1040 <term_move@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1080 <term_refresh@plt>

LLVM IR (-O0):
define void @draw_minibuf_read(i8* %0, i8* %1, i64 %2, i8* %3, i64 %4) {
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i8*
%10 = alloca i64
%11 = alloca i32
%12 = alloca i32
store i8* %0, i8** %6
store i8* %1, i8** %7
store i64 %2, i64* %8
store i8* %3, i8** %9
store i64 %4, i64* %10
store i32 1, i32* %11
store i32 0, i32* %12
%13 = call i64 (...) @term_height()
%14 = sub nsw i64 %13, 1
%15 = call i32 @term_move(i64 %14, i64 0)
%16 = call i32 (...) @term_clrtoeol()
%17 = load i8*, i8** %6
%18 = call i32 @xminibuf_write(i8* %17)
%19 = load i64, i64* %8
%20 = load i64, i64* %10
%21 = add i64 %19, %20
%22 = add i64 %21, 1
%23 = call i64 (...) @term_width()
%24 = icmp uge i64 %22, %23
br i1 %24, label %25, label %38
25: ; preds = %5
%26 = load i32, i32* %11
%27 = add nsw i32 %26, 1
store i32 %27, i32* %11
%28 = call i32 @term_addch(i8 signext 36)
%29 = load i64, i64* %10
%30 = load i64, i64* %10
%31 = call i64 (...) @term_width()
%32 = load i64, i64* %8
%33 = sub i64 %31, %32
%34 = sub i64 %33, 2
%35 = urem i64 %30, %34
%36 = sub i64 %29, %35
%37 = trunc i64 %36 to i32
store i32 %37, i32* %12
br label %38
38: ; preds = %25, %5
%39 = load i8*, i8** %7
%40 = load i32, i32* %12
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i8, i8* %39, i64 %41
%43 = call i64 (...) @term_width()
%44 = load i64, i64* %8
%45 = sub i64 %43, %44
%46 = load i32, i32* %11
%47 = sext i32 %46 to i64
%48 = sub i64 %45, %47
%49 = load i8*, i8** %7
%50 = call i64 @strlen(i8* %49)
%51 = load i32, i32* %12
%52 = sext i32 %51 to i64
%53 = sub i64 %50, %52
%54 = icmp ult i64 %48, %53
br i1 %54, label %55, label %62
55: ; preds = %38
%56 = call i64 (...) @term_width()
%57 = load i64, i64* %8
%58 = sub i64 %56, %57
%59 = load i32, i32* %11
%60 = sext i32 %59 to i64
%61 = sub i64 %58, %60
br label %68
62: ; preds = %38
%63 = load i8*, i8** %7
%64 = call i64 @strlen(i8* %63)
%65 = load i32, i32* %12
%66 = sext i32 %65 to i64
%67 = sub i64 %64, %66
br label %68
68: ; preds = %62, %55
%69 = phi i64 [ %61, %55 ], [ %67, %62 ]
%70 = call i32 @term_addnstr(i8* %42, i64 %69)
%71 = load i8*, i8** %9
%72 = load i8*, i8** %9
%73 = call i64 @strlen(i8* %72)
%74 = call i32 @term_addnstr(i8* %71, i64 %73)
%75 = load i8*, i8** %7
%76 = load i32, i32* %12
%77 = sext i32 %76 to i64
%78 = getelementptr inbounds i8, i8* %75, i64 %77
%79 = call i64 @strlen(i8* %78)
%80 = call i64 (...) @term_width()
%81 = load i64, i64* %8
%82 = sub i64 %80, %81
%83 = load i32, i32* %11
%84 = sext i32 %83 to i64
%85 = sub i64 %82, %84
%86 = icmp uge i64 %79, %85
br i1 %86, label %87, label %94
87: ; preds = %68
%88 = call i64 (...) @term_height()
%89 = sub nsw i64 %88, 1
%90 = call i64 (...) @term_width()
%91 = sub i64 %90, 1
%92 = call i32 @term_move(i64 %89, i64 %91)
%93 = call i32 @term_addch(i8 signext 36)
br label %94
94: ; preds = %87, %68
%95 = call i64 (...) @term_height()
%96 = sub nsw i64 %95, 1
%97 = load i64, i64* %8
%98 = load i32, i32* %11
%99 = sext i32 %98 to i64
%100 = add i64 %97, %99
%101 = sub i64 %100, 1
%102 = load i64, i64* %10
%103 = call i64 (...) @term_width()
%104 = load i64, i64* %8
%105 = sub i64 %103, %104
%106 = load i32, i32* %11
%107 = sext i32 %106 to i64
%108 = sub i64 %105, %107
%109 = urem i64 %102, %108
%110 = add i64 %101, %109
%111 = call i32 @term_move(i64 %96, i64 %110)
%112 = call i32 (...) @term_refresh()
ret void
}

LLVM IR (-O2):
define void @draw_minibuf_read(i8* %0, i8* %1, i64 %2, i8* %3, i64 %4) {
%6 = tail call i64 (...) @term_height()
%7 = add nsw i64 %6, -1
%8 = tail call i32 @term_move(i64 %7, i64 0)
%9 = tail call i32 (...) @term_clrtoeol()
%10 = tail call i32 @xminibuf_write(i8* %0)
%11 = add i64 %2, 1
%12 = add i64 %11, %4
%13 = tail call i64 (...) @term_width()
%14 = icmp ult i64 %12, %13
br i1 %14, label %24, label %15
15: ; preds = %5
%16 = tail call i32 @term_addch(i8 signext 36)
%17 = tail call i64 (...) @term_width()
%18 = sub i64 -2, %2
%19 = add i64 %18, %17
%20 = urem i64 %4, %19
%21 = sub i64 %4, %20
%22 = shl i64 %21, 32
%23 = ashr exact i64 %22, 32
br label %24
24: ; preds = %15, %5
%25 = phi i64 [ 2, %15 ], [ 1, %5 ]
%26 = phi i64 [ %23, %15 ], [ 0, %5 ]
%27 = getelementptr inbounds i8, i8* %1, i64 %26
%28 = tail call i64 (...) @term_width()
%29 = add i64 %25, %2
%30 = sub i64 %28, %29
%31 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%32 = sub i64 %31, %26
%33 = icmp ult i64 %30, %32
br i1 %33, label %34, label %37
34: ; preds = %24
%35 = tail call i64 (...) @term_width()
%36 = sub i64 %35, %29
br label %37
37: ; preds = %24, %34
%38 = phi i64 [ %36, %34 ], [ %32, %24 ]
%39 = tail call i32 @term_addnstr(i8* %27, i64 %38)
%40 = tail call i64 @strlen(i8* dereferenceable(1) %3)
%41 = tail call i32 @term_addnstr(i8* %3, i64 %40)
%42 = tail call i64 @strlen(i8* dereferenceable(1) %27)
%43 = tail call i64 (...) @term_width()
%44 = sub i64 %43, %29
%45 = icmp ult i64 %42, %44
br i1 %45, label %53, label %46
46: ; preds = %37
%47 = tail call i64 (...) @term_height()
%48 = add nsw i64 %47, -1
%49 = tail call i64 (...) @term_width()
%50 = add i64 %49, -1
%51 = tail call i32 @term_move(i64 %48, i64 %50)
%52 = tail call i32 @term_addch(i8 signext 36)
br label %53
53: ; preds = %46, %37
%54 = tail call i64 (...) @term_height()
%55 = add nsw i64 %54, -1
%56 = add i64 %29, -1
%57 = tail call i64 (...) @term_width()
%58 = sub i64 %57, %29
%59 = urem i64 %4, %58
%60 = add i64 %56, %59
%61 = tail call i32 @term_move(i64 %55, i64 %60)
%62 = tail call i32 (...) @term_refresh()
ret void
}