#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 */
char *input_line_and_echo(char, unsigned char, char *);
int /*<<< orphan*/ memset(char **, char, unsigned char);
int /*<<< orphan*/ terminal_send(char *, int /*<<< orphan*/);
int /*<<< orphan*/ terminal_send_left();
char *prompt_line(unsigned char type, unsigned char size, char *existing_text) {
  char b, r, e, i;
  char prompt[66];
  switch (type) {
  case 0:
    b = 0;
    r = 0;
    e = 0;
    break;
  case 1:
    b = '[';
    r = '_';
    e = ']';
    break;
  case 2:
    b = '>';
    r = '_';
    e = '<';
  }
  memset(&prompt, 0x20, 66);
  memset(&prompt, r, size + 1);
  prompt[0] = b;
  prompt[size + 1] = e;
  prompt[size + 2] = '\0';
  terminal_send(prompt, 0);
  for (i = 0; i < size + 1; ++i) {
    terminal_send_left();
  }
  if (existing_text != NULL) {
    terminal_send(existing_text, 0);
  }
  return input_line_and_echo(r, size, existing_text);
}


x86 assembly (clang, -O0):
<prompt_line>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %sil,%al
mov    %dil,%cl
mov    %cl,-0x1(%rbp)
mov    %al,-0x2(%rbp)
mov    %rdx,-0x10(%rbp)
movzbl -0x1(%rbp),%eax
mov    %eax,-0x64(%rbp)
test   %eax,%eax
je     118e <prompt_line+0x4e>
jmp    116c <prompt_line+0x2c>
mov    -0x64(%rbp),%eax
sub    $0x1,%eax
je     119f <prompt_line+0x5f>
jmp    117d <prompt_line+0x3d>
mov    -0x64(%rbp),%eax
sub    $0x2,%eax
je     11b0 <prompt_line+0x70>
jmp    11bc <prompt_line+0x7c>
movb   $0x0,-0x11(%rbp)
movb   $0x0,-0x12(%rbp)
movb   $0x0,-0x13(%rbp)
jmp    11bc <prompt_line+0x7c>
movb   $0x5b,-0x11(%rbp)
movb   $0x5f,-0x12(%rbp)
movb   $0x5d,-0x13(%rbp)
jmp    11bc <prompt_line+0x7c>
movb   $0x3e,-0x11(%rbp)
movb   $0x5f,-0x12(%rbp)
movb   $0x3c,-0x13(%rbp)
lea    -0x60(%rbp),%rdi
mov    $0x20,%esi
mov    $0x42,%edx
call   1050 <memset@plt>
lea    -0x60(%rbp),%rdi
mov    -0x12(%rbp),%cl
movzbl -0x2(%rbp),%eax
add    $0x1,%eax
movsbl %cl,%esi
movzbl %al,%edx
call   1050 <memset@plt>
mov    -0x11(%rbp),%al
mov    %al,-0x60(%rbp)
mov    -0x13(%rbp),%cl
movzbl -0x2(%rbp),%eax
add    $0x1,%eax
cltq
mov    %cl,-0x60(%rbp,%rax,1)
movzbl -0x2(%rbp),%eax
add    $0x2,%eax
cltq
movb   $0x0,-0x60(%rbp,%rax,1)
lea    -0x60(%rbp),%rdi
xor    %esi,%esi
call   1030 <terminal_send@plt>
movb   $0x0,-0x14(%rbp)
movsbl -0x14(%rbp),%eax
movzbl -0x2(%rbp),%ecx
add    $0x1,%ecx
cmp    %ecx,%eax
jge    1242 <prompt_line+0x102>
mov    $0x0,%al
call   1040 <terminal_send_left@plt>
mov    -0x14(%rbp),%al
add    $0x1,%al
mov    %al,-0x14(%rbp)
jmp    121b <prompt_line+0xdb>
cmpq   $0x0,-0x10(%rbp)
je     1258 <prompt_line+0x118>
mov    -0x10(%rbp),%rdi
xor    %esi,%esi
call   1030 <terminal_send@plt>
mov    -0x12(%rbp),%cl
mov    -0x2(%rbp),%al
mov    -0x10(%rbp),%rdx
movsbl %cl,%edi
movzbl %al,%esi
call   1060 <input_line_and_echo@plt>
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<prompt_line>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %rdx,%r14
mov    %esi,%ebx
cmp    $0x2,%dil
je     116a <prompt_line+0x2a>
cmp    $0x1,%dil
jne    1175 <prompt_line+0x35>
mov    $0x5d,%r12b
mov    $0x5f,%r15b
mov    $0x5b,%r13b
jmp    117e <prompt_line+0x3e>
mov    $0x3c,%r12b
mov    $0x5f,%r15b
mov    $0x3e,%r13b
jmp    117e <prompt_line+0x3e>
xor    %r13d,%r13d
xor    %r15d,%r15d
xor    %r12d,%r12d
mov    %rsp,%rbp
mov    %rbp,%rdi
mov    $0x20,%esi
mov    $0x42,%edx
call   1050 <memset@plt>
movzbl %bl,%ebx
lea    0x1(%rbx),%rax
movzbl %r15b,%r15d
movzbl %al,%edx
mov    %rbp,%rdi
mov    %r15d,%esi
call   1050 <memset@plt>
mov    %r13b,(%rsp)
mov    %r12b,0x1(%rsp,%rbx,1)
movb   $0x0,0x2(%rbx,%rbp,1)
mov    %rbp,%rdi
xor    %esi,%esi
call   1030 <terminal_send@plt>
mov    $0x1,%bpl
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1040 <terminal_send_left@plt>
movsbl %bpl,%eax
lea    0x1(%rax),%ebp
cmp    %eax,%ebx
jge    11d0 <prompt_line+0x90>
test   %r14,%r14
je     11f1 <prompt_line+0xb1>
mov    %r14,%rdi
xor    %esi,%esi
call   1030 <terminal_send@plt>
mov    %r15d,%edi
mov    %ebx,%esi
mov    %r14,%rdx
call   1060 <input_line_and_echo@plt>
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i8* @prompt_line(i8 zeroext %0, i8 zeroext %1, i8* %2) {
%4 = alloca i8
%5 = alloca i8
%6 = alloca i8*
%7 = alloca i8
%8 = alloca i8
%9 = alloca i8
%10 = alloca i8
%11 = alloca [66 x i8]
store i8 %0, i8* %4
store i8 %1, i8* %5
store i8* %2, i8** %6
%12 = load i8, i8* %4
%13 = zext i8 %12 to i32
switch i32 %13, label %17 [
i32 0, label %14
i32 1, label %15
i32 2, label %16
]
14: ; preds = %3
store i8 0, i8* %7
store i8 0, i8* %8
store i8 0, i8* %9
br label %17
15: ; preds = %3
store i8 91, i8* %7
store i8 95, i8* %8
store i8 93, i8* %9
br label %17
16: ; preds = %3
store i8 62, i8* %7
store i8 95, i8* %8
store i8 60, i8* %9
br label %17
17: ; preds = %16, %3, %15, %14
%18 = bitcast [66 x i8]* %11 to i8**
%19 = call i32 @memset(i8** %18, i8 signext 32, i8 zeroext 66)
%20 = bitcast [66 x i8]* %11 to i8**
%21 = load i8, i8* %8
%22 = load i8, i8* %5
%23 = zext i8 %22 to i32
%24 = add nsw i32 %23, 1
%25 = trunc i32 %24 to i8
%26 = call i32 @memset(i8** %20, i8 signext %21, i8 zeroext %25)
%27 = load i8, i8* %7
%28 = getelementptr inbounds [66 x i8], [66 x i8]* %11, i64 0, i64 0
store i8 %27, i8* %28
%29 = load i8, i8* %9
%30 = load i8, i8* %5
%31 = zext i8 %30 to i32
%32 = add nsw i32 %31, 1
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds [66 x i8], [66 x i8]* %11, i64 0, i64 %33
store i8 %29, i8* %34
%35 = load i8, i8* %5
%36 = zext i8 %35 to i32
%37 = add nsw i32 %36, 2
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds [66 x i8], [66 x i8]* %11, i64 0, i64 %38
store i8 0, i8* %39
%40 = getelementptr inbounds [66 x i8], [66 x i8]* %11, i64 0, i64 0
%41 = call i32 @terminal_send(i8* %40, i32 0)
store i8 0, i8* %10
br label %42
42: ; preds = %51, %17
%43 = load i8, i8* %10
%44 = sext i8 %43 to i32
%45 = load i8, i8* %5
%46 = zext i8 %45 to i32
%47 = add nsw i32 %46, 1
%48 = icmp slt i32 %44, %47
br i1 %48, label %49, label %54
49: ; preds = %42
%50 = call i32 (...) @terminal_send_left()
br label %51
51: ; preds = %49
%52 = load i8, i8* %10
%53 = add i8 %52, 1
store i8 %53, i8* %10
br label %42
54: ; preds = %42
%55 = load i8*, i8** %6
%56 = icmp ne i8* %55, null
br i1 %56, label %57, label %60
57: ; preds = %54
%58 = load i8*, i8** %6
%59 = call i32 @terminal_send(i8* %58, i32 0)
br label %60
60: ; preds = %57, %54
%61 = load i8, i8* %8
%62 = load i8, i8* %5
%63 = load i8*, i8** %6
%64 = call i8* @input_line_and_echo(i8 signext %61, i8 zeroext %62, i8* %63)
ret i8* %64
}

