#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*/ STDIN_FILENO;
int /*<<< orphan*/ STDOUT_FILENO;
int /*<<< orphan*/ errno;
int linenoiseEdit(int /*<<< orphan*/, int /*<<< orphan*/, char *, size_t,
                  char const *);
int /*<<< orphan*/ printf(char *);
int linenoiseRaw(char *buf, size_t buflen, const char *prompt) {
  int count;
  if (buflen == 0) {
    errno = EINVAL;
    return -1;
  }
  count = linenoiseEdit(STDIN_FILENO, STDOUT_FILENO, buf, buflen, prompt);
  printf("\n");
  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    115d <linenoiseRaw+0x3d>
mov    0x2e8a(%rip),%rax
mov    (%rax),%ecx
mov    0x2e89(%rip),%rax
mov    %ecx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    1195 <linenoiseRaw+0x75>
mov    0x2e64(%rip),%rax
mov    (%rax),%edi
mov    0x2e83(%rip),%rax
mov    (%rax),%esi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
mov    -0x20(%rbp),%r8
call   1040 <linenoiseEdit@plt>
mov    %eax,-0x24(%rbp)
lea    0xe76(%rip),%rdi
call   1030 <printf@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     1156 <linenoiseRaw+0x36>
mov    %rdx,%r8
mov    %rsi,%rcx
mov    %rdi,%rdx
mov    0x2e92(%rip),%rax
mov    (%rax),%edi
mov    0x2eb1(%rip),%rax
mov    (%rax),%esi
call   1040 <linenoiseEdit@plt>
mov    %eax,%ebx
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %ebx,%eax
pop    %rbx
ret
mov    0x2e73(%rip),%rax
mov    (%rax),%eax
mov    0x2e72(%rip),%rcx
mov    %eax,(%rcx)
mov    $0xffffffff,%eax
pop    %rbx
ret

LLVM IR (-O0):
@EINVAL = global i32 0
@errno = global i32 0
@STDIN_FILENO = global i32 0
@STDOUT_FILENO = global i32 0
@.str = [2 x i8] c"\0A\00"
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 i32, i32* @STDIN_FILENO
%15 = load i32, i32* @STDOUT_FILENO
%16 = load i8*, i8** %5
%17 = load i64, i64* %6
%18 = load i8*, i8** %7
%19 = call i32 @linenoiseEdit(i32 %14, i32 %15, i8* %16, i64 %17, i8* %18)
store i32 %19, i32* %8
%20 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%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
@STDIN_FILENO = global i32 0
@STDOUT_FILENO = 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 = load i32, i32* @STDIN_FILENO
%9 = load i32, i32* @STDOUT_FILENO
%10 = tail call i32 @linenoiseEdit(i32 %8, i32 %9, i8* %0, i64 %1, i8* %2)
%11 = tail call i32 @putchar(i32 10)
br label %12
12: ; preds = %7, %5
%13 = phi i32 [ -1, %5 ], [ %10, %7 ]
ret i32 %13
}