#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 STDIN_FILENO;
int /*<<< orphan*/ disableRawMode(int);
int enableRawMode(int);
int /*<<< orphan*/ errno;
int linenoisePrompt(int, char *, size_t, char const *);
int /*<<< orphan*/ printf(char *);
int linenoiseRaw(char *buf, size_t buflen, const char *prompt) {
  int fd = STDIN_FILENO;
  int count;
  if (buflen == 0) {
    errno = EINVAL;
    return -1;
  }
  if (enableRawMode(fd) == -1)
    return -1;
  count = linenoisePrompt(fd, buf, buflen, prompt);
  disableRawMode(fd);
  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)
mov    0x2e75(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1189 <linenoiseRaw+0x49>
mov    0x2e66(%rip),%rax
mov    (%rax),%ecx
mov    0x2e65(%rip),%rax
mov    %ecx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    11d7 <linenoiseRaw+0x97>
mov    -0x24(%rbp),%edi
call   1030 <enableRawMode@plt>
cmp    $0xffffffff,%eax
jne    11a6 <linenoiseRaw+0x66>
movl   $0xffffffff,-0x4(%rbp)
jmp    11d7 <linenoiseRaw+0x97>
mov    -0x24(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
call   1050 <linenoisePrompt@plt>
mov    %eax,-0x28(%rbp)
mov    -0x24(%rbp),%edi
call   1040 <disableRawMode@plt>
lea    0xe34(%rip),%rdi
call   1060 <printf@plt>
mov    -0x28(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<linenoiseRaw>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
test   %rsi,%rsi
je     1191 <linenoiseRaw+0x51>
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %rdi,%r15
mov    0x2e74(%rip),%rax
mov    (%rax),%ebp
mov    %ebp,%edi
call   1030 <enableRawMode@plt>
cmp    $0xffffffff,%eax
je     11a3 <linenoiseRaw+0x63>
mov    %ebp,%edi
mov    %r15,%rsi
mov    %rbx,%rdx
mov    %r14,%rcx
call   1060 <linenoisePrompt@plt>
mov    %eax,%ebx
mov    %ebp,%edi
call   1050 <disableRawMode@plt>
mov    $0xa,%edi
call   1040 <putchar@plt>
mov    %ebx,%eax
jmp    11a8 <linenoiseRaw+0x68>
mov    0x2e40(%rip),%rax
mov    (%rax),%eax
mov    0x2e3f(%rip),%rcx
mov    %eax,(%rcx)
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@STDIN_FILENO = global i32 0
@EINVAL = global i32 0
@errno = 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
%9 = alloca i32
store i8* %0, i8** %5
store i64 %1, i64* %6
store i8* %2, i8** %7
%10 = load i32, i32* @STDIN_FILENO
store i32 %10, i32* %8
%11 = load i64, i64* %6
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %3
%14 = load i32, i32* @EINVAL
store i32 %14, i32* @errno
store i32 -1, i32* %4
br label %30
15: ; preds = %3
%16 = load i32, i32* %8
%17 = call i32 @enableRawMode(i32 %16)
%18 = icmp eq i32 %17, -1
br i1 %18, label %19, label %20
19: ; preds = %15
store i32 -1, i32* %4
br label %30
20: ; preds = %15
%21 = load i32, i32* %8
%22 = load i8*, i8** %5
%23 = load i64, i64* %6
%24 = load i8*, i8** %7
%25 = call i32 @linenoisePrompt(i32 %21, i8* %22, i64 %23, i8* %24)
store i32 %25, i32* %9
%26 = load i32, i32* %8
%27 = call i32 @disableRawMode(i32 %26)
%28 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%29 = load i32, i32* %9
store i32 %29, i32* %4
br label %30
30: ; preds = %20, %19, %13
%31 = load i32, i32* %4
ret i32 %31
}

LLVM IR (-O2):
@STDIN_FILENO = global i32 0
@EINVAL = global i32 0
@errno = global i32 0
define i32 @linenoiseRaw(i8* %0, i64 %1, i8* %2) {
%4 = load i32, i32* @STDIN_FILENO
%5 = icmp eq i64 %1, 0
br i1 %5, label %6, label %8
6: ; preds = %3
%7 = load i32, i32* @EINVAL
store i32 %7, i32* @errno
br label %15
8: ; preds = %3
%9 = tail call i32 @enableRawMode(i32 %4)
%10 = icmp eq i32 %9, -1
br i1 %10, label %15, label %11
11: ; preds = %8
%12 = tail call i32 @linenoisePrompt(i32 %4, i8* %0, i64 %1, i8* %2)
%13 = tail call i32 @disableRawMode(i32 %4)
%14 = tail call i32 @putchar(i32 10)
br label %15
15: ; preds = %8, %11, %6
%16 = phi i32 [ -1, %6 ], [ %12, %11 ], [ -1, %8 ]
ret i32 %16
}