#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 *, int, int /*<<< orphan*/);
int /*<<< orphan*/ stdin;
size_t strlen(char *);
int rib_util_getinput(char *buffer) {
  if (fgets(buffer, 512, stdin) != NULL) {
    size_t actualLength = strlen(buffer);
    if (actualLength > 0 && buffer[actualLength - 1] == '\n')
      buffer[actualLength - 1] = '\0';
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<rib_util_getinput>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2eb1(%rip),%rax
mov    (%rax),%edx
mov    $0x200,%esi
call   1040 <fgets@plt>
cmp    $0x0,%rax
je     119a <rib_util_getinput+0x7a>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jbe    118e <rib_util_getinput+0x6e>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
sub    $0x1,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
jne    118e <rib_util_getinput+0x6e>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
sub    $0x1,%rcx
movb   $0x0,(%rax,%rcx,1)
movl   $0x1,-0x4(%rbp)
jmp    11a1 <rib_util_getinput+0x81>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rib_util_getinput>:
push   %rbx
mov    %rdi,%rbx
mov    0x2ebd(%rip),%rax
mov    (%rax),%edx
mov    $0x200,%esi
call   1040 <fgets@plt>
test   %rax,%rax
je     115f <rib_util_getinput+0x3f>
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %rax,%rcx
mov    $0x1,%eax
test   %rcx,%rcx
je     115d <rib_util_getinput+0x3d>
cmpb   $0xa,-0x1(%rcx,%rbx,1)
jne    115d <rib_util_getinput+0x3d>
movb   $0x0,-0x1(%rbx,%rcx,1)
pop    %rbx
ret
xor    %eax,%eax
pop    %rbx
ret

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

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