#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*/ disableRawMode(int /*<<< orphan*/);
int enableRawMode(int /*<<< orphan*/);
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;
  }
  if (enableRawMode(STDIN_FILENO) == -1)
    return -1;
  count = linenoiseEdit(STDIN_FILENO, STDOUT_FILENO, buf, buflen, prompt);
  disableRawMode(STDIN_FILENO);
  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    117d <linenoiseRaw+0x3d>
mov    0x2e6a(%rip),%rax
mov    (%rax),%ecx
mov    0x2e69(%rip),%rax
mov    %ecx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    11e6 <linenoiseRaw+0xa6>
mov    0x2e44(%rip),%rax
mov    (%rax),%edi
call   1030 <enableRawMode@plt>
cmp    $0xffffffff,%eax
jne    11a0 <linenoiseRaw+0x60>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e6 <linenoiseRaw+0xa6>
mov    0x2e21(%rip),%rax
mov    (%rax),%edi
mov    0x2e40(%rip),%rax
mov    (%rax),%esi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
mov    -0x20(%rbp),%r8
call   1060 <linenoiseEdit@plt>
mov    %eax,-0x24(%rbp)
mov    0x2dfb(%rip),%rax
mov    (%rax),%edi
call   1040 <disableRawMode@plt>
lea    0xe25(%rip),%rdi
call   1050 <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   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
test   %rsi,%rsi
je     119f <linenoiseRaw+0x5f>
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %rdi,%r15
mov    0x2e6b(%rip),%r12
mov    (%r12),%edi
call   1030 <enableRawMode@plt>
cmp    $0xffffffff,%eax
je     11b1 <linenoiseRaw+0x71>
mov    (%r12),%edi
mov    0x2e7a(%rip),%rax
mov    (%rax),%esi
mov    %r15,%rdx
mov    %rbx,%rcx
mov    %r14,%r8
call   1060 <linenoiseEdit@plt>
mov    %eax,%ebx
mov    (%r12),%edi
call   1050 <disableRawMode@plt>
mov    $0xa,%edi
call   1040 <putchar@plt>
mov    %ebx,%eax
jmp    11b6 <linenoiseRaw+0x76>
mov    0x2e2a(%rip),%rax
mov    (%rax),%eax
mov    0x2e29(%rip),%rcx
mov    %eax,(%rcx)
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
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 %29
13: ; preds = %3
%14 = load i32, i32* @STDIN_FILENO
%15 = call i32 @enableRawMode(i32 %14)
%16 = icmp eq i32 %15, -1
br i1 %16, label %17, label %18
17: ; preds = %13
store i32 -1, i32* %4
br label %29
18: ; preds = %13
%19 = load i32, i32* @STDIN_FILENO
%20 = load i32, i32* @STDOUT_FILENO
%21 = load i8*, i8** %5
%22 = load i64, i64* %6
%23 = load i8*, i8** %7
%24 = call i32 @linenoiseEdit(i32 %19, i32 %20, i8* %21, i64 %22, i8* %23)
store i32 %24, i32* %8
%25 = load i32, i32* @STDIN_FILENO
%26 = call i32 @disableRawMode(i32 %25)
%27 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%28 = load i32, i32* %8
store i32 %28, i32* %4
br label %29
29: ; preds = %18, %17, %11
%30 = load i32, i32* %4
ret i32 %30
}

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 %18
7: ; preds = %3
%8 = load i32, i32* @STDIN_FILENO
%9 = tail call i32 @enableRawMode(i32 %8)
%10 = icmp eq i32 %9, -1
br i1 %10, label %18, label %11
11: ; preds = %7
%12 = load i32, i32* @STDIN_FILENO
%13 = load i32, i32* @STDOUT_FILENO
%14 = tail call i32 @linenoiseEdit(i32 %12, i32 %13, i8* %0, i64 %1, i8* %2)
%15 = load i32, i32* @STDIN_FILENO
%16 = tail call i32 @disableRawMode(i32 %15)
%17 = tail call i32 @putchar(i32 10)
br label %18
18: ; preds = %7, %11, %5
%19 = phi i32 [ -1, %5 ], [ %14, %11 ], [ -1, %7 ]
ret i32 %19
}