LLVM IR (-O2):
define i8* @prompt_line(i8 zeroext %0, i8 zeroext %1, i8* %2) {
%4 = alloca [66 x i8]
%5 = getelementptr inbounds [66 x i8], [66 x i8]* %4, i64 0, i64 0
switch i8 %0, label %8 [
i8 2, label %7
i8 1, label %6
]
6: ; preds = %3
br label %8
7: ; preds = %3
br label %8
8: ; preds = %7, %3, %6
%9 = phi i8 [ 62, %7 ], [ 91, %6 ], [ 0, %3 ]
%10 = phi i8 [ 95, %7 ], [ 95, %6 ], [ 0, %3 ]
%11 = phi i8 [ 60, %7 ], [ 93, %6 ], [ 0, %3 ]
%12 = bitcast [66 x i8]* %4 to i8**
%13 = call i32 @memset(i8** %12, i8 signext 32, i8 zeroext 66)
%14 = zext i8 %1 to i32
%15 = add nuw nsw i32 %14, 1
%16 = trunc i32 %15 to i8
%17 = call i32 @memset(i8** %12, i8 signext %10, i8 zeroext %16)
store i8 %9, i8* %5
%18 = zext i32 %15 to i64
%19 = getelementptr inbounds [66 x i8], [66 x i8]* %4, i64 0, i64 %18
store i8 %11, i8* %19
%20 = add nuw nsw i32 %14, 2
%21 = zext i32 %20 to i64
%22 = getelementptr inbounds [66 x i8], [66 x i8]* %4, i64 0, i64 %21
store i8 0, i8* %22
%23 = call i32 @terminal_send(i8* %5, i32 0)
br label %24
24: ; preds = %8, %24
%25 = phi i8 [ 0, %8 ], [ %27, %24 ]
%26 = call i32 (...) @terminal_send_left()
%27 = add i8 %25, 1
%28 = sext i8 %27 to i32
%29 = icmp slt i32 %14, %28
br i1 %29, label %30, label %24
30: ; preds = %24
%31 = icmp eq i8* %2, null
br i1 %31, label %34, label %32
32: ; preds = %30
%33 = call i32 @terminal_send(i8* %2, i32 0)
br label %34
34: ; preds = %32, %30
%35 = call i8* @input_line_and_echo(i8 signext %10, i8 zeroext %1, i8* %2)
ret i8* %35
}