#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*/ fgets(char *, size_t const, int /*<<< orphan*/);
int /*<<< orphan*/ output_prompt();
int /*<<< orphan*/ stdin;
size_t strlen(char *);
bool get_input_line(char *buffer, const size_t size) {
  do {
    output_prompt();
    if (!fgets(buffer, size, stdin)) {
      return false;
    }
    const size_t len = strlen(buffer);
    if (len > 0 && buffer[len - 1] == '\n') {
      buffer[len - 1] = '\0';
    }
  } while (buffer[0] == '\0');
  return true;
}


x86 assembly (clang, -O0):
<get_input_line>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    $0x0,%al
call   1040 <output_prompt@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    0x2e92(%rip),%rax
mov    (%rax),%edx
call   1050 <fgets@plt>
cmp    $0x0,%eax
jne    1172 <get_input_line+0x42>
movl   $0x0,-0x4(%rbp)
jmp    11cf <get_input_line+0x9f>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jbe    11b3 <get_input_line+0x83>
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
sub    $0x1,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
jne    11b3 <get_input_line+0x83>
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
sub    $0x1,%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    11b8 <get_input_line+0x88>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1140 <get_input_line+0x10>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_input_line>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
mov    0x2ea4(%rip),%r15
xor    %ebp,%ebp
jmp    1155 <get_input_line+0x25>
nopl   0x0(%rax,%rax,1)
cmpb   $0x0,(%rbx)
jne    1189 <get_input_line+0x59>
xor    %eax,%eax
call   1040 <output_prompt@plt>
mov    (%r15),%edx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1050 <fgets@plt>
test   %eax,%eax
je     118e <get_input_line+0x5e>
mov    %rbx,%rdi
call   1030 <strlen@plt>
test   %rax,%rax
je     1150 <get_input_line+0x20>
cmpb   $0xa,-0x1(%rax,%rbx,1)
jne    1150 <get_input_line+0x20>
movb   $0x0,-0x1(%rbx,%rax,1)
jmp    1150 <get_input_line+0x20>
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stdin = global i32 0
define i32 @get_input_line(i8* %0, i64 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i64
store i8* %0, i8** %4
store i64 %1, i64* %5
br label %7
7: ; preds = %34, %2
%8 = call i32 (...) @output_prompt()
%9 = load i8*, i8** %4
%10 = load i64, i64* %5
%11 = load i32, i32* @stdin
%12 = call i32 @fgets(i8* %9, i64 %10, i32 %11)
%13 = icmp ne i32 %12, 0
br i1 %13, label %15, label %14
14: ; preds = %7
store i32 0, i32* %3
br label %41
15: ; preds = %7
%16 = load i8*, i8** %4
%17 = call i64 @strlen(i8* %16)
store i64 %17, i64* %6
%18 = load i64, i64* %6
%19 = icmp ugt i64 %18, 0
br i1 %19, label %20, label %33
20: ; preds = %15
%21 = load i8*, i8** %4
%22 = load i64, i64* %6
%23 = sub i64 %22, 1
%24 = getelementptr inbounds i8, i8* %21, i64 %23
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = icmp eq i32 %26, 10
br i1 %27, label %28, label %33
28: ; preds = %20
%29 = load i8*, i8** %4
%30 = load i64, i64* %6
%31 = sub i64 %30, 1
%32 = getelementptr inbounds i8, i8* %29, i64 %31
store i8 0, i8* %32
br label %33
33: ; preds = %28, %20, %15
br label %34
34: ; preds = %33
%35 = load i8*, i8** %4
%36 = getelementptr inbounds i8, i8* %35, i64 0
%37 = load i8, i8* %36
%38 = sext i8 %37 to i32
%39 = icmp eq i32 %38, 0
br i1 %39, label %7, label %40
40: ; preds = %34
store i32 1, i32* %3
br label %41
41: ; preds = %40, %14
%42 = load i32, i32* %3
ret i32 %42
}

LLVM IR (-O2):
@stdin = global i32 0
define i32 @get_input_line(i8* %0, i64 %1) {
br label %3
3: ; preds = %17, %2
%4 = tail call i32 (...) @output_prompt()
%5 = load i32, i32* @stdin
%6 = tail call i32 @fgets(i8* %0, i64 %1, i32 %5)
%7 = icmp eq i32 %6, 0
br i1 %7, label %20, label %8
8: ; preds = %3
%9 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%10 = icmp eq i64 %9, 0
br i1 %10, label %17, label %11
11: ; preds = %8
%12 = add i64 %9, -1
%13 = getelementptr inbounds i8, i8* %0, i64 %12
%14 = load i8, i8* %13
%15 = icmp eq i8 %14, 10
br i1 %15, label %16, label %17
16: ; preds = %11
store i8 0, i8* %13
br label %17
17: ; preds = %16, %11, %8
%18 = load i8, i8* %0
%19 = icmp eq i8 %18, 0
br i1 %19, label %3, label %20
20: ; preds = %17, %3
%21 = phi i32 [ 0, %3 ], [ 1, %17 ]
ret i32 %21
}