#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*/ EINVAL;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ flushWrite();
int /*<<< orphan*/ fputc(char, int /*<<< orphan*/);
int linenoiseEdit(char *, size_t, char const *);
int /*<<< orphan*/ stdout;
int linenoiseRaw(char *buf, size_t buflen, const char *prompt) {
  int count;
  if (buflen == 0) {
    errno = EINVAL;
    return -1;
  }
  count = linenoiseEdit(buf, buflen, prompt);
  fputc('\n', stdout);
  flushWrite();
  return count;
}


x86 assembly (clang, -O0):
<linenoiseRaw>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    116d <linenoiseRaw+0x3d>
mov    0x2e82(%rip),%rax
mov    (%rax),%ecx
mov    0x2e81(%rip),%rax
mov    %ecx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    11a1 <linenoiseRaw+0x71>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1040 <linenoiseEdit@plt>
mov    %eax,-0x24(%rbp)
mov    0x2e48(%rip),%rax
mov    (%rax),%esi
mov    $0xa,%edi
call   1030 <fputc@plt>
mov    $0x0,%al
call   1050 <flushWrite@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<linenoiseRaw>:
push   %rbx
test   %rsi,%rsi
je     115b <linenoiseRaw+0x2b>
call   1040 <linenoiseEdit@plt>
mov    %eax,%ebx
mov    0x2e8c(%rip),%rax
mov    (%rax),%esi
mov    $0xa,%edi
call   1030 <fputc@plt>
xor    %eax,%eax
call   1050 <flushWrite@plt>
mov    %ebx,%eax
pop    %rbx
ret
mov    0x2e76(%rip),%rax
mov    (%rax),%eax
mov    0x2e75(%rip),%rcx
mov    %eax,(%rcx)
mov    $0xffffffff,%eax
pop    %rbx
ret

LLVM IR (-O0):
@EINVAL = global i32 0
@errno = global i32 0
@stdout = global i32 0
define i32 @linenoiseRaw(i8* %0, i64 %1, i8* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i8*
%8 = alloca i32
store i8* %0, i8** %5
store i64 %1, i64* %6
store i8* %2, i8** %7
%9 = load i64, i64* %6
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %3
%12 = load i32, i32* @EINVAL
store i32 %12, i32* @errno
store i32 -1, i32* %4
br label %22
13: ; preds = %3
%14 = load i8*, i8** %5
%15 = load i64, i64* %6
%16 = load i8*, i8** %7
%17 = call i32 @linenoiseEdit(i8* %14, i64 %15, i8* %16)
store i32 %17, i32* %8
%18 = load i32, i32* @stdout
%19 = call i32 @fputc(i8 signext 10, i32 %18)
%20 = call i32 (...) @flushWrite()
%21 = load i32, i32* %8
store i32 %21, i32* %4
br label %22
22: ; preds = %13, %11
%23 = load i32, i32* %4
ret i32 %23
}

LLVM IR (-O2):
@EINVAL = global i32 0
@errno = global i32 0
@stdout = global i32 0
define i32 @linenoiseRaw(i8* %0, i64 %1, i8* %2) {
%4 = icmp eq i64 %1, 0
br i1 %4, label %5, label %7
5: ; preds = %3
%6 = load i32, i32* @EINVAL
store i32 %6, i32* @errno
br label %12
7: ; preds = %3
%8 = tail call i32 @linenoiseEdit(i8* %0, i64 %1, i8* %2)
%9 = load i32, i32* @stdout
%10 = tail call i32 @fputc(i8 signext 10, i32 %9)
%11 = tail call i32 (...) @flushWrite()
br label %12
12: ; preds = %7, %5
%13 = phi i32 [ -1, %5 ], [ %8, %7 ]
ret i32 %13
}